private Either<AttachmentError, TemporaryWebAttachment> addToMonitorCleanUpOnFailure( final TemporaryWebAttachment temporaryAttachment, @Nullable final ApplicationUser user) { final Either<AttachmentError, TemporaryWebAttachment> result = tryAddToMonitor(temporaryAttachment, user); if (result.isLeft()) { attachmentManager.deleteTemporaryAttachment(temporaryAttachment.getTemporaryAttachmentId()); } return result; }
private static <T> List<T> transformRequiredElements(Element element, String elementName, final Function<Element, Either<T, IndexDocumentConfigurationParseException>> function) throws IndexDocumentConfigurationParseException { @SuppressWarnings ("unchecked") final List<Element> childElements = element.elements(elementName); if (childElements.size() < 1) { throw new IndexDocumentConfigurationParseException(MessageFormat.format("Expected at least one {0} element", elementName)); } final ImmutableList.Builder<T> listBuilder = ImmutableList.builder(); for (final Element childElement : childElements) { final Either<T, IndexDocumentConfigurationParseException> output = function.apply(childElement); if (output.isLeft()) { listBuilder.add(output.left().get()); } else { throw output.right().get(); } } return listBuilder.build(); }
@Override protected boolean matchesSafely(final Either<L, R> item, final Description mismatchDescription) { if (!item.isLeft()) { mismatchDescription.appendText("RIGHT[") .appendValue(item.right().get()) .appendText("]"); return false; } else if (!matcher.matches(item.left().get())) { mismatchDescription.appendText("LEFT["); describeMismatch(item.left().get(), mismatchDescription); mismatchDescription.appendText("]"); return false; } else { return true; } }
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()); }
public static ResultWithJiraLocation<?> extract(Either<? extends ResultWithJiraLocation<?>, ? extends ResultWithJiraLocation<?>> either) { if (either.isLeft()) { return either.left().get(); } else { return either.right().get(); } } }
try { futureResult = future.get(RENDER_TIMEOUT_SECONDS, TimeUnit.SECONDS); if (futureResult.isLeft()) { return left(futureResult.left().get()); } else {
@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()); } }
@Deprecated public final static String getEntityToken(Either<Issue, Project> entity) { if (entity == null) { return null; } if (entity.isLeft()) { return getIssueToken(entity.left().get()); } else if (entity.isRight()) { return getProjectToken(entity.right().get()); } else { return null; } }
private void cloneAttachmentsIfNeeded(Issue clone) throws CreateException { /* * Note, that Create Attachment permission is not checked, * the same way Link Issue permission is not checked for cloning links. */ if (isCloneAttachments() && attachmentManager.attachmentsEnabled()) { Map<Long, Either<AttachmentError, Attachment>> result = attachmentManager.copyAttachments(originalIssue, getLoggedInUser(), clone.getKey()); for (final Either<AttachmentError, Attachment> either : result.values()) { if (either.isLeft()) { final AttachmentError error = either.left().get(); log.warn(error.getLogMessage(), error.getException().getOrNull()); } } } }
@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()); } });
@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); }
@Override public ValidationResult validate(@Nonnull final I18nHelper i18nHelper, @Nonnull final String licenseString) { LicenseValidationHelper helper = new LicenseValidationHelper(i18nHelper, helpUrls); Either<String, LicenseDetails> errorOrLicenseDetails = helper.decodeLicenseDetails(licenseString, licenseManager) .flatMap(helper.validateLicenseTypeAndVersion(isDataCenterConfigured(), MIN_LICENSE_VERSION)); int totalUserCount = userManager.getTotalUserCount(); if (errorOrLicenseDetails.isLeft()) { OurValidationResult validationResult = new OurValidationResult(totalUserCount, licenseString, null); validationResult.addError(errorOrLicenseDetails.left().get()); return validationResult; } else { return new OurValidationResult(totalUserCount, licenseString, errorOrLicenseDetails.right().get()); } }
@Override public Either<NegativeResponseStatus, SuccessfulResponse> addAttachment(String issueKey, Attachment attachment) { Either<AttachmentError, Attachment> result = attachmentManager.copyAttachment(attachment, jiraAuthenticationContext.getUser(), issueKey); if (result.isLeft()) { return Either.left(NegativeResponseStatus.errorOccured(jiraLocation, result.left().get().getLogMessage())); } return Either.right(SuccessfulResponse.build(jiraLocation)); }
final ServerConfiguration configuration, final Maybe<Either<NotificationAddress, RoleRecipient>> roleRecipient) { if (roleRecipient.isEmpty() || roleRecipient.get().isLeft()) { return MaybeNot.becauseOf( "This factory exposes content, thus recipient has to be provided in order to perform a VIEW permission check.");
private ServiceOutcome<Date> parseDateFromEither(ApplicationUser user, DateField field, Either<String, Date> date) { if (date.isLeft()) { try { return ServiceOutcomeImpl.ok(parseDate(user, field, date.left().get())); } catch (DateParseException e) { return new ServiceOutcomeImpl<Date>(e.parseErrors); } } else { return ok(date.right().get()); } }
@Override public Either<RuleErrors, RuleValidationResult> validateUpdateRule(String remoteUsername, Rule rule) { final Either<ErrorCollection, Rule> getRuleResult = getRule(remoteUsername, rule.getId()); if (getRuleResult.isLeft()) { return Either.left(new RuleErrors(getRuleResult.left().get(), new ErrorCollection(), Lists.<ErrorCollection>newArrayList())); } final RuleErrors ruleErrors = validateCompleteRule(remoteUsername, rule); if (ruleErrors.hasAnyErrors()) { return Either.left(ruleErrors); } return Either.right(new RuleValidationResult(rule)); }
private Response.ResponseBuilder putRequestParser(final String key, final ApplicationRoleBean bean, @Nullable final String versionHash) { if (featureManager.isOnDemand()) { return forError(helper.getText("application.role.rest.error.cloud")); } if (versionHash != null) { if (!isVersionHashUpToDate(versionHash)) { return createVersionError(helper.getText("application.role.rest.version.wrong")); } } return withApplicationRole(key, role -> { final Either<Response.ResponseBuilder, ApplicationRole> verifiedAppRole = verifyApplicationRole(role, bean); if (verifiedAppRole.isLeft()) { return verifiedAppRole.left().get(); } final ApplicationRole newRole = verifiedAppRole.right().get(); return responseFromOutcome(service.setRole(newRole), toBean); }); }
private ValidationResult validate(@Nonnull final Set<ApplicationKey> applicationKeys, @Nonnull final String licenseString, @Nonnull final I18nHelper i18nHelper) { int totalUserCount = userManager.getTotalUserCount(); if (applicationKeys.isEmpty()) { OurValidationResult validationResult = new OurValidationResult(totalUserCount, licenseString); validationResult.addError(i18nHelper.getText("jira.license.validation.invalid.product.key")); return validationResult; } LicenseValidationHelper helper = new LicenseValidationHelper(i18nHelper, helpUrls); Either<String, LicenseDetails> errorOrLicenseDetails = helper.decodeLicenseDetails(licenseString, licenseManager) .flatMap(helper.validateLicenseTypeAndVersion(isDataCenterConfigured(), MIN_LICENSE_VERSION)) .flatMap(helper.validateLicenseExpiration()) .flatMap(helper.validateLicenseUserLimit(applicationKeys)) .flatMap(helper.validateNonStarterNonEvaluationLicenseChange(licenseManager.getLicenses())) .flatMap(helper.validateMaintenanceForApplications(applicationKeys, applicationManager)) .flatMap(helper.validateMixLicenses(licenseManager.getLicenses(), isDataCenterConfigured())); if (errorOrLicenseDetails.isLeft()) { return new OurValidationResult(totalUserCount, licenseString, null, errorOrLicenseDetails.left().get()); } else { return new OurValidationResult(totalUserCount, licenseString, errorOrLicenseDetails.right().get()); } }
/** * Perform a one dimensional search for a filter with a certain id * * @param filterId The id of the filter whose results we want. * @param statType The statistic type to groups search results by. * @return Errors or the result of the jql query. An error will be returned if a filter with this `filterId` cannot * be found. */ private Either<OneDimensionalStatisticsResultBean, ErrorCollection> oneDimensionalSearchForFilter(final Long filterId, final String statType) { final JiraServiceContextImpl jiraServiceContext = new JiraServiceContextImpl(authenticationContext.getLoggedInUser()); final SearchRequest filter = searchRequestService.getFilter(jiraServiceContext, filterId); if (filter == null) { ErrorCollection errors = new SimpleErrorCollection(); errors.addErrorMessage(authenticationContext.getI18nHelper().getText("rest.error.generating.response", FILTER_ID)); errors.addReason(ErrorCollection.Reason.NOT_FOUND); return Either.right(errors); } Either<OneDimensionalStatisticsResultBean, ErrorCollection> searchResult = oneDimensionalSearchWithJql(filterId, searchService.getJqlString(filter.getQuery()), statType); // Construct a new statistics result so that we can change the filter's name from 'JQL Query' to the actual filter name. if (searchResult.isLeft()) { final OneDimensionalStatisticsResultBean oldResult = searchResult.left().get(); final StatisticsSearchResultBean newBean = new StatisticsSearchResultBean(oldResult.getIssueCount(), oldResult.getResults()); final OneDimensionalStatisticsResultBean newResult = new OneDimensionalStatisticsResultBean(filter.getName(), oldResult.getFilterUrl(), oldResult.getStatType(), newBean); return Either.left(newResult); } return searchResult; }