Skip to content

Commit

Permalink
Towards new workflow events... work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 8, 2017
1 parent fbfe8fd commit 18761c3
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 248 deletions.
Expand Up @@ -535,6 +535,43 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="workItemLifecycleEvent">
<xsd:annotation>
<xsd:documentation>
Subtype of workItemEvent. Represents the fact that a work item was created or deleted.
Operation of ADD means that the work item was created.
Operation of DELETE means that the work item was deleted (usually because it was completed).
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="WORK_ITEM_LIFECYCLE_EVENT"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="workItemAllocationEvent">
<xsd:annotation>
<xsd:documentation>
Subtype of workItemEvent. Represents the fact that a work item was allocated to a user.
(Either automatically when it is created or delegated, or manually when the user has claimed the item.)
Operation of ADD means that the allocation was created.
Operation of MODIFY means that the allocation is about to be deleted (probably as part of timed
delegation/escalation or timed completion).
Operation of DELETE means that the allocation was deleted (because of task completion/deletion or delegation).
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="WORK_ITEM_ALLOCATION_EVENT"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="workItemCustomEvent">
<xsd:annotation>
<xsd:documentation>
Subtype of workItemEvent. Custom notification event emitted by "notify" timed action.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="WORK_ITEM_CUSTOM_EVENT"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="workflowProcessEvent">
<xsd:annotation>
<xsd:appinfo>
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.evolveum.midpoint.notifications.api;

