Create DDX from the attachment names
We then need to create Document Description XML (DDX) document which is used by the Assembler service to assemble documents. The following is the DDX that was created from the process arguments. The NoForms element allows you to flatten XFA based documents before they are assembled. Notice the PDF source elements are in the right order as specified in the process arguments.
Create map of documents
We then create a map of documents with the attachment name as the key and the attachment as the value. Query builder service was used to query the attachments under the payload path and build the map of documents. This map of document along with the DDX is needed for the assembler service to assemble the final pdf.
public Map<String, Object> createMapOfDocuments(String payloadPath,WorkflowSession workflowSession )
{
Map<String, String> queryMap = new HashMap<String, String>();
Map<String,Object>mapOfDocuments = new HashMap<String,Object>();
queryMap.put("type", "nt:file");
queryMap.put("path",payloadPath);
Query query = queryBuilder.createQuery(PredicateGroup.create(queryMap),workflowSession.adaptTo(Session.class));
query.setStart(0);
query.setHitsPerPage(30);
SearchResult result = query.getResult();
log.debug("Get result hits "+result.getHits().size());
for (Hit hit : result.getHits()) {
try {
String path = hit.getPath();
log.debug("The title "+hit.getTitle()+" path "+path);
if(hit.getTitle().endsWith("pdf"))
{
com.adobe.aemfd.docmanager.Document attachmentDocument = new com.adobe.aemfd.docmanager.Document(path);
mapOfDocuments.put(hit.getTitle(),attachmentDocument);
log.debug("@@@@Added to map@@@@@ "+hit.getTitle());
}
}
catch (Exception e)
{
log.debug(e.getMessage());
}
}
return mapOfDocuments;
}