diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAddressibleGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAddressibleGoal.java index 1ee7dcb..1c47f06 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAddressibleGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAddressibleGoal.java @@ -17,8 +17,12 @@ package com.inteligr8.maven.aps.modeling.goal; import java.util.List; import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.settings.Server; +import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest; +import org.apache.maven.settings.crypto.SettingsDecrypter; import com.inteligr8.alfresco.activiti.ApsClientJerseyConfiguration; import com.inteligr8.alfresco.activiti.ApsClientJerseyImpl; @@ -58,6 +62,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal { @Parameter( property = "aps-model.oauth.tokenUrl", required = false ) protected String oauthTokenUrl; + + @Component + private SettingsDecrypter decrypter; private ApsPublicRestApiJerseyImpl api; @@ -69,10 +76,11 @@ public abstract class ApsAddressibleGoal extends DisablableGoal { * * @return An APS client configuration. */ - public ApsClientJerseyConfiguration getApsClientConfiguration() { + public ApsClientJerseyConfiguration getApsClientConfiguration() throws MojoExecutionException { this.getLog().debug("Configuring APS to URL: " + this.activitiAppBaseUrl); ApsClientJerseyConfiguration config = new ApsClientJerseyConfiguration(); config.setBaseUrl(this.activitiAppBaseUrl); + switch (this.activitiAppAuthType.toUpperCase()) { case "BASIC": this.getLog().info("Configuring APS with BASIC authentication"); @@ -82,6 +90,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal { this.getLog().warn("The Maven configuration has no server '" + this.activitiAppAuthBasicServerId + "'; continuing with default credentials"); if (creds != null) { + creds = this.decrypter.decrypt(new DefaultSettingsDecryptionRequest(creds)) + .getServer(); + this.getLog().debug("Username: " + creds.getUsername()); config.setBasicAuthUsername(creds.getUsername()); config.setBasicAuthPassword(creds.getPassword()); @@ -95,16 +106,24 @@ public abstract class ApsAddressibleGoal extends DisablableGoal { if ((this.oauthClientServerId != null || this.oauthServerId != null) && clientCreds == null && oauthCreds == null) this.getLog().warn("The Maven configuration has no server '" + this.oauthClientServerId + "' or '" + this.oauthServerId + "'; continuing without credentials"); - this.getLog().debug("OAuth Code: " + this.oauthCode); - config.setOAuthAuthCode(this.oauthCode); + if (this.oauthCode != null) { + this.getLog().debug("OAuth Code: " + this.oauthCode); + config.setOAuthAuthCode(this.oauthCode); + } if (clientCreds != null) { + creds = this.decrypter.decrypt(new DefaultSettingsDecryptionRequest(clientCreds)) + .getServer(); + this.getLog().debug("OAuth Client ID: " + clientCreds.getUsername()); config.setOAuthClientId(clientCreds.getUsername()); config.setOAuthClientSecret(clientCreds.getPassword()); } if (oauthCreds != null) { + creds = this.decrypter.decrypt(new DefaultSettingsDecryptionRequest(oauthCreds)) + .getServer(); + this.getLog().debug("OAuth Username: " + oauthCreds.getUsername()); config.setOAuthUsername(oauthCreds.getUsername()); config.setOAuthPassword(oauthCreds.getPassword()); @@ -123,8 +142,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal { * This method constructs and caches the APS API accessor. * * @return An APS API instance. + * @throws MojoExecutionException The APS API failed to initialize. */ - public synchronized ApsPublicRestApiJerseyImpl getApsApi() { + public synchronized ApsPublicRestApiJerseyImpl getApsApi() throws MojoExecutionException { if (this.api == null) { ApsClientJerseyConfiguration config = this.getApsClientConfiguration(); ApsClientJerseyImpl apsClient = new ApsClientJerseyImpl(config); @@ -141,8 +161,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal { * This method does not cache the result. * * @return An APS tenant ID; null only if there are no tenants. + * @throws MojoExecutionException The APS API failed to initialize. */ - protected Long findTenantId() { + protected Long findTenantId() throws MojoExecutionException { List tenants = this.getApsApi().getAdminApi().getTenants(); if (tenants == null || tenants.isEmpty()) return null; diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAddressibleGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAddressibleGoal.java index e566256..86a3954 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAddressibleGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsAppAddressibleGoal.java @@ -15,19 +15,15 @@ package com.inteligr8.maven.aps.modeling.goal; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; -import com.inteligr8.activiti.model.Datum; import com.inteligr8.activiti.model.ResultList; import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl; import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType; import com.inteligr8.alfresco.activiti.model.ModelRepresentation; -import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation; -import com.inteligr8.alfresco.activiti.model.Tenant; /** * This class adds the APS App name to APS addressibility to extending goals. @@ -43,21 +39,6 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal { @Parameter( property = "aps-model.appName", required = true ) protected String apsAppName; - /** - * This method makes the appropriate service calls to find the first APS - * tenant ID from the configured APS service. - * - * This method does not cache the result. - * - * @return An APS tenant ID; null only if there are no tenants. - */ - protected Long findTenantId() { - List tenants = this.getApsApi().getAdminApi().getTenants(); - if (tenants == null || tenants.isEmpty()) - return null; - return tenants.iterator().next().getId(); - } - /** * This method makes the appropriate service calls to find all the APS * Apps, returning them as a map of names to models. @@ -65,8 +46,9 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal { * This method does not cache the result. * * @return A map of APS App names to their model; may be empty; never null. + * @throws MojoExecutionException The APS API failed to initialize. */ - protected Map buildAppNameMap() { + protected Map buildAppNameMap() throws MojoExecutionException { ApsPublicRestApiJerseyImpl api = this.getApsApi(); Map apps = new HashMap<>(16); diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsShareGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsShareGoal.java index bb069e2..03fc3c3 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsShareGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsShareGoal.java @@ -26,14 +26,12 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.component.annotations.Component; -import com.inteligr8.activiti.model.Datum; import com.inteligr8.activiti.model.ResultList; import com.inteligr8.alfresco.activiti.api.ModelsApi; import com.inteligr8.alfresco.activiti.model.GroupLight; import com.inteligr8.alfresco.activiti.model.ModelRepresentation; import com.inteligr8.alfresco.activiti.model.PermissionLevel; import com.inteligr8.alfresco.activiti.model.PermissionLight; -import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation; import com.inteligr8.alfresco.activiti.model.ShareInfoRequest; import com.inteligr8.alfresco.activiti.model.SharePermission; import com.inteligr8.alfresco.activiti.model.Tenant; @@ -108,7 +106,7 @@ public class ApsShareGoal extends ApsAddressibleGoal { this.shareModels(ModelsApi.ModelType.Form, this.formReaderSet, this.formEditorSet); } - private void shareModels(ModelsApi.ModelType modelType, Set readers, Set editors) { + private void shareModels(ModelsApi.ModelType modelType, Set readers, Set editors) throws MojoExecutionException { ResultList models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null); if (models.getData() == null) return; @@ -220,7 +218,7 @@ public class ApsShareGoal extends ApsAddressibleGoal { return params; } - protected void buildIdentityIndex() { + protected void buildIdentityIndex() throws MojoExecutionException { List tenants = this.getApsApi().getAdminApi().getTenants(); for (Tenant tenant : tenants) { List groups = this.getApsApi().getAdminApi().getGroups(tenant.getId(), true, true); diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsTemplateAddressibleGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsTemplateAddressibleGoal.java index ddb30fc..3c25c03 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsTemplateAddressibleGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/ApsTemplateAddressibleGoal.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; +import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; import com.inteligr8.activiti.model.ResultList; @@ -52,12 +53,12 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal { @Parameter( property = "aps-model.customEmailTemplateNames", defaultValue = ".*" ) protected String apsCustomEmailTemplateNames; - protected Map> findTemplates() { + protected Map> findTemplates() throws MojoExecutionException { Long tenantId = this.findTenantId(); return this.findTemplates(tenantId); } - protected Map> findTemplates(Long tenantId) { + protected Map> findTemplates(Long tenantId) throws MojoExecutionException { Map> templates = new HashMap<>(32); Map systemEmailTemplateNames = this.findSystemEmailTemplates(tenantId); @@ -75,7 +76,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal { return templates; } - protected Map findSystemEmailTemplates(Long tenantId) { + protected Map findSystemEmailTemplates(Long tenantId) throws MojoExecutionException { this.getLog().debug("Searching for all APS System Email Templates"); List matchingPatterns = this.buildPatterns(this.apsSystemEmailTemplateNames); @@ -94,7 +95,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal { return map; } - protected Map findCustomEmailTemplates(Long tenantId) { + protected Map findCustomEmailTemplates(Long tenantId) throws MojoExecutionException { this.getLog().debug("Searching for all APS Custom Email Templates"); List matchingPatterns = this.buildPatterns(this.apsCustomEmailTemplateNames); @@ -120,7 +121,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal { return map; } - protected Map findDocumentTemplates(Long tenantId) { + protected Map findDocumentTemplates(Long tenantId) throws MojoExecutionException { List matchingPatterns = this.buildPatterns(this.apsDocumentTemplateNames); Map map = new HashMap<>(); int pageSize = 50; diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java index 5c01b1a..d67a628 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadAppGoal.java @@ -56,7 +56,7 @@ public class DownloadAppGoal extends ApsAppAddressibleGoal { try { FileUtils.copyFile(appZip, toAppZip); } catch (IOException ie) { - throw new MojoExecutionException("The downloaded APS App could not be saved", ie); + throw new MojoFailureException("The downloaded APS App could not be saved", ie); } } @@ -69,7 +69,7 @@ public class DownloadAppGoal extends ApsAppAddressibleGoal { } } - private File downloadApp(long appId) { + private File downloadApp(long appId) throws MojoExecutionException { ApsPublicRestApiJerseyImpl api = this.getApsApi(); this.getLog().debug("Downloading APS App: " + appId); return api.getAppDefinitionsApi().export(appId); diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadTemplateGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadTemplateGoal.java index a7407f3..14b15fd 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadTemplateGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/DownloadTemplateGoal.java @@ -31,7 +31,6 @@ import org.codehaus.plexus.component.annotations.Component; import com.fasterxml.jackson.databind.node.ObjectNode; import com.inteligr8.alfresco.activiti.model.BaseTemplateLight; -import com.inteligr8.alfresco.activiti.model.DocumentTemplateLight; import com.inteligr8.alfresco.activiti.model.EmailTemplate; import com.inteligr8.maven.aps.modeling.normalizer.ApsTemplateJsonNormalizer; import com.inteligr8.maven.aps.modeling.util.ModelUtil; @@ -119,7 +118,7 @@ public class DownloadTemplateGoal extends ApsTemplateAddressibleGoal { } } } catch (IOException ie) { - throw new MojoExecutionException("The downloaded APS templates could not be saved", ie); + throw new MojoFailureException("The downloaded APS templates could not be saved", ie); } } diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/PackAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/PackAppGoal.java index 59e0f0c..ed1836d 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/PackAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/PackAppGoal.java @@ -63,7 +63,7 @@ public class PackAppGoal extends ApsAppGoal { try { this.pack(appDirectory, targetFile); } catch (IOException ie) { - throw new MojoExecutionException("The APS App could not be packed", ie); + throw new MojoFailureException("The APS App could not be packed", ie); } } diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/PublishAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/PublishAppGoal.java index d5c4ac3..d16729a 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/PublishAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/PublishAppGoal.java @@ -50,7 +50,7 @@ public class PublishAppGoal extends ApsAppAddressibleGoal { try { this.publishApp(appId); } catch (IOException ie) { - throw new MojoExecutionException("The APS App could not be published", ie); + throw new MojoFailureException("The APS App could not be published", ie); } } diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateAppGoal.java index 742377e..84237b2 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateAppGoal.java @@ -74,7 +74,7 @@ public class TranslateAppGoal extends ApsAppAddressibleGoal { ApsAppCrawler crawler = new ApsAppCrawler(this.apsAppName, apsAppDirectory, true); crawler.execute(translator); } catch (IOException ie) { - throw new MojoExecutionException("An I/O issue occurred", ie); + throw new MojoFailureException("An I/O issue occurred", ie); } catch (IllegalArgumentException iae) { throw new MojoExecutionException("The input is not supported", iae); } catch (IllegalStateException ise) { diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateTemplateGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateTemplateGoal.java index 4b24f8b..e11eefb 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateTemplateGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/TranslateTemplateGoal.java @@ -69,7 +69,7 @@ public class TranslateTemplateGoal extends ApsAddressibleGoal { ApsTemplateCrawler crawler = new ApsTemplateCrawler(this.finalDirectory, true); crawler.execute(translator); } catch (IOException ie) { - throw new MojoExecutionException("An I/O issue occurred", ie); + throw new MojoFailureException("An I/O issue occurred", ie); } catch (IllegalArgumentException iae) { throw new MojoExecutionException("The input is not supported", iae); } catch (IllegalStateException ise) { diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UnpackAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UnpackAppGoal.java index 27a49be..607b0ec 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UnpackAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UnpackAppGoal.java @@ -90,7 +90,7 @@ public class UnpackAppGoal extends ApsAppGoal { try { this.unpack(sourceFile, appDirectory); } catch (IOException ie) { - throw new MojoExecutionException("The downloaded APS App could not be unpacked", ie); + throw new MojoFailureException("The downloaded APS App could not be unpacked", ie); } if (this.reformat) @@ -101,7 +101,7 @@ public class UnpackAppGoal extends ApsAppGoal { ApsAppCrawler crawler = new ApsAppCrawler(this.apsAppName, appDirectory, true); crawler.execute(normalizer); } catch (IOException ie) { - throw new MojoExecutionException("An I/O issue occurred", ie); + throw new MojoFailureException("An I/O issue occurred", ie); } } } @@ -223,7 +223,7 @@ public class UnpackAppGoal extends ApsAppGoal { file.delete(); } } catch (TransformerException | SAXException | IOException e) { - throw new MojoFailureException("The following file faild to be reformatted: " + file, e); + throw new MojoFailureException("The following file failed to be reformatted: " + file, e); } } } diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java index 8bc0990..c43cce5 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadAppGoal.java @@ -65,7 +65,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal { try { this.uploadApp(appModel, sourceFile); } catch (IOException ie) { - throw new MojoExecutionException("The APS App could not be uploaded", ie); + throw new MojoFailureException("The APS App could not be uploaded", ie); } } @@ -87,7 +87,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal { return sourceFile; } - private void uploadApp(ModelRepresentation appModel, File appZip) throws IOException, MojoExecutionException { + private void uploadApp(ModelRepresentation appModel, File appZip) throws IOException, MojoExecutionException, MojoFailureException { ApsPublicRestApiJerseyImpl api = this.getApsApi(); FileInputStream fistream = new FileInputStream(appZip); @@ -103,7 +103,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal { this.getLog().info("Uploading & publishing new APS App: " + this.apsAppName); AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(multipart); if (Boolean.TRUE.equals(appDefUpdate.getError())) - throw new MojoExecutionException(appDefUpdate.getErrorDescription()); + throw new MojoFailureException(appDefUpdate.getErrorDescription()); } } else { if (this.dryRun) { @@ -121,7 +121,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal { this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appModel.getId() + ")"); AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appModel.getId(), multipart); if (Boolean.TRUE.equals(appDefUpdate.getError())) - throw new MojoExecutionException(appDefUpdate.getErrorDescription()); + throw new MojoFailureException(appDefUpdate.getErrorDescription()); } } else { if (this.dryRun) { diff --git a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadTemplateGoal.java b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadTemplateGoal.java index c77516f..687f743 100644 --- a/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadTemplateGoal.java +++ b/src/main/java/com/inteligr8/maven/aps/modeling/goal/UploadTemplateGoal.java @@ -30,7 +30,6 @@ import org.codehaus.plexus.component.annotations.Component; import com.fasterxml.jackson.core.JsonProcessingException; import com.inteligr8.alfresco.activiti.model.DocumentTemplateLight; import com.inteligr8.alfresco.activiti.model.EmailTemplate; -import com.inteligr8.alfresco.activiti.model.EmailTemplateLight; import com.inteligr8.alfresco.activiti.model.FileMultipartJersey; import com.inteligr8.maven.aps.modeling.util.ModelUtil; @@ -153,9 +152,9 @@ public class UploadTemplateGoal extends ApsAddressibleGoal { } } } catch (JsonProcessingException jpe) { - throw new MojoExecutionException("The APS templates JSON files could not be parsed", jpe); + throw new MojoFailureException("The APS templates JSON files could not be parsed", jpe); } catch (IOException ie) { - throw new MojoExecutionException("The APS templates could not be uploaded", ie); + throw new MojoFailureException("The APS templates could not be uploaded", ie); } catch (ParseException pe) { throw new MojoFailureException("This should never happen", pe); }