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
|
/*******************************************************************************
* Copyright (c) 2012 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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.ats.api.ai.IAtsActionableItem;
import org.eclipse.osee.ats.api.data.AtsRelationTypes;
import org.eclipse.osee.ats.api.team.CreateTeamOption;
import org.eclipse.osee.ats.api.team.IAtsTeamDefinition;
import org.eclipse.osee.ats.api.user.IAtsUser;
import org.eclipse.osee.ats.core.client.action.ActionManager;
import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.internal.AtsClientService;
import org.eclipse.osee.ats.util.AtsUtil;
import org.eclipse.osee.ats.world.AtsWorldEditorRenderer;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Conditions;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam;
import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;
/**
* @author Ryan D. Brooks
*/
public class WorkflowPortingBlam extends AbstractBlam {
private final static String SOURCE_WORKFLOWS = "Source Workflows (drop here)";
private final static String ACTIONABLE_ITEM = "Destination actionable item(s)";
private List<TeamWorkFlowArtifact> sourceWorkflows;
@Override
public void runOperation(final VariableMap variableMap, IProgressMonitor monitor) throws OseeCoreException {
sourceWorkflows = Collections.castAll(variableMap.getArtifacts(SOURCE_WORKFLOWS));
Conditions.checkNotNullOrEmpty(sourceWorkflows, SOURCE_WORKFLOWS);
List<IAtsActionableItem> actionableItems =
getActionableItems((IAtsActionableItem) variableMap.getValue(ACTIONABLE_ITEM));
Conditions.checkNotNullOrEmpty(actionableItems, ACTIONABLE_ITEM);
SkynetTransaction transaction =
TransactionManager.createTransaction(AtsUtil.getAtsBranch(), "Create Porting Workflow(s)");
List<Artifact> destinationWorkflows = createDestinationWorkflows(transaction, actionableItems);
transaction.execute();
AtsWorldEditorRenderer renderer = new AtsWorldEditorRenderer();
renderer.open(destinationWorkflows, PresentationType.SPECIALIZED_EDIT);
}
private List<Artifact> createDestinationWorkflows(SkynetTransaction transaction, List<IAtsActionableItem> actionableItems) throws OseeCoreException {
IAtsTeamDefinition teamDefinition = actionableItems.get(0).getTeamDefinition();
List<Artifact> destinationWorkflows = new ArrayList<Artifact>();
IAtsUser createdBy = AtsClientService.get().getUserAdmin().getCurrentUser();
Date createdDate = new Date();
for (TeamWorkFlowArtifact sourceWorkflow : sourceWorkflows) {
Artifact destinationWorkflow;
if (sourceWorkflow.getRelatedArtifacts(AtsRelationTypes.Port_To).isEmpty()) {
List<IAtsUser> assignees = sourceWorkflow.getStateMgr().getAssignees();
destinationWorkflow =
ActionManager.createTeamWorkflow(sourceWorkflow.getParentActionArtifact(), teamDefinition,
actionableItems, assignees, transaction, createdDate, createdBy, null,
CreateTeamOption.Duplicate_If_Exists);
destinationWorkflow.setName(sourceWorkflow.getName());
destinationWorkflow.persist(transaction);
sourceWorkflow.addRelation(AtsRelationTypes.Port_To, destinationWorkflow);
sourceWorkflow.persist(transaction);
} else {
destinationWorkflow = sourceWorkflow.getRelatedArtifact(AtsRelationTypes.Port_To);
log("Reusing destination workflow " + destinationWorkflow);
}
destinationWorkflows.add(destinationWorkflow);
}
return destinationWorkflows;
}
private List<IAtsActionableItem> getActionableItems(IAtsActionableItem actionableItem) throws OseeCoreException {
List<IAtsActionableItem> actionableItems;
if (actionableItem == null) {
actionableItems =
new ArrayList<IAtsActionableItem>(sourceWorkflows.get(0).getActionableItemsDam().getActionableItems());
} else {
actionableItems = java.util.Collections.singletonList(actionableItem);
}
return actionableItems;
}
@Override
public String getXWidgetsXml() {
return "<xWidgets><XWidget xwidgetType=\"XListDropViewer\" displayName=\"" + SOURCE_WORKFLOWS + "\" /><XWidget xwidgetType=\"XActionableItemCombo\" displayName=\"" + ACTIONABLE_ITEM + "\" /></xWidgets>";
}
@Override
public String getDescriptionUsage() {
return "Create porting workflows related by port relation for selected actionable items (or same as source workflow)";
}
@Override
public Collection<String> getCategories() {
return Arrays.asList("ATS");
}
}
|