Skip to main content
summaryrefslogtreecommitdiffstats
blob: ff22f0c0673b9dc3ea27a5c239d99af85a36df76 (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
/*******************************************************************************
 * Copyright (c) 2011 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.util;

import java.util.Collection;
import org.eclipse.osee.ats.core.type.AtsArtifactTypes;
import org.eclipse.osee.ats.core.type.AtsAttributeTypes;
import org.eclipse.osee.ats.core.type.AtsRelationTypes;
import org.eclipse.osee.ats.core.workdef.RuleDefinitionOption;
import org.eclipse.osee.ats.core.workdef.StateDefinition;
import org.eclipse.osee.ats.core.workflow.AbstractWorkflowArtifact;
import org.eclipse.osee.ats.core.workflow.StateManager;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeStateException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;

/**
 * @author Donald G. Dunne
 */
public class WorkflowManagerCore {

   public static StateManager getStateManager(Artifact artifact) {
      return cast(artifact).getStateMgr();
   }

   public static AbstractWorkflowArtifact cast(Artifact artifact) {
      if (artifact instanceof AbstractWorkflowArtifact) {
         return (AbstractWorkflowArtifact) artifact;
      }
      return null;
   }

   public static boolean isEditable(AbstractWorkflowArtifact sma, StateDefinition stateDef, boolean priviledgedEditEnabled) throws OseeCoreException {
      // must be writeable
      return !sma.isReadOnly() &&
      // and access control writeable
      sma.isAccessControlWrite() &&
      // and current state
      (stateDef == null || sma.isInState(stateDef)) &&
      // and one of these
      //
      // page is define to allow anyone to edit
      (sma.getStateDefinition().hasRule(RuleDefinitionOption.AllowEditToAll) ||
      // team definition has allowed anyone to edit
      sma.teamDefHasRule(RuleDefinitionOption.AllowEditToAll) ||
      // priviledged edit mode is on
      priviledgedEditEnabled ||
      // current user is assigned
      sma.isAssigneeMe() ||
      // current user is ats admin
      AtsUtilCore.isAtsAdmin());
   }

   public static AbstractWorkflowArtifact getParentAWA(Artifact artifact) throws OseeCoreException {
      if (artifact.isOfType(AtsArtifactTypes.Task)) {
         Collection<Artifact> awas = artifact.getRelatedArtifacts(AtsRelationTypes.SmaToTask_Sma);
         if (awas.isEmpty()) {
            throw new OseeStateException("Task has no parent [%s]", artifact.getHumanReadableId());
         }
         return (AbstractWorkflowArtifact) awas.iterator().next();
      } else if (artifact.isOfType(AtsArtifactTypes.ReviewArtifact)) {
         Collection<Artifact> awas = artifact.getRelatedArtifacts(AtsRelationTypes.TeamWorkflowToReview_Team);
         if (!awas.isEmpty()) {
            return (AbstractWorkflowArtifact) awas.iterator().next();
         }
      }
      return null;
   }

   public static Artifact getTeamDefinition(Artifact artifact) throws OseeCoreException {
      Artifact team = getParentTeamWorkflow(artifact);
      if (team != null) {
         String teamDefGuid = team.getSoleAttributeValue(AtsAttributeTypes.TeamDefinition);
         return ArtifactQuery.getArtifactFromId(teamDefGuid, BranchManager.getCommonBranch());
      }
      return null;
   }

   public static Artifact getParentActionArtifact(Artifact artifact) throws OseeCoreException {
      Artifact team = getParentTeamWorkflow(artifact);
      if (team != null) {
         return artifact.getRelatedArtifact(AtsRelationTypes.ActionToWorkflow_Action);
      }
      return null;
   }

   public static Artifact getParentTeamWorkflow(Artifact artifact) throws OseeCoreException {
      if (artifact.isOfType(AtsArtifactTypes.TeamWorkflow)) {
         return artifact;
      } else if (artifact.isOfType(AtsArtifactTypes.Task)) {
         return getParentAWA(artifact);
      } else if (artifact.isOfType(AtsArtifactTypes.ReviewArtifact)) {
         return getParentAWA(artifact);
      }
      return null;
   }

}

Back to the top