Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4f191955309a0ec000152ad8d1c7d56e8c5a80b3 (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
/*******************************************************************************
 * 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.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osee.ats.api.ai.IAtsActionableItem;
import org.eclipse.osee.ats.api.data.AtsArtifactTypes;
import org.eclipse.osee.ats.api.data.AtsAttributeTypes;
import org.eclipse.osee.ats.core.client.util.AtsUtilCore;
import org.eclipse.osee.ats.internal.Activator;
import org.eclipse.osee.ats.internal.AtsClientService;
import org.eclipse.osee.ats.world.search.ActionableItemWorldSearchItem;
import org.eclipse.osee.ats.world.search.UserRelatedToAtsObjectSearch;
import org.eclipse.osee.ats.world.search.WorldSearchItem.LoadView;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.User;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCheck;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;

/**
 * Check for certain conditions that must be met to delete an ATS object or User artifact.
 * 
 * @author Donald G. Dunne
 */
public class AtsArtifactChecks extends ArtifactCheck {
   @Override
   public IStatus isDeleteable(Collection<Artifact> artifacts) throws OseeCoreException {
      String result = checkActionableItems(artifacts);
      if (result != null) {
         return createStatus(result);
      }

      result = checkTeamDefinitions(artifacts);
      if (result != null) {
         return createStatus(result);
      }

      result = checkAtsWorkDefinitions(artifacts);
      if (result != null) {
         return createStatus(result);
      }

      result = checkUsers(artifacts);
      if (result != null) {
         return createStatus(result);
      }

      return OK_STATUS;
   }

   private IStatus createStatus(String message) {
      return new Status(IStatus.ERROR, Activator.PLUGIN_ID, message);
   }

   private String checkActionableItems(Collection<Artifact> artifacts) throws OseeCoreException {
      Set<IAtsActionableItem> aias = new HashSet<IAtsActionableItem>();
      for (Artifact art : artifacts) {
         if (art.isOfType(AtsArtifactTypes.ActionableItem)) {
            IAtsActionableItem aia =
               AtsClientService.get().getAtsConfig().getSoleByGuid(art.getGuid(), IAtsActionableItem.class);
            if (aia != null) {
               aias.add(aia);
            }
         }
      }
      if (aias.size() > 0) {
         ActionableItemWorldSearchItem srch = new ActionableItemWorldSearchItem("AI search", aias, true, true, false);
         if (srch.performSearchGetResults(false).size() > 0) {
            return String.format(
               "Actionable Items (or children AIs) [%s] selected to delete have related Team Workflows; Delete or re-assign Team Workflows first.",
               aias);
         }
      }
      return null;
   }

   private String checkTeamDefinitions(Collection<Artifact> artifacts) throws OseeCoreException {
      List<String> guids = new ArrayList<String>();
      for (Artifact art : artifacts) {
         if (art.isOfType(AtsArtifactTypes.TeamDefinition)) {
            guids.add(art.getGuid());
         }
      }
      if (guids.size() > 0) {
         List<Artifact> artifactListFromIds =
            ArtifactQuery.getArtifactListFromAttributeValues(AtsAttributeTypes.TeamDefinition, guids,
               AtsUtil.getAtsBranch(), 5);
         if (artifactListFromIds.size() > 0) {
            return String.format(
               "Team Definition (or children Team Definitions) [%s] selected to delete have related Team Workflows; Delete or re-assign Team Workflows first.",
               guids);
         }
      }
      return null;
   }

   private String checkAtsWorkDefinitions(Collection<Artifact> artifacts) throws OseeCoreException {
      for (Artifact art : artifacts) {
         if (art.isOfType(AtsArtifactTypes.WorkDefinition)) {
            List<Artifact> artifactListFromTypeAndAttribute =
               ArtifactQuery.getArtifactListFromTypeAndAttribute(AtsArtifactTypes.WorkDefinition,
                  AtsAttributeTypes.WorkflowDefinition, art.getName(), AtsUtilCore.getAtsBranchToken());
            if (artifactListFromTypeAndAttribute.size() > 0) {
               return String.format(
                  "ATS WorkDefinition [%s] selected to delete has ats.WorkDefinition attributes set to it's name in %d artifact.  These must be changed first.",
                  art, artifactListFromTypeAndAttribute.size());
            }
         }
      }
      return null;
   }

   private String checkUsers(Collection<Artifact> artifacts) throws OseeCoreException {
      Set<User> users = new HashSet<User>();
      for (Artifact art : artifacts) {
         if (art instanceof User) {
            users.add((User) art);
         }
      }
      for (User user : users) {
         UserRelatedToAtsObjectSearch srch =
            new UserRelatedToAtsObjectSearch("User search", AtsClientService.get().getUserAdmin().getUserFromOseeUser(user), false,
               LoadView.None);
         if (srch.performSearchGetResults().size() > 0) {
            return String.format(
               "User name: \"%s\" userId: \"%s\" selected to delete has related ATS Objects; Un-relate to ATS first before deleting.",
               user.getName(), user.getUserId());
         }
      }
      return null;
   }
}

Back to the top