@Override public Option<HipChatLink> getDefaultLink() { return first(getLinks()); }
@Override public Option<Application> apply(final Iterable<Application> applications) { return com.atlassian.fugue.Iterables.findFirst(applications, new Predicate<Application>() { @Override public boolean apply(final Application input) { boolean isPlatform = input instanceof PlatformApplication; boolean hasPostInstallStep = input.getPostInstallURI().isDefined(); if (log.isDebugEnabled()) { log.debug(String.format( "Application %s(%s), isPlatform %b, postInstallStep: %s", input.getName(), input.getKey(), isPlatform, input.getPostInstallURI())); } return !isPlatform && hasPostInstallStep; } }); } });
@Override public Promise<Map<String, Result<ExpandedRoom>>> apply(List<RoomResult> input) { for (RoomResult result : input) { results.put(result.roomId, result.expandedRoom); } final Iterable<String> remaining = Iterables.drop(BATCH_SIZE, roomIds); //If there are still more results if (!isEmpty(remaining)) { return expandRoomsForIds(hipChatAPI, remaining, results); } else { return Promises.<Map<String, Result<ExpandedRoom>>>promise(results.build()); } } };
@Override public Iterable<HipChatMessage> apply(final String renderedMessage) { return Iterables.flatMap(notificationInfos, new Function<NotificationInfo, Iterable<HipChatMessage>>() { @Override public Iterable<HipChatMessage> apply(@Nullable NotificationInfo notificationInfo) { try { return Collections.singleton( new HipChatMessage.Builder().setRoomName(notificationInfo.getRoomNameOrId()) .setMessage(renderedMessage) .setBgColor(HipChatNotificationOptions.GRAY.getBackgroundColor()) .setNotifyingClients(notificationInfo.isNotifyingClients()) .build()); } catch (Exception e) { throw new RuntimeException(e); } } }); } }).getOrElse(Collections.<HipChatMessage>emptyList());
final Iterable<RestAwareField> restAwareNavigableFields = filter(navigableFields, RestAwareField.class); return Iterables.collect(restAwareNavigableFields, new Function<RestAwareField, Option<FieldData>>()
private Promise<Map<String, Result<ExpandedRoom>>> expandRoomsForIds(final HipChatAPI hipChatAPI, final Iterable<String> roomIds, final ImmutableMap.Builder<String, Result<ExpandedRoom>> results) { final ImmutableList.Builder<Promise<RoomResult>> builder = ImmutableList .builder(); final boolean usingPersonalToken = hipChatAPI.getTokenType() instanceof HipChatAPI.TokenType.PersonalToken; //Only schedule at most BATCH_SIZE requests for (final String roomId : Iterables.take(BATCH_SIZE, roomIds)) { Promise<Result<ExpandedRoom>> roomPromise = hipChatAPI.rooms() .getRoom(roomId); if (!usingPersonalToken) { roomPromise = roomPromise.map(FILTER_PRIVATE_ROOM); } builder.add(roomPromise.map(toRoomResult(roomId))); } return Promises.when(builder.build()).flatMap(expandRoomBatch(hipChatAPI, roomIds, results)); }
private static List<String> convertToCommitMessages(RestDevResponse<RestChangesetRepository> response) { List<RestChangesetRepository> results = response.getRepositories(); Iterable<String> transformedResults = Iterables.flatMap(results, new Function<RestChangesetRepository, Iterable<String>>() { @Override public Iterable<String> apply(@Nullable final RestChangesetRepository input) { return Collections2.transform(input.getCommits(), new Function<RestChangeset, String>() { @Override public String apply(@Nullable final RestChangeset input) { return input.getMessage(); } }); } }); return Lists.newArrayList(transformedResults); }
private ImmutableMap<String, String> getDashboardItemProperties(final Long id) { List<String> propertyKeys = jsonEntityPropertyManager.findKeys(DASHBOARD_ITEM_PROPERTY.getDbEntityName(), id); return ImmutableMaps.toMap(Iterables.collect(propertyKeys, new Function<String, Option<Map.Entry<String, String>>>() { @Override public Option<Map.Entry<String, String>> apply(final String propertyKey) { return Option.option(jsonEntityPropertyManager.get(DASHBOARD_ITEM_PROPERTY.getDbEntityName(), id, propertyKey)).map(new Function<EntityProperty, Map.Entry<String, String>>() { @Override public Map.Entry<String, String> apply(final EntityProperty entityProperty) { final String value = fromJsonString(entityProperty.getValue()); return Maps.immutableEntry(propertyKey, Strings.nullToEmpty(value)); } }); } })); }
jiraAuthenticationContext.getUser().getKey())); if (!hipChatUser.isEmpty()) { for (final ApplicationUser applicationUser : Iterables.take(MAX_CONTRIBUTORS, contributors)) { Contributor c = createContributor(applicationUser); (c.isHipChatUser() ? hipchatUsers : appUsers).add(c);
/** * Implementation of Option 1 from https://extranet.atlassian.com/pages/viewpage.action?pageId=2188216661 * Secured by ensuring request is an Application Link request (check User-Agent header) */ private void ensureRequestIsFromApplink(HttpHeaders headers) { List<String> userAgents = MoreObjects.firstNonNull(headers.getRequestHeader(HttpHeaders.USER_AGENT), Collections.<String>emptyList()); String userAgent = Iterables.first(userAgents).getOrElse(""); if (!userAgent.toLowerCase().contains("httpclient")) { // applink request factory uses HttpClient. throw new NonApplinkRequestException(); } }
@Override public Option<PluginApplicationMetaData> getApplication(final ApplicationKey key) { return Iterables.findFirst(getApplications(), new Predicate<PluginApplicationMetaData>() { @Override public boolean apply(@Nullable final PluginApplicationMetaData input) { return input != null && input.getKey().equals(key); } }); }
@Override protected Iterable<HipChatMessage> doRender(ConfigurationEvent configurationEvent, Iterable<NotificationInfo> notificationInfos) { final String renderedMessage = renderNotification(configurationEvent); return Iterables.flatMap(notificationInfos, new Function<NotificationInfo, Iterable<HipChatMessage>>() { @Override public Iterable<HipChatMessage> apply(@Nullable NotificationInfo notificationInfo) { return Collections.singleton( new HipChatMessage.Builder().setRoomName(notificationInfo.getRoomNameOrId()) .setMessage(renderedMessage) .setBgColor(HipChatNotificationOptions.GREEN.getBackgroundColor()) .setNotifyingClients(notificationInfo.isNotifyingClients()) .build()); } }); }
public List<SearchResultRow> getSearchResults() { return Lists.transform(newArrayList(drop(1, searchResults.findAll(By.tagName("tr")))), input -> { final List<PageElement> cols = input.findAll(By.tagName("td")); Assert.assertEquals("should have 5 columns, got " + cols, 5, cols.size()); return new SearchResultRow(cols.get(3).getText(), cols.get(2)); }); }
return Iterables.collect(includedFieldLayoutItems, new Function<FieldLayoutItem, Option<FieldData>>()
@Override public Option<AccessError> getAccessError(@Nullable final UserKey userKey) { final ApplicationUser user = getApplicationUserFromKey(userKey); final ApplicationKey key = role.getKey(); // Returns the most important error, from enumSet ordered by priority return Iterables.first(authorizationService.getAccessErrors(user, key)); }
public Option<String> getHttpHeaderFromLastRequest(final String name) { Predicate<String> equalsIgnoreCase = headerName -> headerName.equalsIgnoreCase(name); Option<String> maybeHeaderName = Iterables.findFirst(this.headersFromLastRequest.keySet(), equalsIgnoreCase); return maybeHeaderName.flatMap(headerName -> Option.option(headersFromLastRequest.get(headerName))); }
@Override public Iterable<Pair<JiraIssueEvent,NotificationInfo>> apply(@Nullable ProjectConfigurationGroupSelector selector) { try { return Iterables.flatMap(taskBuilder.newFilterTask(event, selector).call(), new Function<NotificationInfo, Iterable<Pair<JiraIssueEvent, NotificationInfo>>>() { @Override public Iterable<Pair<JiraIssueEvent, NotificationInfo>> apply(@Nullable NotificationInfo input) { return Collections.singleton(new Pair<JiraIssueEvent,NotificationInfo>(event, input)); } }); } catch (Exception e) { throw new RuntimeException("Error processing task", e); } } });
/** * Moves all items one position down. * * @param dashboardItems dashboard items which are moved one position down. * @param firstNewRow the first row, starting from which the items are moved down. * @param column in which the items are going to be moved. */ private void moveDashboardItemsOnePositionDown(final Iterable<DashboardItemState> dashboardItems, final int firstNewRow, final int column) { final Long dashboardId = toLong(updateDashboardState.getId()); final Iterable<DashboardItemState> itemsBelowNewItem = drop(firstNewRow, dashboardItems); int row = firstNewRow; for (DashboardItemState dashboardItemState : itemsBelowNewItem) { portletConfigurationStore.updateGadgetPosition(toLong(dashboardItemState.getId()), row, column, dashboardId); row += 1; } } }
public void writeBanners(Writer writer) { final Map<String, Object> context = contextSupplier.get(); final Option<WebPanelModuleDescriptor> displayableWebPanelDescriptors = Iterables.first(webInterfaceManager.getDisplayableWebPanelDescriptors(LOCATION, context)); for (WebPanelModuleDescriptor descriptor : displayableWebPanelDescriptors) { try { descriptor.getModule().writeHtml(writer, context); } catch (IOException | RuntimeException e) { LOG.debug(String.format("Unable to render banner '%s'.", descriptor.getCompleteKey()), e); } } } }
private <E> RegistrationStrategy<E> registrationStrategy() { return Iterables.findFirst(SUPPORTED_EXTRACTOR_TYPES.entrySet(), new Predicate<Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>>>() { @Override public boolean apply(final Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>> entry) { return entry.getKey().isAssignableFrom(getModuleClass()); } }).fold(new Supplier<RegistrationStrategy<E>>() { @Override public RegistrationStrategy<E> get() { throw new PluginException("Class " + getModuleClassName() + " is not implementing extractor for comment, issue or change history"); } }, new Function<Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>>, RegistrationStrategy<E>>() { @Override public RegistrationStrategy<E> apply(final Map.Entry<Class<? extends EntitySearchExtractor>, RegistrationStrategy<?>> entry) { // noinspection unchecked return (RegistrationStrategy<E>) entry.getValue(); } }); }