blob: 2393b2f7f0ef99607317912dc64eb898e683ba9c (
plain) (
blame)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*******************************************************************************
* Copyright (c) 2013 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.ats.core.client.internal.query;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.osee.ats.api.IAtsWorkItem;
import org.eclipse.osee.ats.api.query.IAtsQuery;
import org.eclipse.osee.ats.api.team.IAtsTeamDefinition;
import org.eclipse.osee.ats.api.workdef.StateType;
import org.eclipse.osee.ats.api.workflow.IAtsWorkData;
import org.eclipse.osee.ats.api.workflow.IAtsWorkItemService;
import org.eclipse.osee.ats.core.client.internal.IAtsWorkItemArtifactService;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
/**
* @author Donald G. Dunne
*/
public class AtsQuery implements IAtsQuery {
private final Collection<? extends IAtsWorkItem> items;
private final IAtsWorkItemService workItemService;
private final IAtsWorkItemArtifactService workItemArtifactProvider;
public AtsQuery(Collection<? extends IAtsWorkItem> workItems, IAtsWorkItemService workItemService, IAtsWorkItemArtifactService teamDefService) {
this.items = workItems;
this.workItemService = workItemService;
this.workItemArtifactProvider = teamDefService;
}
@Override
public IAtsQuery isOfType(IArtifactType... artifactType) throws OseeCoreException {
boolean found = false;
for (IAtsWorkItem item : new CopyOnWriteArrayList<IAtsWorkItem>(items)) {
for (IArtifactType matchType : artifactType) {
if (workItemService.isOfType(item, matchType)) {
found = true;
break;
}
}
if (!found) {
items.remove(item);
}
}
return this;
}
@Override
public IAtsQuery union(IAtsQuery... atsQuery) throws OseeCoreException {
Set<IAtsWorkItem> items = new HashSet<IAtsWorkItem>();
for (IAtsQuery query : atsQuery) {
items.addAll(query.getItems());
}
return this;
}
@Override
public IAtsQuery fromTeam(IAtsTeamDefinition teamDef) throws OseeCoreException {
for (IAtsWorkItem workItem : new CopyOnWriteArrayList<IAtsWorkItem>(items)) {
IAtsTeamDefinition itemTeamDef = workItemArtifactProvider.getTeamDefinition(workItem);
if (!itemTeamDef.getGuid().equals(teamDef.getGuid())) {
items.remove(workItem);
}
}
return this;
}
@Override
public IAtsQuery isStateType(StateType... stateType) throws OseeCoreException {
List<StateType> types = new ArrayList<StateType>();
for (StateType type : stateType) {
types.add(type);
}
for (IAtsWorkItem workItem : new CopyOnWriteArrayList<IAtsWorkItem>(items)) {
IAtsWorkData workData = workItemService.getWorkData(workItem);
if (workData.isCompleted() && !types.contains(StateType.Completed)) {
items.remove(workItem);
} else if (workData.isCancelled() && !types.contains(StateType.Cancelled)) {
items.remove(workItem);
} else if (workData.isInWork() && !types.contains(StateType.Working)) {
items.remove(workItem);
}
}
return this;
}
@Override
public Collection<? extends IAtsWorkItem> getItems() {
return items;
}
@Override
public IAtsQuery withOrValue(IAttributeType attributeType, Collection<? extends Object> matchValues) throws OseeCoreException {
if (matchValues != null && !matchValues.isEmpty()) {
for (IAtsWorkItem workItem : new CopyOnWriteArrayList<IAtsWorkItem>(items)) {
Collection<Object> currAttrValues = workItemService.getAttributeValues(workItem, attributeType);
boolean found = false;
for (Object matchValue : matchValues) {
if (currAttrValues.contains(matchValue)) {
found = true;
break;
}
}
if (!found) {
items.remove(workItem);
}
}
}
return this;
}
}
|