Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
2d89466813 | |||
a856f9580b | |||
9e62c994ec | |||
6041898be3 | |||
0b9473465e | |||
a65a6df1f8 | |||
98c01db50d | |||
b974bc8f5c |
4
pom.xml
4
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.inteligr8.alfresco</groupId>
|
<groupId>com.inteligr8.alfresco</groupId>
|
||||||
<artifactId>aps-model-maven-plugin</artifactId>
|
<artifactId>aps-model-maven-plugin</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.4.1</version>
|
||||||
<packaging>maven-plugin</packaging>
|
<packaging>maven-plugin</packaging>
|
||||||
|
|
||||||
<name>A Maven plugin for Alfresco Process Services model portability</name>
|
<name>A Maven plugin for Alfresco Process Services model portability</name>
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.inteligr8.alfresco</groupId>
|
<groupId>com.inteligr8.alfresco</groupId>
|
||||||
<artifactId>aps-public-rest-api</artifactId>
|
<artifactId>aps-public-rest-api</artifactId>
|
||||||
<version>2.0.14</version>
|
<version>2.0.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.inteligr8.alfresco</groupId>
|
<groupId>com.inteligr8.alfresco</groupId>
|
||||||
|
@@ -22,8 +22,10 @@ import org.apache.maven.plugin.MojoExecutionException;
|
|||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
|
|
||||||
import com.inteligr8.activiti.model.Datum;
|
import com.inteligr8.activiti.model.Datum;
|
||||||
|
import com.inteligr8.activiti.model.ResultList;
|
||||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||||
import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
|
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.ResultListDataRepresentation;
|
||||||
import com.inteligr8.alfresco.activiti.model.Tenant;
|
import com.inteligr8.alfresco.activiti.model.Tenant;
|
||||||
|
|
||||||
@@ -58,24 +60,23 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method makes the appropriate service calls to find all the APS
|
* 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.
|
* 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.
|
||||||
*/
|
*/
|
||||||
protected Map<String, Long> findAppNameIds() {
|
protected Map<String, ModelRepresentation> buildAppNameMap() {
|
||||||
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
ApsPublicRestApiJerseyImpl 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");
|
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");
|
this.getLog().debug("Found " + results.getTotal() + " APS Apps");
|
||||||
for (Datum datum : results.getData()) {
|
for (ModelRepresentation model : results.getData()) {
|
||||||
String name = (String)datum.getAdditionalProperties().get("name");
|
String name = model.getName();
|
||||||
Number id = (Number)datum.getAdditionalProperties().get("id");
|
apps.put(name, model);
|
||||||
apps.put(name, id.longValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return apps;
|
return apps;
|
||||||
@@ -88,11 +89,11 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal {
|
|||||||
* This method does not cache the result.
|
* This method does not cache the result.
|
||||||
*
|
*
|
||||||
* @param failOnNotFound true to fail if not found; false to return null.
|
* @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.
|
* @throws MojoExecutionException The APS App could not be found.
|
||||||
*/
|
*/
|
||||||
protected Long findAppId(boolean failOnNotFound) throws MojoExecutionException {
|
protected ModelRepresentation findAppModel(boolean failOnNotFound) throws MojoExecutionException {
|
||||||
return this.findAppIdByName(this.apsAppName, failOnNotFound);
|
return this.findAppModelByName(this.apsAppName, failOnNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,15 +104,15 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal {
|
|||||||
*
|
*
|
||||||
* @param apsName An APS App name.
|
* @param apsName An APS App name.
|
||||||
* @param failOnNotFound true to fail if not found; false to return null.
|
* @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.
|
* @throws MojoExecutionException The APS App could not be found.
|
||||||
*/
|
*/
|
||||||
protected Long findAppIdByName(String appName, boolean failOnNotFound) throws MojoExecutionException {
|
protected ModelRepresentation findAppModelByName(String appName, boolean failOnNotFound) throws MojoExecutionException {
|
||||||
Map<String, Long> apps = this.findAppNameIds();
|
Map<String, ModelRepresentation> apps = this.buildAppNameMap();
|
||||||
Long appId = apps.get(this.apsAppName);
|
ModelRepresentation appModel = apps.get(this.apsAppName);
|
||||||
if (failOnNotFound && appId == null)
|
if (failOnNotFound && appModel == null)
|
||||||
throw new MojoExecutionException("The APS App '" + this.apsAppName + "' could not be found; valid apps: " + apps.keySet());
|
throw new MojoExecutionException("The APS App '" + this.apsAppName + "' could not be found; valid apps: " + apps.keySet());
|
||||||
return appId;
|
return appModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import com.inteligr8.activiti.model.Datum;
|
|||||||
import com.inteligr8.activiti.model.ResultList;
|
import com.inteligr8.activiti.model.ResultList;
|
||||||
import com.inteligr8.alfresco.activiti.api.ModelsApi;
|
import com.inteligr8.alfresco.activiti.api.ModelsApi;
|
||||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
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.PermissionLevel;
|
||||||
import com.inteligr8.alfresco.activiti.model.PermissionLight;
|
import com.inteligr8.alfresco.activiti.model.PermissionLight;
|
||||||
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
|
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
|
||||||
@@ -108,14 +109,12 @@ public class ApsShareGoal extends ApsAddressibleGoal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void shareModels(ModelsApi.ModelType modelType, Set<String> readers, Set<String> editors) {
|
private void shareModels(ModelsApi.ModelType modelType, Set<String> readers, Set<String> editors) {
|
||||||
ResultListDataRepresentation<Datum> models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null);
|
ResultList<ModelRepresentation> models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null);
|
||||||
if (models.getData() == null)
|
if (models.getData() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (Datum datum : models.getData()) {
|
for (ModelRepresentation model : models.getData()) {
|
||||||
Number modelId = (Number)datum.getAdditionalProperties().get("id");
|
if (this.modelName != null && !this.modelName.equals(model.getName()))
|
||||||
String modelName = (String)datum.getAdditionalProperties().get("name");
|
|
||||||
if (this.modelName != null && !this.modelName.equals(modelName))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Set<String> groupsAddressed = new HashSet<>();
|
Set<String> groupsAddressed = new HashSet<>();
|
||||||
@@ -123,7 +122,7 @@ public class ApsShareGoal extends ApsAddressibleGoal {
|
|||||||
Set<String> editorsUnaddressed = new HashSet<>(editors);
|
Set<String> editorsUnaddressed = new HashSet<>(editors);
|
||||||
ShareInfoRequest changeRequest = new ShareInfoRequest();
|
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) {
|
if (shares.getData() != null) {
|
||||||
for (SharePermission share : shares.getData()) {
|
for (SharePermission share : shares.getData()) {
|
||||||
if (share.getGroup() != null) {
|
if (share.getGroup() != null) {
|
||||||
@@ -145,7 +144,7 @@ public class ApsShareGoal extends ApsAddressibleGoal {
|
|||||||
|
|
||||||
if (!changeRequest.getAdded().isEmpty() || !changeRequest.getUpdated().isEmpty() || !changeRequest.getRemoved().isEmpty()) {
|
if (!changeRequest.getAdded().isEmpty() || !changeRequest.getUpdated().isEmpty() || !changeRequest.getRemoved().isEmpty()) {
|
||||||
this.getLog().info("Sharing model: " + modelType + " => '" + modelName + "'");
|
this.getLog().info("Sharing model: " + modelType + " => '" + modelName + "'");
|
||||||
this.getApsApi().getShareApi().setShareInfo(modelId.toString(), changeRequest);
|
this.getApsApi().getShareApi().setShareInfo(model.getId().toString(), changeRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -102,7 +102,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
|||||||
int pageSize = 50;
|
int pageSize = 50;
|
||||||
int page = 1;
|
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()) {
|
while (!templates.getData().isEmpty()) {
|
||||||
for (EmailTemplateLight template : templates.getData()) {
|
for (EmailTemplateLight template : templates.getData()) {
|
||||||
for (Pattern pattern : matchingPatterns) {
|
for (Pattern pattern : matchingPatterns) {
|
||||||
@@ -112,7 +112,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
page++;
|
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());
|
this.getLog().debug("Found APS Custom Email Templates: " + map.size());
|
||||||
@@ -126,7 +126,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
|||||||
int pageSize = 50;
|
int pageSize = 50;
|
||||||
int page = 1;
|
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()) {
|
while (!templates.getData().isEmpty()) {
|
||||||
for (DocumentTemplateLight template : templates.getData()) {
|
for (DocumentTemplateLight template : templates.getData()) {
|
||||||
for (Pattern pattern : matchingPatterns) {
|
for (Pattern pattern : matchingPatterns) {
|
||||||
@@ -136,7 +136,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
page++;
|
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());
|
this.getLog().debug("Found APS Document Templates: " + map.size());
|
||||||
|
@@ -46,7 +46,7 @@ public class DownloadAppGoal extends ApsAppAddressibleGoal {
|
|||||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||||
this.validateTargetDirectory();
|
this.validateTargetDirectory();
|
||||||
|
|
||||||
Long appId = this.findAppId(true);
|
Long appId = this.findAppModel(true).getId();
|
||||||
File appZip = this.downloadApp(appId);
|
File appZip = this.downloadApp(appId);
|
||||||
|
|
||||||
File toAppZip = new File(this.zipDirectory, this.apsAppName + ".zip");
|
File toAppZip = new File(this.zipDirectory, this.apsAppName + ".zip");
|
||||||
|
@@ -66,35 +66,43 @@ public class DownloadTemplateGoal extends ApsTemplateAddressibleGoal {
|
|||||||
try {
|
try {
|
||||||
Map<TemplateType, Map<String, ? extends BaseTemplateLight>> templates = this.findTemplates(tenantId);
|
Map<TemplateType, Map<String, ? extends BaseTemplateLight>> templates = this.findTemplates(tenantId);
|
||||||
for (TemplateType ttype : templates.keySet()) {
|
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()) {
|
for (Entry<String, ? extends BaseTemplateLight> template : templates.get(ttype).entrySet()) {
|
||||||
switch (ttype) {
|
switch (ttype) {
|
||||||
case Document:
|
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());
|
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);
|
ModelUtil.getInstance().writeJson(djson, dfile, this.diffFriendly);
|
||||||
if (this.normalize)
|
if (this.normalize)
|
||||||
new ApsTemplateJsonNormalizer(this.diffFriendly).normalizeFile(dfile, null);
|
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;
|
break;
|
||||||
case CustomEmail:
|
case CustomEmail:
|
||||||
EmailTemplate etemplate = this.getApsApi().getTemplatesApi().getCustomEmailTemplate(template.getValue().getId(), tenantId);
|
EmailTemplate etemplate = this.getApsApi().getTemplatesApi().getCustomEmailTemplate(template.getValue().getId(), tenantId);
|
||||||
ObjectNode ejson = ModelUtil.getInstance().readPojo(etemplate);
|
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);
|
ModelUtil.getInstance().writeJson(ejson, efile, this.diffFriendly);
|
||||||
if (this.normalize)
|
if (this.normalize)
|
||||||
new ApsTemplateJsonNormalizer(this.diffFriendly).normalizeFile(efile, null);
|
new ApsTemplateJsonNormalizer(this.diffFriendly).normalizeFile(efile, null);
|
||||||
@@ -103,7 +111,7 @@ public class DownloadTemplateGoal extends ApsTemplateAddressibleGoal {
|
|||||||
case SystemEmail:
|
case SystemEmail:
|
||||||
EmailTemplate stemplate = this.getApsApi().getTemplatesApi().getSystemEmailTemplate(template.getValue().getName(), tenantId);
|
EmailTemplate stemplate = this.getApsApi().getTemplatesApi().getSystemEmailTemplate(template.getValue().getName(), tenantId);
|
||||||
ObjectNode sjson = ModelUtil.getInstance().readPojo(stemplate);
|
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);
|
ModelUtil.getInstance().writeJson(sjson, sfile, this.diffFriendly);
|
||||||
if (this.normalize)
|
if (this.normalize)
|
||||||
new ApsTemplateJsonNormalizer(this.diffFriendly).normalizeFile(sfile, null);
|
new ApsTemplateJsonNormalizer(this.diffFriendly).normalizeFile(sfile, null);
|
||||||
|
@@ -39,10 +39,13 @@ public class PublishAppGoal extends ApsAppAddressibleGoal {
|
|||||||
|
|
||||||
@Parameter( property = "aps-model.publish.comment", required = true, defaultValue = "Automated by 'aps-model-maven-plugin'" )
|
@Parameter( property = "aps-model.publish.comment", required = true, defaultValue = "Automated by 'aps-model-maven-plugin'" )
|
||||||
protected String comment;
|
protected String comment;
|
||||||
|
|
||||||
|
@Parameter( property = "aps-model.dryRun", required = true, defaultValue = "false" )
|
||||||
|
protected boolean dryRun;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||||
Long appId = this.findAppId(false);
|
Long appId = this.findAppModel(false).getId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.publishApp(appId);
|
this.publishApp(appId);
|
||||||
@@ -56,7 +59,12 @@ public class PublishAppGoal extends ApsAppAddressibleGoal {
|
|||||||
|
|
||||||
AppDefinitionPublishRepresentation appDefPublish = new AppDefinitionPublishRepresentation();
|
AppDefinitionPublishRepresentation appDefPublish = new AppDefinitionPublishRepresentation();
|
||||||
appDefPublish.setComment(this.comment);
|
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);
|
||||||
|
api.getAppDefinitionsApi().publish(appId, appDefPublish);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,7 @@ import org.codehaus.plexus.component.annotations.Component;
|
|||||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
|
||||||
import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation;
|
import com.inteligr8.alfresco.activiti.model.AppDefinitionUpdateResultRepresentation;
|
||||||
import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
|
import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
|
||||||
|
import com.inteligr8.alfresco.activiti.model.ModelRepresentation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that implements an APS service upload goal.
|
* A class that implements an APS service upload goal.
|
||||||
@@ -49,6 +50,9 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
|
|||||||
|
|
||||||
@Parameter( property = "publish", required = true, defaultValue = "false" )
|
@Parameter( property = "publish", required = true, defaultValue = "false" )
|
||||||
protected boolean publish = false;
|
protected boolean publish = false;
|
||||||
|
|
||||||
|
@Parameter( property = "aps-model.dryRun", required = true, defaultValue = "false" )
|
||||||
|
protected boolean dryRun;
|
||||||
|
|
||||||
protected final int bufferSize = 128 * 1024;
|
protected final int bufferSize = 128 * 1024;
|
||||||
|
|
||||||
@@ -56,10 +60,10 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
|
|||||||
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
public void executeEnabled() throws MojoExecutionException, MojoFailureException {
|
||||||
File sourceFile = this.validateSourceDirectory();
|
File sourceFile = this.validateSourceDirectory();
|
||||||
|
|
||||||
Long appId = this.findAppId(false);
|
ModelRepresentation appModel = this.findAppModel(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.uploadApp(appId, sourceFile);
|
this.uploadApp(appModel, sourceFile);
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
throw new MojoExecutionException("The APS App could not be uploaded", ie);
|
throw new MojoExecutionException("The APS App could not be uploaded", ie);
|
||||||
}
|
}
|
||||||
@@ -83,7 +87,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
|
|||||||
return sourceFile;
|
return sourceFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uploadApp(Long appId, File appZip) throws IOException, MojoExecutionException {
|
private void uploadApp(ModelRepresentation appModel, File appZip) throws IOException, MojoExecutionException {
|
||||||
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
ApsPublicRestApiJerseyImpl api = this.getApsApi();
|
||||||
|
|
||||||
FileInputStream fistream = new FileInputStream(appZip);
|
FileInputStream fistream = new FileInputStream(appZip);
|
||||||
@@ -91,25 +95,41 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
|
|||||||
try {
|
try {
|
||||||
FileMultipartJersey multipart = FileMultipartJersey.from(appZip.getName(), bistream);
|
FileMultipartJersey multipart = FileMultipartJersey.from(appZip.getName(), bistream);
|
||||||
|
|
||||||
if (appId == null) {
|
if (appModel == null) {
|
||||||
if (this.publish) {
|
if (this.publish) {
|
||||||
this.getLog().info("Uploading & publishing new APS App: " + this.apsAppName);
|
if (this.dryRun) {
|
||||||
AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(multipart);
|
this.getLog().info("[DRYRUN]: Uploading & publishing new APS App: " + this.apsAppName);
|
||||||
if (Boolean.TRUE.equals(appDefUpdate.getError()))
|
} else {
|
||||||
throw new MojoExecutionException(appDefUpdate.getErrorDescription());
|
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());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.getLog().info("Uploading new APS App: " + this.apsAppName);
|
if (this.dryRun) {
|
||||||
api.getAppDefinitionsJerseyApi().importApp(multipart, true);
|
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 {
|
} else {
|
||||||
if (this.publish) {
|
if (this.publish) {
|
||||||
this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appId + ")");
|
if (this.dryRun) {
|
||||||
AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appId, multipart);
|
this.getLog().info("[DRYRUN]: Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appModel.getId() + ")");
|
||||||
if (Boolean.TRUE.equals(appDefUpdate.getError()))
|
} else {
|
||||||
throw new MojoExecutionException(appDefUpdate.getErrorDescription());
|
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());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.getLog().info("Uploading & versioning APS App: " + this.apsAppName + " (" + appId + ")");
|
if (this.dryRun) {
|
||||||
api.getAppDefinitionsJerseyApi().importApp(appId, multipart, true);
|
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) {
|
} catch (ParseException pe) {
|
||||||
|
@@ -30,6 +30,7 @@ import org.codehaus.plexus.component.annotations.Component;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.inteligr8.alfresco.activiti.model.DocumentTemplateLight;
|
import com.inteligr8.alfresco.activiti.model.DocumentTemplateLight;
|
||||||
import com.inteligr8.alfresco.activiti.model.EmailTemplate;
|
import com.inteligr8.alfresco.activiti.model.EmailTemplate;
|
||||||
|
import com.inteligr8.alfresco.activiti.model.EmailTemplateLight;
|
||||||
import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
|
import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
|
||||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||||
|
|
||||||
@@ -50,6 +51,12 @@ public class UploadTemplateGoal extends ApsAddressibleGoal {
|
|||||||
|
|
||||||
@Parameter( property = "aps-model.upload.directory", required = true, defaultValue = "${project.build.directory}/aps" )
|
@Parameter( property = "aps-model.upload.directory", required = true, defaultValue = "${project.build.directory}/aps" )
|
||||||
protected File templateDirectory;
|
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;
|
protected final int bufferSize = 128 * 1024;
|
||||||
|
|
||||||
@@ -66,36 +73,84 @@ public class UploadTemplateGoal extends ApsAddressibleGoal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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);
|
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");
|
File dfile = new File(file.getParent(), file.getName().substring(0, file.getName().length() - ".dt.json".length()));
|
||||||
if (!docxfile.exists())
|
if (!dfile.exists())
|
||||||
throw new FileNotFoundException("The file, '" + docxfile.getName() + "' was expected and not found");
|
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);
|
BufferedInputStream bistream = new BufferedInputStream(fistream, this.bufferSize);
|
||||||
try {
|
try {
|
||||||
FileMultipartJersey multipart = FileMultipartJersey.from(docxfile.getName(), bistream);
|
FileMultipartJersey multipart = FileMultipartJersey.from(dfile.getName(), bistream);
|
||||||
if (template.getId() == null) {
|
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 {
|
} 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 {
|
} finally {
|
||||||
bistream.close();
|
bistream.close();
|
||||||
fistream.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);
|
EmailTemplate template = ModelUtil.getInstance().writePojo(ModelUtil.getInstance().readJsonAsMap(file), EmailTemplate.class);
|
||||||
if (template.getId() == null) {
|
if (!this.alwaysOverwrite && template.getId() != null && template.getCreated() != null) {
|
||||||
this.getApsApi().getTemplatesJerseyApi().createCustomEmailTemplate(template);
|
EmailTemplate serverSideTemplate = this.getApsApi().getTemplatesApi().getCustomEmailTemplate(template.getId(), tenantId);
|
||||||
} else {
|
if (serverSideTemplate != null && !serverSideTemplate.getCreated().isBefore(template.getCreated())) {
|
||||||
this.getApsApi().getTemplatesJerseyApi().updateCustomEmailTemplate(template.getId(), template);
|
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);
|
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) {
|
} catch (JsonProcessingException jpe) {
|
||||||
throw new MojoExecutionException("The APS templates JSON files could not be parsed", jpe);
|
throw new MojoExecutionException("The APS templates JSON files could not be parsed", jpe);
|
||||||
|
@@ -27,7 +27,7 @@ import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
|||||||
/**
|
/**
|
||||||
* This class implements an APS template JSON configuration file normalizer.
|
* 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
|
* @author brian@inteligr8.com
|
||||||
*/
|
*/
|
||||||
@@ -66,7 +66,7 @@ public class ApsTemplateJsonNormalizer implements ApsFileNormalizer {
|
|||||||
this.logger.trace("Removing excess template meta-data: {}", jsonModel.get("name"));
|
this.logger.trace("Removing excess template meta-data: {}", jsonModel.get("name"));
|
||||||
|
|
||||||
int fields = jsonModel.size();
|
int fields = jsonModel.size();
|
||||||
jsonModel.remove(Arrays.asList("created", "createdBy"));
|
jsonModel.remove(Arrays.asList("createdBy"));
|
||||||
return jsonModel.size() < fields;
|
return jsonModel.size() < fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,9 +27,11 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.inteligr8.activiti.model.Datum;
|
import com.inteligr8.activiti.model.Datum;
|
||||||
|
import com.inteligr8.activiti.model.ResultList;
|
||||||
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
import com.inteligr8.alfresco.activiti.ApsPublicRestApi;
|
||||||
import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
|
import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
|
||||||
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
import com.inteligr8.alfresco.activiti.model.GroupLight;
|
||||||
|
import com.inteligr8.alfresco.activiti.model.ModelRepresentation;
|
||||||
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
|
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
|
||||||
import com.inteligr8.alfresco.activiti.model.Tenant;
|
import com.inteligr8.alfresco.activiti.model.Tenant;
|
||||||
import com.inteligr8.maven.aps.modeling.crawler.ApsAppCrawlable;
|
import com.inteligr8.maven.aps.modeling.crawler.ApsAppCrawlable;
|
||||||
@@ -196,18 +198,15 @@ public class ApsAppTranslator implements ApsAppCrawlable {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected Index<Long, String> buildApsModelIndex(ModelType modelType) {
|
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());
|
this.logger.debug("APS {} models found: {} out of {}", modelType, results.getSize(), results.getTotal());
|
||||||
|
|
||||||
Index<Long, String> map = new Index<>(results.getSize().intValue(), false);
|
Index<Long, String> map = new Index<>(results.getSize().intValue(), false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (Datum datum : results.getData()) {
|
for (ModelRepresentation model : results.getData()) {
|
||||||
Number defId = (Number)datum.getAdditionalProperties().get("id");
|
map.put(model.getId(), model.getName());
|
||||||
String defName = (String)datum.getAdditionalProperties().get("name");
|
|
||||||
map.put(defId.longValue(), defName);
|
|
||||||
|
|
||||||
// FIXME add paging support
|
// FIXME add paging support
|
||||||
}
|
}
|
||||||
|
@@ -110,7 +110,7 @@ public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
|||||||
int perPage = 50;
|
int perPage = 50;
|
||||||
int page = 1;
|
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);
|
Index<Long, String> index = new Index<>(templates.getTotal() / 2, false);
|
||||||
|
|
||||||
while (!templates.getData().isEmpty()) {
|
while (!templates.getData().isEmpty()) {
|
||||||
@@ -120,7 +120,7 @@ public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
|||||||
index.put(template.getId(), template.getName());
|
index.put(template.getId(), template.getName());
|
||||||
|
|
||||||
page++;
|
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;
|
return index;
|
||||||
@@ -130,7 +130,7 @@ public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
|||||||
int perPage = 50;
|
int perPage = 50;
|
||||||
int page = 1;
|
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);
|
Index<Long, String> index = new Index<>(templates.getTotal() / 2, false);
|
||||||
|
|
||||||
while (!templates.getData().isEmpty()) {
|
while (!templates.getData().isEmpty()) {
|
||||||
@@ -140,7 +140,7 @@ public class ApsTemplateTranslator implements ApsTemplateCrawlable {
|
|||||||
index.put(template.getId(), template.getName());
|
index.put(template.getId(), template.getName());
|
||||||
|
|
||||||
page++;
|
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;
|
return index;
|
||||||
|
Reference in New Issue
Block a user