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(); }
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); } } }
@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; } }
@Override public ServiceResult perform() throws GenericEntityException { if (id.equals(permissionSchemeManager.getDefaultSchemeObject().getId())) { return fail(i18n.getText("admin.schemes.permissions.cannot.delete.default.scheme"), Reason.VALIDATION_FAILED); } Either<ServiceOutcome<Object>, PermissionScheme> schemeToDelete = getScheme(user, id); if (schemeToDelete.isRight()) { if (!permissionSchemeManager.getProjects(representationConverter.scheme(schemeToDelete.right().get())).isEmpty()) { return fail(i18n.getText("admin.schemes.permissions.cannot.delete.with.projects", id), Reason.VALIDATION_FAILED); } permissionSchemeManager.deleteScheme(id); return ok(); } else { return schemeToDelete.left().get(); } } });
@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; } }
@SuppressWarnings("unchecked") @Override public RegistrationResult onModule(ConnectModuleProviderModuleDescriptor moduleDescriptor, ConnectModuleProvider<?> provider) { final String descriptorKey = provider.getMeta().getDescriptorKey(); final Collection moduleBeans = builtModuleList.get(descriptorKey); if (moduleBeans == null) return RegistrationResult.emptyFor(provider); if (vertigoState.isVertigoSpiEnabled()) { final Either<GenerationResult, RegistrationResult> potentialDescriptors = BeanToModuleRegistrar.this.getDescriptorsToRegisterForModulesVertigoStyle(provider, moduleBeans, addon, translations); if (potentialDescriptors.isRight()) { return potentialDescriptors.right().get(); } else { if (potentialDescriptors.left().get() != GenerationResult.NOT_IMPLEMENTED && systemPropertyService.isVertigoFallbackDisabled()) { throw new IllegalStateException("The module provider " + provider.getClass() + " implemented serializeToPluginModules but failed to run the whole process. Fallback disabled: failing hard."); } } } return new RegistrationResult(provider, provider.createPluginModuleDescriptors(ImmutableList.copyOf(moduleBeans), addon), ImmutableList.of()); } });
@Override public Either<List<ProjectVersionBean>, ErrorCollection> getVersions(@Nonnull final String jql) { ApplicationUser user = authenticationContext.getUser(); Either<Query, ErrorCollection> queryOrError = queryParser.getQuery(user, jql); if (queryOrError.isRight()) { return Either.right(queryOrError.right().get()); } Query query = queryOrError.left().get(); Option<Query> filterQuery = projectOrFilterQueryParser.getFilterQuery(user, query); if (filterQuery.isDefined()) { query = filterQuery.get(); } Collection<Project> projects = getProjectsForQuery(user, query); List<ProjectVersionBean> projectVersionBeanList = getVersionsForProjects(query, projects); return Either.left(projectVersionBeanList); }
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()); } } } }
@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; } }
@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()); } }
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)); }
@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())); } } });
public PermissionGrant getGrant() { return actual.left().get(); }
public static ResultWithJiraLocation<?> extract(Either<? extends ResultWithJiraLocation<?>, ? extends ResultWithJiraLocation<?>> either) { if (either.isLeft()) { return either.left().get(); } else { return either.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)); }
@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 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()); }
@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()); } }
@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); }