final Long avatarId = createdAvatar.getId(); final com.atlassian.jira.bc.project.ProjectService.UpdateProjectValidationResult result = validateSetAvatar(user, project, avatarId); if (result.isValid()) throw new RemoteException("Error setting Avatar on project: " + result.getErrorCollection());
@Override public Project updateProject(final UpdateProjectValidationResult result) { if (result == null) { throw new IllegalArgumentException("You can not update a project with a null validation result."); } if (!result.isValid()) { throw new IllegalStateException("You can not update a project with an invalid validation result."); } Project newProject = projectManager.updateProject(result.getOriginalProject(), result.getName(), result.getDescription(), keyFor(result.getLeadUsername()), result.getUrl(), result.getAssigneeType(), result.getAvatarId(), result.getKey()); projectEventManager.dispatchProjectUpdated(result.getUser(), newProject, result.getOriginalProject()); return newProject; }
firstIfNotNull(updateData.getAssigneeTypeOrNull(), projectToEdit.getAssigneeType()), firstIfNotNull(updateData.getAvatarId(), projectToEdit.getAvatar().getId())); if (basicValidationResult.isValid()) return responses.errorResponse(basicValidationResult.getErrorCollection());
final ProjectService.UpdateProjectValidationResult updateValidationResult = projectService.validateUpdateProject(authenticationContext.getUser(), project.getName(), project.getKey(), project.getDescription(), project.getLeadUserName(), project.getUrl(), project.getAssigneeType(), avatarId); if (!updateValidationResult.isValid()) return Response.status(Response.Status.BAD_REQUEST).entity(ErrorCollection.of(updateValidationResult.getErrorCollection())).cacheControl(NO_CACHE).build();
if (!getProjectResult.isValid() || getProjectResult.getProject() == null) return new UpdateProjectValidationResult(ErrorCollections.copyOf(getProjectResult.getErrorCollection())); return new UpdateProjectValidationResult(ErrorCollections.create(PROJECT_KEY, i18nBean.getText(ProjectAction.EDIT_PROJECT_KEY.getErrorKey()), Reason.FORBIDDEN)); if (errorCollection.hasAnyErrors()) return new UpdateProjectValidationResult(errorCollection); return new UpdateProjectValidationResult(validationErrors); return new UpdateProjectValidationResult(ErrorCollections.empty(), name, newKey, description, leadName, url, assigneeType, avatarId, project, !StringUtils.equals(oldKey, newKey), user);
public RemoteProject updateProject(User user, RemoteProject rProject) throws RemoteException { //Note: The permissionScheme should never be null, but just in case. final Long permissionSchemeId = rProject.getPermissionScheme() == null ? null : rProject.getPermissionScheme().getId(); final Long notificationSchemeId = rProject.getNotificationScheme() == null ? null : rProject.getNotificationScheme().getId(); final Long issueSecuritySchemeId = rProject.getIssueSecurityScheme() == null ? null : rProject.getIssueSecurityScheme().getId(); com.atlassian.jira.bc.project.ProjectService.UpdateProjectValidationResult result = projectService.validateUpdateProject(user, rProject.getName(), rProject.getKey(), rProject.getDescription(), rProject.getLead(), rProject.getProjectUrl(), null); com.atlassian.jira.bc.project.ProjectService.UpdateProjectSchemesValidationResult schemesResult = projectService.validateUpdateProjectSchemes(user, permissionSchemeId, notificationSchemeId, issueSecuritySchemeId); ErrorCollection errors = new SimpleErrorCollection(); errors.addErrorCollection(result.getErrorCollection()); errors.addErrorCollection(schemesResult.getErrorCollection()); if (errors.hasAnyErrors()) { throw new RemoteValidationException("Cannot update project: ", errors); } final Project updatedProject = projectService.updateProject(result); projectService.updateProjectSchemes(schemesResult, updatedProject); final RemoteProject remoteProject = new RemoteProject(updatedProject, applicationProperties); remoteProject.setNotificationScheme(rProject.getNotificationScheme()); remoteProject.setPermissionScheme(rProject.getPermissionScheme()); remoteProject.setIssueSecurityScheme(rProject.getIssueSecurityScheme()); return remoteProject; }
public void deleteProjectAvatar(final User user, final long avatarId) throws RemoteException { final Avatar avatar = avatarManager.getById(avatarId); // only when the avtatar is system, the owner is null, but we check either since we cannot proceed either way if (avatar == null || avatar.isSystemAvatar() || avatar.getOwner() == null) { throw new RemoteException("No such custom Avatar with id " + avatarId); } Project project = retrieveProjectForAdministration(user, Long.valueOf(avatar.getOwner())); final boolean deletingTheCurrentAvatar = project.getAvatar().getId() == avatarId; if (deletingTheCurrentAvatar) { // deleting the current one need to switch current avatar to default final Long defaultAvatarId = avatarManager.getDefaultAvatarId(Avatar.Type.PROJECT); final com.atlassian.jira.bc.project.ProjectService.UpdateProjectValidationResult updateProjectValidationResult = validateSetAvatar(user, project, defaultAvatarId); if (updateProjectValidationResult.isValid()) { projectService.updateProject(updateProjectValidationResult); avatarManager.delete(avatarId, true); } } else { avatarManager.delete(avatarId, true); } }
protected void doValidation() { // First check that the Project still exists if (getProjectObject() == null) { addErrorMessage(getText("admin.errors.project.no.project.with.id")); // Don't try to do any more validation. return; } final Project projectObject = getProjectObject(); final ProjectService.UpdateProjectValidationResult result = projectService.validateUpdateProject(getLoggedInUser(), projectObject.getName(), projectObject.getKey(), projectObject.getDescription(), getLead(), projectObject.getUrl(), getAssigneeType(), getAvatarId()); if (!result.isValid()) { //map keyed errors to JSP field names mapErrorCollection(result.getErrorCollection()); } if (getLeadUserObj() == null) { setLeadError(getLead()); } }
protected void doValidation() { // First check that the Project still exists if (getProjectObject() == null) { addErrorMessage(getText("admin.errors.project.no.project.with.id")); // Don't try to do any more validation. return; } final ProjectService.UpdateProjectValidationResult result = getUpdateProjectValidationResult(); if (!result.isValid()) { //map keyed errors to JSP field names mapErrorCollection(result.getErrorCollection()); } if(result.isKeyChanged()) { if (!projectReindexService.isReindexPossible(getProjectObject())) { addError("key", getText("admin.errors.project.key.other.reindex")); } } // This validation seems to be redundant now - but leave it in case we add something special to ViewProject.doValidation() super.doValidation(); }
@Override public Response apply(final Project project) { final String id = avatarBean.getId(); Long avatarId; try { avatarId = id == null ? null : Long.valueOf(id); } catch (NumberFormatException e) { avatarId = null; } final ProjectService.UpdateProjectValidationResult updateProjectValidationResult = projectService.validateUpdateProject(authContext.getUser(), project.getName(), project.getKey(), project.getDescription(), project.getLeadUserName(), project.getUrl(), project.getAssigneeType(), avatarId); if (!updateProjectValidationResult.isValid()) { throwWebException(updateProjectValidationResult.getErrorCollection()); } projectService.updateProject(updateProjectValidationResult); return responses.noContent(); } });
public void setProjectAvatar(final User user, final String projectKey, final Long avatarId) throws RemoteException { Project project = retrieveProjectForAdministration(user, projectKey); final com.atlassian.jira.bc.project.ProjectService.UpdateProjectValidationResult result = validateSetAvatar(user, project, avatarId); if (result.isValid()) { projectService.updateProject(result); } else { throw new RemoteException("Error setting Avatar on project: " + result.getErrorCollection()); } }