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; } }
@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; } }
@Override public ErrorCollection addConditionToWorkflow(@Nonnull String transitionName, @Nonnull ConditionDescriptor condition, @Nonnull JiraWorkflow workflow) { ErrorCollection errorCollection = checkArguments(transitionName, workflow, condition, "admin.workflowtransitions.service.error.null.condition"); if (errorCollection.hasAnyErrors()) { return errorCollection; } Option<JiraWorkflow> getDraft = draftOf(errorCollection, workflow); if (getDraft.isEmpty()) { //Draft creation might fail, if so, return the resulting error. return errorCollection; } JiraWorkflow draftWorkflow = getDraft.get(); Either<Collection<ActionDescriptor>, ErrorCollection> getActions = getActionsByName(transitionName, draftWorkflow); if (getActions.isRight()) { return getActions.right().get(); } for (ActionDescriptor action : getActions.left().get()) { transitionConditionUtil.addCondition(action, "", condition); } workflowService.updateWorkflow(getServiceContext(errorCollection), draftWorkflow); return errorCollection; }
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); }); }
@SuppressWarnings("unchecked") @Override public ErrorCollection setScreen(@Nonnull String transitionName, @Nullable FieldScreen screen, @Nonnull JiraWorkflow workflow) { ErrorCollection errorCollection = checkArguments(transitionName, workflow); if (errorCollection.hasAnyErrors()) { return errorCollection; } Option<JiraWorkflow> getDraft = draftOf(errorCollection, workflow); if (getDraft.isEmpty()) { return errorCollection; } JiraWorkflow draftWorkflow = getDraft.get(); Either<Collection<ActionDescriptor>, ErrorCollection> getActions = getActionsByName(transitionName, draftWorkflow); if (getActions.isRight()) { return getActions.right().get(); } for (ActionDescriptor action : getActions.left().get()) { setActionScreen(action, screen); } workflowService.updateWorkflow(getServiceContext(errorCollection), draftWorkflow); return errorCollection; }
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 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 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); }
@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()); } });
@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()); } }
public static ResultWithJiraLocation<?> extract(Either<? extends ResultWithJiraLocation<?>, ? extends ResultWithJiraLocation<?>> either) { if (either.isLeft()) { return either.left().get(); } else { return either.right().get(); } } }
@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()); }
public PermissionGrantInput getGrantInput() { return actual.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 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); }