Skip to content

Commit

Permalink
Cleaned up common process instance variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 8, 2016
1 parent 8788bcd commit bf4e9f6
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 228 deletions.
Expand Up @@ -68,6 +68,7 @@ public abstract class SchemaConstants {
public static final QName C_ITEM = new QName(NS_C, "item");
public static final QName C_OBJECTS = new QName(NS_C, "objects");
public static final QName C_OBJECT = new QName(NS_C, "object");
public static final QName C_TARGET = new QName(NS_C, "target");
public static final QName C_ABSTRACT_ROLE = new QName(NS_C, "abstractRole");
public static final QName C_FOCUS = new QName(NS_C, "focus");
public static final QName C_OBJECT_TYPE = new QName(NS_C, "ObjectType");
Expand Down
Expand Up @@ -58,7 +58,7 @@ public void stopProcessInstance(String instanceId, String username, OperationRes
LOGGER.trace("Stopping process instance {} on the request of {}", instanceId, username);
String deletionMessage = "Process instance stopped on the request of " + username;
// rs.setVariable(instanceId, CommonProcessVariableNames.VARIABLE_WF_STATE, deletionMessage);
rs.setVariable(instanceId, CommonProcessVariableNames.VARIABLE_MIDPOINT_IS_PROCESS_INSTANCE_STOPPING, Boolean.TRUE);
rs.setVariable(instanceId, CommonProcessVariableNames.VARIABLE_PROCESS_INSTANCE_IS_STOPPING, Boolean.TRUE);
rs.deleteProcessInstance(instanceId, deletionMessage);
result.recordSuccess();
} catch (ActivitiException e) {
Expand Down
Expand Up @@ -149,7 +149,7 @@ private WfContextType activitiToMidpointWfContextHistory(HistoricProcessInstance
wfc.setTargetRef(targetRef.toObjectReferenceType());
}

ChangeProcessor cp = wfConfiguration.findChangeProcessor((String) vars.get(CommonProcessVariableNames.VARIABLE_MIDPOINT_CHANGE_PROCESSOR));
ChangeProcessor cp = wfConfiguration.findChangeProcessor((String) vars.get(CommonProcessVariableNames.VARIABLE_CHANGE_PROCESSOR));
if (cp == null) {
throw new SchemaException("No change processor information in process instance " + instance.getId());
}
Expand Down
Expand Up @@ -593,7 +593,7 @@ private WorkItemType taskExtractToWorkItem(TaskExtract task, boolean getAssignee
}
wi.setName(new PolyStringType(task.getName()));
wi.setProcessInstanceId(task.getProcessInstanceId());
wi.setChangeProcessor((String) task.getVariables().get(CommonProcessVariableNames.VARIABLE_MIDPOINT_CHANGE_PROCESSOR));
wi.setChangeProcessor((String) task.getVariables().get(CommonProcessVariableNames.VARIABLE_CHANGE_PROCESSOR));
MetadataType metadataType = new MetadataType();
metadataType.setCreateTimestamp(XmlTypeConverter.createXMLGregorianCalendar(task.getCreateTime()));
wi.setMetadata(metadataType);
Expand Down Expand Up @@ -660,7 +660,7 @@ private <T> T asObjectable(PrismObject<? extends T> prismObject) {
}

private ChangeProcessor getChangeProcessor(TaskExtract task, Map<String, Object> variables) {
String cpClassName = (String) variables.get(CommonProcessVariableNames.VARIABLE_MIDPOINT_CHANGE_PROCESSOR);
String cpClassName = (String) variables.get(CommonProcessVariableNames.VARIABLE_CHANGE_PROCESSOR);
if (cpClassName == null) {
throw new IllegalStateException("Change processor is unknown for task: " + task);
}
Expand Down
Expand Up @@ -353,7 +353,7 @@ private void onProcessFinishedEvent(ProcessEvent event, WfTask wfTask, Operation
}

private ChangeProcessor getChangeProcessor(Map<String,Object> variables) {
String cpName = (String) variables.get(CommonProcessVariableNames.VARIABLE_MIDPOINT_CHANGE_PROCESSOR);
String cpName = (String) variables.get(CommonProcessVariableNames.VARIABLE_CHANGE_PROCESSOR);
Validate.notNull(cpName, "Change processor is not defined among process instance variables");
return wfConfiguration.findChangeProcessor(cpName);
}
Expand Down
Expand Up @@ -346,30 +346,21 @@ public void addTaskModelContext(ModelContext modelContext) throws SchemaExceptio
//region Setters for process variables
public void initializeCommonProcessVariables() {
addProcessVariable(VARIABLE_UTIL, new ActivitiUtil());
addProcessVariable(VARIABLE_MIDPOINT_CHANGE_PROCESSOR, changeProcessor.getClass().getName());
addProcessVariable(VARIABLE_CHANGE_PROCESSOR, changeProcessor.getClass().getName());
addProcessVariable(VARIABLE_START_TIME, new Date());
}

public void setRequesterOidAndRefInProcess(PrismObject<UserType> requester) {
addProcessVariable(VARIABLE_MIDPOINT_REQUESTER_OID, requester.getOid());
addProcessVariable(VARIABLE_REQUESTER_REF, new LightweightObjectRefImpl(createObjectRef(requester)));
}

public void setObjectOidInProcess(String objectOid) {
if (objectOid != null) {
addProcessVariable(VARIABLE_MIDPOINT_OBJECT_OID, objectOid);
} else {
removeProcessVariable(VARIABLE_MIDPOINT_OBJECT_OID);
}
}

public void setProcessInstanceName(String name) {
processInstanceName = name;
addProcessVariable(VARIABLE_PROCESS_INSTANCE_NAME, name);
}

public void setProcessInterfaceBean(ProcessMidPointInterface processInterfaceBean) {
addProcessVariable(VARIABLE_MIDPOINT_PROCESS_INTERFACE_BEAN_NAME, processInterfaceBean.getBeanName());
addProcessVariable(VARIABLE_PROCESS_INTERFACE_BEAN_NAME, processInterfaceBean.getBeanName());
}
//endregion

Expand Down
Expand Up @@ -34,9 +34,9 @@ public class ProcessInterfaceFinder implements BeanFactoryAware {
private BeanFactory beanFactory;

public ProcessMidPointInterface getProcessInterface(Map<String, Object> variables) {
String interfaceBeanName = (String) variables.get(CommonProcessVariableNames.VARIABLE_MIDPOINT_PROCESS_INTERFACE_BEAN_NAME);
String interfaceBeanName = (String) variables.get(CommonProcessVariableNames.VARIABLE_PROCESS_INTERFACE_BEAN_NAME);
if (interfaceBeanName == null) {
throw new IllegalStateException("No " + CommonProcessVariableNames.VARIABLE_MIDPOINT_PROCESS_INTERFACE_BEAN_NAME + " variable found");
throw new IllegalStateException("No " + CommonProcessVariableNames.VARIABLE_PROCESS_INTERFACE_BEAN_NAME + " variable found");
}
return beanFactory.getBean(interfaceBeanName, ProcessMidPointInterface.class);
}
Expand Down
Expand Up @@ -18,13 +18,21 @@

import com.evolveum.midpoint.model.api.expr.MidpointFunctions;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.wf.impl.util.SerializationSafeContainer;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import org.activiti.engine.delegate.DelegateExecution;

import java.io.Serializable;

import static com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.*;

/**
* General utilities that can be used from within processes.
*
Expand Down Expand Up @@ -64,11 +72,24 @@ public void revive(SerializationSafeContainer<?> container) {

// todo - better name?
public MidpointFunctions midpoint() {
return SpringApplicationContextHolder.getMidpointFunctions();
return getMidpointFunctions();
}

@Override
public String toString() {
return this.getClass().getName() + " object.";
}

public static Task getTask(DelegateExecution execution, OperationResult result) {
String oid = execution.getVariable(CommonProcessVariableNames.VARIABLE_MIDPOINT_TASK_OID, String.class);
if (oid == null) {
throw new IllegalStateException("No task OID in process " + execution.getProcessInstanceId());
}

try {
return getTaskManager().getTask(oid, result);
} catch (ObjectNotFoundException|SchemaException|RuntimeException e) {
throw new SystemException("Couldn't get task " + oid + " corresponding to process " + execution.getProcessInstanceId(), e);
}
}
}
Expand Up @@ -26,57 +26,52 @@ public class CommonProcessVariableNames {
// Used for diagnostic purposes.
public static final String VARIABLE_PROCESS_INSTANCE_NAME = "processInstanceName";

// When the process instance was started. [java.util.Date]
// [java.util.Date]
// When the process instance was started.
public static final String VARIABLE_START_TIME = "startTime";

// OID of task related to the process instance. [String]
// [String]
// OID of task related to the process instance.
public static final String VARIABLE_MIDPOINT_TASK_OID = "midPointTaskOid";

// Java class name of the change processor (the same as wf:changeProcessor task property) [String]
public static final String VARIABLE_MIDPOINT_CHANGE_PROCESSOR = "midPointChangeProcessor";
// [String]
// Java class name of the change processor (the same as wf:changeProcessor task property)
public static final String VARIABLE_CHANGE_PROCESSOR = "changeProcessor";

// OID of the user who requested the particular operation.
// Used e.g. for searching for process instances requested by particular user. [String]
public static final String VARIABLE_MIDPOINT_REQUESTER_OID = "requesterOid";

// Requester - OID + name + perhaps additional information [LightweightObjectRef]
// Pure OID is kept in order to allow searching.
// [LightweightObjectRef]
// Requester - OID + name + perhaps additional information
public static final String VARIABLE_REQUESTER_REF = "requesterRef";

// [LightweightObjectRef]
// Object of the operation - if can be specified like this
public static final String VARIABLE_OBJECT_REF = "objectRef";

// OID of the object (typically, a user) that is being changed within the operation. [String]
// In some cases (e.g. for PrimaryChangeProcessor) the OID is determined clearly.
// In other situations, e.g. for GeneralChangeProcessor there must be a code that provides
// this information. In some cases, there may be no OID - e.g. when an object is yet to be created.
//
// TODO think about storing also object class (currently we fetch an object from the repo as "ObjectType.class" but that's far from ideal).
public static final String VARIABLE_MIDPOINT_OBJECT_OID = "midPointObjectOid";

// Object that provides various utility methods for use in processes, e.g. getApprover(RoleType r). [ActivitiUtil]
public static final String VARIABLE_UTIL = "util";

// Basic decision returned from a work item.
// for most work items it is simple __APPROVED__ or __REJECTED__, but in principle this can be any string value
public static final String FORM_FIELD_DECISION = "[H]decision";

// Comment related to that decision - set by user task (form). [String]
// this value is put into audit record, so its advisable to use this particular name
public static final String FORM_FIELD_COMMENT = "comment";

public static final String FORM_BUTTON_PREFIX = "[B]";
// [LightweightObjectRef]
// Target of the operation - if any
public static final String VARIABLE_TARGET_REF = "targetRef";

// [Boolean]
// A signal that the process instance is being stopped. Used e.g. to suppress propagation of exceptions
// occurring in the process instance end listener.
// [Boolean]
public static final String VARIABLE_MIDPOINT_IS_PROCESS_INSTANCE_STOPPING = "midPointIsProcessInstanceStopping";
public static final String VARIABLE_PROCESS_INSTANCE_IS_STOPPING = "processInstanceIsStopping";

// [String]
// Name of process interface bean (ProcessMidPointInterface implementation) that is related to this process
public static final String VARIABLE_PROCESS_INTERFACE_BEAN_NAME = "processInterfaceBeanName";

// Name of process interface bean (ProcessMidPointInterface implementation) that is related to this process [String]
public static final String VARIABLE_MIDPOINT_PROCESS_INTERFACE_BEAN_NAME = "midPointProcessInterfaceBeanName";
// [ActivitiUtil]
// Object that provides various utility methods for use in processes, e.g. getApprover(RoleType r).
public static final String VARIABLE_UTIL = "util";

// Object of the operation - if can be specified like this [LightweightObjectRef]
public static final String VARIABLE_OBJECT_REF = "objectRef";
// [String]
// Basic decision returned from a work item.
// for most work items it is simple __APPROVED__ or __REJECTED__, but in principle this can be any string value
public static final String FORM_FIELD_DECISION = "[H]decision";

// Target of the operation - if any [LightweightObjectRef]
public static final String VARIABLE_TARGET_REF = "targetRef";
// [String]
// Comment related to that decision - set by user task (form).
// this value is put into audit record, so its advisable to use this particular name
public static final String FORM_FIELD_COMMENT = "comment";

public static final String FORM_BUTTON_PREFIX = "[B]";
}
Expand Up @@ -49,7 +49,7 @@ public void notify(DelegateExecution execution) {
getActivitiInterface().notifyMidpointAboutProcessFinishedEvent(execution);
} catch (RuntimeException e) {
LOGGER.trace("Got exception while processing process end event in midpoint", e);
if (TRUE.equals(execution.getVariable(CommonProcessVariableNames.VARIABLE_MIDPOINT_IS_PROCESS_INSTANCE_STOPPING))) {
if (TRUE.equals(execution.getVariable(CommonProcessVariableNames.VARIABLE_PROCESS_INSTANCE_IS_STOPPING))) {
LOGGER.trace("... the process is ending anyway, so we just ignore this exception");
} else {
throw e;
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.model.api.expr.MidpointFunctions;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.wf.impl.activiti.ActivitiInterface;
import com.evolveum.midpoint.wf.impl.jobs.WfTaskController;
import com.evolveum.midpoint.wf.impl.processors.primary.PcpRepoAccessHelper;
Expand Down Expand Up @@ -91,6 +92,10 @@ public static MidpointFunctions getMidpointFunctions() {
public static PcpRepoAccessHelper getPcpRepoAccessHelper() {
return getBean("pcpRepoAccessHelper", PcpRepoAccessHelper.class);
}

public static TaskManager getTaskManager() {
return getBean(TaskManager.class);
}
}


0 comments on commit bf4e9f6

Please sign in to comment.