summaryrefslogtreecommitdiffstats
blob: d1409f6107dcec35c81dbfa9e5262f33155f19a8 (plain)
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
/*******************************************************************************
 * 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.define.blam.operation;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.core.util.XResultData;
import org.eclipse.osee.framework.jdk.core.util.AHTML;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.relation.RelationManager;
import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam;
import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
import org.eclipse.osee.framework.ui.skynet.results.XResultDataUI;
import org.eclipse.osee.framework.ui.skynet.results.html.XResultPage.Manipulations;

public class RequirementsTestReport extends AbstractBlam {
   private static final String MISSING = "?";
   private static final String EMPTY = " ";
   private static final String SPACE = " ";
   private String[] previousCells = {MISSING, MISSING, MISSING, MISSING};
   private final String[] columnHeaders = {"Requirement", "Test Procedure(s)", "Test Status", "Result File(s)"};
   private Collection<Artifact> inputArtifacts;
   private Collection<Artifact> requirementsBulkLoad;
   private StringBuilder report;

   @Override
   public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws Exception {
      init(variableMap);

      for (Artifact input : inputArtifacts) {
         processArtifacts(input);
      }

      report();
   }

   private void processArtifacts(Artifact node) throws OseeCoreException, IOException {
      Collection<Artifact> children = node.getChildren();

      if (isRequirement(node)) {
         processRequirement(node);
      } else {
         reportLine(getReqCellOutput(node), "N/A (" + node.getArtifactTypeName() + ")", EMPTY, EMPTY);
      }
      for (Artifact child : children) {
         processArtifacts(child);
      }
   }

   private void processRequirement(Artifact req) throws OseeCoreException {
      Collection<Artifact> testProcs = req.getRelatedArtifacts(CoreRelationTypes.Verification__Verifier);
      if (testProcs.isEmpty()) {
         reportLine(getReqCellOutput(req), MISSING, MISSING, MISSING);
      } else {
         for (Artifact testProc : testProcs) {
            processTestProcedure(req, testProc);
         }
      }
   }

   private void processTestProcedure(Artifact req, Artifact testProc) throws OseeCoreException {
      String testStatus;
      if (testProc.isAttributeTypeValid(CoreAttributeTypes.TestProcedureStatus)) {
         testStatus = testProc.getSoleAttributeValue(CoreAttributeTypes.TestProcedureStatus, MISSING);
      } else {
         testStatus = "N/A (" + testProc.getArtifactTypeName() + ")";
      }
      Collection<Artifact> resultFiles = testProc.getRelatedArtifacts(CoreRelationTypes.Test_Unit_Result__Test_Result);

      if (resultFiles.isEmpty()) {
         reportLine(getReqCellOutput(req), testProc.getName(), testStatus, MISSING);
      } else {
         for (Artifact resultFile : resultFiles) {
            reportLine(getReqCellOutput(req), testProc.getName(), testStatus, resultFile.getName());
         }
      }
   }

   private String getReqCellOutput(Artifact req) throws OseeCoreException {
      String paragraphNumber = req.getSoleAttributeValue(CoreAttributeTypes.ParagraphNumber, "");
      String reqName = req.getName();
      String returnValue = paragraphNumber + SPACE + reqName;
      return returnValue;
   }

   private boolean isRequirement(Artifact src) {
      ArtifactType temp = src.getArtifactType();
      if (temp.inheritsFrom(CoreArtifactTypes.Requirement)) {
         return true;
      }

      return false;
   }

   private void reportLine(String... cells) {
      String[] outputCells = new String[4];
      for (int i = 0; i < cells.length; i++) {
         if (previousCells[i].equals(cells[i])) {
            if (i == 0 || outputCells[i - 1].equals(" ")) {
               outputCells[i] = " ";
            } else {
               outputCells[i] = cells[i];
            }
         } else {
            outputCells[i] = cells[i];
         }
      }
      previousCells = cells.clone();
      report.append(AHTML.addRowMultiColumnTable(outputCells));
   }

   private void report() throws OseeCoreException, IOException {
      report.append(AHTML.endMultiColumnTable());
      XResultData rd = new XResultData();
      rd.addRaw(report.toString());
      XResultDataUI.report(rd, "Requirements Test Report", Manipulations.RAW_HTML);
   }

   private void init(VariableMap variableMap) throws OseeCoreException, IOException {
      inputArtifacts = variableMap.getArtifacts("artifacts");
      initReport();
      load();
   }

   private void initReport() throws OseeCoreException, IOException {
      report = new StringBuilder(AHTML.beginMultiColumnTable(100, 1));
      report.append(AHTML.addHeaderRowMultiColumnTable(columnHeaders));
   }

   private void load() throws OseeCoreException {
      requirementsBulkLoad = new ArrayList<Artifact>();
      for (Artifact input : inputArtifacts) {
         requirementsBulkLoad.addAll(input.getDescendants());
      }
      Collection<Artifact> temp =
         RelationManager.getRelatedArtifacts(requirementsBulkLoad, 1, CoreRelationTypes.Verification__Verifier);
      Collection<Artifact> temp2 =
         RelationManager.getRelatedArtifacts(temp, 1, CoreRelationTypes.Test_Unit_Result__Test_Result);
      logf("Bulk loaded %d test results", temp2.size());
   }

   @Override
   public String getXWidgetsXml() {
      return "<xWidgets><XWidget xwidgetType=\"XListDropViewer\" displayName=\"artifacts\" /></xWidgets>";
   }

   @Override
   public Collection<String> getCategories() {
      return Arrays.asList("Define");
   }

   @Override
   public String getName() {
      return "Requirements Test Report";
   }
}