...
getProcessId()
Gets process ID (never null, see constants incom.noheto.restapi.ProcessID
)getServiceId()
Gets service ID (or null if no service is involved, see constants incom.noheto.restapi.ServiceId
)Collection<ProcessObject> getObjects()
Gets a list of all processed objects (including those in error or not found). To determine whether an object is in error, you can test whether it implementscom.noheto.restapi.ProcessObjectReject
.
Objects are not necessarily in the same processing order. The same object can only appear once.Collection<ProcessObject> getModifiedObjects()
Gets a list of all objects modified during processingCollection<ProcessObjectReject> getRejectedObjects()
Gets a list of all objects rejected during processingString getObjectType()
Gets the type of the object processed, or null, if several types are involvedCollection<String> getObjectTypes()
Gets all object types processedCTSurfer getSurfer()
Gets the surferMap<String,String> getAdditionalParameters()
Gets additional specific parameters (e.g. an API parameter)Map<String,Object> getAdditionalProperties()
Gets additional specific properties (e.g. a parent object)
com.noheto.restapi.ProcessObject
...
Set<String> getModifiedProperties()
Gets a list of database object properties that have been modified by the process onlyboolean isModified()
Returns true if the object is considered modified by the processIObjectReadOnly getOldObject()
Gets the database object instance before modification, if any. May return null if object did not exist.IObjectReadOnly getNewObject()
Gets the database object instance after modification, if any. May return null if object does not exist (if old object is not null, it has been deleted). Some hooks may concern object transformations or copies: new object is not necessarily the same identifier or even of the same type as old object.ObjectReference getObjectReference()
Returns object referenceMap<String,String> getOldValues()
Returns the properties of the object processed prior to processing if it is not a database objectMap<String,String> getNewValues()
Returns the properties of the processed object after processing if it is not a database objectMap<String,Object> getAdditionalProperties()
Gets additional specific properties (e.g. a process status)
Example
Code Block | ||||
---|---|---|---|---|
| ||||
public class TestProcessEndHook extends ProcessEndHookAdapter { @Override public boolean processEnd(ObjectContext objectContext, String processId, String serviceId) { return StringUtils.equalsIgnoreCase("testhook",objectContext.getObjectType()) // this component will only be executed if the object type is testhook && StringUtils.equalsIgnoreCase(ProcessID.STATUS_CHANGE,processId); // this component will only be executed for the "status_change" process } @Override public void processEnd(ProcessEndContext context) { Collection<ProcessObject> modified = context.getModifiedObjects(); // list of objects modified during the process Collection<ProcessObjectReject> rejected = context.getRejectedObjects(); // list of objects rejected during the process Map<String,String> additionalParameters = context.getAdditionalParameters(); System.out.println("additional parameters: " + additionalParameters); // displays additional parameters (here, the action identifier passed to the service) for(ProcessObject object : context.getObjects()) { // iterate over all processed objects ObjectReference ref = object.getObjectReference(); System.out.print(ref.getType()+"/"+ref.getId()); // displays UID of object if ( modified.contains(object) ) { // if the objet is modified... System.out.println(" modified "); // prints "modified" System.out.println("modified properties " + object.getModifiedProperties()); // then prints modified properties (i.e. status) System.out.println("old object: " + object.getOldObject()); // then prints the old instance System.out.println("new object: " + object.getNewObject()); // then prints the new instance for(String property : object.getModifiedProperties()) { // for each modified property System.out.print( property ); System.out.print( " " ); try { System.out.print( object.getOldObject().getProperty(property) ); // prints old value } catch (Throwable e) { System.out.print( e ); } System.out.print( " => " ); try { System.out.print( object.getNewObject().getProperty(property) ); // prints new value } catch (Throwable e) { System.out.print( e ); } System.out.println(); } } else if ( rejected.contains(object) ) { // if object is rejected System.out.print(" rejected "); // prints "rejected" ProcessObjectReject rejection = (ProcessObjectReject) object; String error = rejection.getError(); // then prints error if any if ( error==null ) { Throwable t = rejection.getThrowable(); if ( t!=null ) { error = t.getMessage(); } if ( error==null ) { error = "Unknown error"; } } System.out.print(" error= "); System.out.println(error); } else { System.out.println(" not modified "); // if object is neither modified nor rejected, prints "not modified" } } System.out.println("type: " + context.getObjectType()); System.out.println("types: " + context.getObjectTypes()); System.out.println("surfer: " + context.getSurfer()); } } |
Here’s a sample display (api/rest/dam/data/testhook/workflow/1,2,42/activate
):
Code Block |
---|
additional parameters: {action=activate} testhook/1 not modified testhook/42 rejected error= Object not found 42 for action DAM/testhook testhook/2 modified modified properties [status] old object: testhook/2 new object: testhook/2 status 2 => 6 type: testhook types: [testhook] surfer: CTSurfer { connected:true , uid: user_42, id: 42, name: Jane Smith, roleId: 37, role: Contributor } |