if (!projectResult.isValid()) return Response.status(Response.Status.BAD_REQUEST).entity(ErrorCollection.of(projectResult.getErrorCollection())).cacheControl(NO_CACHE).build();
projectService.getProjectByKeyForAction(authContext.getUser(), projectKey, VIEW_PROJECT); if (projectResult.getErrorCollection().hasAnyErrors()) final ErrorCollection errors = ErrorCollection.of(projectResult.getErrorCollection()); return Response.status(Response.Status.NOT_FOUND).entity(errors).cacheControl(never()).build();
@Nonnull @Override public CreateProjectValidationResult validateCreateProjectBasedOnExistingProject( final ApplicationUser user, @Nonnull final Long existingProjectId, @Nonnull ProjectCreationData input ) { final JiraServiceContext serviceContext = getServiceContext(user, ErrorCollections.empty()); final I18nHelper i18nBean = getI18nBean(user); if (!globalPermissionManager.hasPermission(GlobalPermissionKey.ADMINISTER, user)) { serviceContext.getErrorCollection().addErrorMessage(i18nBean.getText("admin.projects.service.error.no.admin.permission"), Reason.FORBIDDEN); return new CreateProjectValidationResult(serviceContext.getErrorCollection()); } final GetProjectResult projectById = getProjectByIdForAction(user, existingProjectId, ProjectAction.EDIT_PROJECT_CONFIG); if (!projectById.isValid()) { return new CreateProjectValidationResult(projectById.getErrorCollection()); } final ProjectCreationData creationData = new ProjectCreationData.Builder().fromExistingProject(projectById.get(), input).build(); isValidAllProjectData(serviceContext, creationData); return new CreateProjectValidationResult(serviceContext.getErrorCollection(), user, creationData, Optional.of(existingProjectId)); }
if (!getResult.isValid()) throwWebException(getResult.getErrorCollection());
return responseFactory.okNoCache(SecurityListLevelJsonBean.of(SecurityLevelJsonBean.shortBeans(usersSecurityLevels, baseUrls))); return responseFactory.errorResponse(getProjectResult.getErrorCollection());
if (!getProjectResult.isValid() || getProjectResult.getProject() == null) return new UpdateProjectValidationResult(ErrorCollections.copyOf(getProjectResult.getErrorCollection()));
/** * Retrieve a single project, throwing an exception if the user has no permissions. */ Project retrieveProjectByKey(String projectKey, User user) throws RemoteException { try { final com.atlassian.jira.bc.project.ProjectService.GetProjectResult result = projectService.getProjectByKey(user, projectKey); if (!result.isValid()) { throw new RemoteValidationException("Error retrieving project with key '" + projectKey + "':", result.getErrorCollection()); } else { return result.getProject(); } } catch (DataAccessException e) { throw new RemoteException("Error retrieving project: " + projectKey, e); } }
private Project getProjectByIdOrKey(String projectIdOrKey) { final ProjectService.GetProjectResult result = projectFinder.getGetProjectForActionByIdOrKey(authContext.getUser(), projectIdOrKey, ProjectAction.EDIT_PROJECT_CONFIG); if (result.getErrorCollection().hasAnyErrors()) { final ErrorCollection errors = ErrorCollection.of(result.getErrorCollection()); if (result.getErrorCollection().getReasons().contains(com.atlassian.jira.util.ErrorCollection.Reason.FORBIDDEN)) { throw new NotAuthorisedWebException(errors); } else { throw new NotFoundWebException(errors); } } return result.getProject(); }
@Override public DeleteProjectValidationResult validateDeleteProject(ApplicationUser user, String key) { final I18nHelper i18nBean = getI18nBean(user); if (!globalPermissionManager.hasPermission(GlobalPermissionKey.ADMINISTER, user)) { return new DeleteProjectValidationResult(ErrorCollections.create(i18nBean.getText("admin.projects.service.error.no.admin.permission"), Reason.FORBIDDEN)); } //check if the project exists. If not return with an error. final GetProjectResult oldProjectResult = getProjectByKeyForAction(user, key, ProjectAction.EDIT_PROJECT_CONFIG); if (!oldProjectResult.isValid() || oldProjectResult.getProject() == null) { return new DeleteProjectValidationResult(ErrorCollections.copyOf(oldProjectResult.getErrorCollection())); } return new DeleteProjectValidationResult(ErrorCollections.empty(), oldProjectResult.getProject()); }
private Either<Response, Project> getEitherProjectOrErrors(final String projectIdOrKey, final ProjectAction action) { final ProjectService.GetProjectResult projectResult = projectFinder.getGetProjectForActionByIdOrKey(authContext.getUser(), projectIdOrKey, action); if (!projectResult.isValid()) { return Either.left(responses.errorResponse(projectResult.getErrorCollection())); } return Either.right(projectResult.getProject()); } }
private Project getProject(ApplicationUser user, Long id) { ProjectService.GetProjectResult projectResult = projectService.getProjectById(user, id); if (projectResult.isValid()) { return projectResult.getProject(); } else { return throwFourOhFour(projectResult.getErrorCollection()); } }
private Project getProjectForAdmin(ProjectComponent component) { ProjectService.GetProjectResult projectResult = projectService.getProjectByIdForAction(authContext.getUser(), component.getProjectId(), EDIT_PROJECT_CONFIG); if (!projectResult.isValid()) { throw new NotFoundWebException(ErrorCollection.of(projectResult.getErrorCollection())); } return projectResult.getProject(); }
private Either<Response, Project> getEitherProjectOrErrors(final String projectIdOrKey, final ProjectAction action) { final ProjectService.GetProjectResult projectResult = projectFinder.getGetProjectForActionByIdOrKey(authContext.getLoggedInUser(), projectIdOrKey, action); if (projectResult.isValid()) { return Either.right(projectResult.getProject()); } return Either.left(responseFactory.errorResponse(projectResult.getErrorCollection())); }
private Project getProject(ProjectComponent component) { ProjectService.GetProjectResult projectResult = projectService.getProjectById(authContext.getUser(), component.getProjectId()); if (!projectResult.isValid()) { throw new NotFoundWebException(ErrorCollection.of(projectResult.getErrorCollection())); } return projectResult.getProject(); } private Project getProjectForAdmin(ProjectComponent component)
Project retrieveProjectById(Long id, User user) throws RemoteException { final com.atlassian.jira.bc.project.ProjectService.GetProjectResult result = projectService.getProjectById(user, id); if (!result.isValid()) { throw new RemoteValidationException("Error retrieving project with id '" + id + "':", result.getErrorCollection()); } else { return result.getProject(); } }
@Override public ServiceResult validateUpdateProject(final ApplicationUser user, final String key) { //check if the project exists. If not return with an error. final GetProjectResult oldProjectResult = getProjectByKeyForAction(user, key, ProjectAction.EDIT_PROJECT_CONFIG); if (!oldProjectResult.isValid() || oldProjectResult.getProject() == null) { return new ServiceResultImpl(ErrorCollections.copyOf(oldProjectResult.getErrorCollection())); } return new ServiceResultImpl(ErrorCollections.empty()); }