@Override public Option<HipChatLink> getDefaultLink() { return first(getLinks()); }
/** * 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<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)); }
@Override public Option<AOHipChatLink> getLinkByUrlAndGroup(String apiUrl, int groupId) { final Query query = Query.select() .from(AOHipChatLink.class) .where("GROUP_ID = ? and API_URL = ?", groupId, apiUrl ); final AOHipChatLink[] links = ao.find(AOHipChatLink.class, query); return first(ImmutableList.copyOf(links)); }
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 Issue getDummyIssue(final User user) { return DummyIssueFactory.create("HC-123", "A test issue", user, first(issueTypeManager.getIssueTypes()).getOrNull()); }
public boolean isEvaluationLicenseOld(final Period period) { final Iterable<LicenseDetails> allLicenses = ImmutableList.copyOf(licenses); final boolean evaluation = isEvaluation(allLicenses); Option<LicenseDetails> evaluationLicense = evaluation ? com.atlassian.fugue.Iterables.first(allLicenses) : Option.<LicenseDetails>none(); final Boolean isEvaluatingEnough = evaluationLicense.fold(Suppliers.alwaysFalse(), new Function<LicenseDetails, Boolean>() { @Override public Boolean apply(final LicenseDetails input) { return isLicenseThisOld(input, period); } }); return isEvaluatingEnough; }
/** * This are predefined webhooks delivered by plugins which we use to directly send the information to that command * * @param key the key * @param roomMessage the room message * @param request for the https * @param roomMessage the message that triggered this webhook */ @POST @Path ("/webhook/{key}") @Consumes (MediaType.APPLICATION_JSON) @AnonymousAllowed public Response commandCallback(@PathParam ("key") final String key, @Context HttpServletRequest request, final RoomMessage roomMessage) { final Option<InternalHipChatLink> link = Iterables.first(linkManager.getLinks()); if(!link.isDefined() || !StringUtils.equalsIgnoreCase(link.get().getOAuthId(), roomMessage.getOauthClientId())){ return Response.serverError().entity("Invalid OAuth id").build(); } final Option<HipChatWebhook> webhook = pluginExtensions.findWebhook(key); if (!webhook.isDefined()) { final String msg = "Webhook with key " + key + " not found. Maybe the plugin is disabled?"; log.error(msg); return Response.serverError().entity(msg).build(); } webhook.get().execute(roomMessage); return Response.ok().build(); }
@POST @Path ("user") public Response linkUser( @FormParam ("username") String username, @FormParam ("hipchatUserId") String hipChatUserId) { final UserProfile profile = userManager.getUserProfile(username); if (profile == null) { return Response.status(Status.BAD_REQUEST).build(); } final Option<InternalHipChatLink> defaultLink = Iterables.first(hipChatAOLinkManager.getLinks()); if (defaultLink.isEmpty()) { return Response.status(Status.BAD_REQUEST).build(); } final HipChatLinkId linkId = new HipChatLinkId(defaultLink.get().getID()); final Option<AOHipChatLink> linkById = hipChatAOLinkManager.getLinkById(linkId); hipChatAOUserManager.create(profile.getUserKey(), new HipChatUserId(hipChatUserId, linkId), "Nacho Woman", linkById.get(), Option.<GenerateTokenResult>none(), Sets.<HipChatScope>newHashSet()); return Response.ok().status(Status.NO_CONTENT).build(); }
/** * Returns the current link * * @return returns the current Link */ @GET @Path ("link") public Response getCurrentLink() { final Option<InternalHipChatLink> defaultLink = Iterables.first(hipChatAOLinkManager.getLinks()); if (defaultLink.isEmpty()) { return Response.status(Status.BAD_REQUEST).build(); } final HipChatLinkId linkId = new HipChatLinkId(defaultLink.get().getID()); final Option<AOHipChatLink> linkById = hipChatAOLinkManager.getLinkById(linkId); AOHipChatLink link = linkById.get(); Date addonTokenExpiry = link.getAddonTokenExpiry(); InstallationData data = new InstallationData(link.getOAuthId(), link.getSecretKey(), link.getToken(), addonTokenExpiry.getTime()); return Response.ok().entity(data).build(); }
private static <Step> Option<Step> getPendingStep(final Map<Step, SetupStrategy.Status> steps) { final ImmutableSetMultimap<SetupStrategy.Status, Step> stepsForStatuses = ImmutableSetMultimap.copyOf(Multimaps.forMap(steps)).inverse(); return first(stepsForStatuses.get(SetupStrategy.Status.PENDING)); }
@Override public Map<String, Object> getContextMap(Map<String, Object> context) { final ImmutableMap.Builder<String, Object> panelContext = ImmutableMap.builder(); final com.atlassian.hipchat.api.HipChatRoutesProvider.Routes<?> hipChatRoutes = hipchatRoutes.routes( DefaultInstallationService.HIPCHAT_API, DefaultInstallationService.DEFAULT_TOKEN); panelContext.putAll(context); panelContext.put("hipchat", hipChatRoutes); final HipChatRoutesProvider hipChatRoutesProvider = getProvider(context); final URI adminInvitePageURI = hipChatRoutesProvider.getAdminInvitePage(); panelContext.put("adminInvitePageURI", adminInvitePageURI.toString()); panelContext.put("inviteEnabled", hipChatDarkFeatureService.isInviteToHipChatEnabled()); panelContext.put("installedImage", hipChatPluginResourceProvider.getInstalledImage()); panelContext.put("installingImage", hipChatPluginResourceProvider.getInstallingImage()); panelContext.put("uninstallingImage", hipChatPluginResourceProvider.getUninstallingImage()); panelContext.put("routes", getRoutesMap(context)); final Option<InternalHipChatLink> link = Iterables.first(linkManager.getLinks()); if (link.isDefined()) { panelContext.put("link", link.get()); // Provide the HipChat URL to the 'HipChat Integration' admin page so that the linked HipChat // instance can be shown to the administrator. The link provided here should be retrieved // from the OAuth result, but this may not be the case. See issue HC-7650. InternalHipChatLink aoHipChatLink = link.get(); String hipChatApiUrl = aoHipChatLink.getApiUrl(); panelContext.put("hipChatApiUrl", hipChatApiUrl); } return panelContext.build(); }
@POST @Path ("/command") @Consumes (MediaType.APPLICATION_JSON) @AnonymousAllowed public Response commandCallback(final RoomMessage roomMessage) { final Option<InternalHipChatLink> link = Iterables.first(linkManager.getLinks()); if(!link.isDefined() || !StringUtils.equalsIgnoreCase(link.get().getOAuthId(), roomMessage.getOauthClientId())){ return Response.serverError().entity("Invalid OAuth id").build(); } // all required fields in RoomMessage final String message = roomMessage.getItem().getMessage().getText(); final MessageCommand messageCommand = new MessageCommand(message); if (messageCommand.isValid()) { if (HELP_COMMAND.equalsIgnoreCase(messageCommand.getCommand())) { showHelp(roomMessage); } else { runCommandFor(roomMessage, messageCommand); } } return Response.ok().build(); }
/** * Determines if parent issue selector should be rendered. * * <p> * This method is used on choose context page to determine if parent issue selector should be rendered. * It should be rendered when we are not moving subtasks, since subtasks have Project selector locked * and parent issue inherited from their parent so You can't choose new parent there. * </p> * * @param bulkEditBean Currently processed {@link BulkEditBean} * @return true if we want to render parent issue picker, false otherwise */ public boolean isIssueToSubtaskPossible(final BulkEditBean bulkEditBean) { //currently is issue return Iterables.first(bulkEditBean.getIssueTypeObjects()).map(issueType -> !issueType.isSubTask()).getOrElse(false); }
int maxUsers = Iterables.first(jiraLicenseManager.getLicenses()).get().getJiraLicense().getMaximumNumberOfUsers(); if (maxUsers != UNLIMITED_USERS && activeUsers >= maxUsers)
@Override public FieldConfig getRelevantConfig(final IssueContext issueContext, final ConfigurableField field) { final FieldConfigScheme scheme = getRelevantConfigScheme(issueContext.getProjectId(), field.getId()); if (scheme != null) { final Map<String, FieldConfig> configs = scheme.getConfigs(); if (configs != null) { final FieldConfig configForAnyIssueType = configs.get(null); if (configForAnyIssueType != null) { return configForAnyIssueType; } final IssueType issueType = issueContext.getIssueTypeObject(); final String issueTypeId = issueType == null ? null : issueType.getId(); //there may be many configs here but these point to one config if (issueTypeId == null && !configs.isEmpty()) { return Iterables.first(configs.values()).get(); } final FieldConfig config = configs.get(issueTypeId); if (config != null) { return config; } } return null; } return null; }
@Override public void updateFieldLayoutSchemeEntity(final FieldLayoutSchemeEntity fieldLayoutSchemeEntity) { final Option<FieldLayoutSchemeEntity> originalEntity = com.atlassian.fugue.Iterables.first(Iterables.filter(getFieldLayoutSchemeEntities(fieldLayoutSchemeEntity.getFieldLayoutScheme()), new Predicate<FieldLayoutSchemeEntity>() { @Override public boolean apply(@Nullable final FieldLayoutSchemeEntity input) { return StringUtils.equals(input.getIssueTypeId(), fieldLayoutSchemeEntity.getIssueTypeId()); } })); try { fieldLayoutSchemeEntity.getGenericValue().store(); eventPublisher.publish(new FieldLayoutSchemeEntityUpdatedEvent(fieldLayoutSchemeEntity.getFieldLayoutScheme(), originalEntity.getOrElse(fieldLayoutSchemeEntity), fieldLayoutSchemeEntity)); clearCaches(); } catch (GenericEntityException e) { throw new DataAccessException("Error occurred while persisting field layout scheme entity.", e); } }
@Override protected Iterable<HipChatMessage> doRender(JiraCommandEvent commandEvent, Iterable<NotificationInfo> notificationInfos) { final String renderedMessage = renderNotification(commandEvent); // Commands send information only to one room, so there is no need to iterate here // And it is never null , cause the room was given before Option<NotificationInfo> first = Iterables.first(notificationInfos); final NotificationInfo notificationInfo = first.get(); try { return Collections.singleton( new HipChatMessage.Builder().setRoomName(notificationInfo.getRoomNameOrId()) .setMessage(renderedMessage) .setBgColor(HipChatNotificationOptions.GRAY.getBackgroundColor()) .setNotifyingClients(notificationInfo.isNotifyingClients()) .setCard(renderCard(commandEvent)) .build()); } catch (MalformedURLException e) { throw new RuntimeException("Error rendering CommandEvent", e); } }
Iterables.first(status.getErrors()).foreach(switcher::setError); throw new RuntimeException("Upgrade has failed");