fixed template handling
This commit is contained in:
parent
b974bc8f5c
commit
98c01db50d
2
pom.xml
2
pom.xml
@ -51,7 +51,7 @@
|
||||
<dependency>
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
<artifactId>aps-public-rest-api</artifactId>
|
||||
<version>2.0.14</version>
|
||||
<version>2.0.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inteligr8.alfresco</groupId>
|
||||
|
@ -66,30 +66,38 @@ 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().getId() + ".doc-template.docx");
|
||||
|
||||
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");
|
||||
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);
|
||||
|
@ -30,6 +30,7 @@ import org.codehaus.plexus.component.annotations.Component;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.inteligr8.alfresco.activiti.model.DocumentTemplateLight;
|
||||
import com.inteligr8.alfresco.activiti.model.EmailTemplate;
|
||||
import com.inteligr8.alfresco.activiti.model.EmailTemplateLight;
|
||||
import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
|
||||
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
|
||||
|
||||
@ -50,6 +51,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;
|
||||
|
||||
@ -68,6 +75,13 @@ public class UploadTemplateGoal extends ApsAddressibleGoal {
|
||||
try {
|
||||
if (file.getName().endsWith(".doc-template.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())
|
||||
@ -78,9 +92,19 @@ public class UploadTemplateGoal extends ApsAddressibleGoal {
|
||||
try {
|
||||
FileMultipartJersey multipart = FileMultipartJersey.from(docxfile.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();
|
||||
@ -88,14 +112,45 @@ public class UploadTemplateGoal extends ApsAddressibleGoal {
|
||||
}
|
||||
} else if (file.getName().endsWith(".custom-email-template.json")) {
|
||||
EmailTemplate template = ModelUtil.getInstance().writePojo(ModelUtil.getInstance().readJsonAsMap(file), EmailTemplate.class);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (template.getId() == null) {
|
||||
this.getApsApi().getTemplatesJerseyApi().createCustomEmailTemplate(template);
|
||||
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 {
|
||||
this.getApsApi().getTemplatesJerseyApi().updateCustomEmailTemplate(template.getId(), template);
|
||||
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(".system-email-template.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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user