Skip to content

Commit

Permalink
Emitting events when cases are created.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Nov 3, 2017
1 parent 496d1b2 commit 1409c1c
Show file tree
Hide file tree
Showing 18 changed files with 735 additions and 82 deletions.
Expand Up @@ -494,6 +494,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="simpleCaseManagementNotifier" type="tns:SimpleCaseManagementNotifierType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="userPasswordNotifier" type="tns:UserPasswordNotifierType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -673,6 +680,13 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="caseWorkItemEvent">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="CASE_WORK_ITEM_EVENT"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="accessCertificationEvent">
<xsd:annotation>
<xsd:appinfo>
Expand Down Expand Up @@ -701,6 +715,13 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="caseManagementEvent">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="CASE_MANAGEMENT_EVENT"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="taskEvent">
<xsd:annotation>
<xsd:appinfo>
Expand Down Expand Up @@ -998,6 +1019,18 @@
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="SimpleCaseManagementNotifierType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:GeneralNotifierType">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="UserPasswordNotifierType">
<xsd:annotation>
<xsd:documentation>
Expand Down
Expand Up @@ -3200,6 +3200,7 @@ private void assignWillRoleOne(final String TEST_NAME, String expectedFullName)
OperationResult result = task.getResult();

accountWillReqestTimestampStart = clock.currentTimeXMLGregorianCalendar();
dummyTransport.clearMessages();

// WHEN
displayWhen(TEST_NAME);
Expand All @@ -3217,6 +3218,8 @@ private void assignWillRoleOne(final String TEST_NAME, String expectedFullName)
accountWillReqestTimestampEnd = clock.currentTimeXMLGregorianCalendar();

assertAccountWillAfterAssign(TEST_NAME, expectedFullName);

display("dummy transport", dummyTransport);
}

private void assertAccountWillAfterAssign(final String TEST_NAME, String expectedFullName) throws Exception {
Expand Down
Expand Up @@ -39,6 +39,15 @@
</appender>
</logging>
<notificationConfiguration>
<handler>
<simpleCaseManagementNotifier>
<recipientExpression>
<value>recipient@evolveum.com</value>
</recipientExpression>
<showTechnicalInformation>true</showTechnicalInformation>
<transport>dummy:caseNotifier</transport>
</simpleCaseManagementNotifier>
</handler>
<handler>
<simplePolicyRuleNotifier>
<recipientExpression>
Expand Down
@@ -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);
}
}
@@ -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();
}
}
@@ -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();
}
}

0 comments on commit 1409c1c

Please sign in to comment.