-
Notifications
You must be signed in to change notification settings - Fork 188
/
CaseWorkItemUtil.java
93 lines (78 loc) · 3.16 KB
/
CaseWorkItemUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Copyright (c) 2010-2015 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.schema.util;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author bpowers
*/
public class CaseWorkItemUtil {
@NotNull
public static CaseType getCaseRequired(CaseWorkItemType workItem) {
CaseType rv = getCase(workItem);
if (rv != null) {
return rv;
} else {
throw new IllegalStateException("No parent case for " + workItem);
}
}
public static CaseType getCase(CaseWorkItemType workItem) {
if (workItem == null) {
return null;
}
@SuppressWarnings({"unchecked", "raw"})
PrismContainerable<CaseWorkItemType> parent = workItem.asPrismContainerValue().getParent();
if (!(parent instanceof PrismContainer)) {
return null;
}
PrismValue parentParent = ((PrismContainer<CaseWorkItemType>) parent).getParent();
if (!(parentParent instanceof PrismContainerValue)) {
return null;
}
@SuppressWarnings({"unchecked", "raw"})
PrismContainerValue<CaseType> parentParentPcv = (PrismContainerValue<CaseType>) parentParent;
return parentParentPcv.asContainerable();
}
public static WorkItemId getId(CaseWorkItemType workItem) {
return WorkItemId.of(workItem);
}
public static CaseWorkItemType getWorkItem(CaseType aCase, long id) {
for (CaseWorkItemType workItem : aCase.getWorkItem()) {
if (workItem.getId() != null && workItem.getId() == id) {
return workItem;
}
}
return null;
}
public static boolean isCaseWorkItemNotClosed(CaseWorkItemType workItem) {
return workItem != null && workItem.getCloseTimestamp() == null;
}
public static boolean isCaseWorkItemClosed(CaseWorkItemType workItem) {
return workItem != null && workItem.getCloseTimestamp() != null;
}
public static boolean isWorkItemClaimable(CaseWorkItemType workItem){
return workItem != null && (workItem.getOriginalAssigneeRef() == null || StringUtils.isEmpty(workItem.getOriginalAssigneeRef().getOid()))
&& !doesAssigneeExist(workItem) && CollectionUtils.isNotEmpty(workItem.getCandidateRef());
}
public static boolean doesAssigneeExist(CaseWorkItemType workItem){
if (workItem == null || CollectionUtils.isEmpty(workItem.getAssigneeRef())){
return false;
}
for (ObjectReferenceType assignee : workItem.getAssigneeRef()){
if (StringUtils.isNotEmpty(assignee.getOid())){
return true;
}
}
return false;
}
}