public AttachmentsBulkOperationResult(final Pair<List<AttachmentError>, List<T>> errorAndResult) { this(errorAndResult.left(), errorAndResult.right()); }
private Collection<Pair<JiraIssueEvent, NotificationInfo>> filterDuplicateMessages( Collection<ListenableFuture<Iterable<Pair<JiraIssueEvent, NotificationInfo>>>> futures ) throws ExecutionException, InterruptedException, TimeoutException { Map<Pair<JiraIssueEvent, NotificationInfo>, Pair<JiraIssueEvent, NotificationInfo>> notifications = Maps .newHashMap(); for (Pair<JiraIssueEvent, NotificationInfo> ni : Iterables.concat(Futures.allAsList(futures) .get(1, TimeUnit.MINUTES))) { Pair<JiraIssueEvent, NotificationInfo> existing = notifications.get(ni); if (existing != null && ni.right().isNotifyingClients()) { existing.right().setNotifyingClients(true); } if (existing == null) { notifications.put(ni, ni); } } return notifications.values(); }
public Translations download(ConnectAddonBean addonBean) throws TranslationsDownloadException { List<DownloadResult<ResponsePromise>> downloadsInProgress = Stream.of(Language.values()) .map(lang -> pair(lang, lang.getPath(addonBean.getTranslations().getPaths()))) .filter(langAndPath -> langAndPath.right().isPresent()) .map(langAndPath -> scheduleDownload(langAndPath.left(), addonBean.getBaseUrl(), langAndPath.right().get())) .collect(toList()); final Map<Language, I18nKeysMapping> translations = downloadsInProgress.stream() .map(this::download) .collect(Collectors.toMap(DownloadResult::getLanguage, DownloadResult::getResult)); return Translations.from(translations); }
private Map<String, VersionAndFile> getInstalledPluginVersions() { final File[] installedPluginFiles = pluginTargetFolder.listFiles(ApplicationSource::jarsOnly); if (ArrayUtils.isNotEmpty(installedPluginFiles)) { return stream(installedPluginFiles) .map(file -> new Pair<>(file, versionDiscovery.getBundleNameAndVersion(file))) .collect(Collectors.toMap( fileAndVersion -> fileAndVersion.right().getSymbolicName(), fileAndVersion -> new VersionAndFile(fileAndVersion.right().getVersion(), fileAndVersion.left()), PluginBundleInstaller::useNewestVersion )); } return ImmutableMap.of(); }
public boolean allow(HttpServletRequest request) { if (!httpMethod.equals(request.getMethod())) { return false; } final String pathInfo = ServletUtils.extractPathInfo(request); if (path.equals(pathInfo)) { Optional<Pair<String, String>> maybeNamespaceAndName = getMethod(request); if (!maybeNamespaceAndName.isPresent()) { return false; } Pair<String, String> namespaceAndName = maybeNamespaceAndName.get(); for (SoapScope scope : soapActions) { if (scope.match(namespaceAndName.left(), namespaceAndName.right())) { return true; } } } return false; }
public boolean allow(HttpServletRequest request) { if (!httpMethod.equals(request.getMethod())) { return false; } final String pathInfo = ServletUtils.extractPathInfo(request); if (path.equals(pathInfo)) { Optional<Pair<String, String>> maybeNamespaceAndName = getMethod(request); if (!maybeNamespaceAndName.isPresent()) { return false; } Pair<String, String> namespaceAndName = maybeNamespaceAndName.get(); for (SoapScope scope : soapActions) { if (scope.match(namespaceAndName.left(), namespaceAndName.right())) { return true; } } } return false; }
public <T extends Enum<T>> Either<ErrorCollection, OrderByRequest<T>> parse(String orderByValue, Class<T> fields) { Pair<Order, String> orderAndField = extractOrderAndField(orderByValue); Order order = orderAndField.left(); String value = orderAndField.right(); for (T field : fields.getEnumConstants()) { if (field.toString().equalsIgnoreCase(value)) { return Either.right(new OrderByRequest<T>(field, order)); } } return Either.<ErrorCollection, OrderByRequest<T>>left(new SimpleErrorCollection(i18n.getText("util.errors.order.query.parse", value, Arrays.toString(fields.getEnumConstants())), ErrorCollection.Reason.VALIDATION_FAILED)); }
private List<Pair<String, Option<Level>>> configureLevels() { long start = System.currentTimeMillis(); List<Pair<String, Option<Level>>> transformed = newArrayList(); for (Pair<String, Option<Level>> level : levels) { Level newLevel = restClient.getAdminSession().getLoggingComponent().setLogLevel(level.left(), level.right().getOrNull()); transformed.add(pair(level.left(), option(newLevel))); } LOG.info("Changed log levels in {}ms: {}", System.currentTimeMillis() - start, levels); return transformed; }
/** * This method gathers errors from all failed installations and combines them into one message. */ private String describeAllFailures(List<MarketplaceInstallationResult> installations) { return installations.stream() .filter(MarketplaceInstallationResult::failed) .map(failure -> failure .getException().map(ex -> ex.getI18nKey() != null ? pair(ex.getI18nKey(), ex.getI18nArgs()) : null) .orElse(pair(failure.getError().get().getI18nKey(), new String[]{failure.getAddonKey()}))) .map(pair -> i18nResolver.getText(pair.left(), pair.right())) .collect(Collectors.joining(" ")); } }
public String getHipChatUserName() { final UserKey userKey = userManager.getRemoteUserKey(); Option<Pair<HipChatUserId, String>> hipChatUser = hipChatUserFinder.findHipChatUserAndName(userKey); if (hipChatUser.isEmpty()) { return null; } return hipChatUser.get().right(); }
private Properties getPropertiesFromPlugin(final Pair<ResourceDescriptor, Plugin> pluginFeatureDesc) { return loadRequiredProperties( path -> resourceLoader.getResourceAsStream(pluginFeatureDesc.right(), path), pluginFeatureDesc.left().getLocation()); }
public String getHipChatUserName() { final ApplicationUser user = jiraAuthenticationContext.getUser(); if(user == null) { return null; } Option<Pair<HipChatUserId, String>> hipChatUser = hipChatUserFinder.findHipChatUserAndName(new UserKey(user.getKey())); if(hipChatUser.isEmpty()) { return null; } return hipChatUser.get().right(); } }
@Override public Void call() throws Exception { final Collection<EventMatcherType> eventMatcherTypes = issueEventToEventMatcherTypeConverter.match(event); List<ListenableFuture<Iterable<Pair<JiraIssueEvent, NotificationInfo>>>> futures = new ArrayList<>(); // Multiple events can be fired for a given {@link IssueEvent}, multiple notifications // can be sent as a result so they are filtered below for (EventMatcherType eventMatcherType : eventMatcherTypes) { JiraIssueEvent jiraIssueEvent = new DefaultJiraIssueEvent.Builder(issueEventHelperBridge) .setEventMatcher(eventMatcherType) .setIssueEvent(event) .build(); futures.add(taskExecutorService.submitTask(taskBuilder.newDedicatedRoomProcessorTask(jiraIssueEvent))); futures.add(taskExecutorService.submitTask(taskBuilder.newEventProcessorTask(jiraIssueEvent))); } try { for (Pair<JiraIssueEvent, NotificationInfo> ni : filterDuplicateMessages(futures)) { taskExecutorService.submitTask(taskBuilder.newSendNotificationTask(ni.left(), Collections.singleton(ni.right()))); } } catch (Exception e) { LOG.error("Error processing event", e); } return null; } });
/** * Trim potentially sensitive values from REST calls, append method name for SOAP/RPC. * * @param rq * @return a path that is safe to use for analytics */ private static String toAnalyticsSafePath(HttpServletRequest rq) { String path = StringUtils.removeEnd(ServletUtils.extractPathInfo(rq), "/"); if (isXmlRpcUri(path)) { String method = XmlRpcApiScopeHelper.extractMethod(rq); return path + "/" + method; } else if (isJsonRpcUri(path)) { String method = JsonRpcApiScopeHelper.extractMethod(rq); return path + "/" + method; } else if (isSoapUri(path)) { Optional<Pair<String, String>> maybeMethod = RpcEncodedSoapApiScopeHelper.getMethod(rq); if (!maybeMethod.isPresent()) { return path; } // We're ignoring the namespace String method = maybeMethod.get().right(); return path + "/" + method; } else if (isJsonRpcLightUri(rq)) { return path; } else { return trimRestPath(path); } }
@Override public StreamItem apply(final PageElement input) { final Pair<Maybe<String>, String> author = extractAuthor(input); return new StreamItem(extractTitle(input), author.left(), author.right(), extractIcons(input), extractCountItems(input)); }
public String getHipChatUserName() { final ApplicationUser user = getLoggedInApplicationUser(); Option<Pair<HipChatUserId, String>> hipChatUser = hipChatUserFinder.findHipChatUserAndName(new UserKey(user.getKey())); if (hipChatUser.isEmpty()) { return null; } return hipChatUser.get().right(); }
/** * Trim potentially sensitive values from REST calls, append method name for SOAP/RPC. * * @param rq * @return a path that is safe to use for analytics */ private static String toAnalyticsSafePath(HttpServletRequest rq) { String path = StringUtils.removeEnd(ServletUtils.extractPathInfo(rq), "/"); if (isXmlRpcUri(path)) { String method = XmlRpcApiScopeHelper.extractMethod(rq); return path + "/" + method; } else if (isJsonRpcUri(path)) { String method = JsonRpcApiScopeHelper.extractMethod(rq); return path + "/" + method; } else if (isSoapUri(path)) { Optional<Pair<String, String>> maybeMethod = RpcEncodedSoapApiScopeHelper.getMethod(rq); if (!maybeMethod.isPresent()) { return path; } // We're ignoring the namespace String method = maybeMethod.get().right(); return path + "/" + method; } else if (isJsonRpcLightUri(rq)) { return path; } else { return trimRestPath(path); } }
private String getHipChatUsername() { if (authenticationContext.getUser() == null) { return null; } final Option<Pair<HipChatUserId, String>> hipChatUserAndName = hipChatUserFinder.findHipChatUserAndName(new UserKey( authenticationContext.getUser().getKey())); if (hipChatUserAndName.isEmpty()) { return null; } return hipChatUserAndName.get().right(); }
@Override public Void get(final Pair<Attachment, AttachmentKey> input) { final Promise<Attachment> op = attachmentStore.putAttachment(input.left(), source.getAttachmentFile(input.right())) .fail(new Effect<Throwable>() { @Override public void apply(final Throwable throwable) { abortCause.set(Option.some(throwable)); } }); onCompleteAttachment.foreach(new com.atlassian.fugue.Effect<Effect<Attachment>>() { @Override public void apply(final Effect<Attachment> attachmentEffect) { op.done(attachmentEffect); } }); return null; } }, ExceptionPolicy.Policies.THROW);
final String contentType = contentForId.right();