@Override public Either<Exception, File> get() { return Either.right(tempFileById); } }, new Function<Exception, Either<Exception, File>>()
@Override public Either<String, HipChatUserId> apply(@Nullable HipChatUserId id) { return Either.right(id); } }
@Override public ServiceOutcome<IssueSecurityLevelScheme> getIssueSecurityLevelSchemeForProject(final ApplicationUser user, final String projectKey) { return getIssueSecurityLevelSchemeForProject(user, Either.right(projectKey)); }
private PermissionGrantAsPureData(PermissionGrant grant, PermissionGrantInput grantData) { if (grant != null) { actual = left(grant); } else { actual = right(grantData); } }
@Override public Either<AttachmentError, ChangeItemBean> tryCreateAttachment(final CreateAttachmentParamsBean params) { return createAttachmentImpl(params).right().map(ATTACHMENT_TO_CHANGE_ITEM_BEAN); }
@Override public Either<AttachmentError, ChangeItemBean> convertTemporaryAttachment(final ConvertTemporaryAttachmentParams params) { return createAttachmentFromTemporaryAttachment(params).right().map(ATTACHMENT_TO_CHANGE_ITEM_BEAN); }
private Either<IOException, Option<Properties>> tryLoadProperties(final Supplier<Option<InputStream>> resourceSupplier) { final Option<InputStream> streamOption = resourceSupplier.get(); final Supplier<Either<IOException, Option<Properties>>> emptyPropertiesSupplier = () -> Either.<IOException, Option<Properties>>right(Option.none()); return streamOption.map(this::tryLoadProperties). getOrElse(emptyPropertiesSupplier); }
private Either<ServiceOutcome<PermissionScheme>, String> validateSchemeName(@Nullable String oldName, String newName) throws GenericEntityException { if (!newName.equals(oldName) && permissionSchemeManager.schemeExists(newName)) { return left(DefaultPermissionSchemeService.<PermissionScheme>fail(i18n.getText("admin.schemes.permissions.scheme.already.exists", newName), Reason.VALIDATION_FAILED)); } else { return right(newName); } }
public boolean canCreateAttachments(final JiraServiceContext jiraServiceContext, @Nullable final Project project) { return validateNonNullProject(jiraServiceContext, project) && attachmentValidator.canCreateTemporaryAttachments( jiraServiceContext.getLoggedInApplicationUser(), Either.<Issue, Project>right(project), jiraServiceContext.getErrorCollection()); }
private Either<ErrorCollection, PermissionSchemeBean> validated(final PermissionSchemeBean bean) { if (isNullOrEmpty(bean.getName())) { return left(ErrorCollections.validationError("name", i18n.getText("rest.missing.field", "name"))); } return right(bean); }
private Response.ResponseBuilder withApplicationRole(String key, Function<ApplicationRole, Response.ResponseBuilder> valid) { final Either<Response.ResponseBuilder, ApplicationRole> appRoleEither = getApplicationRole(key); if (appRoleEither.isLeft()) { return appRoleEither.left().get(); } return valid.apply(appRoleEither.right().get()); }
private Either<Project, ErrorCollection> notifyProjectTypeUpdated(ApplicationUser user, Project project, ProjectTypeKey oldProjectType, ProjectTypeKey newProjectType) { boolean notificationWasSuccessful = projectTypeUpdatedNotifier.notifyAllHandlers(user, project, oldProjectType, newProjectType); if (!notificationWasSuccessful) { // rollback the project type update, since something went wrong on one of the project type update handlers projectManager.updateProjectType(user, project, oldProjectType); return Either.right(new SimpleErrorCollection("admin.errors.project.type.update.error", Reason.SERVER_ERROR)); } return Either.left(project); }
private static <F> Either<ServiceResult, F> validate(ServiceOutcome<F> outcome) { if (outcome.isValid()) { return right(outcome.get()); } else { return Either.<ServiceResult, F>left(new ServiceResultImpl(outcome.getErrorCollection())); } }
@Override public <T> Either<Response, T> validateOutcome(ServiceOutcome<T> outcome) { if (outcome.isValid()) { return Either.right(outcome.get()); } else { return Either.left(errorResponse(outcome.getErrorCollection())); } }
@Override public ErrorCollection apply(final ApplicationUser user, final ChangeHistory changeGroup) { Either<ErrorCollection, Issue> issue = getIssueFromChangeHistory(changeGroup); if (issue.isLeft()) { return issue.left().get(); } return issuePermissionFunction.apply(user, issue.right().get()); } }
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())); }
@Override public Response apply(@Nullable final Project project) { Either<Project, com.atlassian.jira.util.ErrorCollection> updateResult = projectService.updateProjectType(authContext.getLoggedInUser(), project, new ProjectTypeKey(newProjectTypeKey)); if (updateResult.isLeft()) { return responses.okNoCache(projectBeanFactory.fullProject(updateResult.left().get(), "")); } return responses.errorResponse(updateResult.right().get()); } });
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()); } }
@Override public Either<NegativeResponseStatus, Projects> apply(JiraProxy input) { Either<NegativeResponseStatus, PluginVersion> version = input.isPluginInstalled(); if(version.isLeft()) return Either.left(version.left().get()); if(version.right().get().getResult().equals(PluginInfoResource.PLUGIN_VERSION)){ return input.getProjects(); } else { return Either.left(NegativeResponseStatus.unsupportedVersion(input.getJiraLocation())); } } });
@Override public Promise<Unit> moveTemporaryToAttachment(final TemporaryAttachmentId temporaryAttachmentId, final AttachmentKey destinationKey) { final Either<Exception, File> tempFileEitherException = localTemporaryFileStore.getTemporaryAttachmentFile(temporaryAttachmentId); if (tempFileEitherException.isLeft()) { return Promises.rejected(tempFileEitherException.left().get()); } final File tempFile = tempFileEitherException.right().get(); final File destinationFile = getAttachmentFileHolder(destinationKey); return moveFile(tempFile, destinationFile, true); }