Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3611b4b3408fd595785ac57e1994bbefd22a4334 (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
186
187
188
189
190
191
/*******************************************************************************
 * Copyright (c) 2014 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.disposition.rest.internal.report;

import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import org.eclipse.osee.disposition.model.DispoAnnotationData;
import org.eclipse.osee.disposition.model.DispoItem;
import org.eclipse.osee.disposition.model.DispoProgram;
import org.eclipse.osee.disposition.model.DispoSet;
import org.eclipse.osee.disposition.rest.DispoApi;
import org.eclipse.osee.disposition.rest.internal.DispoConnector;
import org.eclipse.osee.disposition.rest.util.DispoUtil;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.io.xml.ExcelXmlWriter;
import org.json.JSONArray;
import org.json.JSONException;

/**
 * @author Angel Avila
 */

public class STRSReport {
   private final DispoApi dispoApi;

   public STRSReport(DispoApi dispoApi) {
      this.dispoApi = dispoApi;
   }

   public void runReport(DispoProgram program, DispoSet setPrimary, DispoSet setSecondary, OutputStream outputStream) {
      List<DispoItem> itemsFromPrimary = dispoApi.getDispoItems(program, setPrimary.getGuid());
      List<DispoItem> itemsFromSecondary = dispoApi.getDispoItems(program, setSecondary.getGuid());

      HashMap<String, DispoItem> idsToDryRun = convertToMap(itemsFromSecondary);

      try {
         Writer writer = new OutputStreamWriter(outputStream, "UTF-8");
         ExcelXmlWriter sheetWriter = new ExcelXmlWriter(writer);

         String[] headers = getHeaders();
         int columns = headers.length;
         sheetWriter.startSheet("STRS Report", headers.length);
         sheetWriter.writeRow((Object[]) headers);

         for (DispoItem demoItem : itemsFromPrimary) {
            DispoConnector connector = new DispoConnector();
            List<Integer> allUncoveredDiscprepancies = connector.getAllUncoveredDiscprepancies(demoItem);
            String[] row = new String[columns];
            int index = 0;

            DispoItem dryrunItem = idsToDryRun.get(demoItem.getName());
            JSONArray annotationsList = demoItem.getAnnotationsList();
            HashMap<String, Integer> issueTypeToCount = convertToIssueTypeToCounttMap(annotationsList);

            row[index++] = String.valueOf(demoItem.getName());
            if (dryrunItem != null) {
               row[index++] = String.valueOf(dryrunItem.getTotalPoints());
               row[index++] = String.valueOf(dryrunItem.getDiscrepanciesList().length());
            } else {
               row[index++] = "No corresponding Item";
               row[index++] = "No corresponding Item";
            }
            row[index++] = String.valueOf(demoItem.getTotalPoints());
            row[index++] = String.valueOf(issueTypeToCount.get("CODE"));
            row[index++] = String.valueOf(issueTypeToCount.get("SCRIPT"));
            row[index++] = String.valueOf(issueTypeToCount.get("REQ"));
            row[index++] = String.valueOf(allUncoveredDiscprepancies.size());
            row[index++] = String.valueOf(issueTypeToCount.get("OTHER"));
            row[index++] = String.valueOf(demoItem.getDiscrepanciesList().length());
            row[index++] = " ";
            row[index++] = String.valueOf(getCustomerNotes(demoItem.getAnnotationsList()));

            sheetWriter.writeRow((Object[]) row);
         }

         sheetWriter.endSheet();
         sheetWriter.endWorkbook();

      } catch (Exception ex) {
         throw new OseeCoreException(ex);
      }
   }

   private HashMap<String, DispoItem> convertToMap(List<DispoItem> list) {
      HashMap<String, DispoItem> toReturn = new HashMap<String, DispoItem>();
      for (DispoItem item : list) {
         toReturn.put(item.getName(), item);
      }

      return toReturn;
   }

   private String getCustomerNotes(JSONArray annotations) throws JSONException {
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < annotations.length(); i++) {
         DispoAnnotationData annotation = DispoUtil.jsonObjToDispoAnnotationData(annotations.getJSONObject(i));
         String customerNotes = annotation.getCustomerNotes();
         if (!customerNotes.equalsIgnoreCase("--Enter Notes--")) {
            sb.append(annotation.getCustomerNotes());
            sb.append("\n");
         }
      }
      if (sb.length() == 0) {
         sb.append(" ");
      }
      return sb.toString();
   }

   private static String[] getHeaders() {
      String[] toReturn =
         {
            "Test Case",
            "Dry Run Results:Test Points",
            "Dry Run Results:Total Fails",
            "DemoResults:Total Test Points",
            "Demo: Code Problems",
            "Script Problems",
            "Requirements",
            "Under Investigation",
            "Other",
            "Total Fails",
            "Verification of RPCR",
            "Commnets"};
      return toReturn;
   }

   private HashMap<String, Integer> convertToIssueTypeToCounttMap(JSONArray jsonArray) {
      HashMap<String, Integer> toReturn = new HashMap<String, Integer>();
      int codeCount = 0;
      int scriptCount = 0;
      int reqCount = 0;
      int other = 0;
      for (int i = 0; i < jsonArray.length(); i++) {
         DispoAnnotationData annotation;
         try {
            annotation = DispoUtil.jsonObjToDispoAnnotationData(jsonArray.getJSONObject(i));
            if (annotation.isValid()) {
               String resolutionType = annotation.getResolutionType();
               if (resolutionType != null) {
                  if (resolutionType.equalsIgnoreCase("CODE")) {
                     codeCount += getTotalLocationOfAnnotation(annotation);
                  } else if (resolutionType.equalsIgnoreCase("TEST")) {
                     scriptCount += getTotalLocationOfAnnotation(annotation);
                  } else if (resolutionType.equalsIgnoreCase("REQ")) {
                     reqCount += getTotalLocationOfAnnotation(annotation);
                  } else {
                     other += getTotalLocationOfAnnotation(annotation);
                  }
               }
            }
         } catch (JSONException ex) {
            throw new OseeCoreException(ex);
         }
      }

      toReturn.put("CODE", new Integer(codeCount));
      toReturn.put("SCRIPT", new Integer(scriptCount));
      toReturn.put("REQ", new Integer(reqCount));
      toReturn.put("OTHER", new Integer(other));

      return toReturn;
   }

   private int getTotalLocationOfAnnotation(DispoAnnotationData annotation) {
      String locationRefs = annotation.getLocationRefs();
      String[] locationsRefsArray = locationRefs.split(",");
      int toReturn = 0;
      for (int i = 0; i < locationsRefsArray.length; i++) {
         String singleRef = locationsRefsArray[i];
         if (singleRef.contains("-")) {
            String[] split = singleRef.split("-");
            int gap = Integer.valueOf(split[1]) - Integer.valueOf(split[0]);
            toReturn += gap + 1; //add one since the gap is 1 less than what the range covers. i.e. 3-6 gap is 3 but covers 4
         } else {
            toReturn++;
         }
      }
      return toReturn;
   }
}

Back to the top