Skip to main content
summaryrefslogtreecommitdiffstats
blob: 403c6617cdf41148c068087170f8090b72ca7092 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.actions;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osee.ats.AtsImage;
import org.eclipse.osee.ats.column.ActionableItemsColumn;
import org.eclipse.osee.ats.core.action.ActionArtifactRollup;
import org.eclipse.osee.ats.core.actions.ISelectedAtsArtifacts;
import org.eclipse.osee.ats.core.config.ActionableItemArtifact;
import org.eclipse.osee.ats.core.config.TeamDefinitionArtifact;
import org.eclipse.osee.ats.core.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.core.team.TeamWorkFlowManager;
import org.eclipse.osee.ats.core.workflow.ActionableItemManagerCore;
import org.eclipse.osee.ats.internal.Activator;
import org.eclipse.osee.ats.util.AtsUtil;
import org.eclipse.osee.ats.util.widgets.dialog.AICheckTreeDialog;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.enums.Active;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeStateException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.util.Result;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;

/**
 * @author Donald G. Dunne
 */
public class ConvertActionableItemsAction extends Action {

   private final ISelectedAtsArtifacts selectedAtsArtifacts;

   public ConvertActionableItemsAction(ISelectedAtsArtifacts selectedAtsArtifacts) {
      super("Convert to Actionable Item/Team");
      this.selectedAtsArtifacts = selectedAtsArtifacts;
      setToolTipText(getText());
   }

   @Override
   public void run() {
      try {
         Collection<TeamWorkFlowArtifact> teamArts =
            Collections.castMatching(TeamWorkFlowArtifact.class, selectedAtsArtifacts.getSelectedSMAArtifacts());
         if (teamArts.isEmpty()) {
            throw new OseeStateException("No TeamWorkflows selected");
         }

         TeamWorkFlowArtifact teamArt = teamArts.iterator().next();
         AWorkbench.popup("Capability disabled in this release.  Add Actionable Item and cancel old workflow instead.");
         return;
         //         Result result = convertActionableItems(teamArt);
         //         if (result.isFalse() && !result.getText().equals("")) {
         //            AWorkbench.popup(result);
         //         }
      } catch (Exception ex) {
         OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
      }
   }

