@Override public boolean userCanCreateAvatarFor(final ApplicationUser user, final String owningObjectId) { final long owningProjectId; try { owningProjectId = Long.parseLong(owningObjectId); } catch (Exception x) { throw new IllegalArgumentException("ownerId", x); } final ProjectService.GetProjectResult getProjectResult = projectService.getProjectByIdForAction(user, owningProjectId, ProjectAction.EDIT_PROJECT_CONFIG); return getProjectResult.isValid(); }
@Override public Project apply(@Nullable final String input) { Long id = new Long(input); ProjectService.GetProjectResult projectResult = projectService.getProjectById(user, id); if (projectResult.isValid()) { return projectResult.getProject(); } return null; } });
if (!projectResult.isValid())
if (!getProjectResult.isValid() || getProjectResult.getProject() == null)
@Override public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { final Matcher matcher = PATTERN.matcher(request.getPathInfo()); if (matcher.matches()) { String projectKey = matcher.group(1); final ApplicationUser user = authenticationContext.getUser(); ProjectService.GetProjectResult result = projectService.getProjectByKeyForAction(user, projectKey, ProjectAction.EDIT_PROJECT_CONFIG); if (result.isValid()) { Project project = result.getProject(); final Map<String, Object> context = velocityParamFactory.getDefaultVelocityParams(MapBuilder.<String, Object>newBuilder() .add("project", project) .add(POST_FUNCTIONS_KEY_NAME, getHipChatPostFunctions( project)) .add(HAS_HIP_CHAT_API_TOKEN, hasHipChatApiToken()) .toMap(), authenticationContext ); // The content-type needs to be set so that Sitemesh will decorate responses generated by Velocity correctly. response.setContentType("text/html; charset=UTF-8"); renderer.render("templates/hip-chat-notifications.vm", context, response.getWriter()); } } }
/** * 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); } }
@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 (result.isValid())
public Option<Object> apply(String key) { ApplicationUser loggedInUser = jiraAuthenticationContext.getLoggedInUser(); ProjectService.GetProjectResult projectByKey = projectService.getProjectByKey(loggedInUser, key); Option<Object> option; if (projectByKey.isValid()) { option = Option.<Object>some(projectByKey.getProject()); } else { option = Option.none(); } return option; } }
@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()); }
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(); } }
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)
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() { ProjectService.GetProjectResult projectResult = getProjectResult(); if (projectResult != null && projectResult.isValid()) { return projectResult.getProject(); } else { return null; } }
@Override public boolean apply(final Project project) { return projectService.getProjectByIdForAction(user, project.getId(), ProjectAction.EDIT_PROJECT_CONFIG).isValid(); } }));
@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()); }
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 Option<Project> getProject(final String currentProjectId, final ApplicationUser user) { if (StringUtils.isNotBlank(currentProjectId)) { GetProjectResult projectResult = projectFinder.getGetProjectForActionByIdOrKey(user, currentProjectId, ProjectAction.VIEW_ISSUES); return projectResult.isValid() ? some(projectResult.getProject()) : none(Project.class); } return none(Project.class); }