private File delegateToFileStoreOrThrowException(final Function<FileBasedAttachmentStore, File> delegateToFileStore) { return fileSystemAttachmentStore.fold(new Supplier<File>() { @Override public File get() { throw new UnsupportedOperationException("Direct operations on file system are not supported."); } }, delegateToFileStore); }
@Override public Option<String> getIssuePageEditHtml(final Map<String, Object> context) { return resources.get(TEMPLATE_NAME_ISSUE_EDIT).fold(emptySupplier, new RenderCommentPanelFunction(context)); }
@Override public Option<String> getFieldViewHtml(final Map<String, Object> context) { return resources.get(TEMPLATE_NAME_VIEW).fold(emptySupplier, new RenderCommentPanelFunction(context)); }
@Override public Option<String> getIssuePageViewHtml(final Map<String, Object> context) { return resources.get(TEMPLATE_NAME_ISSUE_VIEW).fold(emptySupplier, new RenderCommentPanelFunction(context)); }
@Override public Option<String> getFieldEditHtml(final Map<String, Object> context) { return resources.get(TEMPLATE_NAME_EDIT).fold(emptySupplier, new RenderCommentPanelFunction(context)); }
private Boolean isAdmin(final Option<ApplicationUser> userOption) { return userOption.fold(Suppliers.alwaysFalse(), new Function<ApplicationUser, Boolean>() { @Override public Boolean apply(final ApplicationUser user) { final boolean isAdmin = permissionManager.hasPermission(GlobalPermissionKey.ADMINISTER, user); return isAdmin; } }); } }
@Override public Boolean apply(final ApplicationUser user) { return instantSetupUser.fold(Suppliers.alwaysFalse(), new Function<String, Boolean>() { @Override public Boolean apply(final String input) { return user.getKey().equals(input); } }); } });
public void clickRemotePluginLinkWithoutBinding() { link.get().fold( () -> { throw new IllegalStateException(format("Could not find link '%s'", link())); }, actualLink -> { actualLink.click(); logger.debug("Link '{}' was found and clicked.", actualLink); return null; } ); }
public String getRemotePluginLinkHref() { return link.get().fold( () -> { throw new IllegalStateException(format("Could not find link '%s'", link())); }, actualLink -> actualLink.getAttribute("href") ); }
@Override public Promise<Unit> deleteAttachmentContainerForIssue(@Nonnull final Issue issue) { //noinspection NullableProblems return fileSystemAttachmentStore.fold(Suppliers.ofInstance(Promises.promise(Unit.VALUE)), new Function<FileBasedAttachmentStore, Promise<Unit>>() { @Override public Promise<Unit> apply(final FileBasedAttachmentStore fileBasedAttachmentStore) { return fileBasedAttachmentStore.deleteAttachmentContainerForIssue(issue); } }); }
@Override protected int getCount(final Map<String, Object> context) { return WorkflowTransitionContext.getTransition(context).fold(Suppliers.ofInstance(0), new Function<ActionDescriptor, Integer>() { @Override public Integer apply(final ActionDescriptor input) { return input.getValidators() == null ? 0 : input.getValidators().size(); } }); } }
@Override protected int getCount(final Map<String, Object> context) { return WorkflowTransitionContext.getTransition(context).fold(Suppliers.ofInstance(0), new Function<ActionDescriptor, Integer>() { @Override public Integer apply(final ActionDescriptor input) { final ResultDescriptor result = input.getUnconditionalResult(); return result != null && result.getPostFunctions() != null ? result.getPostFunctions().size() : 0 ; } }); } }
@Override public boolean removePermission(final int permissionId, final String group) { // When roles enabled, passing USE as a permission is unsupported; roles should be used ensureUsePermissionNotUsedIfRolesEnabled(permissionId); return getGlobalPermission(permissionId).fold(() -> { throw new IllegalArgumentException("Permission id passed must be a global permission, " + permissionId + " is not"); }, globalPermissionType -> removePermission(globalPermissionType, group) ); }
public String getPermTypeName() { return globalPermissionManager.getGlobalPermission(globalPermTypeName).fold( returnUnknownString, globalPermissionType -> getText(globalPermissionType.getNameI18nKey()) ); }
public String getDescription(String permType) { return globalPermissionManager.getGlobalPermission(permType).fold( returnUnknownString, globalPermissionType -> getText(globalPermissionType.getDescriptionI18nKey()) ); }
@Override public ServiceOutcome<IssueSecurityLevelScheme> getIssueSecurityLevelScheme(ApplicationUser user, final long schemeId) { return asAdminOrProjectAdminWithAccessToScheme(user, schemeId, () -> { Supplier<ServiceOutcome<IssueSecurityLevelScheme>> notFoundSupplier = notFoundSupplier("rest.error.issuesecurityscheme.securityscheme.not.found", String.valueOf(schemeId)); return Option.option(issueSecuritySchemeManager.getIssueSecurityLevelScheme(schemeId)) .fold(notFoundSupplier, IssueSecuritySchemeServiceImpl.<IssueSecurityLevelScheme>okOutcome()); }); }
@Override public ServiceOutcome<IssueSecurityLevel> getIssueSecurityLevel(ApplicationUser user, final long securityLevelId) { return asAdmin(user, () -> { Supplier<ServiceOutcome<IssueSecurityLevel>> notFoundSupplier = notFoundSupplier("rest.error.issuesecurityscheme.securitylevel.not.found", String.valueOf(securityLevelId)); return Option.option(issueSecurityLevelManager.getSecurityLevel(securityLevelId)) .fold(notFoundSupplier, IssueSecuritySchemeServiceImpl.<IssueSecurityLevel>okOutcome()); }); }
@Override public ServiceOutcome<? extends List<IssueSecurityLevel>> getIssueSecurityLevels(ApplicationUser user, final long schemeId) { return asAdminOrProjectAdminWithAccessToScheme(user, schemeId, () -> { Supplier<ServiceOutcome<List<IssueSecurityLevel>>> notFoundSupplier = notFoundSupplier("rest.error.issuesecurityscheme.securityscheme.not.found", String.valueOf(schemeId)); return Option.option(issueSecuritySchemeManager.getIssueSecurityLevelScheme(schemeId)) .fold(notFoundSupplier, securityLevelScheme -> ServiceOutcomeImpl.ok(issueSecurityLevelManager.getIssueSecurityLevels(schemeId))); }); }
@Override public ServiceOutcome<? extends Collection<IssueSecurityLevelPermission>> getPermissionsByIssueSecurityLevel(ApplicationUser user, final long securityLevelId) { return asAdmin(user, () -> { Supplier<ServiceOutcome<Collection<IssueSecurityLevelPermission>>> notFoundSupplier = notFoundSupplier("rest.error.issuesecurityscheme.securitylevel.not.found", String.valueOf(securityLevelId)); return Option.option(issueSecurityLevelManager.getSecurityLevel(securityLevelId)) .fold(notFoundSupplier, issueSecurityLevel -> { Collection<IssueSecurityLevelPermission> collection = issueSecuritySchemeManager.getPermissionsBySecurityLevel(securityLevelId); return ServiceOutcomeImpl.ok(collection); }); }); }
private ServiceOutcome<IssueSecurityLevelScheme> getIssueSecurityLevelSchemeForProject(final ApplicationUser user, final Either<Long, String> projectIdOrKey) { Supplier<ServiceOutcome<IssueSecurityLevelScheme>> notFoundSupplier = notFoundSupplier("rest.error.issuesecurityscheme.securitylevel.for.project.not.found", projectIdOrKey.fold(l -> l.toString(), String::toString)); return asAdminOrProjectAdminWithAdminAccessToProject(user, projectIdOrKey, project -> { final Long schemeIdForProject = issueSecuritySchemeManager.getSchemeIdFor(project); final IssueSecurityLevelScheme issueSecurityLevelScheme = issueSecuritySchemeManager.getIssueSecurityLevelScheme(schemeIdForProject); return Option.option(issueSecurityLevelScheme) .fold(notFoundSupplier, IssueSecuritySchemeServiceImpl.okOutcome()); }); }