Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7ffb2badeaad278e8c8303ef362c774e8bcd8a61 (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
/*******************************************************************************
 * 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.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.model.Branch;
import org.eclipse.osee.framework.core.util.XResultData;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
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.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.relation.RelationManager;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
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 SubsystemRequirementVerificationLevel extends AbstractBlam {

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

   @Override
   public String getName() {
      return "Set Verification Level for Subsystem Requirements";
   }

   private Branch branch;
   private Collection<Artifact> subsystemRequirements;
   private StringBuilder report;
   private SkynetTransaction transaction;
   private final String[] columnHeaders = {
      "Requirement",
      "Subsystem",
      CoreAttributeTypes.ParagraphNumber.getName(),
      "Current Verification Level",
      "Changed"};

   @SuppressWarnings("unused")
   private Collection<Artifact> bulkRequirements;

   private void loadFields(VariableMap variableMap) throws OseeCoreException {
      branch = variableMap.getBranch("Branch");
      subsystemRequirements =
         ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.SubsystemRequirementMSWord, branch);
      bulkRequirements =
         RelationManager.getRelatedArtifacts(subsystemRequirements, 1, CoreRelationTypes.Requirement_Trace__Lower_Level);
      report = new StringBuilder(AHTML.beginMultiColumnTable(100, 1));
      transaction = TransactionManager.createTransaction(branch, "Set Verification Level for Subsystem Requirements");
   }

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

      for (Artifact req : subsystemRequirements) {
         processSubsystemRequirement(req);
      }

      report();
      transaction.execute();
   }

   private void report() {
      report.append(AHTML.endMultiColumnTable());
      XResultData rd = new XResultData();
      rd.addRaw(report.toString());
      XResultDataUI.report(rd, "Set Verification Level", Manipulations.RAW_HTML);
   }

   private void beginReport() {
      report.append(AHTML.addHeaderRowMultiColumnTable(columnHeaders));
   }

   private void addReportRow(String... cells) {
      report.append(AHTML.addRowMultiColumnTable(cells));
   }

   private void processSubsystemRequirement(Artifact reqArt) throws OseeCoreException {
      SubsystemRequirement req = new SubsystemRequirement(reqArt);
      req.process();
   }

   private class SubsystemRequirement {
      private final Artifact req;
      private int hardwareComponents;
      private int softwareRequirements;
      private String verificationLevel;
      private String paragraphNumber;
      private String subsystem;

      public SubsystemRequirement(Artifact req) {
         this.req = req;
      }

      public void process() throws OseeCoreException {
         getData();
         if (meetsCriteria()) {
            if (isUnspecified()) {
               adjustVerificationLevel();
            }
            report();
         }
      }

      private void getData() throws OseeCoreException {
         this.hardwareComponents = getHardwareComponentCount();
         this.softwareRequirements = getSoftwareRequirementCount();
         paragraphNumber = req.getSoleAttributeValue(CoreAttributeTypes.ParagraphNumber, "UNDEFINED");
         subsystem = req.getSoleAttributeValue(CoreAttributeTypes.Subsystem, "UNDEFINED");
         verificationLevel = req.getSoleAttributeValue(CoreAttributeTypes.VerificationLevel, "UNDEFINED");
      }

      private int getHardwareComponentCount() throws OseeCoreException {
         return RelationManager.getRelatedArtifactsCount(req, CoreRelationTypes.Allocation__Component);
      }

      private int getSoftwareRequirementCount() throws OseeCoreException {
         Collection<Artifact> traceCollection =
            RelationManager.getRelatedArtifacts(req, CoreRelationTypes.Requirement_Trace__Lower_Level);
         int ret = 0;
         for (Artifact trace : traceCollection) {
            if (trace.isOfType(CoreArtifactTypes.AbstractSoftwareRequirement)) {
               ret++;
            }
         }
         return ret;
      }

      private boolean meetsCriteria() {
         return hardwareComponents == 1 && softwareRequirements == 0;
      }

      private void adjustVerificationLevel() throws OseeCoreException {
         req.setSoleAttributeValue(CoreAttributeTypes.VerificationLevel, "Component");
         req.persist(SubsystemRequirementVerificationLevel.this.transaction);
      }

      public void report() {
         SubsystemRequirementVerificationLevel.this.addReportRow(req.getName(), subsystem, paragraphNumber,
            verificationLevel, String.valueOf(isUnspecified()));
      }

      private boolean isUnspecified() {
         return verificationLevel.equals("Unspecified");
      }
   }
}

Back to the top