Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emitting events when cases are created.
- Loading branch information
Showing
18 changed files
with
735 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...api/src/main/java/com/evolveum/midpoint/notifications/api/events/CaseManagementEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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.task.api.LightweightIdentifierGenerator; | ||
import com.evolveum.midpoint.util.DebugUtil; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author mederly | ||
*/ | ||
abstract public class CaseManagementEvent extends BaseEvent { | ||
|
||
@NotNull protected final CaseType aCase; | ||
@NotNull private final ChangeType changeType; | ||
|
||
public CaseManagementEvent(@NotNull LightweightIdentifierGenerator lightweightIdentifierGenerator, | ||
@NotNull ChangeType changeType, @NotNull CaseType aCase) { | ||
super(lightweightIdentifierGenerator); | ||
this.changeType = changeType; | ||
this.aCase = aCase; | ||
} | ||
|
||
@Override | ||
public boolean isStatusType(EventStatusType eventStatusType) { | ||
// temporary implementation | ||
return eventStatusType == EventStatusType.SUCCESS || eventStatusType == EventStatusType.ALSO_SUCCESS || eventStatusType == EventStatusType.IN_PROGRESS; | ||
} | ||
|
||
@NotNull | ||
public ChangeType getChangeType() { | ||
return changeType; | ||
} | ||
|
||
@NotNull | ||
public CaseType getCase() { | ||
return aCase; | ||
} | ||
|
||
@Override | ||
public boolean isOperationType(EventOperationType eventOperationType) { | ||
return changeTypeMatchesOperationType(changeType, eventOperationType); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CaseManagementEvent{" + | ||
"aCase=" + aCase + | ||
", changeType=" + changeType + | ||
'}'; | ||
} | ||
|
||
@Override | ||
protected void debugDumpCommon(StringBuilder sb, int indent) { | ||
super.debugDumpCommon(sb, indent); | ||
DebugUtil.debugDumpWithLabelLn(sb, "case", getCase().asPrismContainerValue(), indent + 1); | ||
DebugUtil.debugDumpWithLabelToStringLn(sb, "changeType", changeType, indent + 1); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...s-api/src/main/java/com/evolveum/midpoint/notifications/api/events/CaseWorkItemEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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.prism.path.ItemPath; | ||
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.util.DebugUtil; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.xml.namespace.QName; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author mederly | ||
*/ | ||
public class CaseWorkItemEvent extends CaseManagementEvent { | ||
|
||
@NotNull protected final CaseWorkItemType workItem; | ||
@NotNull protected final SimpleObjectRef assignee; | ||
|
||
public CaseWorkItemEvent(@NotNull LightweightIdentifierGenerator lightweightIdentifierGenerator, | ||
@NotNull ChangeType changeType, @NotNull CaseWorkItemType workItem, @NotNull SimpleObjectRef assignee, | ||
@NotNull CaseType aCase) { | ||
super(lightweightIdentifierGenerator, changeType, aCase); | ||
this.workItem = workItem; | ||
this.assignee = assignee; | ||
} | ||
|
||
public String getWorkItemName() { | ||
return workItem.getName(); | ||
} | ||
|
||
@NotNull | ||
public CaseWorkItemType getWorkItem() { | ||
return workItem; | ||
} | ||
|
||
@Override | ||
public boolean isCategoryType(EventCategoryType eventCategoryType) { | ||
return eventCategoryType == EventCategoryType.WORK_ITEM_EVENT || eventCategoryType == EventCategoryType.WORKFLOW_EVENT; | ||
} | ||
|
||
@NotNull | ||
public SimpleObjectRef getAssignee() { | ||
return assignee; | ||
} | ||
|
||
@Override | ||
public void createExpressionVariables(Map<QName, Object> variables, OperationResult result) { | ||
super.createExpressionVariables(variables, result); | ||
variables.put(SchemaConstants.C_ASSIGNEE, assignee.resolveObjectType(result, false)); | ||
variables.put(SchemaConstants.C_WORK_ITEM, workItem); | ||
} | ||
|
||
@Override | ||
public boolean isRelatedToItem(ItemPath itemPath) { | ||
return false; // TODO reconsider | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CaseWorkItemEvent{" + | ||
"workItem=" + workItem + | ||
", assignee=" + assignee + | ||
", aCase=" + aCase + | ||
'}'; | ||
} | ||
|
||
@SuppressWarnings("Duplicates") | ||
@Override | ||
public String debugDump(int indent) { | ||
StringBuilder sb = DebugUtil.createTitleStringBuilderLn(this.getClass(), indent); | ||
debugDumpCommon(sb, indent); | ||
DebugUtil.debugDumpWithLabelLn(sb, "workItemName", getWorkItemName(), indent + 1); | ||
DebugUtil.debugDumpWithLabelToString(sb, "assignee", assignee, indent + 1); | ||
return sb.toString(); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...s-impl/src/main/java/com/evolveum/midpoint/notifications/impl/CaseManagementListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.impl; | ||
|
||
import com.evolveum.midpoint.casemgmt.api.CaseManager; | ||
import com.evolveum.midpoint.casemgmt.api.CaseWorkItemListener; | ||
import com.evolveum.midpoint.notifications.api.NotificationManager; | ||
import com.evolveum.midpoint.notifications.api.events.*; | ||
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.xml.ns._public.common.common_3.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
/** | ||
* Listener that accepts events generated by case management module. These events are related to case work items. | ||
* | ||
* @author mederly | ||
*/ | ||
@Component | ||
public class CaseManagementListener implements CaseWorkItemListener { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(CaseManagementListener.class); | ||
|
||
//private static final String DOT_CLASS = WorkflowListener.class.getName() + "."; | ||
|
||
@Autowired private NotificationManager notificationManager; | ||
@Autowired private NotificationFunctionsImpl functions; | ||
@Autowired private LightweightIdentifierGenerator identifierGenerator; | ||
@Autowired private CaseManager caseManager; | ||
|
||
@PostConstruct | ||
public void init() { | ||
caseManager.registerWorkItemListener(this); | ||
} | ||
|
||
@Override | ||
public void onWorkItemCreation(CaseWorkItemType workItem, CaseType aCase, Task task, OperationResult result) { | ||
for (ObjectReferenceType assigneeRef : workItem.getAssigneeRef()) { | ||
CaseWorkItemEvent event = new CaseWorkItemEvent(identifierGenerator, ChangeType.ADD, workItem, | ||
SimpleObjectRefImpl.create(functions, assigneeRef), aCase); | ||
processEvent(event, result); | ||
} | ||
} | ||
|
||
private void processEvent(CaseWorkItemEvent event, OperationResult result) { | ||
try { | ||
notificationManager.processEvent(event); | ||
} catch (RuntimeException e) { | ||
result.recordFatalError("An unexpected exception occurred when preparing and sending notifications: " + e.getMessage(), e); | ||
LoggingUtils.logUnexpectedException(LOGGER, "An unexpected exception occurred when preparing and sending notifications: " + e.getMessage(), e); | ||
} | ||
|
||
// todo work correctly with operationResult (in whole notification module) | ||
if (result.isUnknown()) { | ||
result.computeStatus(); | ||
} | ||
result.recordSuccessIfUnknown(); | ||
} | ||
} |
Oops, something went wrong.