Skip to main content
summaryrefslogtreecommitdiffstats
blob: 86f06ea2d13f08176d59e50b30ed4a33f1ee1fea (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
/*******************************************************************************
 * 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.workdef.provider;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.osee.ats.api.ai.IAtsActionableItem;
import org.eclipse.osee.ats.api.team.IAtsTeamDefinition;
import org.eclipse.osee.ats.api.user.IAtsUser;
import org.eclipse.osee.ats.api.version.IAtsVersion;
import org.eclipse.osee.ats.core.config.ActionableItems;
import org.eclipse.osee.ats.core.config.TeamDefinitions;
import org.eclipse.osee.ats.dsl.atsDsl.ActionableItemDef;
import org.eclipse.osee.ats.dsl.atsDsl.AtsDsl;
import org.eclipse.osee.ats.dsl.atsDsl.BooleanDef;
import org.eclipse.osee.ats.dsl.atsDsl.TeamDef;
import org.eclipse.osee.ats.dsl.atsDsl.UserByName;
import org.eclipse.osee.ats.dsl.atsDsl.VersionDef;
import org.eclipse.osee.ats.dsl.atsDsl.impl.AtsDslFactoryImpl;
import org.eclipse.osee.ats.internal.Activator;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.XResultData;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;

/**
 * Take existing AIs, TeamDefs and Versions and create AtsDsl
 * 
 * @author Donald G. Dunne
 */
public class ConvertAIsAndTeamsToAtsDsl {

   private final XResultData resultData;
   private AtsDsl atsDsl;
   private final Map<String, TeamDef> dslTeamDefs = new HashMap<String, TeamDef>();
   private final Map<String, ActionableItemDef> dslAIDefs = new HashMap<String, ActionableItemDef>();

   public ConvertAIsAndTeamsToAtsDsl(XResultData resultData) {
      this.resultData = resultData;
   }

   public AtsDsl convert(String definitionName) {
      resultData.log("Converting AIs and Teams to ATS DSL");
      atsDsl = AtsDslFactoryImpl.init().createAtsDsl();

      try {
         // Add all TeamDef definitions
         TeamDef topTeam = convertTeamDef(TeamDefinitions.getTopTeamDefinition(), null);
         atsDsl.getTeamDef().add(topTeam);

         // Add all AI definitions
         ActionableItemDef topAi = convertAIDef(ActionableItems.getTopActionableItem(), null);
         atsDsl.getActionableItemDef().add(topAi);

      } catch (OseeCoreException ex) {
         resultData.logError("Exception: " + ex.getLocalizedMessage());
         OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
      }
      return atsDsl;
   }

   private ActionableItemDef convertAIDef(IAtsActionableItem aiArt, ActionableItemDef dslParentAIDef) throws OseeCoreException {
      ActionableItemDef dslAIDef = AtsDslFactoryImpl.init().createActionableItemDef();
      if (dslParentAIDef != null) {
         dslParentAIDef.getChildren().add(dslAIDef);
      }
      dslAIDef.setName(aiArt.getName());
      dslAIDefs.put(aiArt.getName(), dslAIDef);
      if (aiArt.isActive()) {
         dslAIDef.setActive(BooleanDef.TRUE);
      }
      if (aiArt.isActionable()) {
         dslAIDef.setActionable(BooleanDef.TRUE);
      }
      for (String staticId : aiArt.getStaticIds()) {
         dslAIDef.getStaticId().add(staticId);
      }
      for (IAtsUser user : aiArt.getLeads()) {
         dslAIDef.getLead().add(getUserByName(user));
      }
      IAtsTeamDefinition teamDef = aiArt.getTeamDefinition();
      if (teamDef != null) {
         dslAIDef.setTeamDef(teamDef.getName());
      }
      // process children
      for (IAtsActionableItem childAiArt : aiArt.getChildrenActionableItems()) {
         convertAIDef(childAiArt, dslAIDef);
      }
      return dslAIDef;
   }

   private TeamDef convertTeamDef(IAtsTeamDefinition teamDef, TeamDef dslParentTeamDef) throws OseeCoreException {
      TeamDef dslTeamDef = AtsDslFactoryImpl.init().createTeamDef();
      if (dslParentTeamDef != null) {
         dslParentTeamDef.getChildren().add(dslTeamDef);
      }

      dslTeamDef.setName(teamDef.getName());
      dslTeamDefs.put(teamDef.getName(), dslTeamDef);
      if (teamDef.isActive()) {
         dslTeamDef.setActive(BooleanDef.TRUE);
      }
      for (String staticId : teamDef.getStaticIds()) {
         dslTeamDef.getStaticId().add(staticId);
      }
      for (IAtsUser user : teamDef.getLeads()) {
         dslTeamDef.getLead().add(getUserByName(user));
      }
      for (IAtsUser user : teamDef.getMembers()) {
         dslTeamDef.getMember().add(getUserByName(user));
      }
      for (IAtsUser user : teamDef.getPrivilegedMembers()) {
         dslTeamDef.getPrivileged().add(getUserByName(user));
      }
      for (IAtsVersion verArt : teamDef.getVersions()) {
         convertVersionArtifact(dslTeamDef, verArt, teamDef);
      }
      // process children
      for (IAtsTeamDefinition childAiArt : teamDef.getChildrenTeamDefinitions()) {
         convertTeamDef(childAiArt, dslTeamDef);
      }
      return dslTeamDef;
   }

   private void convertVersionArtifact(TeamDef dslTeamDef, IAtsVersion verArt, IAtsTeamDefinition teamDef) {
      VersionDef dslVerDef = AtsDslFactoryImpl.init().createVersionDef();
      dslVerDef.setName(verArt.getName());
      if (verArt.isNextVersion()) {
         dslVerDef.setNext(BooleanDef.TRUE);
      }
      for (String staticId : teamDef.getStaticIds()) {
         dslVerDef.getStaticId().add(staticId);
      }
      if (verArt.isReleased()) {
         dslVerDef.setReleased(BooleanDef.TRUE);
      }
      if (verArt.isAllowCommitBranchInherited().isTrue()) {
         dslVerDef.setAllowCommitBranch(BooleanDef.TRUE);
      }
      if (verArt.isAllowCreateBranchInherited().isTrue()) {
         dslVerDef.setAllowCreateBranch(BooleanDef.TRUE);
      }
      if (verArt.getBaselineBranchGuidInherited() != null) {
         dslVerDef.setBaselineBranchGuid(verArt.getBaselineBranchGuidInherited());
      }
      dslTeamDef.getVersion().add(dslVerDef);
   }

   private UserByName getUserByName(IAtsUser user) {
      UserByName userByName = AtsDslFactoryImpl.init().createUserByName();
      userByName.setUserName(user.getName());
      return userByName;
   }
}

Back to the top