How to trigger a Process from APS when an E-mail comes to ACS ?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member II

How to trigger a Process from APS when an E-mail comes to ACS ?

I have created a Process for Alfresco Process Service and now I want to trigger it from Alfresco Content Service when, an E-mail comes to Alfresco Content Service, how it's possible?

22 Replies
Highlighted
Master

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

When an email arrives at ACS (i.e. "is filed as a document") you can have a custom behaviour (which you implemented using Java APIs) fire and call APS via its REST API to trigger your custom process.

Highlighted
Active Member II

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

Thank you for the reply!.
can you please tell me which behavior I supposed to use in my case? 

Highlighted
Master

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

onCreateNode sounds about right when you want to start it as soon as the document / email has been filed.

Highlighted
Active Member II

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

Thank you!!
but while getting Process definition from activiti webscript by the following call:

GET /alfresco/service/activiti/server/{token1} 
It shows: 


What is token1 here?

Highlighted
Master

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

I don't really understand why you would be calling that webscript... That webscript is a backend for APS to call, and I thought you wanted to trigger an APS process from ACS, so you'd have to do call in the exact opposite direction. Also, that webscript is likely part of the Enterprise-only ACS / APS connector used for some internal handling, and as such is not supposed to be called from custom code (I mean, the response message states it hasn't been whitelisted).

For calling APS from ACS, take a look at the Alfresco Process Services ReST API documentation.

Highlighted
Active Member II

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

Thank you!

Now I am using already defined method  from  com.activiti.alfresco.service.ActivitiService  Interface which is :

"public void startProcessById(String processId, String processName, Map<String, Object> formValues, ActivitiService.DocumentContext documentContext)"
but I  have no idea about  "ActivitiService.DocumentContext documentContext" Parameter and how to pass "formValues" parameter as

Map<String, Object> in startProcessById() method ?

Could you please guide me, how to use those Parameters in my custom Behaviour?

 

Highlighted
Active Member II

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

Hi,

I have written following code to trigger the process, Please have a look!

private Behaviour onCreateNode;

public void init() {
this.onCreateNode = new JavaBehaviour(this, "onCreateNode", NotificationFrequency.TRANSACTION_COMMIT);

this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), ContentModel.TYPE_CONTENT, this.onCreateNode);
}


public void onCreateNode(ChildAssociationRef childasso) {
NodeRef node=childasso.getChildRef();

DocumentContext documentContext= new DocumentContext(node,"formFieldId");
Map<String, Object> formValues = new HashMap<String, Object>();

formValues.put(key,value);

try {
public void startProcessById(String processId, String processName, Map<String, Object> formValues, ActivitiService.DocumentContext documentContext)
  } catch (RemoteActivitiException | ActivitiAuthenticationException e) {
    e.printStackTrace();
    }


 but while executing it in Maven it shows me that: Package does not exist but I have uploaded the Package. 

Thank you!

Highlighted
Master

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

Can you please provide the full class code as an attachment or in a syntax highlighter? The piece of code you provided does not make much sense - you have a method declaration inside the try-catch block, which would not compile at all.

Highlighted
Active Member II

Re: How to trigger a Process from APS when an E-mail comes to ACS ?

not able to attach, there is no option for attaching document so providing only startProcessId() code from RemoteActivitiService class that belongs to com.activiti.alfresco.service package.

public void startProcessById(String processId, String processName, Map<String, Object> formValues, ActivitiService.DocumentContext documentContext)
throws RemoteActivitiException, ActivitiAuthenticationException
{
JSONObject startProcessVars = new JSONObject();
try
{
if (formValues != null) {
for (Map.Entry<String, Object> formValue : formValues.entrySet()) {
if ((formValue.getValue() instanceof ActivitiService.JsonSerializable)) {
startProcessVars.put((String)formValue.getKey(), ((ActivitiService.JsonSerializable)formValue.getValue()).toJSON());
} else {
startProcessVars.put((String)formValue.getKey(), formValue.getValue());
}
}
}
if (documentContext != null)
{
NodeRef nodeRef = documentContext.getNodeRef();
FileInfo fileInfo = this.fileFolderService.getFileInfo(nodeRef);
if ((!fileInfo.isFolder()) && (!fileInfo.isLink()))
{
SiteInfo siteInfo = this.siteService.getSite(nodeRef);
String sourceId = nodeRef.getId() + (siteInfo != null ? "@" + siteInfo.getShortName() : "");
JSONObject body = new JSONObject();
body.put("source", this.activitiParameters.getAlfrescoRepositoryName());
body.put("sourceId", sourceId);
body.put("name", fileInfo.getName());
body.put("mimeType", JSONObject.NULL);
body.put("simpleType", JSONObject.NULL);
body.put("link", false);
JSONObject contentObject = doJsonPost("app/rest/content", body);
int contentId = contentObject.getInt("id");
startProcessVars.put(documentContext.getFormFieldId(), String.valueOf(contentId));
}
}
startProcessInternal(processId, processName, startProcessVars);
}
catch (JSONException e)
{
e.printStackTrace();
}
}