private void addEntity(final ApplicationLink applicationLink, final String jiraProjectKey, final String entityKey, final String entityName, final EntityType entityType) { entityLinkService.addEntityLink(jiraProjectKey, JiraProjectEntityType.class, entityLinkBuilderFactory.builder() .type(entityType) .key(entityKey) //name of repo is unique for each FE instance .name(entityName) .applicationLink(applicationLink) .primary(false) //TODO: think about how to determine primary-ness of a repo. .build() ); }
public void deleteApplicationLink(ApplicationId applicationId) { try { final MutableApplicationLink applicationLink = applinkservice.getApplicationLink(applicationId); if (applicationLink != null) { applinkservice.deleteApplicationLink(applicationLink); } } catch (TypeNotInstalledException e) { //ignore } }
@Override public void hastaLaVistaAppLinks() { for (ApplicationLink applicationLink : applicationLinkService.getApplicationLinks()) { applicationLinkService.deleteApplicationLink(applicationLink); } } }
private Response update(final MutableApplicationLink link, final URI rpcUrl, final URI displayUrl) { link.update(ApplicationLinkDetails .builder(link) .rpcUrl(rpcUrl) .displayUrl(displayUrl) .build()); LOG.info("Changed RPC URL from {} to {} and display URL from {} to {} for ApplicationLink {} .", link.getRpcUrl(), rpcUrl, link.getDisplayUrl(), displayUrl, link.getId()); return noContent(); // returning the updated applink might be more restful } }
/** * Find the ApplicationLink by its id. */ private ApplicationLink findApplicationLink(final String id) throws TypeNotInstalledException { ApplicationId applicationId; try { applicationId = new ApplicationId(id); } catch (IllegalArgumentException e) { return null; } return applicationLinkService.getApplicationLink(applicationId); }
public void rollbackApplicationLinkConfiguration(ApplicationLink applicationLink) { // try to clean up local state changes, so the user can retry the connection after manually clearing state // from the target JIRA instance (as per the troubleshooting guide) try { if (applicationLink != null) { applicationLinkService.deleteApplicationLink(applicationLink); } // TODO: How to delete the reverse application link? LOG.info("Rolled back 2-way application link to JIRA."); } catch (Exception rollbackException) { // this is possibly what caused the original failure necessitating the rollback, log & ignore LOG.error("Failed to rollback local UAL/Crowd configuration", rollbackException); } }
@Override public URI getApplinkLinkSelfLink(final ApplicationLink applink) { return applicationLinkService.createSelfLinkFor(applink.getId()); }
private void configureTwoWayAuth(final ConfigureAuthEntity entity, ApplicationLink link) throws AuthenticationConfigurationException { linkService.configureAuthenticationForApplicationLink( link, new AuthenticationScenario() { public boolean isCommonUserBase() { return entity.sharedUserBase; } public boolean isTrusted() { return entity.trusted; } }, entity.username, entity.password); }
public boolean checkAdminCredential(URI remoteUrl, String username, String password) { try { return applicationLinkService.isAdminUserInRemoteApplication(remoteUrl, username, password); } catch (ResponseException e) { return false; } } }
public ApplicationLinkDetails build() { // be nice - rpcUrl & displayUrl are generally the same thing, so accept either if (rpcUrl == null) { rpcUrl = displayUrl; } else if (displayUrl == null) { displayUrl = rpcUrl; } if (rpcUrl == null) { throw new NullPointerException("either displayUrl or rpcUrl must be set before build()"); } cleanUriPaths(); return new ApplicationLinkDetails(checkNotNull(name, "name"), checkNotNull(displayUrl, "displayUrl"), checkNotNull(rpcUrl, "rpcUrl"), isPrimary); }
public static Builder builder() { return new Builder(); }
private void cleanUriPaths() { String rpcUrlString = stripTrailingSlash(rpcUrl.getPath()); String displayString = stripTrailingSlash(displayUrl.getPath()); try { this.rpcUrl = new URI(rpcUrl.getScheme(), rpcUrl.getUserInfo(), rpcUrl.getHost(), rpcUrl.getPort(), rpcUrlString, rpcUrl.getQuery(), rpcUrl.getFragment()); this.displayUrl = new URI(displayUrl.getScheme(), displayUrl.getUserInfo(), displayUrl.getHost(), displayUrl.getPort(), displayString, displayUrl.getQuery(), displayUrl.getFragment()); } catch (URISyntaxException e) { log.info("Supplied rpc URL " + rpcUrlString + " and display URL" + displayString + "were not " + "sanitized for trailing slashes because one or both were invalid"); } }
/** * Find the ApplicationLink by its id. */ private ApplicationLink findApplicationLink(final String id) throws TypeNotInstalledException { ApplicationId applicationId; try { applicationId = new ApplicationId(id); } catch (IllegalArgumentException e) { return null; } return applicationLinkService.getApplicationLink(applicationId); } }
protected Link createSelfLinkFor(final ApplicationId appID) { return Link.self(applicationLinkService.createSelfLinkFor(appID)); }
/** * Creates a new {@link com.atlassian.applinks.spi.link.ApplicationLinkDetails.Builder} * initialized with the state from the supplied * {@link com.atlassian.applinks.spi.link.ApplicationLinkDetails} * instance. */ public static Builder builder(final ApplicationLinkDetails details) { final Builder builder = new Builder(); builder.displayUrl = details.displayUrl; builder.rpcUrl = details.rpcUrl; builder.name = details.name; builder.isPrimary = details.isPrimary; return builder; }
@Nonnull public ApplicationLinkDetails toDetails() throws IllegalRestRepresentationStateException { return ApplicationLinkDetails.builder() .name(validateString(NAME, getName())) .rpcUrl(validateURI(RPC_URL, getRpcUrl())) .displayUrl(validateURI(DISPLAY_URL, getDisplayUrl())) .isPrimary(isPrimary()) .build(); }
protected Link createSelfLinkFor(final ApplicationId appID) { return Link.self(applicationLinkService.createSelfLinkFor(appID)); }
/** * Creates a new {@link com.atlassian.applinks.spi.link.ApplicationLinkDetails.Builder} * initialized with the state from the supplied * {@link com.atlassian.applinks.api.ApplicationLink} instance. */ public static Builder builder(final ApplicationLink applicationLink) { final Builder builder = new Builder(); builder.displayUrl = applicationLink.getDisplayUrl(); builder.rpcUrl = applicationLink.getRpcUrl(); builder.name = applicationLink.getName(); builder.isPrimary = applicationLink.isPrimary(); return builder; }