import com.evolveum.midpoint.notifications.api.events.Event;
import com.evolveum.midpoint.notifications.api.events.WorkflowEventCreator;
import com.evolveum.midpoint.notifications.api.transports.Transport;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
Expand All @@ -32,8 +31,6 @@ public interface NotificationManager {
void registerTransport(String name, Transport transport);
Transport getTransport(String name);

WorkflowEventCreator getWorkflowEventCreator(Task wfTask);

// event may be null
void processEvent(Event event);

Expand Down
Expand Up @@ -34,9 +34,9 @@
*/
public class WorkItemEvent extends WorkflowEvent {

@NotNull private final WorkItemType workItem;
private final SimpleObjectRef assignee;
private WorkItemNotificationActionType notificationAction; // temporary implementation
@NotNull protected final WorkItemType workItem;
protected final SimpleObjectRef assignee;
@Deprecated private WorkItemNotificationActionType notificationAction; // temporary implementation

public WorkItemEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, ChangeType changeType, @NotNull WorkItemType workItem,
@Nullable SimpleObjectRef assignee, WfContextType workflowContext) {
Expand Down
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.notifications.api.events;

import com.evolveum.midpoint.prism.delta.ChangeType;
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.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.xml.namespace.QName;
import java.util.Map;

/**
* @author mederly
*/
public class WorkItemLifecycleEvent extends WorkItemEvent {

public WorkItemLifecycleEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, ChangeType changeType, @NotNull WorkItemType workItem,
@Nullable SimpleObjectRef assignee, WfContextType workflowContext) {
super(lightweightIdentifierGenerator, changeType, workItem, assignee, workflowContext);
}

@Override
public boolean isCategoryType(EventCategoryType eventCategoryType) {
return eventCategoryType == EventCategoryType.WORK_ITEM_LIFECYCLE_EVENT
|| eventCategoryType == EventCategoryType.WORK_ITEM_EVENT
|| eventCategoryType == EventCategoryType.WORKFLOW_EVENT;
}

@Override
public void createExpressionVariables(Map<QName, Object> variables, OperationResult result) {
super.createExpressionVariables(variables, result);
}

@Override
public String toString() {
return "WorkItemLifecycleEvent:" + super.toString();
}
}
Expand Up @@ -40,6 +40,8 @@ public WorkflowEvent(@NotNull LightweightIdentifierGenerator lightweightIdentifi
this.workflowContext = workflowContext;
}



public String getProcessInstanceName() {
return workflowContext.getProcessInstanceName();
}
Expand Down

This file was deleted.

Expand Up @@ -18,6 +18,7 @@

import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.task.api.LightweightIdentifierGenerator;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventCategoryType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType;

Expand All @@ -26,8 +27,8 @@
*/
public class WorkflowProcessEvent extends WorkflowEvent {

public WorkflowProcessEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, ChangeType changeType, WfContextType workflowContext) {
super(lightweightIdentifierGenerator, changeType, workflowContext);
public WorkflowProcessEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, ChangeType changeType, Task wfTask) {
super(lightweightIdentifierGenerator, changeType, wfTask.getWorkflowContext());
}

@Override
Expand Down
Expand Up @@ -21,9 +21,7 @@
import com.evolveum.midpoint.notifications.api.NotificationManager;
import com.evolveum.midpoint.notifications.api.events.BaseEvent;
import com.evolveum.midpoint.notifications.api.events.Event;
import com.evolveum.midpoint.notifications.api.events.WorkflowEventCreator;
import com.evolveum.midpoint.notifications.api.transports.Transport;
import com.evolveum.midpoint.notifications.impl.events.workflow.DefaultWorkflowEventCreator;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
Expand Down Expand Up @@ -56,9 +54,6 @@ public class NotificationManagerImpl implements NotificationManager {
@Qualifier("cacheRepositoryService")
private transient RepositoryService cacheRepositoryService;

@Autowired
private DefaultWorkflowEventCreator defaultWorkflowEventCreator;

@Autowired
private NotificationFunctions notificationFunctions;

Expand Down Expand Up @@ -102,12 +97,6 @@ public Transport getTransport(String name) {
}
}

@Override
public WorkflowEventCreator getWorkflowEventCreator(Task wfTask) {
// TODO
return defaultWorkflowEventCreator;
}

public void processEvent(@Nullable Event event) {
Task task = taskManager.createTaskInstance(OPERATION_PROCESS_EVENT);
processEvent(event, task, task.getResult());
Expand Down
Expand Up @@ -19,16 +19,18 @@
import com.evolveum.midpoint.notifications.api.NotificationManager;
import com.evolveum.midpoint.notifications.api.events.WorkItemEvent;
import com.evolveum.midpoint.notifications.api.events.WorkflowEvent;
import com.evolveum.midpoint.notifications.api.events.WorkflowEventCreator;
import com.evolveum.midpoint.notifications.api.events.WorkflowProcessEvent;
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.task.api.Task;
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.xml.ns._public.common.common_3.WfContextType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemNotificationActionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -48,14 +50,14 @@ public class WorkflowListener implements ProcessListener, WorkItemListener {

//private static final String DOT_CLASS = WorkflowListener.class.getName() + ".";

@Autowired
private NotificationManager notificationManager;
@Autowired private NotificationManager notificationManager;
@Autowired private NotificationFunctionsImpl functions;
@Autowired private LightweightIdentifierGenerator identifierGenerator;

// WorkflowManager is not required, because e.g. within model-test and model-intest we have no workflows.
// However, during normal operation, it is expected to be available.

@Autowired(required = false)
private WorkflowManager workflowManager;
@Autowired(required = false) private WorkflowManager workflowManager;

@PostConstruct
public void init() {
Expand All @@ -69,38 +71,54 @@ public void init() {

@Override
public void onProcessInstanceStart(Task wfTask, OperationResult result) {
WorkflowEventCreator workflowEventCreator = notificationManager.getWorkflowEventCreator(wfTask);
WorkflowProcessEvent event = workflowEventCreator.createWorkflowProcessStartEvent(wfTask, result);
WorkflowProcessEvent event = new WorkflowProcessEvent(identifierGenerator, ChangeType.ADD, wfTask);
initializeWorkflowEvent(event, wfTask);
processEvent(event, result);
}

@Override
public void onProcessInstanceEnd(Task wfTask, OperationResult result) {
WorkflowEventCreator workflowEventCreator = notificationManager.getWorkflowEventCreator(wfTask);
WorkflowProcessEvent event = workflowEventCreator.createWorkflowProcessEndEvent(wfTask, result);
processEvent(event, result);
}
@Override
public void onProcessInstanceEnd(Task wfTask, OperationResult result) {
WorkflowProcessEvent event = new WorkflowProcessEvent(identifierGenerator, ChangeType.DELETE, wfTask);
initializeWorkflowEvent(event, wfTask);
processEvent(event, result);
}

private void initializeWorkflowEvent(WorkflowEvent event, Task wfTask) {
WfContextType wfc = wfTask.getWorkflowContext();
event.setRequester(new SimpleObjectRefImpl(functions, wfc.getRequesterRef()));
if (wfc.getObjectRef() != null) {
event.setRequestee(new SimpleObjectRefImpl(functions, wfc.getObjectRef()));
}
// TODO what if requestee is yet to be created?
}



@Override
public void onWorkItemCreation(WorkItemType workItem, Task wfTask, OperationResult result) {
WorkflowEventCreator workflowEventCreator = notificationManager.getWorkflowEventCreator(wfTask);
WorkItemEvent event = workflowEventCreator.createWorkItemCreateEvent(workItem, wfTask, result);
processEvent(event);
SimpleObjectRefImpl assignee = workItem.getOriginalAssigneeRef() != null ?
new SimpleObjectRefImpl(functions, workItem.getOriginalAssigneeRef()) : null;
WorkItemEvent event = new WorkItemEvent(identifierGenerator, ChangeType.ADD, workItem, assignee, wfTask.getWorkflowContext());
initializeWorkflowEvent(event, wfTask);
processEvent(event, result);
}

@Override
public void onWorkItemCompletion(WorkItemType workItem, Task wfTask, OperationResult result) {
WorkflowEventCreator workflowEventCreator = notificationManager.getWorkflowEventCreator(wfTask);
WorkItemEvent event = workflowEventCreator.createWorkItemCompleteEvent(workItem, wfTask, result);
processEvent(event);
SimpleObjectRefImpl assignee = workItem.getOriginalAssigneeRef() != null ?
new SimpleObjectRefImpl(functions, workItem.getOriginalAssigneeRef()) : null;
WorkItemEvent event = new WorkItemEvent(identifierGenerator, ChangeType.DELETE, workItem, assignee, wfTask.getWorkflowContext());
initializeWorkflowEvent(event, wfTask);
processEvent(event, result);
}

@Override
public void onWorkItemNotificationAction(WorkItemType workItem, WorkItemNotificationActionType notificationAction,
Task wfTask, OperationResult result) {
WorkflowEventCreator workflowEventCreator = notificationManager.getWorkflowEventCreator(wfTask);
WorkItemEvent event = workflowEventCreator.createWorkItemEventForNotificationAction(workItem, notificationAction, wfTask, result);
processEvent(event);
// WorkflowEventCreator workflowEventCreator = notificationManager.getWorkflowEventCreator(wfTask);
// WorkItemEvent event = workflowEventCreator.createWorkItemEventForNotificationAction(workItem, notificationAction, wfTask, result);
// processEvent(event);
throw new UnsupportedOperationException();
}

private void processEvent(WorkflowEvent event, OperationResult result) {
Expand Down

0 comments on commit 18761c3

Please sign in to comment.