@Override protected boolean matchesSafely(final Either<L, R> item, final Description mismatchDescription) { if (!item.isRight()) { mismatchDescription.appendText("LEFT[") .appendValue(item.left().get()) .appendText("]"); return false; } else if (!matcher.matches(item.right().get())) { mismatchDescription.appendText("RIGHT["); matcher.describeMismatch(item.right().get(), mismatchDescription); mismatchDescription.appendText("]"); return false; } else { return true; } }
/** * @see Option#fold */ private static <A, B> Function<Option<A>, B> fold(final Supplier<B> none, final Function<A, B> some) { return new Function<Option<A>, B>() { @Override public B apply(final Option<A> op) { return op.fold(none, some); } }; }
@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<Throwable, Set<MentionRoom>> apply(final Throwable input) { return Either.left(input); } },
@Override public Either<Exception, File> get() { return Either.right(tempFileById); } }, new Function<Exception, Either<Exception, File>>()
public void validateFilter(final MessageCollection.Builder errorCollectionBuilder, final Optional<String> filter) { if (filter.isPresent() && StringUtils.isNotBlank(filter.get())) { final String jql = filter.get(); final Either<JqlParseException, String> jqlValid = isJqlValid(jql); if (!jqlValid.isRight()) { final Message errorMessage = new ErrorMessage("jql", i18n.getText("webhooks.invalid.jql", jql, jqlValid.left().get())); errorCollectionBuilder.addMessage(errorMessage, MessageCollection.Reason.VALIDATION_FAILED); } } }
private <L> Response doGetIssueMentionsInfo(final Issue issue, final Function<Iterable<IssueMention>, Either<Throwable, L>> responseLoadExtractor) { final Function<Issue, Either<Throwable, Iterable<IssueMention>>> issueToMentions = new Function<Issue, Either<Throwable, Iterable<IssueMention>>>() { @Override public Either<Throwable, Iterable<IssueMention>> apply(@Nullable Issue issue) { return issueMentionService.getIssueMentions(issue.getId()); } }; final Function<L, Response> successResponse = new Function<L, Response>() { @Override public Response apply(@Nullable L load) { return Response.ok(load).build(); } }; return issueToMentions.apply(issue) .right() .flatMap(responseLoadExtractor) .fold(errorResponse(issue.getKey()), successResponse); }
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()); } } } }
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."); final RoleRecipient recipient = roleRecipient.get().right().get(); final ConfluenceUser recipientUser = userAccessor.getUserByKey(recipient.getUserKey());
public boolean isValid() { return result.isRight(); }
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 Either<RestParamError, String> propertyValue(final HttpServletRequest request) { int contentLength = request.getContentLength(); if (contentLength > AddonPropertyServiceImpl.MAXIMUM_PROPERTY_VALUE_LENGTH) { return Either.left(RestParamError.PROPERTY_VALUE_TOO_LONG); } try { return Either.right(readHttpServletRequestBody(request)); } catch (IOException e) { return Either.left(RestParamError.PROPERTY_VALUE_TOO_LONG); } }
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()); } }
@Override public Either<Exception, File> apply(final Exception exception) { return Either.left(exception); } });
@Override public Either<ClientError, T> apply(Response r) { return Either.right(t); } }
public boolean isValid() { return result.isRight(); }
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()); }