Skip to content

Commit

Permalink
Cleaned-up workflow notifications (API and SimpleWorktlowNotifier).
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 7, 2017
1 parent 2536d73 commit 861aa3c
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 273 deletions.
Expand Up @@ -2159,8 +2159,7 @@
<xsd:simpleType name="WorkItemOperationKindType">
<xsd:annotation>
<xsd:documentation>
Kind of (explicit) operation. Implicit operations like "work item deletion when process instance finishes"
are not covered here.
Kind of operation.
</xsd:documentation>
<xsd:appinfo>
<a:since>3.6</a:since>
Expand Down Expand Up @@ -2218,6 +2217,18 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="cancel">
<xsd:annotation>
<xsd:documentation>
Cancel operation. Work item was cancelled as a result of other action. (E.g. another work item
was completed, resulting in process or stage completion. Or the process was cancelled/deleted
externally.)
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="CANCEL"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

Expand Down
Expand Up @@ -19,6 +19,8 @@
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.LightweightIdentifierGenerator;
import com.evolveum.midpoint.wf.api.WorkItemOperationInfo;
import com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -32,14 +34,13 @@
*/
public class WorkItemAllocationEvent extends WorkItemEvent {

public WorkItemAllocationEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, ChangeType changeType,
@NotNull WorkItemType workItem, @Nullable SimpleObjectRef assignee, WorkItemOperationKindType operationKind,
SimpleObjectRef initiator, WorkItemResultType workItemResult, AbstractWorkItemActionType source,
WorkItemEventCauseInformationType cause,
WfContextType workflowContext,
Duration timeBefore) {
super(lightweightIdentifierGenerator, changeType, workItem, assignee, initiator, operationKind,
workItemResult, source, cause, workflowContext,null, timeBefore);
public WorkItemAllocationEvent(@NotNull LightweightIdentifierGenerator lightweightIdentifierGenerator,
@NotNull ChangeType changeType,
@NotNull WorkItemType workItem, @Nullable SimpleObjectRef assignee, @Nullable SimpleObjectRef initiator,
@Nullable WorkItemOperationInfo operationInfo, @Nullable WorkItemOperationSourceInfo sourceInfo,
@NotNull WfContextType workflowContext, @Nullable Duration timeBefore) {
super(lightweightIdentifierGenerator, changeType, workItem, assignee, initiator, operationInfo, sourceInfo,
workflowContext,null, timeBefore);
}

@Override
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.LightweightIdentifierGenerator;
import com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -31,11 +32,12 @@
*/
public class WorkItemCustomEvent extends WorkItemEvent {

public WorkItemCustomEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, ChangeType changeType,
@NotNull WorkItemType workItem, @Nullable SimpleObjectRef assignee, @NotNull WorkItemNotificationActionType source,
WorkItemEventCauseInformationType cause, WfContextType workflowContext) {
super(lightweightIdentifierGenerator, changeType, workItem, assignee, null, null, null, source,
cause, workflowContext, source.getHandler(), null);
public WorkItemCustomEvent(@NotNull LightweightIdentifierGenerator lightweightIdentifierGenerator, @NotNull ChangeType changeType,
@NotNull WorkItemType workItem,
@Nullable SimpleObjectRef assignee, @Nullable WorkItemOperationSourceInfo sourceInfo,
@NotNull WfContextType workflowContext, @Nullable EventHandlerType handler) {
super(lightweightIdentifierGenerator, changeType, workItem, assignee, null, null,
sourceInfo, workflowContext, handler, null);
}

@Override
Expand Down
Expand Up @@ -20,6 +20,8 @@
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.LightweightIdentifierGenerator;
import com.evolveum.midpoint.wf.api.WorkItemOperationInfo;
import com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.NotNull;
Expand All @@ -44,28 +46,23 @@ public class WorkItemEvent extends WorkflowEvent {
* In case of automated actions (completion, delegation/escalation) this is not filled-in.
*/
protected final SimpleObjectRef initiator;
protected final WorkItemOperationKindType operationKind;
protected final AbstractWorkItemActionType source;
protected final WorkItemEventCauseInformationType cause;
protected final WorkItemOperationInfo operationInfo;
protected final WorkItemOperationSourceInfo sourceInfo;
protected final Duration timeBefore;
protected final WorkItemResultType workItemResult;

WorkItemEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, ChangeType changeType,
WorkItemEvent(@NotNull LightweightIdentifierGenerator lightweightIdentifierGenerator, @NotNull ChangeType changeType,
@NotNull WorkItemType workItem,
@Nullable SimpleObjectRef assignee, SimpleObjectRef initiator, WorkItemOperationKindType operationKind,
WorkItemResultType workItemResult, @Nullable AbstractWorkItemActionType source,
@Nullable WorkItemEventCauseInformationType cause,
WfContextType workflowContext,
EventHandlerType handler, Duration timeBefore) {
@Nullable SimpleObjectRef assignee, @Nullable SimpleObjectRef initiator,
@Nullable WorkItemOperationInfo operationInfo, @Nullable WorkItemOperationSourceInfo sourceInfo,
@NotNull WfContextType workflowContext,
@Nullable EventHandlerType handler, @Nullable Duration timeBefore) {
super(lightweightIdentifierGenerator, changeType, workflowContext, handler);
Validate.notNull(workItem);
this.workItem = workItem;
this.assignee = assignee;
this.initiator = initiator;
this.operationKind = operationKind;
this.workItemResult = workItemResult;
this.source = source;
this.cause = cause;
this.operationInfo = operationInfo;
this.sourceInfo = sourceInfo;
this.timeBefore = timeBefore;
}

Expand All @@ -92,21 +89,29 @@ public SimpleObjectRef getInitiator() {
}

public WorkItemOperationKindType getOperationKind() {
return operationKind;
return operationInfo != null ? operationInfo.getOperationKind() : null;
}

public AbstractWorkItemActionType getSource() {
return source;
return sourceInfo != null ? sourceInfo.getSource() : null;
}

public WorkItemEventCauseInformationType getCause() {
return cause;
return sourceInfo != null ? sourceInfo.getCause() : null;
}

public Duration getTimeBefore() {
return timeBefore;
}

public WorkItemOperationInfo getOperationInfo() {
return operationInfo;
}

public WorkItemOperationSourceInfo getSourceInfo() {
return sourceInfo;
}

@Override
public void createExpressionVariables(Map<QName, Object> variables, OperationResult result) {
super.createExpressionVariables(variables, result);
Expand All @@ -115,7 +120,7 @@ public void createExpressionVariables(Map<QName, Object> variables, OperationRes
}

public WorkItemResultType getWorkItemResult() {
return workItemResult != null ? workItemResult : workItem.getResult();
return workItem.getResult();
}

@Override
Expand Down
Expand Up @@ -19,6 +19,8 @@
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.LightweightIdentifierGenerator;
import com.evolveum.midpoint.wf.api.WorkItemOperationInfo;
import com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -31,14 +33,13 @@
*/
public class WorkItemLifecycleEvent extends WorkItemEvent {

public WorkItemLifecycleEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, ChangeType changeType,
public WorkItemLifecycleEvent(@NotNull LightweightIdentifierGenerator lightweightIdentifierGenerator, @NotNull ChangeType changeType,
@NotNull WorkItemType workItem,
@Nullable SimpleObjectRef assignee, @Nullable SimpleObjectRef initiator,
WorkItemOperationKindType operationKind,
WorkItemResultType workItemResult, AbstractWorkItemActionType source, WorkItemEventCauseInformationType cause,
WfContextType workflowContext) {
super(lightweightIdentifierGenerator, changeType, workItem, assignee, initiator, operationKind,
workItemResult, source, cause, workflowContext, null, null);
@Nullable WorkItemOperationInfo operationInfo, @Nullable WorkItemOperationSourceInfo sourceInfo,
@NotNull WfContextType workflowContext) {
super(lightweightIdentifierGenerator, changeType, workItem, assignee, initiator,
operationInfo, sourceInfo, workflowContext, null, null);
}

@Override
Expand Down
Expand Up @@ -25,12 +25,11 @@
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.wf.api.ProcessListener;
import com.evolveum.midpoint.wf.api.WorkItemListener;
import com.evolveum.midpoint.wf.api.WorkflowManager;
import com.evolveum.midpoint.wf.api.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -89,88 +88,89 @@ public void onProcessInstanceEnd(Task wfTask, OperationResult result) {

//region WorkItem-level notifications
@Override
public void onWorkItemCreation(WorkItemType workItem, ObjectReferenceType originalAssigneeRef, Task wfTask,
OperationResult result) {
public void onWorkItemCreation(ObjectReferenceType assignee, @NotNull WorkItemType workItem,
Task wfTask, OperationResult result) {
WorkItemEvent event = new WorkItemLifecycleEvent(identifierGenerator, ChangeType.ADD, workItem,
SimpleObjectRefImpl.create(functions, originalAssigneeRef), null, null, null, null, null, wfTask.getWorkflowContext());
SimpleObjectRefImpl.create(functions, assignee), null, null, null, wfTask.getWorkflowContext());
initializeWorkflowEvent(event, wfTask);
processEvent(event, result);
}

@Override
public void onWorkItemDeletion(WorkItemType workItem, ObjectReferenceType assignee, ObjectReferenceType initiator,
WorkItemOperationKindType operationKind,
WorkItemResultType workItemResult, AbstractWorkItemActionType source, WorkItemEventCauseInformationType cause,
public void onWorkItemDeletion(ObjectReferenceType assignee, @NotNull WorkItemType workItem,
WorkItemOperationInfo operationInfo, WorkItemOperationSourceInfo sourceInfo,
Task wfTask, OperationResult result) {
WorkItemEvent event = new WorkItemLifecycleEvent(identifierGenerator, ChangeType.DELETE, workItem,
SimpleObjectRefImpl.create(functions, assignee),
SimpleObjectRefImpl.create(functions, initiator),
operationKind, workItemResult, source, cause, wfTask.getWorkflowContext());
getInitiator(sourceInfo), operationInfo, sourceInfo, wfTask.getWorkflowContext());
initializeWorkflowEvent(event, wfTask);
processEvent(event, result);
}

@Override
public void onWorkItemCustomEvent(WorkItemType workItem, ObjectReferenceType assignee,
public void onWorkItemCustomEvent(ObjectReferenceType assignee, @NotNull WorkItemType workItem,
@NotNull WorkItemNotificationActionType notificationAction, WorkItemEventCauseInformationType cause, Task wfTask,
OperationResult result) {
WorkItemEvent event = new WorkItemCustomEvent(identifierGenerator, ChangeType.ADD, workItem,
SimpleObjectRefImpl.create(functions, assignee), notificationAction, cause, wfTask.getWorkflowContext());
SimpleObjectRefImpl.create(functions, assignee),
new WorkItemOperationSourceInfo(null, cause, notificationAction),
wfTask.getWorkflowContext(), notificationAction.getHandler());
initializeWorkflowEvent(event, wfTask);
processEvent(event, result);
}

@Override
public void onWorkItemAllocationChangeCurrentActors(WorkItemType workItem, List<ObjectReferenceType> currentActors,
Duration timeBefore, WorkItemOperationKindType operationKind, ObjectReferenceType initiator,
WorkItemResultType workItemResult, AbstractWorkItemActionType source,
WorkItemEventCauseInformationType cause, Task task, OperationResult result) {
checkOids(currentActors);
for (ObjectReferenceType currentActor : currentActors) {
onWorkItemAllocationModifyDelete(currentActor, workItem, timeBefore, operationKind, initiator, workItemResult, source, cause, task, result);
@Override
public void onWorkItemAllocationChangeCurrentActors(@NotNull WorkItemType workItem,
@NotNull WorkItemAllocationChangeOperationInfo operationInfo,
@Nullable WorkItemOperationSourceInfo sourceInfo,
Duration timeBefore, Task task, OperationResult result) {
checkOids(operationInfo.getCurrentActors());
for (ObjectReferenceType currentActor : operationInfo.getCurrentActors()) {
onWorkItemAllocationModifyDelete(currentActor, workItem, operationInfo, sourceInfo, timeBefore, task, result);
}
}

@Override
public void onWorkItemAllocationChangeNewActors(WorkItemType workItem, List<ObjectReferenceType> currentActors,
List<ObjectReferenceType> newActors, WorkItemOperationKindType operationKind, ObjectReferenceType initiator,
AbstractWorkItemActionType source,
WorkItemEventCauseInformationType cause, Task task, OperationResult result) {

checkOids(currentActors);
checkOids(newActors);
for (ObjectReferenceType newActor : newActors) {
// if (!ObjectTypeUtil.containsOid(currentActors, newActor.getOid())) {
onWorkItemAllocationAdd(newActor, workItem, operationKind, initiator, source, cause, task, result);
// }
public void onWorkItemAllocationChangeNewActors(@NotNull WorkItemType workItem,
@NotNull WorkItemAllocationChangeOperationInfo operationInfo,
@Nullable WorkItemOperationSourceInfo sourceInfo,
Task task, OperationResult result) {
Validate.notNull(operationInfo.getNewActors());

checkOids(operationInfo.getCurrentActors());
checkOids(operationInfo.getNewActors());
for (ObjectReferenceType newActor : operationInfo.getNewActors()) {
onWorkItemAllocationAdd(newActor, workItem, operationInfo, sourceInfo, task, result);
}
}

private void checkOids(List<ObjectReferenceType> refs) {
refs.forEach(r -> Validate.notNull(r.getOid(), "No OID in actor object reference " + r));
}

private void onWorkItemAllocationAdd(ObjectReferenceType newActor, WorkItemType workItem,
WorkItemOperationKindType operationKind, ObjectReferenceType initiator, AbstractWorkItemActionType source,
WorkItemEventCauseInformationType cause, Task task, OperationResult result) {
private void onWorkItemAllocationAdd(ObjectReferenceType newActor, @NotNull WorkItemType workItem,
@Nullable WorkItemOperationInfo operationInfo, @Nullable WorkItemOperationSourceInfo sourceInfo,
Task task, OperationResult result) {
WorkItemAllocationEvent event = new WorkItemAllocationEvent(identifierGenerator, ChangeType.ADD, workItem,
SimpleObjectRefImpl.create(functions, newActor),
operationKind, SimpleObjectRefImpl.create(functions, initiator),
null, source, cause,
getInitiator(sourceInfo), operationInfo, sourceInfo,
task.getWorkflowContext(), null);
initializeWorkflowEvent(event, task);
processEvent(event, result);
}

private void onWorkItemAllocationModifyDelete(ObjectReferenceType currentActor, WorkItemType workItem, Duration timeBefore,
WorkItemOperationKindType operationKind, ObjectReferenceType initiator, WorkItemResultType workItemResult,
AbstractWorkItemActionType source,
WorkItemEventCauseInformationType cause,
Task task, OperationResult result) {
private SimpleObjectRef getInitiator(WorkItemOperationSourceInfo sourceInfo) {
return sourceInfo != null ?
SimpleObjectRefImpl.create(functions, sourceInfo.getInitiatorRef()) : null;
}

private void onWorkItemAllocationModifyDelete(ObjectReferenceType currentActor, @NotNull WorkItemType workItem,
@Nullable WorkItemOperationInfo operationInfo, @Nullable WorkItemOperationSourceInfo sourceInfo,
Duration timeBefore, Task task, OperationResult result) {
WorkItemAllocationEvent event = new WorkItemAllocationEvent(identifierGenerator,
timeBefore != null ? ChangeType.MODIFY : ChangeType.DELETE, workItem,
SimpleObjectRefImpl.create(functions, currentActor), operationKind, SimpleObjectRefImpl.create(functions, initiator),
workItemResult, source, cause,
SimpleObjectRefImpl.create(functions, currentActor),
getInitiator(sourceInfo), operationInfo, sourceInfo,
task.getWorkflowContext(), timeBefore);
initializeWorkflowEvent(event, task);
processEvent(event, result);
Expand All @@ -192,14 +192,6 @@ private void processEvent(WorkflowEvent event, OperationResult result) {
result.recordSuccessIfUnknown();
}

private void processEvent(WorkflowEvent event) {
try {
notificationManager.processEvent(event);
} catch (RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "An unexpected exception occurred when preparing and sending notifications: " + e.getMessage(), e);
}
}

private void initializeWorkflowEvent(WorkflowEvent event, Task wfTask) {
WfContextType wfc = wfTask.getWorkflowContext();
event.setRequester(SimpleObjectRefImpl.create(functions, wfc.getRequesterRef()));
Expand Down

0 comments on commit 861aa3c

Please sign in to comment.