@Override protected void doValidation() { setUrlAndTokenIfTesting(); if (StringUtils.isBlank(organization) || StringUtils.isBlank(url)) { addErrorMessage("Invalid request, missing url or organization/account information."); } if (StringUtils.isNotBlank(organization)) { Organization integratedAccount = organizationService.findIntegratedAccount(); if (integratedAccount != null && organization.trim().equalsIgnoreCase(integratedAccount.getName())) { addErrorMessage("It is not possible to add the same account as the integrated one."); } } AccountInfo accountInfo = organizationService.getAccountInfo(url, organization, BitbucketCommunicator.BITBUCKET); // Bitbucket REST API to determine existence of accountInfo accepts valid email associated with // BB account, but // it is not possible to create an account containing the '@' character. // [https://confluence.atlassian.com/display/BITBUCKET/account+Resource#accountResource-GETtheaccountprofile] if (accountInfo == null || organization.contains("@")) { addErrorMessage("Invalid user/team account."); } if (organizationService.getByHostAndName(url, organization) != null) { addErrorMessage("Account is already integrated with JIRA."); } if (invalidInput()) { triggerAddFailedEvent(FailureReason.VALIDATION); } }
private String doAddOrganization() { try { Organization newOrganization = new Organization(); newOrganization.setName(organization); newOrganization.setHostUrl(url); newOrganization.setDvcsType(BitbucketCommunicator.BITBUCKET); newOrganization.setCredential( new Credential( oAuthStore.getClientId(Host.BITBUCKET.id), oAuthStore.getSecret(Host.BITBUCKET.id), accessToken)); newOrganization.setAutolinkNewRepos(hadAutolinkingChecked()); newOrganization.setSmartcommitsOnNewRepos(hadAutoSmartCommitsChecked()); organizationService.save(newOrganization); } catch (SourceControlException.UnauthorisedException e) { addErrorMessage("Failed adding the account: [" + e.getMessage() + "]"); log.debug("Failed adding the account: [" + e.getMessage() + "]"); triggerAddFailedEvent(FailureReason.OAUTH_UNAUTH); return INPUT; } catch (SourceControlException e) { addErrorMessage("Failed adding the account: [" + e.getMessage() + "]"); log.debug("Failed adding the account: [" + e.getMessage() + "]"); triggerAddFailedEvent(FailureReason.OAUTH_SOURCECONTROL); return INPUT; } triggerAddSucceededEvent(DvcsType.BITBUCKET); // go back to main DVCS configuration page return getRedirect( "ConfigureDvcsOrganizations.jspa?atl_token=" + CustomStringUtils.encode(getXsrfToken()) + getSourceAsUrlParam()); }