public <B> Promise<B> fold(Function<Throwable, ? extends B> handleThrowable, Function<? super T, ? extends B> function) { return delegate.fold(handleThrowable, function); }
@Override public <B> Promise<B> fold(Function<Throwable, ? extends B> handleThrowable, Function<? super A, ? extends B> function) { return delegate().fold(handleThrowable, function); } }
@Override public Option<AggregateRoot> getRootByKey(Option<String> strings, final String key) { Promise<Result<List<CollapsedRoom>>> allRooms = hipChat.getAllRooms(); return allRooms.fold(new Function<Throwable, Option<AggregateRoot>>() { @Override public Option<AggregateRoot> apply(@Nullable Throwable input) { return Option.none(); } }, new Function<Result<List<CollapsedRoom>>, Option<AggregateRoot>>() { @Override public Option<AggregateRoot> apply(@Nullable Result<List<CollapsedRoom>> input) { if (input != null && input.isSuccess()) { for (CollapsedRoom room : input.success()) { if (StringUtils.equalsIgnoreCase(key, room.getId())) { return Option.some(createAggregateRoot(room)); } } } return Option.none(); } }).claim(); }
@Override protected void getVelocityParamsForView(Map<String, Object> velocityParams, AbstractDescriptor descriptor) { final ViewDto viewDto; if (!service.isEnabled()) { viewDto = new ViewDto(false, false); velocityParams.put("dto", viewDto); return; } final FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor; final String jql = Strings.nullToEmpty((String) functionDescriptor.getArgs().get(JQL_FILTER_PARAM)); final boolean notifyClients = Boolean.parseBoolean((String) functionDescriptor.getArgs() .get(NOTIFY_CLIENTS_PARAM)); viewDto = getRooms().fold( new Function<Throwable, ViewDto>() { @Override public ViewDto apply(@Nullable Throwable throwable) { return new ViewDto(true, true); } }, new Function<Result<List<CollapsedRoom>>, ViewDto>() { @Override public ViewDto apply(Result<List<CollapsedRoom>> rooms) { return getViewDto(rooms, functionDescriptor, jql, notifyClients); } }).claim(); velocityParams.put("dto", viewDto); }
@Override public Option<AttachmentArchive> apply(@Nullable final File temporaryFile) { Preconditions.checkNotNull(temporaryFile, "temporaryFile"); final AttachmentKey attachmentKey = attachmentKeyMapper.fromAttachment(attachment); final com.atlassian.util.concurrent.Function<InputStream, Unit> saveStream = inputStreamFunctionFactory.saveStream(temporaryFile); return attachmentStore.getAttachment(attachmentKey, saveStream).fold(new Function<Throwable, Option<AttachmentArchive>>() { @Override public Option<AttachmentArchive> apply(@Nullable Throwable throwable) { log.debug(String.format("Failed to retrieve attachment with %s while generating attachment index.", attachmentKey), throwable); return Option.none(); } }, new Function<Unit, Option<AttachmentArchive>>() { @Override public Option<AttachmentArchive> apply(@Nullable Unit unit) { return processAttachmentAndCreateIndex(temporaryFile, attachment, issue, maxEntries); } }).claim(); } };
editDto = getRooms().fold(new Function<Throwable, EditDto>() { @Override public EditDto apply(@Nullable Throwable throwable) {
@Override public Promise<Boolean> exists(final AttachmentKey attachmentKey) { return primaryStore.exists(attachmentKey).fold(new com.google.common.base.Function<Throwable, Promise<Boolean>>() { @Override public Promise<Boolean> apply(final Throwable ignored) { return secondaryStore.exists(attachmentKey); } }, new com.google.common.base.Function<Boolean, Promise<Boolean>>() { @Override public Promise<Boolean> apply(final Boolean exists) { if (exists) { return Promises.promise(true); } else { return secondaryStore.exists(attachmentKey); } } }).flatMap(Functions.<Promise<Boolean>>identity()); }
.fold(new com.google.common.base.Function<Throwable, Promise<V>>()
@Override public Option<Boolean> apply(HipChatAPI<HipChatAPI.TokenType.PersonalToken> personalApi) { return personalApi.rooms().getRoom(Long.toString(room.getRoomId())).fold( new Function<Throwable, Option<Boolean>>() { @Override
return ResponsePromises.toResponsePromise(asyncClient.execute(op, new BasicHttpContext()).fold( throwable -> { final long requestDuration = System.currentTimeMillis() - start;
return ResponsePromises.toResponsePromise(getPromiseHttpAsyncClient(request).execute(op, new BasicHttpContext()).fold( new Function<Throwable, Response>()
).fold(new com.google.common.base.Function<Throwable, Promise<A>>()
@Override protected void getVelocityParamsForInput(Map<String, Object> velocityParams) { EditDto editDto; if (service.isEnabled()) { final String hipChatUsername = getHipChatUsername(); editDto = getRooms().fold( new Function<Throwable, EditDto>() { @Override public EditDto apply(Throwable error) { return new EditDto(pluginConfigurationManager.getConfiguration(), true); } }, new Function<Result<List<CollapsedRoom>>, EditDto>() { @Override public EditDto apply(Result<List<CollapsedRoom>> rooms) { return new EditDto(toRoomDtos(rooms.success()), pluginConfigurationManager.getConfiguration(), hipChatUsername); } } ).claim(); } else { editDto = new EditDto(pluginConfigurationManager.getConfiguration(), false); } velocityParams.put("dto", editDto); velocityParams.put("baseUrl", velocityRequestContextFactory.getJiraVelocityRequestContext().getBaseUrl()); pageBuilderService.assembler().resources().requireWebResource(BASE_USER_LINK_RESOURCE); }