Skip to main content
summaryrefslogtreecommitdiffstats
blob: 03435b68482554d5147dcf515b1244e39cd59d95 (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
/*******************************************************************************
 * 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.navigate.report;

import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osee.ats.api.commit.ICommitConfigItem;
import org.eclipse.osee.ats.api.data.AtsAttributeTypes;
import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.internal.Activator;
import org.eclipse.osee.ats.internal.AtsClientService;
import org.eclipse.osee.ats.util.AtsBranchManager;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.util.Result;
import org.eclipse.osee.framework.core.util.XResultData;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.attribute.EnumeratedAttribute;
import org.eclipse.osee.framework.skynet.core.revision.ChangeData;
import org.eclipse.osee.framework.skynet.core.revision.ChangeData.KindType;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.results.XResultDataUI;
import org.eclipse.osee.framework.ui.skynet.results.html.XResultPage.Manipulations;
import org.eclipse.osee.framework.ui.skynet.util.HtmlExportTable;
import org.eclipse.osee.framework.ui.swt.Displays;

/**
 * @author Donald G. Dunne
 */
public class CreateActionArtifactChangeReportJob extends Job {
   private final Set<TeamWorkFlowArtifact> teamArts;
   private final IAttributeType attributeType;

   public CreateActionArtifactChangeReportJob(String jobName, Set<TeamWorkFlowArtifact> teamArts, IAttributeType attributeType) {
      super(jobName);
      this.teamArts = teamArts;
      this.attributeType = attributeType;
   }

   @Override
   public IStatus run(IProgressMonitor monitor) {
      return runIt(monitor, getName(), teamArts, attributeType);
   }

   public static IStatus runIt(IProgressMonitor monitor, String jobName, Collection<TeamWorkFlowArtifact> teamArts, IAttributeType attributeType) {
      XResultData rd = new XResultData();
      try {
         if (teamArts.isEmpty()) {
            throw new OseeStateException("No Actions/Workflows Specified");
         }
         retrieveData(monitor, teamArts, attributeType, rd);
         if (rd.toString().equals("")) {
            rd.log("No Problems Found");
         }
         final String html = XResultDataUI.getReport(rd, jobName).getManipulatedHtml(Arrays.asList(Manipulations.NONE));
         final String title = jobName;
         Displays.pendInDisplayThread(new Runnable() {
            @Override
            public void run() {
               Result result = new HtmlExportTable(title, html, true, false).exportCsv();
               if (result.isFalse()) {
                  AWorkbench.popup(result);
                  return;
               }
               AWorkbench.popup(
                  title,
                  "Completed " + title + "\n\nFile saved to " + System.getProperty("user.home") + File.separator + "table.csv");
            }
         });
         monitor.done();
         return Status.OK_STATUS;
      } catch (Exception ex) {
         OseeLog.log(Activator.class, Level.SEVERE, ex);
         return new Status(IStatus.ERROR, Activator.PLUGIN_ID, -1, "Failed", ex);
      }
   }

   /**
    * used recursively when originally passed a directory, thus an array of files is accepted
    */
   private static void retrieveData(IProgressMonitor monitor, Collection<TeamWorkFlowArtifact> teamArts, IAttributeType attributeType, XResultData rd) throws OseeCoreException {
      monitor.subTask("Retrieving Actions");

      int x = 1;
      rd.addRaw(AHTML.beginMultiColumnTable(95));
      rd.addRaw(AHTML.addHeaderRowMultiColumnTable(new String[] {
         "ID",
         "Bulld",
         "UI",
         attributeType.getName(),
         "RPCR",
         "Change"}));
      for (TeamWorkFlowArtifact teamArt : teamArts) {
         String rcprId = teamArt.getSoleAttributeValue(AtsAttributeTypes.LegacyPcrId, "");
         String result =
            String.format("Processing %s/%s RPCR %s for \"%s\"", x, teamArts.size(), rcprId,
               teamArt.getTeamDefinition().getName());
         monitor.subTask(result);
         rd.log("\nRPCR " + rcprId);
         for (ICommitConfigItem commitConfigArt : AtsClientService.get().getBranchService().getConfigArtifactsConfiguredToCommitTo(
            teamArt)) {
            processTeam(teamArt, AtsClientService.get().getBranchService().getBranchShortName(commitConfigArt),
               attributeType, commitConfigArt, rd);
         }
         x++;

         //          System.err.println("Developmental purposes only, don't release with this");
         //          if (x >= 5)
         //          break;
      }
      rd.addRaw(AHTML.endMultiColumnTable());
   }

   private static void processTeam(TeamWorkFlowArtifact teamArt, String buildId, IAttributeType attributeType, ICommitConfigItem commitConfigArt, XResultData rd) throws OseeCoreException {
      String rpcrNum = teamArt.getSoleAttributeValue(AtsAttributeTypes.LegacyPcrId, "");
      ChangeData changeData = AtsBranchManager.getChangeData(teamArt, commitConfigArt);
      for (Artifact modArt : changeData.getArtifacts(KindType.Artifact, ModificationType.NEW, ModificationType.MODIFIED)) {
         List<String> attrStrs = modArt.getAttributesToStringList(attributeType);
         if (attrStrs.isEmpty()) {
            attrStrs.add(EnumeratedAttribute.UNSPECIFIED_VALUE);
         }
         for (String attrStr : attrStrs) {
            rd.addRaw(AHTML.addRowMultiColumnTable(new String[] {
               teamArt.getAtsId(),
               buildId,
               modArt.getName(),
               attrStr,
               rpcrNum,
               "Content"}));
         }
      }
      for (Artifact artChg : changeData.getArtifacts(KindType.Artifact, ModificationType.DELETED)) {
         List<String> attrStrs = artChg.getAttributesToStringList(attributeType);
         if (attrStrs.isEmpty()) {
            attrStrs.add(EnumeratedAttribute.UNSPECIFIED_VALUE);
         }
         for (String attrStr : attrStrs) {
            rd.addRaw(AHTML.addRowMultiColumnTable(new String[] {
               teamArt.getAtsId(),
               buildId,
               artChg.getName(),
               attrStr,
               rpcrNum,
               "Deleted"}));
         }
      }
      for (Artifact artChg : changeData.getArtifacts(KindType.RelationOnly, ModificationType.NEW,
         ModificationType.MODIFIED)) {
         List<String> attrStrs = artChg.getAttributesToStringList(attributeType);
         if (attrStrs.isEmpty()) {
            attrStrs.add(EnumeratedAttribute.UNSPECIFIED_VALUE);
         }
         for (String attrStr : attrStrs) {
            rd.addRaw(AHTML.addRowMultiColumnTable(new String[] {
               teamArt.getAtsId(),
               buildId,
               artChg.getName(),
               attrStr,
               rpcrNum,
               "Relation"}));
         }
      }
   }

}

Back to the top