Il componente Assegna attività viene utilizzato per assegnare le attività ai partecipanti del flusso di lavoro. Quando un’attività viene assegnata a un utente o a un gruppo, viene inviata una notifica e-mail all’utente o ai membri del gruppo definiti.
Questa notifica di posta elettronica contiene in genere dati dinamici relativi all'attività. Questi dati dinamici vengono recuperati utilizzando il sistema generato proprietà dei metadati.
Per includere i valori dei dati del modulo inviati nella notifica e-mail, è necessario creare una proprietà di metadati personalizzata e quindi utilizzare queste proprietà di metadati personalizzate nel modello e-mail
L’approccio consigliato è quello di creare un componente OSGI che implementa il metodo getUserMetadata del WorkitemUserMetadataService
Il codice seguente crea 4 proprietà di metadati(firstName,lastName,motivo e amountRequested) e imposta il relativo valore dai dati inviati. Ad esempio, la proprietà metadata firstName Il valore di è impostato sul valore dell'elemento denominato firstName dai dati inviati. Il codice seguente presuppone che i dati inviati del modulo adattivo siano in formato xml. Forms adattivo basato su schema JSON o modello dati modulo genera dati in formato JSON.
package com.aemforms.workitemuserservice.core;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Session;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.*;
import com.adobe.fd.workspace.service.external.WorkitemUserMetadataService;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
@Component(property={Constants.SERVICE_DESCRIPTION+"=A sample implementation of a user metadata service.",
Constants.SERVICE_VENDOR+"=Adobe Systems",
"process.label"+"=Sample Custom Metadata Service"})
public class WorkItemUserServiceImpl implements WorkitemUserMetadataService {
private static final Logger log = LoggerFactory.getLogger(WorkItemUserServiceImpl.class);
@Override
public Map<String, String> getUserMetadata(WorkItem workItem, WorkflowSession workflowSession,MetaDataMap metadataMap)
{
HashMap<String, String> customMetadataMap = new HashMap<String, String>();
String payloadPath = workItem.getWorkflowData().getPayload().toString();
String dataFilePath = payloadPath + "/Data.xml/jcr:content";
Session session = workflowSession.adaptTo(Session.class);
DocumentBuilderFactory factory = null;
DocumentBuilder builder = null;
Document xmlDocument = null;
javax.jcr.Node xmlDataNode = null;
try
{
xmlDataNode = session.getNode(dataFilePath);
InputStream xmlDataStream = xmlDataNode.getProperty("jcr:data").getBinary().getStream();
XPath xPath = javax.xml.xpath.XPathFactory.newInstance().newXPath();
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
xmlDocument = builder.parse(xmlDataStream);
Node firstNameNode = (org.w3c.dom.Node) xPath.compile("afData/afUnboundData/data/firstName")
.evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODE);
log.debug("The value of first name element is " + firstNameNode.getTextContent());
Node lastNameNode = (org.w3c.dom.Node) xPath.compile("afData/afUnboundData/data/lastName")
.evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODE);
Node amountRequested = (org.w3c.dom.Node) xPath
.compile("afData/afUnboundData/data/amountRequested")
.evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODE);
Node reason = (org.w3c.dom.Node) xPath.compile("afData/afUnboundData/data/reason")
.evaluate(xmlDocument, javax.xml.xpath.XPathConstants.NODE);
customMetadataMap.put("firstName", firstNameNode.getTextContent());
customMetadataMap.put("lastName", lastNameNode.getTextContent());
customMetadataMap.put("amountRequested", amountRequested.getTextContent());
customMetadataMap.put("reason", reason.getTextContent());
log.debug("Created " + customMetadataMap.size() + " metadata properties");
}
catch (Exception e)
{
log.debug(e.getMessage());
}
return customMetadataMap;
}
}
Nel modello e-mail puoi includere la proprietà dei metadati utilizzando la seguente sintassi dove amountRequested è la proprietà dei metadati ${amountRequested}
Dopo aver generato e distribuito il componente OSGi AEM server, configura il componente Assegna attività come mostrato di seguito per utilizzare le proprietà dei metadati personalizzate.
Al momento dell’invio del modulo, la notifica di assegnazione dell’attività viene inviata all’ID e-mail associato all’utente amministratore. La schermata seguente mostra un esempio di notifica di assegnazione delle attività
Il modello e-mail per la notifica dell’attività di assegnazione deve essere nel seguente formato.
subject=Task assegnato - ${workitem_title}
message=String che rappresenta il modello e-mail senza nuovi caratteri di riga.
In alcuni casi, è possibile includere i commenti del proprietario dell'attività precedente nelle notifiche successive. Il codice per acquisire l'ultimo commento dell'attività è elencato di seguito:
package samples.aemforms.taskcomments.core;
import org.osgi.service.component.annotations.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jcr.Session;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.HistoryItem;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.adobe.fd.workspace.service.external.WorkitemUserMetadataService;
@Component(property = {
Constants.SERVICE_DESCRIPTION + "=A sample implementation of a user metadata service.",
Constants.SERVICE_VENDOR + "=Adobe Systems",
"process.label" + "=Capture Workflow Comments"
})
public class CaptureTaskComments implements WorkitemUserMetadataService {
private static final Logger log = LoggerFactory.getLogger(CaptureTaskComments.class);
@Override
public Map <String, String> getUserMetadata(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metadataMap) {
HashMap < String, String > customMetadataMap = new HashMap < String, String > ();
workflowSession.adaptTo(Session.class);
try {
List <HistoryItem> workItemsHistory = workflowSession.getHistory(workItem.getWorkflow());
int listSize = workItemsHistory.size();
HistoryItem lastItem = workItemsHistory.get(listSize - 1);
String reviewerComments = (String) lastItem.getWorkItem().getMetaDataMap().get("workitemComment");
log.debug("####The comment I got was ...." + reviewerComments);
customMetadataMap.put("comments", reviewerComments);
log.debug("Created " + customMetadataMap.size() + " metadata properties");
} catch (Exception e) {
log.debug(e.getMessage());
}
return customMetadataMap;
}
}
Il bundle con il codice di cui sopra può essere scaricato da qui