Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
45320f3802 | |||
e8663123c7 | |||
85ad7cdded | |||
36aa216a59 | |||
ee0f0b4824 | |||
d94c0783db | |||
997fe3d286 | |||
04d26fb251 | |||
9b4287b811 | |||
653eccec17 | |||
2e88bd5af4 | |||
0eafc03acd | |||
8d634670e1 | |||
2d89466813 | |||
a856f9580b | |||
9e62c994ec | |||
6041898be3 | |||
0b9473465e | |||
a65a6df1f8 | |||
98c01db50d | |||
b974bc8f5c |
26
pom.xml
26
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-model-maven-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<version>1.5.0</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<name>A Maven plugin for Alfresco Process Services model portability</name>
|
||||
@@ -42,26 +42,26 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.version>3.6.3</maven.version>
|
||||
<maven.version>3.9.9</maven.version>
|
||||
|
||||
<jersey.version>2.39.1</jersey.version>
|
||||
<jersey.version>3.1.10</jersey.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-public-rest-api</artifactId>
|
||||
<version>2.0.14</version>
|
||||
<version>3.0.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-public-rest-client</artifactId>
|
||||
<version>2.0.5-jersey</version>
|
||||
<version>3.0.2-jersey</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
<version>3.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.inject</groupId>
|
||||
@@ -76,7 +76,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>file-management</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
@@ -87,7 +87,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.15.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -111,7 +111,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -121,7 +121,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-invoker-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<version>3.9.0</version>
|
||||
<configuration>
|
||||
<projectsDirectory>${basedir}/src/it</projectsDirectory>
|
||||
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
|
||||
@@ -146,7 +146,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<version>3.15.1</version>
|
||||
<configuration>
|
||||
<goalPrefix>aps-model</goalPrefix>
|
||||
</configuration>
|
||||
@@ -168,7 +168,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-component-metadata</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -269,7 +269,7 @@
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.13</version>
|
||||
<version>1.7.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
|
@@ -45,4 +45,9 @@ public interface ApsAppCrawlable {
|
||||
*/
|
||||
ApsFileTransformer getFormJsonTransformer();
|
||||
|
||||
/**
|
||||
* @return A file transformer for APS Decision Table JSON files.
|
||||
*/
|
||||
ApsFileTransformer getDecisionTableJsonTransformer();
|
||||
|
||||
}
|
||||
|
@@ -83,6 +83,7 @@ public class ApsAppCrawler {
|
||||
|
||||
this.transform(crawlable.getAppJsonTransformer(), this.appDescriptor, this.appName, null);
|
||||
this.crawlModels("form-models", crawlable.getFormJsonTransformer());
|
||||
this.crawlModels("decision-table-models", crawlable.getDecisionTableJsonTransformer());
|
||||
this.crawlModels("bpmn-models", processTransformers);
|
||||
this.crawlModels("bpmn-subprocess-models", crawlable.getProcessJsonTransformer());
|
||||
}
|
||||
|
@@ -17,12 +17,16 @@ 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;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.ApsProtectedRestApiJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.model.Tenant;
|
||||
|
||||
/**
|
||||
@@ -58,8 +62,11 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
|
||||
|
||||
@Parameter( property = "aps-model.oauth.tokenUrl", required = false )
|
||||
protected String oauthTokenUrl;
|
||||
|
||||
@Component
|
||||
private SettingsDecrypter decrypter;
|
||||
|
||||
private ApsPublicRestApiJerseyImpl api;
|
||||
private ApsProtectedRestApiJerseyImpl api;
|
||||
|
||||
/**
|
||||
* Retrieves an APS client configuration.
|
||||
@@ -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,19 +106,29 @@ 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 (clientCreds.getPassword() != null && clientCreds.getPassword().length() > 0)
|
||||
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());
|
||||
if (oauthCreds.getPassword() != null && oauthCreds.getPassword().length() > 0)
|
||||
config.setOAuthPassword(oauthCreds.getPassword());
|
||||
}
|
||||
|
||||
config.setOAuthTokenUrl(this.oauthTokenUrl);
|
||||
@@ -123,12 +144,13 @@ 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 ApsProtectedRestApiJerseyImpl getApsApi() throws MojoExecutionException {
|
||||
if (this.api == null) {
|
||||
ApsClientJerseyConfiguration config = this.getApsClientConfiguration();
|
||||
ApsClientJerseyImpl apsClient = new ApsClientJerseyImpl(config);
|
||||
this.api = new ApsPublicRestApiJerseyImpl(apsClient);
|
||||
this.api = new ApsProtectedRestApiJerseyImpl(apsClient);
|
||||
}
|
||||
|
||||
return this.api;
|
||||
@@ -141,8 +163,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<Tenant> tenants = this.getApsApi().getAdminApi().getTenants();
|
||||
if (tenants == null || tenants.isEmpty())
|
||||
return null;
|
||||
|
@@ -15,17 +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.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
import com.inteligr8.activiti.model.ResultList;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
|
||||
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
|
||||
import com.inteligr8.alfresco.activiti.model.Tenant;
|
||||
import com.inteligr8.alfresco.activiti.model.ModelRepresentation;
|
||||
|
||||
/**
|
||||
* This class adds the APS App name to APS addressibility to extending goals.
|
||||
@@ -41,41 +39,26 @@ 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<Tenant> 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 IDs.
|
||||
* Apps, returning them as a map of names to models.
|
||||
*
|
||||
* This method does not cache the result.
|
||||
*
|
||||
* @return A map of APS App names to their respective IDs; may be empty; never null.
|
||||
* @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<String, Long> findAppNameIds() {
|
||||
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
||||
protected Map<String, ModelRepresentation> buildAppNameMap() throws MojoExecutionException {
|
||||
ApsPublicRestApi api = this.getApsApi();
|
||||
|
||||
Map<String, Long> apps = new HashMap<>(16);
|
||||
Map<String, ModelRepresentation> apps = new HashMap<>(16);
|
||||
|
||||
this.getLog().debug("Searching for all APS Apps");
|
||||
ResultListDataRepresentation<Datum> results = api.getModelsApi().get("everyone", null, ModelType.App.getId(), null);
|
||||
ResultList<ModelRepresentation> results = api.getModelsApi().get("everyone", null, ModelType.App.getId(), null);
|
||||
this.getLog().debug("Found " + results.getTotal() + " APS Apps");
|
||||
for (Datum datum : results.getData()) {
|
||||
String name = (String)datum.getAdditionalProperties().get("name");
|
||||
Number id = (Number)datum.getAdditionalProperties().get("id");
|
||||
apps.put(name, id.longValue());
|
||||
for (ModelRepresentation model : results.getData()) {
|
||||
String name = model.getName();
|
||||
apps.put(name, model);
|
||||
}
|
||||
|
||||
return apps;
|
||||
@@ -88,11 +71,11 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal {
|
||||
* This method does not cache the result.
|
||||
*
|
||||
* @param failOnNotFound true to fail if not found; false to return null.
|
||||
* @return An APS App ID; null if not found.
|
||||
* @return An APS App model; null if not found.
|
||||
* @throws MojoExecutionException The APS App could not be found.
|
||||
*/
|
||||
protected Long findAppId(boolean failOnNotFound) throws MojoExecutionException {
|
||||
return this.findAppIdByName(this.apsAppName, failOnNotFound);
|
||||
protected ModelRepresentation findAppModel(boolean failOnNotFound) throws MojoExecutionException {
|
||||
return this.findAppModelByName(this.apsAppName, failOnNotFound);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,15 +86,15 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal {
|
||||
*
|
||||
* @param apsName An APS App name.
|
||||
* @param failOnNotFound true to fail if not found; false to return null.
|
||||
* @return An APS App ID; null if not found.
|
||||
* @return An APS App model; null if not found.
|
||||
* @throws MojoExecutionException The APS App could not be found.
|
||||
*/
|
||||
protected Long findAppIdByName(String appName, boolean failOnNotFound) throws MojoExecutionException {
|
||||
Map<String, Long> apps = this.findAppNameIds();
|
||||
Long appId = apps.get(this.apsAppName);
|
||||
if (failOnNotFound && appId == null)
|
||||
protected ModelRepresentation findAppModelByName(String appName, boolean failOnNotFound) throws MojoExecutionException {
|
||||
Map<String, ModelRepresentation> apps = this.buildAppNameMap();
|
||||
ModelRepresentation appModel = apps.get(this.apsAppName);
|
||||
if (failOnNotFound && appModel == null)
|
||||
throw new MojoExecutionException("The APS App '" + this.apsAppName + "' could not be found; valid apps: " + apps.keySet());
|
||||
return appId;
|
||||
return appModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,13 +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;
|
||||
@@ -107,15 +106,13 @@ public class ApsShareGoal extends ApsAddressibleGoal {
|
||||
this.shareModels(ModelsApi.ModelType.Form, this.formReaderSet, this.formEditorSet);
|
||||
}
|
||||
|
||||
private void shareModels(ModelsApi.ModelType modelType, Set<String> readers, Set<String> editors) {
|
||||
ResultListDataRepresentation<Datum> models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null);
|
||||
private void shareModels(ModelsApi.ModelType modelType, Set<String> readers, Set<String> editors) throws MojoExecutionException {
|
||||
ResultList<ModelRepresentation> models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null);
|
||||
if (models.getData() == null)
|
||||
return;
|
||||
|
||||
for (Datum datum : models.getData()) {
|
||||
Number modelId = (Number)datum.getAdditionalProperties().get("id");
|
||||
String modelName = (String)datum.getAdditionalProperties().get("name");
|
||||
if (this.modelName != null && !this.modelName.equals(modelName))
|
||||
for (ModelRepresentation model : models.getData()) {
|
||||
if (this.modelName != null && !this.modelName.equals(model.getName()))
|
||||
continue;
|
||||
|
||||
Set<String> groupsAddressed = new HashSet<>();
|
||||
@@ -123,7 +120,7 @@ public class ApsShareGoal extends ApsAddressibleGoal {
|
||||
Set<String> editorsUnaddressed = new HashSet<>(editors);
|
||||
ShareInfoRequest changeRequest = new ShareInfoRequest();
|
||||
|
||||
ResultList<SharePermission> shares = this.getApsApi().getShareApi().getShareInfo(modelId.toString());
|
||||
ResultList<SharePermission> shares = this.getApsApi().getShareApi().getShareInfo(model.getId().toString());
|
||||
if (shares.getData() != null) {
|
||||
for (SharePermission share : shares.getData()) {
|
||||
if (share.getGroup() != null) {
|
||||
@@ -145,7 +142,7 @@ public class ApsShareGoal extends ApsAddressibleGoal {
|
||||
|
||||
if (!changeRequest.getAdded().isEmpty() || !changeRequest.getUpdated().isEmpty() || !changeRequest.getRemoved().isEmpty()) {
|
||||
this.getLog().info("Sharing model: " + modelType + " => '" + modelName + "'");
|
||||
this.getApsApi().getShareApi().setShareInfo(modelId.toString(), changeRequest);
|
||||
this.getApsApi().getShareApi().setShareInfo(model.getId().toString(), changeRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,7 +218,7 @@ public class ApsShareGoal extends ApsAddressibleGoal {
|
||||
return params;
|
||||
}
|
||||
|
||||
protected void buildIdentityIndex() {
|
||||
protected void buildIdentityIndex() throws MojoExecutionException {
|
||||
List<Tenant> tenants = this.getApsApi().getAdminApi().getTenants();
|
||||
for (Tenant tenant : tenants) {
|
||||
List<GroupLight> groups = this.getApsApi().getAdminApi().getGroups(tenant.getId(), true, true);
|
||||
|
@@ -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<TemplateType, Map<String, ? extends BaseTemplateLight>> findTemplates() {
|
||||
protected Map<TemplateType, Map<String, ? extends BaseTemplateLight>> findTemplates() throws MojoExecutionException {
|
||||
Long tenantId = this.findTenantId();
|
||||
return this.findTemplates(tenantId);
|
||||
}
|
||||
|
||||
protected Map<TemplateType, Map<String, ? extends BaseTemplateLight>> findTemplates(Long tenantId) {
|
||||
protected Map<TemplateType, Map<String, ? extends BaseTemplateLight>> findTemplates(Long tenantId) throws MojoExecutionException {
|
||||
Map<TemplateType, Map<String, ? extends BaseTemplateLight>> templates = new HashMap<>(32);
|
||||
|
||||
Map<String, ? extends BaseTemplateLight> systemEmailTemplateNames = this.findSystemEmailTemplates(tenantId);
|
||||
@@ -75,7 +76,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
||||
return templates;
|
||||
}
|
||||
|
||||
protected Map<String, ? extends BaseTemplateLight> findSystemEmailTemplates(Long tenantId) {
|
||||
protected Map<String, ? extends BaseTemplateLight> findSystemEmailTemplates(Long tenantId) throws MojoExecutionException {
|
||||
this.getLog().debug("Searching for all APS System Email Templates");
|
||||
|
||||
List<Pattern> matchingPatterns = this.buildPatterns(this.apsSystemEmailTemplateNames);
|
||||
@@ -94,7 +95,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
||||
return map;
|
||||
}
|
||||
|
||||
protected Map<String, ? extends BaseTemplateLight> findCustomEmailTemplates(Long tenantId) {
|
||||
protected Map<String, ? extends BaseTemplateLight> findCustomEmailTemplates(Long tenantId) throws MojoExecutionException {
|
||||
this.getLog().debug("Searching for all APS Custom Email Templates");
|
||||
|
||||
List<Pattern> matchingPatterns = this.buildPatterns(this.apsCustomEmailTemplateNames);
|
||||
@@ -102,7 +103,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
||||
int pageSize = 50;
|
||||
int page = 1;
|
||||
|
||||
ResultList<EmailTemplateLight> templates = this.getApsApi().getTemplatesApi().getCustomEmailTemplates(null, (page-1) * pageSize, pageSize, null, tenantId);
|
||||
ResultList<EmailTemplateLight> templates = this.getApsApi().getTemplatesApi().getCustomEmailTemplates(null, (page-1) * pageSize, pageSize, "sort_by_name_asc", tenantId);
|
||||
while (!templates.getData().isEmpty()) {
|
||||
for (EmailTemplateLight template : templates.getData()) {
|
||||
for (Pattern pattern : matchingPatterns) {
|
||||
@@ -112,7 +113,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
||||
}
|
||||
|
||||
page++;
|
||||
templates = this.getApsApi().getTemplatesApi().getCustomEmailTemplates(null, (page-1) * pageSize, pageSize, null, tenantId);
|
||||
templates = this.getApsApi().getTemplatesApi().getCustomEmailTemplates(null, (page-1) * pageSize, pageSize, "sort_by_name_asc", tenantId);
|
||||
}
|
||||
|
||||
this.getLog().debug("Found APS Custom Email Templates: " + map.size());
|
||||
@@ -120,13 +121,13 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
||||
return map;
|
||||
}
|
||||
|
||||
protected Map<String, ? extends BaseTemplateLight> findDocumentTemplates(Long tenantId) {
|
||||
protected Map<String, ? extends BaseTemplateLight> findDocumentTemplates(Long tenantId) throws MojoExecutionException {
|
||||
List<Pattern> matchingPatterns = this.buildPatterns(this.apsDocumentTemplateNames);
|
||||
Map<String, DocumentTemplateLight> map = new HashMap<>();
|
||||
int pageSize = 50;
|
||||
int page = 1;
|
||||
|
||||
ResultList<DocumentTemplateLight> templates = this.getApsApi().getTemplatesApi().getDocumentTemplates(null, (page-1) * pageSize, pageSize, null, tenantId);
|
||||
ResultList<DocumentTemplateLight> templates = this.getApsApi().getTemplatesApi().getDocumentTemplates(null, (page-1) * pageSize, pageSize, "sort_by_name_asc", tenantId);
|
||||
while (!templates.getData().isEmpty()) {
|
||||
for (DocumentTemplateLight template : templates.getData()) {
|
||||
for (Pattern pattern : matchingPatterns) {
|
||||
@@ -136,7 +137,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
||||
}
|
||||
|
||||
page++;
|
||||
templates = this.getApsApi().getTemplatesApi().getDocumentTemplates(null, (page-1) * pageSize, pageSize, null, tenantId);
|
||||
templates = this.getApsApi().getTemplatesApi().getDocumentTemplates(null, (page-1) * pageSize, pageSize, "sort_by_name_asc", tenantId);
|
||||
}
|
||||
|
||||
this.getLog().debug("Found APS Document Templates: " + map.size());
|
||||
|
@@ -24,7 +24,7 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
|
||||
/**
|
||||
* A class that implements an APS service download goal.
|
||||
@@ -46,7 +46,7 @@ public class DownloadAppGoal extends ApsAppAddressibleGoal {
|
||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||
this.validateTargetDirectory();
|
||||
|
||||
Long appId = this.findAppId(true);
|
||||
Long appId = this.findAppModel(true).getId();
|
||||
File appZip = this.downloadApp(appId);
|
||||
|
||||
File toAppZip = new File(this.zipDirectory, this.apsAppName + ".zip");
|
||||
@@ -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,8 +69,8 @@ public class DownloadAppGoal extends ApsAppAddressibleGoal {
|
||||
}
|
||||
}
|
||||
|
||||
private File downloadApp(long appId) {
|
||||
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
||||
private File downloadApp(long appId) throws MojoExecutionException {
|
||||
ApsPublicRestApi api = this.getApsApi();
|
||||
this.getLog().debug("Downloading APS App: " + appId);
|
||||
return api.getAppDefinitionsApi().export(appId);
|
||||
}
|
||||
|
@@ -20,8 +20,6 @@ import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
@@ -31,11 +29,12 @@ 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;
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* A class that implements an APS service download goal.
|
||||
*
|
||||
@@ -66,35 +65,43 @@ public class DownloadTemplateGoal extends ApsTemplateAddressibleGoal {
|
||||
try {
|
||||
Map<TemplateType, Map<String, ? extends BaseTemplateLight>> templates = this.findTemplates(tenantId);
|
||||
for (TemplateType ttype : templates.keySet()) {
|
||||
this.getLog().debug("Downloading templates: " + ttype);
|
||||
this.getLog().info("Downloading " + templates.get(ttype).size() + " " + ttype + " templates");
|
||||
|
||||
for (Entry<String, ? extends BaseTemplateLight> template : templates.get(ttype).entrySet()) {
|
||||
switch (ttype) {
|
||||
case Document:
|
||||
File dfilebin = new File(this.templateDirectory, template.getValue().getName());
|
||||
|
||||
Response response = this.getApsApi().getTemplatesApi().getDocumentTemplate(
|
||||
template.getValue().getId(),
|
||||
System.currentTimeMillis());
|
||||
try {
|
||||
if (response.getStatus() / 100 == 2) {
|
||||
InputStream istream = (InputStream) response.getEntity();
|
||||
try {
|
||||
FileUtils.copyInputStreamToFile(istream, dfilebin);
|
||||
} finally {
|
||||
istream.close();
|
||||
}
|
||||
} else {
|
||||
this.getLog().warn("The document template could not be downloaded; skipping: " + template.getValue().getName());
|
||||
continue;
|
||||
}
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
|
||||
ObjectNode djson = ModelUtil.getInstance().readPojo(template.getValue());
|
||||
File dfile = new File(this.templateDirectory, template.getValue().getId() + ".doc-template.json");
|
||||
File dfile = new File(this.templateDirectory, template.getValue().getName() + ".dt.json");
|
||||
ModelUtil.getInstance().writeJson(djson, dfile, this.diffFriendly);
|
||||
if (this.normalize)
|
||||
new ApsTemplateJsonNormalizer(this.diffFriendly).normalizeFile(dfile, null);
|
||||
|
||||
File dfilebin = new File(this.templateDirectory, template.getValue().getId() + ".doc-template.docx");
|
||||
|
||||
Response response = this.getApsApi().getTemplatesApi().getDocumentTemplate((DocumentTemplateLight) template.getValue());
|
||||
try {
|
||||
InputStream istream = (InputStream) response.getEntity();
|
||||
try {
|
||||
FileUtils.copyInputStreamToFile(istream, dfilebin);
|
||||
} finally {
|
||||
istream.close();
|
||||
}
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
|
||||
break;
|
||||
case CustomEmail:
|
||||
EmailTemplate etemplate = this.getApsApi().getTemplatesApi().getCustomEmailTemplate(template.getValue().getId(), tenantId);
|
||||
ObjectNode ejson = ModelUtil.getInstance().readPojo(etemplate);
|
||||
File efile = new File(this.templateDirectory, template.getValue().getId() + ".custom-email-template.json");
|
||||
File efile = new File(this.templateDirectory, template.getValue().getName() + ".cet.json");
|
||||
ModelUtil.getInstance().writeJson(ejson, efile, this.diffFriendly);
|
||||
if (this.normalize)
|
||||
new ApsTemplateJsonNormalizer(this.diffFriendly).normalizeFile(efile, null);
|
||||
@@ -103,7 +110,7 @@ public class DownloadTemplateGoal extends ApsTemplateAddressibleGoal {
|
||||
case SystemEmail:
|
||||
EmailTemplate stemplate = this.getApsApi().getTemplatesApi().getSystemEmailTemplate(template.getValue().getName(), tenantId);
|
||||
ObjectNode sjson = ModelUtil.getInstance().readPojo(stemplate);
|
||||
File sfile = new File(this.templateDirectory, template.getValue().getName() + ".system-email-template.json");
|
||||
File sfile = new File(this.templateDirectory, template.getValue().getName() + ".set.json");
|
||||
ModelUtil.getInstance().writeJson(sjson, sfile, this.diffFriendly);
|
||||
if (this.normalize)
|
||||
new ApsTemplateJsonNormalizer(this.diffFriendly).normalizeFile(sfile, null);
|
||||
@@ -111,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,8 +22,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.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.model.AppDefinitionPublishRepresentation;
|
||||
import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation;
|
||||
|
||||
import jakarta.ws.rs.WebApplicationException;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* A class that implements an APS Service publish goal.
|
||||
@@ -39,24 +43,34 @@ public class PublishAppGoal extends ApsAppAddressibleGoal {
|
||||
|
||||
@Parameter( property = "aps-model.publish.comment", required = true, defaultValue = "Automated by 'aps-model-maven-plugin'" )
|
||||
protected String comment;
|
||||
|
||||
@Parameter( property = "aps-model.dryRun", required = true, defaultValue = "false" )
|
||||
protected boolean dryRun;
|
||||
|
||||
@Override
|
||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||
Long appId = this.findAppId(false);
|
||||
Long appId = this.findAppModel(false).getId();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void publishApp(Long appId) throws IOException, MojoExecutionException {
|
||||
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
||||
ApsPublicRestApi api = this.getApsApi();
|
||||
|
||||
AppDefinitionPublishRepresentation appDefPublish = new AppDefinitionPublishRepresentation();
|
||||
appDefPublish.setComment(this.comment);
|
||||
api.getAppDefinitionsApi().publish(appId, appDefPublish);
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Publishing app: " + appId);
|
||||
} else {
|
||||
this.getLog().info("Publishing app: " + appId);
|
||||
AppDefinitionUpdateResultRepresentation response = api.getAppDefinitionsApi().publish(appId, appDefPublish);
|
||||
if (Boolean.TRUE.equals(response.getError()))
|
||||
throw new WebApplicationException(response.getErrorDescription(), Response.Status.PRECONDITION_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,9 +26,13 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestJerseyApi;
|
||||
import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation;
|
||||
import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
|
||||
import com.inteligr8.alfresco.activiti.model.ModelRepresentation;
|
||||
|
||||
import jakarta.ws.rs.WebApplicationException;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* A class that implements an APS service upload goal.
|
||||
@@ -49,6 +53,9 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
|
||||
|
||||
@Parameter( property = "publish", required = true, defaultValue = "false" )
|
||||
protected boolean publish = false;
|
||||
|
||||
@Parameter( property = "aps-model.dryRun", required = true, defaultValue = "false" )
|
||||
protected boolean dryRun;
|
||||
|
||||
protected final int bufferSize = 128 * 1024;
|
||||
|
||||
@@ -56,12 +63,12 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
|
||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||
File sourceFile = this.validateSourceDirectory();
|
||||
|
||||
Long appId = this.findAppId(false);
|
||||
ModelRepresentation appModel = this.findAppModel(false);
|
||||
|
||||
try {
|
||||
this.uploadApp(appId, sourceFile);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,33 +90,49 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
private void uploadApp(Long appId, File appZip) throws IOException, MojoExecutionException {
|
||||
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
||||
private void uploadApp(ModelRepresentation appModel, File appZip) throws IOException, MojoExecutionException, MojoFailureException {
|
||||
ApsPublicRestJerseyApi api = this.getApsApi();
|
||||
|
||||
FileInputStream fistream = new FileInputStream(appZip);
|
||||
BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize);
|
||||
try {
|
||||
FileMultipartJersey multipart = FileMultipartJersey.from(appZip.getName(), bistream);
|
||||
|
||||
if (appId == null) {
|
||||
if (appModel == null) {
|
||||
if (this.publish) {
|
||||
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());
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Uploading & publishing new APS App: " + this.apsAppName);
|
||||
} else {
|
||||
this.getLog().info("Uploading & publishing new APS App: " + this.apsAppName);
|
||||
AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(multipart);
|
||||
if (Boolean.TRUE.equals(appDefUpdate.getError()))
|
||||
throw new WebApplicationException(appDefUpdate.getErrorDescription(), Response.Status.PRECONDITION_FAILED);
|
||||
}
|
||||
} else {
|
||||
this.getLog().info("Uploading new APS App: " + this.apsAppName);
|
||||
api.getAppDefinitionsJerseyApi().importApp(multipart, true);
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Uploading new APS App: " + this.apsAppName);
|
||||
} else {
|
||||
this.getLog().info("Uploading new APS App: " + this.apsAppName);
|
||||
api.getAppDefinitionsJerseyApi().importApp(multipart, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.publish) {
|
||||
this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appId + ")");
|
||||
AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appId, multipart);
|
||||
if (Boolean.TRUE.equals(appDefUpdate.getError()))
|
||||
throw new MojoExecutionException(appDefUpdate.getErrorDescription());
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appModel.getId() + ")");
|
||||
} else {
|
||||
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 WebApplicationException(appDefUpdate.getErrorDescription(), Response.Status.PRECONDITION_FAILED);
|
||||
}
|
||||
} else {
|
||||
this.getLog().info("Uploading & versioning APS App: " + this.apsAppName + " (" + appId + ")");
|
||||
api.getAppDefinitionsJerseyApi().importApp(appId, multipart, true);
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Uploading & versioning APS App: " + this.apsAppName + " (" + appModel.getId() + ")");
|
||||
} else {
|
||||
this.getLog().info("Uploading & versioning APS App: " + this.apsAppName + " (" + appModel.getId() + ")");
|
||||
api.getAppDefinitionsJerseyApi().importApp(appModel.getId(), multipart, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ParseException pe) {
|
||||
|
@@ -50,6 +50,12 @@ public class UploadTemplateGoal extends ApsAddressibleGoal {
|
||||
|
||||
@Parameter( property = "aps-model.upload.directory", required = true, defaultValue = "${project.build.directory}/aps" )
|
||||
protected File templateDirectory;
|
||||
|
||||
@Parameter( required = true, defaultValue = "false" )
|
||||
protected boolean alwaysOverwrite;
|
||||
|
||||
@Parameter( property = "aps-model.dryRun", required = true, defaultValue = "false" )
|
||||
protected boolean dryRun;
|
||||
|
||||
protected final int bufferSize = 128 * 1024;
|
||||
|
||||
@@ -66,41 +72,89 @@ public class UploadTemplateGoal extends ApsAddressibleGoal {
|
||||
}
|
||||
|
||||
try {
|
||||
if (file.getName().endsWith(".doc-template.json")) {
|
||||
if (file.getName().endsWith(".dt.json")) {
|
||||
DocumentTemplateLight template = ModelUtil.getInstance().writePojo(ModelUtil.getInstance().readJsonAsMap(file), DocumentTemplateLight.class);
|
||||
if (!this.alwaysOverwrite && template.getId() != null && template.getCreated() != null) {
|
||||
DocumentTemplateLight serverSideTemplate = this.getApsApi().getTemplatesApi().getDocumentTemplate(template.getId());
|
||||
if (serverSideTemplate != null && !serverSideTemplate.getCreated().isBefore(template.getCreated())) {
|
||||
this.getLog().debug("Document template unchanged; not updating: " + template.getId());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
File docxfile = new File(file.getParent(), file.getName().substring(0, file.getName().length() - ".json".length()) + ".docx");
|
||||
if (!docxfile.exists())
|
||||
throw new FileNotFoundException("The file, '" + docxfile.getName() + "' was expected and not found");
|
||||
File dfile = new File(file.getParent(), file.getName().substring(0, file.getName().length() - ".dt.json".length()));
|
||||
if (!dfile.exists())
|
||||
throw new FileNotFoundException("The file, '" + dfile.getName() + "' was expected and not found");
|
||||
|
||||
FileInputStream fistream = new FileInputStream(docxfile);
|
||||
FileInputStream fistream = new FileInputStream(dfile);
|
||||
BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize);
|
||||
try {
|
||||
FileMultipartJersey multipart = FileMultipartJersey.from(docxfile.getName(), bistream);
|
||||
FileMultipartJersey multipart = FileMultipartJersey.from(dfile.getName(), bistream);
|
||||
if (template.getId() == null) {
|
||||
this.getApsApi().getTemplatesJerseyApi().createDocumentTemplate(tenantId, multipart);
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Creating document template: " + template.getName());
|
||||
} else {
|
||||
this.getLog().info("Creating document template: " + template.getName());
|
||||
this.getApsApi().getTemplatesJerseyApi().createDocumentTemplate(tenantId, multipart);
|
||||
}
|
||||
} else {
|
||||
this.getApsApi().getTemplatesJerseyApi().updateDocumentTemplate(template.getId(), tenantId, multipart);
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Updating document template: " + template.getName());
|
||||
} else {
|
||||
this.getLog().info("Updating document template: " + template.getName());
|
||||
this.getApsApi().getTemplatesJerseyApi().updateDocumentTemplate(template.getId(), tenantId, multipart);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
bistream.close();
|
||||
fistream.close();
|
||||
}
|
||||
} else if (file.getName().endsWith(".custom-email-template.json")) {
|
||||
} else if (file.getName().endsWith(".cet.json")) {
|
||||
EmailTemplate template = ModelUtil.getInstance().writePojo(ModelUtil.getInstance().readJsonAsMap(file), EmailTemplate.class);
|
||||
if (template.getId() == null) {
|
||||
this.getApsApi().getTemplatesJerseyApi().createCustomEmailTemplate(template);
|
||||
} else {
|
||||
this.getApsApi().getTemplatesJerseyApi().updateCustomEmailTemplate(template.getId(), template);
|
||||
if (!this.alwaysOverwrite && template.getId() != null && template.getCreated() != null) {
|
||||
EmailTemplate serverSideTemplate = this.getApsApi().getTemplatesApi().getCustomEmailTemplate(template.getId(), tenantId);
|
||||
if (serverSideTemplate != null && !serverSideTemplate.getCreated().isBefore(template.getCreated())) {
|
||||
this.getLog().debug("Custom email template unchanged; not updating: " + template.getId());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (file.getName().endsWith(".system-email-template.json")) {
|
||||
|
||||
if (template.getId() == null) {
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Creating custom email template: " + template.getName());
|
||||
} else {
|
||||
this.getLog().info("Creating custom email template: " + template.getName());
|
||||
this.getApsApi().getTemplatesJerseyApi().createCustomEmailTemplate(template);
|
||||
}
|
||||
} else {
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Updating custom email template: " + template.getName());
|
||||
} else {
|
||||
this.getLog().info("Updating custom email template: " + template.getName());
|
||||
this.getApsApi().getTemplatesJerseyApi().updateCustomEmailTemplate(template.getId(), template);
|
||||
}
|
||||
}
|
||||
} else if (file.getName().endsWith(".set.json")) {
|
||||
EmailTemplate template = ModelUtil.getInstance().writePojo(ModelUtil.getInstance().readJsonAsMap(file), EmailTemplate.class);
|
||||
this.getApsApi().getTemplatesJerseyApi().updateSystemEmailTemplate(template.getName(), template);
|
||||
if (!this.alwaysOverwrite) {
|
||||
EmailTemplate serverSideTemplate = this.getApsApi().getTemplatesApi().getSystemEmailTemplate(template.getName(), tenantId);
|
||||
if (serverSideTemplate != null && template.getTemplate().equals(serverSideTemplate.getTemplate())) {
|
||||
this.getLog().debug("System email template unchanged; not updating: " + template.getName());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.dryRun) {
|
||||
this.getLog().info("[DRYRUN]: Updating system email template: " + template.getName());
|
||||
} else {
|
||||
this.getLog().info("Updating system email template: " + template.getName());
|
||||
this.getApsApi().getTemplatesJerseyApi().updateSystemEmailTemplate(template.getName(), template);
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
|
@@ -62,6 +62,11 @@ public class ApsAppNormalizer implements ApsAppCrawlable {
|
||||
public ApsFileTransformer getFormJsonTransformer() {
|
||||
return new ApsFormJsonNormalizer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApsFileTransformer getDecisionTableJsonTransformer() {
|
||||
return new ApsDecisionTableJsonNormalizer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApsFileTransformer getProcessJsonTransformer() {
|
||||
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.maven.aps.modeling.normalizer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* This class implements an APS Decision Table JSON configuration file
|
||||
* normalizer.
|
||||
*
|
||||
* This does nothing but log at this time.
|
||||
*
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
public class ApsDecisionTableJsonNormalizer implements ApsFileNormalizer {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ApsDecisionTableJsonNormalizer.class);
|
||||
|
||||
@Override
|
||||
public void normalizeFile(File file, String modelName) throws IOException {
|
||||
this.logger.debug("Normalizing Form JSON file: {}", file);
|
||||
this.logger.trace("Nothing to normalize: {}", modelName);
|
||||
}
|
||||
|
||||
}
|
@@ -27,7 +27,7 @@ import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||
/**
|
||||
* This class implements an APS template JSON configuration file normalizer.
|
||||
*
|
||||
* This will remove the 'created' date of each defined template.
|
||||
* This will remove the 'createdBy' of each defined template.
|
||||
*
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ public class ApsTemplateJsonNormalizer implements ApsFileNormalizer {
|
||||
this.logger.trace("Removing excess template meta-data: {}", jsonModel.get("name"));
|
||||
|
||||
int fields = jsonModel.size();
|
||||
jsonModel.remove(Arrays.asList("created", "createdBy"));
|
||||
jsonModel.remove(Arrays.asList("createdBy"));
|
||||
return jsonModel.size() < fields;
|
||||
}
|
||||
|
||||
|
@@ -26,11 +26,11 @@ import java.util.regex.Pattern;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.inteligr8.activiti.model.Datum;
|
||||
import com.inteligr8.activiti.model.ResultList;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
|
||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
|
||||
import com.inteligr8.alfresco.activiti.model.ModelRepresentation;
|
||||
import com.inteligr8.alfresco.activiti.model.Tenant;
|
||||
import com.inteligr8.maven.aps.modeling.crawler.ApsAppCrawlable;
|
||||
import com.inteligr8.maven.aps.modeling.crawler.ApsFileTransformer;
|
||||
@@ -64,6 +64,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
private boolean indexesBuilt = false;
|
||||
private Map<String, GroupLight> apsOrgIndex;
|
||||
private Index<Long, String> apsFormIndex;
|
||||
private Index<Long, String> apsDecisionTableIndex;
|
||||
private Index<Long, String> apsProcessIndex;
|
||||
private Index<Long, String> fileFormIndex;
|
||||
private Index<Long, String> fileProcessIndex;
|
||||
@@ -107,6 +108,9 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
|
||||
this.apsFormIndex = this.buildApsModelIndex(ModelType.Form);
|
||||
this.logLarge("APS form models: {}", this.apsFormIndex);
|
||||
|
||||
this.apsDecisionTableIndex = this.buildApsModelIndex(ModelType.DecisionTable);
|
||||
this.logLarge("APS decision table models: {}", this.apsDecisionTableIndex);
|
||||
|
||||
this.fileFormIndex = this.buildFileIndex("form-models", this.apsFormIndex, true);
|
||||
this.logLarge("File form models: {}", this.fileFormIndex);
|
||||
@@ -156,6 +160,15 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
return new ApsFormJsonTranslator(
|
||||
this.apsFormIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApsFileTransformer getDecisionTableJsonTransformer() {
|
||||
if (!this.indexesBuilt)
|
||||
throw new IllegalStateException("The indexes are never built");
|
||||
|
||||
return new ApsDecisionTableJsonTranslator(
|
||||
this.apsDecisionTableIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApsFileTransformer getProcessJsonTransformer() {
|
||||
@@ -166,7 +179,8 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
this.api,
|
||||
this.apsProcessIndex,
|
||||
this.apsOrgIndex,
|
||||
this.apsFormIndex);
|
||||
this.apsFormIndex,
|
||||
this.apsDecisionTableIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,6 +193,7 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
this.apsProcessIndex,
|
||||
this.apsOrgIndex,
|
||||
this.apsFormIndex,
|
||||
this.apsDecisionTableIndex,
|
||||
this.fileFormIndex);
|
||||
}
|
||||
|
||||
@@ -196,18 +211,15 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
||||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Index<Long, String> buildApsModelIndex(ModelType modelType) {
|
||||
ResultListDataRepresentation<Datum> results = this.api.getModelsApi().get("everyone", null, modelType.getId(), null);
|
||||
ResultList<ModelRepresentation> results = this.api.getModelsApi().get("everyone", null, modelType.getId(), null);
|
||||
this.logger.debug("APS {} models found: {} out of {}", modelType, results.getSize(), results.getTotal());
|
||||
|
||||
Index<Long, String> map = new Index<>(results.getSize().intValue(), false);
|
||||
|
||||
try {
|
||||
for (Datum datum : results.getData()) {
|
||||
Number defId = (Number)datum.getAdditionalProperties().get("id");
|
||||
String defName = (String)datum.getAdditionalProperties().get("name");
|
||||
map.put(defId.longValue(), defName);
|
||||
for (ModelRepresentation model : results.getData()) {
|
||||
map.put(model.getId(), model.getName());
|
||||
|
||||
// FIXME add paging support
|
||||
}
|
||||
|
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.maven.aps.modeling.translator;
|
||||
|
||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||
|
||||
/**
|
||||
* This class implements an APS Decision Table JSON configuration file
|
||||
* translator.
|
||||
*
|
||||
* This will translate the decision table ID embedded into APS Decision Table
|
||||
* descriptor.
|
||||
*
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
public class ApsDecisionTableJsonTranslator extends ApsResourceJsonTranslator {
|
||||
|
||||
/**
|
||||
* This constructor initializes the default translator.
|
||||
*
|
||||
* @param apsDecisionTableIndex A map of form IDs to form names as defined in the APS Service.
|
||||
*/
|
||||
public ApsDecisionTableJsonTranslator(Index<Long, String> apsDecisionTableIndex) {
|
||||
super(apsDecisionTableIndex);
|
||||
}
|
||||
|
||||
}
|
@@ -14,16 +14,7 @@
|
||||
*/
|
||||
package com.inteligr8.maven.aps.modeling.translator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||
|
||||
/**
|
||||
* This class implements an APS Form JSON configuration file translator.
|
||||
@@ -32,10 +23,7 @@ import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||
*
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
public class ApsFormJsonTranslator implements ApsFileTranslator {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ApsFormJsonTranslator.class);
|
||||
private final Index<Long, String> apsIndex;
|
||||
public class ApsFormJsonTranslator extends ApsResourceJsonTranslator {
|
||||
|
||||
/**
|
||||
* This constructor initializes the default translator.
|
||||
@@ -43,36 +31,7 @@ public class ApsFormJsonTranslator implements ApsFileTranslator {
|
||||
* @param apsFormIndex A map of form IDs to form names as defined in the APS Service.
|
||||
*/
|
||||
public ApsFormJsonTranslator(Index<Long, String> apsFormIndex) {
|
||||
this.apsIndex = apsFormIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateFile(File file, String formName, Long formId) throws IOException {
|
||||
this.logger.debug("Translating JSON file: {}", file);
|
||||
boolean changed = false;
|
||||
|
||||
ObjectNode jsonDescriptor = ModelUtil.getInstance().readJson(file, ObjectNode.class);
|
||||
JsonNode jsonResourceId = jsonDescriptor.get("resourceId");
|
||||
if (jsonResourceId == null || jsonResourceId.isNull()) {
|
||||
this.logger.debug("The form has no ID to translate");
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.trace("Found ID {} in the '{}' APS Form descriptor", jsonResourceId, formName);
|
||||
|
||||
Long apsFormId = this.apsIndex.getFirstKey(formName);
|
||||
if (apsFormId == null) {
|
||||
this.logger.debug("The form '{}' does not exist in APS; leaving unchanged", formName);
|
||||
} else if (!formId.equals(apsFormId)) {
|
||||
this.logger.debug("The form '{}' exists in APS with ID {}; changing descriptor", formName, apsFormId);
|
||||
jsonDescriptor.put("resourceId", apsFormId);
|
||||
changed = true;
|
||||
} else {
|
||||
this.logger.trace("The form '{}' ID does not change; leaving unchanged", formName, apsFormId);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
ModelUtil.getInstance().writeJson(jsonDescriptor, file, false);
|
||||
super(apsFormIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -63,7 +63,8 @@ public class ApsProcessBpmnTranslator extends ApsOrganizationHandler implements
|
||||
private final Index<Long, String> apsIndex;
|
||||
private final Map<String, GroupLight> apsOrgIndex;
|
||||
private final Index<Long, String> apsFormIndex;
|
||||
private final Index<Long, String> fileFormIndex;
|
||||
private final Index<Long, String> apsDecisionTableIndex;
|
||||
private final Index<Long, String> fileFormIndex;
|
||||
|
||||
/**
|
||||
* This constructor initializes the default translator.
|
||||
@@ -79,12 +80,14 @@ public class ApsProcessBpmnTranslator extends ApsOrganizationHandler implements
|
||||
Index<Long, String> apsProcessIndex,
|
||||
Map<String, GroupLight> apsOrgIndex,
|
||||
Index<Long, String> apsFormIndex,
|
||||
Index<Long, String> apsDecisionTableIndex,
|
||||
Index<Long, String> fileFormIndex) {
|
||||
super(api, apsOrgIndex);
|
||||
this.apsIndex = apsProcessIndex;
|
||||
this.apsOrgIndex = apsOrgIndex;
|
||||
this.apsFormIndex = apsFormIndex;
|
||||
this.fileFormIndex = fileFormIndex;
|
||||
this.apsDecisionTableIndex = apsDecisionTableIndex;
|
||||
this.fileFormIndex = fileFormIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,6 +114,12 @@ public class ApsProcessBpmnTranslator extends ApsOrganizationHandler implements
|
||||
Element formKeyElement = (Element)formKeyElements.item(n);
|
||||
changed = this.translateTaskForm(formKeyElement) || changed;
|
||||
}
|
||||
|
||||
NodeList decisionTableRefElements = ModelUtil.getInstance().xpath(definitionsElement, "//modeler:decisiontable-reference");
|
||||
for (int n = 0; n < decisionTableRefElements.getLength(); n++) {
|
||||
Element decisionTableRefElement = (Element)decisionTableRefElements.item(n);
|
||||
changed = this.translateDecisionTableRef(decisionTableRefElement, bpmn) || changed;
|
||||
}
|
||||
|
||||
NodeList subprocessElements = ModelUtil.getInstance().xpath(definitionsElement, "//tns:subProcess");
|
||||
for (int n = 0; n < subprocessElements.getLength(); n++) {
|
||||
@@ -258,6 +267,47 @@ public class ApsProcessBpmnTranslator extends ApsOrganizationHandler implements
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private boolean translateDecisionTableRef(Element decisionTableRefElement, Document xmldoc) throws XPathExpressionException {
|
||||
String dtRefIdStr = decisionTableRefElement.getAttributeNS(NAMESPACE_ACTIVITI_MODELER, "decisiontablereferenceid");
|
||||
this.logger.trace("Translating decision table: {}", dtRefIdStr);
|
||||
if (dtRefIdStr == null)
|
||||
throw new IllegalStateException("A decision table was detected, but no identifier was found");
|
||||
Long dtRefId = new Long(dtRefIdStr);
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
String dtRefName = decisionTableRefElement.getAttributeNS(NAMESPACE_ACTIVITI_MODELER, "decisiontablereferencename");
|
||||
if (dtRefName == null)
|
||||
throw new IllegalStateException("A decision table was detected, but no name was found: " + dtRefId);
|
||||
dtRefName = dtRefName.trim();
|
||||
this.logger.trace("Found '{}' decision table in the APS Process BPMN model", dtRefName);
|
||||
|
||||
Long apsDecisionTableId = this.apsDecisionTableIndex.getFirstKey(dtRefName);
|
||||
if (apsDecisionTableId == null) {
|
||||
this.logger.debug("The decision table '{}' does not exist in APS; leaving unchanged", dtRefName);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.logger.trace("Found ID {} for the decision table '{}' in the APS Process BPMN model", apsDecisionTableId, dtRefName);
|
||||
|
||||
String dtRefKey = (String) ModelUtil.getInstance().xpath(
|
||||
decisionTableRefElement.getParentNode(),
|
||||
"activiti:field[@name=\"decisionTableReferenceKey\"]/activiti:string/text()",
|
||||
XPathConstants.STRING);
|
||||
if (dtRefKey == null)
|
||||
throw new IllegalStateException("A decision table was detected, but no key was found: " + dtRefId);
|
||||
|
||||
if (!apsDecisionTableId.equals(dtRefId)) {
|
||||
this.logger.debug("The decision table '{}' exists in APS with ID {}; changing model", dtRefName, apsDecisionTableId);
|
||||
decisionTableRefElement.setAttributeNS(NAMESPACE_ACTIVITI_MODELER, "decisiontablereferenceid", apsDecisionTableId.toString());
|
||||
changed = true;
|
||||
} else {
|
||||
this.logger.trace("The decision table '{}' key does not change; leaving unchanged", dtRefName);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private boolean translateSubprocess(Element subprocessElement) throws XPathExpressionException {
|
||||
this.logger.trace("Translating subprocess: {}", subprocessElement.getAttribute("id"));
|
||||
|
@@ -48,6 +48,7 @@ public class ApsProcessJsonTranslator extends ApsOrganizationHandler implements
|
||||
private final Index<Long, String> apsIndex;
|
||||
private final Map<String, GroupLight> apsOrgIndex;
|
||||
private final Index<Long, String> apsFormIndex;
|
||||
private final Index<Long, String> apsDecisionTableIndex;
|
||||
|
||||
/**
|
||||
* This constructor initializes the default translator.
|
||||
@@ -56,16 +57,19 @@ public class ApsProcessJsonTranslator extends ApsOrganizationHandler implements
|
||||
* @param apsProcessIndex A map of process IDs to process names as defined in the APS Service.
|
||||
* @param apsOrgIndex A map of organizations (groups) to organization meta-data as defined in the APS Service.
|
||||
* @param apsFormIndex A map of form IDs to form names as defined in the APS Service.
|
||||
* @param apsDecisionTableIndex A map of decision table IDs to decision table names as defined in the APS Service.
|
||||
*/
|
||||
public ApsProcessJsonTranslator(
|
||||
ApsPublicRestApi api,
|
||||
Index<Long, String> apsProcessIndex,
|
||||
Map<String, GroupLight> apsOrgIndex,
|
||||
Index<Long, String> apsFormIndex) {
|
||||
Index<Long, String> apsFormIndex,
|
||||
Index<Long, String> apsDecisionTableIndex) {
|
||||
super(api, apsOrgIndex);
|
||||
this.apsIndex = apsProcessIndex;
|
||||
this.apsOrgIndex = apsOrgIndex;
|
||||
this.apsFormIndex = apsFormIndex;
|
||||
this.apsDecisionTableIndex = apsDecisionTableIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,7 +83,7 @@ public class ApsProcessJsonTranslator extends ApsOrganizationHandler implements
|
||||
|
||||
changed = this.translateResourceId(jsonDescriptor, processName, apsProcessId) || changed;
|
||||
changed = this.translateOrganizations(jsonDescriptor, processName) || changed;
|
||||
changed = this.translateForms(jsonDescriptor, processName) || changed;
|
||||
changed = this.translateResources(jsonDescriptor, processName) || changed;
|
||||
changed = this.translateSubprocesses(jsonDescriptor, processName) || changed;
|
||||
|
||||
if (changed)
|
||||
@@ -171,8 +175,8 @@ public class ApsProcessJsonTranslator extends ApsOrganizationHandler implements
|
||||
|
||||
|
||||
|
||||
private boolean translateForms(ObjectNode jsonDescriptor, String processName) {
|
||||
this.logger.trace("Translating forms in process: {}", processName);
|
||||
private boolean translateResources(ObjectNode jsonDescriptor, String processName) {
|
||||
this.logger.trace("Translating resources in process: {}", processName);
|
||||
boolean changed = false;
|
||||
|
||||
for (JsonNode jsonChildShape : this.getChildShapes(jsonDescriptor)) {
|
||||
@@ -182,6 +186,9 @@ public class ApsProcessJsonTranslator extends ApsOrganizationHandler implements
|
||||
|
||||
JsonNode jsonFormRef = (JsonNode)jsonChildShape.get("properties").get("formreference");
|
||||
changed = this.translateReference(jsonFormRef, this.apsFormIndex) || changed;
|
||||
|
||||
JsonNode jsonDecitionTableRef = (JsonNode)jsonChildShape.get("properties").get("decisiontaskdecisiontablereference");
|
||||
changed = this.translateReference(jsonDecitionTableRef, this.apsDecisionTableIndex) || changed;
|
||||
} catch (NullPointerException npe) {
|
||||
// suppress; gracefully skip
|
||||
}
|
||||
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.inteligr8.maven.aps.modeling.translator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.inteligr8.maven.aps.modeling.util.Index;
|
||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||
|
||||
/**
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
public class ApsResourceJsonTranslator implements ApsFileTranslator {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final Index<Long, String> apsResourceIndex;
|
||||
|
||||
/**
|
||||
* This constructor initializes the default translator.
|
||||
*
|
||||
* @param apsResourceIndex A map of resource IDs to resource names as defined in the APS Service.
|
||||
*/
|
||||
public ApsResourceJsonTranslator(Index<Long, String> apsResourceIndex) {
|
||||
this.apsResourceIndex = apsResourceIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateFile(File file, String formName, Long resourceId) throws IOException {
|
||||
this.logger.debug("Translating JSON file: {}", file);
|
||||
boolean changed = false;
|
||||
|
||||
ObjectNode jsonDescriptor = ModelUtil.getInstance().readJson(file, ObjectNode.class);
|
||||
JsonNode jsonResourceId = jsonDescriptor.get("resourceId");
|
||||
if (jsonResourceId == null || jsonResourceId.isNull()) {
|
||||
this.logger.debug("The resource has no ID to translate");
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.trace("Found ID {} in the '{}' APS resource descriptor", jsonResourceId, formName);
|
||||
|
||||
Long apsResourceId = this.apsResourceIndex.getFirstKey(formName);
|
||||
if (apsResourceId == null) {
|
||||
this.logger.debug("The resource '{}' does not exist in APS; leaving unchanged", formName);
|
||||
} else if (!resourceId.equals(apsResourceId)) {
|
||||
this.logger.debug("The resource '{}' exists in APS with ID {}; changing descriptor", formName, apsResourceId);
|
||||
jsonDescriptor.put("resourceId", apsResourceId);
|
||||
changed = true;
|
||||
} else {
|
||||
this.logger.trace("The resource '{}' ID does not change; leaving unchanged", formName, apsResourceId);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
ModelUtil.getInstance().writeJson(jsonDescriptor, file, false);
|
||||
}
|
||||
|
||||
}
|
@@ -21,7 +21,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.inteligr8.activiti.model.ResultList;
|
||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||
import com.inteligr8.alfresco.activiti.ApsProtectedRestApi;
|
||||
import com.inteligr8.alfresco.activiti.model.BaseTemplateLight;
|
||||
import com.inteligr8.alfresco.activiti.model.Tenant;
|
||||
import com.inteligr8.maven.aps.modeling.crawler.ApsFileTransformer;
|
||||
@@ -49,13 +49,13 @@ import com.inteligr8.maven.aps.modeling.util.Index;
|
||||
public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ApsTemplateTranslator.class);
|
||||
private final ApsPublicRestApi api;
|
||||
private final ApsProtectedRestApi api;
|
||||
|
||||
private boolean indexesBuilt = false;
|
||||
private Index<Long, String> apsDocumentTemplateIndex;
|
||||
private Index<Long, String> apsCustomEmailTemplateIndex;
|
||||
|
||||
public ApsTemplateTranslator(ApsPublicRestApi api) {
|
||||
public ApsTemplateTranslator(ApsProtectedRestApi api) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
||||
int perPage = 50;
|
||||
int page = 1;
|
||||
|
||||
ResultList<? extends BaseTemplateLight> templates = this.api.getTemplatesApi().getDocumentTemplates(null, (page-1)*perPage, perPage, null, tenantId);
|
||||
ResultList<? extends BaseTemplateLight> templates = this.api.getTemplatesApi().getDocumentTemplates(null, (page-1)*perPage, perPage, "sort_by_name_asc", tenantId);
|
||||
Index<Long, String> index = new Index<>(templates.getTotal() / 2, false);
|
||||
|
||||
while (!templates.getData().isEmpty()) {
|
||||
@@ -120,7 +120,7 @@ public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
||||
index.put(template.getId(), template.getName());
|
||||
|
||||
page++;
|
||||
templates = this.api.getTemplatesApi().getDocumentTemplates(null, (page-1)*perPage, perPage, null, tenantId);
|
||||
templates = this.api.getTemplatesApi().getDocumentTemplates(null, (page-1)*perPage, perPage, "sort_by_name_asc", tenantId);
|
||||
}
|
||||
|
||||
return index;
|
||||
@@ -130,7 +130,7 @@ public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
||||
int perPage = 50;
|
||||
int page = 1;
|
||||
|
||||
ResultList<? extends BaseTemplateLight> templates = this.api.getTemplatesApi().getCustomEmailTemplates(null, (page-1)*perPage, perPage, null, tenantId);
|
||||
ResultList<? extends BaseTemplateLight> templates = this.api.getTemplatesApi().getCustomEmailTemplates(null, (page-1)*perPage, perPage, "sort_by_name_asc", tenantId);
|
||||
Index<Long, String> index = new Index<>(templates.getTotal() / 2, false);
|
||||
|
||||
while (!templates.getData().isEmpty()) {
|
||||
@@ -140,7 +140,7 @@ public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
||||
index.put(template.getId(), template.getName());
|
||||
|
||||
page++;
|
||||
templates = this.api.getTemplatesApi().getCustomEmailTemplates(null, (page-1)*perPage, perPage, null, tenantId);
|
||||
templates = this.api.getTemplatesApi().getCustomEmailTemplates(null, (page-1)*perPage, perPage, "sort_by_name_asc", tenantId);
|
||||
}
|
||||
|
||||
return index;
|
||||
|
Reference in New Issue
Block a user