Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • getProcessId()
    Gets process ID (never null, see constants in com.noheto.restapi.ProcessID)

  • getServiceId()
    Gets service ID (or null if no service is involved, see constants in com.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 implements com.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 processing

  • Collection<ProcessObjectReject> getRejectedObjects()
    Gets a list of all objects rejected during processing

  • String getObjectType()
    Gets the type of the object processed, or null, if several types are involved

  • Collection<String> getObjectTypes()
    Gets all object types processed

  • CTSurfer getSurfer()
    Gets the surfer

  • Map<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 only

  • boolean isModified()
    Returns true if the object is considered modified by the process

  • IObjectReadOnly 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 reference

  • Map<String,String> getOldValues()
    Returns the properties of the object processed prior to processing if it is not a database object

  • Map<String,String> getNewValues()
    Returns the properties of the processed object after processing if it is not a database object

  • Map<String,Object> getAdditionalProperties()
    Gets additional specific properties (e.g. a process status)

Example

Code Block
breakoutModewide
languagejava
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 }