   private Result convertActionableItems(TeamWorkFlowArtifact teamArt) throws OseeCoreException {
      Result toReturn = Result.FalseResult;
      AICheckTreeDialog diag =
         new AICheckTreeDialog(
            "Convert Impacted Actionable Items",
            "NOTE: This should NOT be the normal path to changing actionable items.\n\nIf a team has " +
            //
            "determined " + "that there is NO impact and that another actionable items IS impacted:\n" +
            //
            "   1) Cancel this operation\n" + "   2) Select \"Edit Actionable Items\" to add/remove " +
            //
            "impacted items \n" + "      which will create new teams as needed.\n" +
            //
            "   3) Then cancel the team that has no impacts.\n   Doing this will show that the original " +
            //
            "team analyzed the impact\n" + "   and determined that there was no change.\n\n" + "However, " +
            //
            "there are some cases where an impacted item was incorrectly chosen\n" + "and the original team " +
            //
            "does not need to do anything, this dialog will purge the\n" + "team from the DB as if it was " +
            //
            "never chosen.\n\n" + "Current Actionable Item(s): " + ActionableItemsColumn.getActionableItemsStr(teamArt) + "\n" +
            //
            "Current Team: " + teamArt.getTeamDefinition().getName() + "\n" +
            //
            "Select SINGLE Actionable Item below to convert this workflow to.\n\n" +
            //
            "You will be prompted to confirm this conversion.", Active.Both);

      diag.setInput(ActionableItemManagerCore.getTopLevelActionableItems(Active.Both));
      if (diag.open() != 0) {
         return Result.FalseResult;
      }
      if (diag.getChecked().isEmpty()) {
         return new Result("At least one actionable item must must be selected.");
      }
      if (diag.getChecked().size() > 1) {
         return new Result("Only ONE actionable item can be selected for converts");
      }
      ActionableItemArtifact selectedAia = diag.getChecked().iterator().next();
      Collection<TeamDefinitionArtifact> teamDefs =
         ActionableItemManagerCore.getImpactedTeamDefs(Arrays.asList(selectedAia));
      if (teamDefs.size() == 1) {
         TeamDefinitionArtifact newTeamDef = teamDefs.iterator().next();
         // NEED TO FIX THIS
         /**
          * In order for conversion to work, need to validate work defs are same and valid for new AI, check the
          * attribute work def to see if it's valid anymore and make sure current state is valid for new work def. <br/>
          * <br/>
          * May not want to allow this feature anymore
          */
         if (newTeamDef.equals(teamArt.getTeamDefinition())) {
            toReturn =
               new Result(
                  "Actionable Item selected belongs to same team as currently selected team.\n" + "Use \"Edit Actionable Items\" instead.");
         }
         //         else if (!newTeamDef.getWorkDefinition().equals(teamArt.getTeamDefinition())) {
         //            toReturn =
         //               new Result(
         //                  "Work Definitions configuration is not the same for these teams.  Use \"Edit Actionable Items\" instead.");
         //         }
         Result result = isResultingArtifactTypesSame(newTeamDef, teamArt, selectedAia);
         if (result.isFalse()) {
            return result;
         }
         StringBuffer sb = new StringBuffer("Converting...\nActionable Item(s): ");
         sb.append(ActionableItemsColumn.getActionableItemsStr(teamArt));
         sb.append("\nTeam: ");
         sb.append(teamArt.getTeamDefinition().getName());
         sb.append("\nto\nActionable Item(s): ");
         sb.append(selectedAia);
         sb.append("\nTeam: ");
         sb.append(newTeamDef.getName());
         if (MessageDialog.openConfirm(Displays.getActiveShell(), "Confirm Convert", sb.toString())) {
            Set<ActionableItemArtifact> toProcess = new HashSet<ActionableItemArtifact>();
            toProcess.add(selectedAia);
            toReturn = actionableItemsTx(teamArt, AtsUtil.getAtsBranch(), toProcess, newTeamDef);
         }

      } else {
         toReturn = new Result("Single team can not retrieved for " + selectedAia.getName());
      }
      return toReturn;
   }

   private Result isResultingArtifactTypesSame(TeamDefinitionArtifact newTeamDef, TeamWorkFlowArtifact teamArt, ActionableItemArtifact newAI) throws OseeCoreException {
      IArtifactType newTeamWorkflowArtifactType =
         TeamWorkFlowManager.getTeamWorkflowArtifactType(newTeamDef, Arrays.asList(newAI));
      if (!newTeamWorkflowArtifactType.equals(teamArt.getArtifactType())) {
         return new Result(
            String.format(
               "Can not convert because new workflow type [%s] does not match old type [%s].  Use \"Edit Actionable Items\" instead.",
               newTeamWorkflowArtifactType, teamArt.getArtifactType()));
      }
      return Result.TrueResult;
   }

   private Result actionableItemsTx(TeamWorkFlowArtifact teamArt, Branch branch, Set<ActionableItemArtifact> selectedAlias, TeamDefinitionArtifact teamDefinition) throws OseeCoreException {
      Result workResult = teamArt.getActionableItemsDam().setActionableItems(selectedAlias);
      if (workResult.isTrue()) {
         if (teamDefinition != null) {
            teamArt.setTeamDefinition(teamDefinition);
         }
         SkynetTransaction transaction = new SkynetTransaction(branch, "Convert Actionable Item");
         ActionArtifactRollup rollup = new ActionArtifactRollup(teamArt.getParentActionArtifact(), transaction);
         rollup.resetAttributesOffChildren();
         teamArt.persist(transaction);
         transaction.execute();
      }
      return workResult;
   }

   @Override
   public ImageDescriptor getImageDescriptor() {
      return ImageManager.getImageDescriptor(AtsImage.TEAM_DEFINITION);
   }

   public void updateEnablement() {
      try {
         Collection<TeamWorkFlowArtifact> teamArts =
            Collections.castMatching(TeamWorkFlowArtifact.class, selectedAtsArtifacts.getSelectedSMAArtifacts());
         setEnabled(teamArts.size() == 1);
      } catch (Exception ex) {
         OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
         setEnabled(false);
      }
   }
}

Back to the top