Implement the com.noheto.restapi.ProcessEndHookAdapter
class for processing after a treatment has been completed
Methods
boolean processEnd(ObjectContext object, String processId, String serviceId)
Use this method to select the component for the treatment you wish to complete.
Arguments
object
(classcom.noheto.restapi.ObjectContext
) describes the main object processed. Never null, butgetObjectType()
,getStructure()
andgetTable()
may return null if no database object is particularly concerned.processId (
String
) the ID of process to complete (never null). The classcom.noheto.restapi.ProcessID
lists all process identifiers.serviceId (String) the ID of API service (may be null)
void processEnd(ProcessEndContext context)
This method is called for this instance of ProcessEndHookAdapter
if the method processEnd(ObjectContext , String, String)
returns true for the current execution context.
Methods of ProcessEndContext
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)
com.noheto.restapi.ProcessObject
This class is used to test processed objects.
Methods
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.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 object
Example
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
):
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 }