Skip to main content
summaryrefslogtreecommitdiffstats
blob: 623e100bf00b41824f44c8c397d3c6db82d660c4 (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
/*******************************************************************************
 * 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.define.blam.operation;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.data.IOseeBranch;
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.jdk.core.type.HashCollection;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.jdk.core.util.io.CharBackedInputStream;
import org.eclipse.osee.framework.jdk.core.util.io.xml.ExcelXmlWriter;
import org.eclipse.osee.framework.jdk.core.util.io.xml.ISheetWriter;
import org.eclipse.osee.framework.plugin.core.util.AIFile;
import org.eclipse.osee.framework.plugin.core.util.OseeData;
import org.eclipse.osee.framework.skynet.core.OseeSystemArtifacts;
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.utility.Requirements;
import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam;
import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
import org.eclipse.swt.program.Program;

/**
 * @author Ryan D. Brooks
 */
public class PublishSystemLevelSSDD extends AbstractBlam {
   private CharBackedInputStream charBak;
   private ISheetWriter excelWriter;
   private List<Artifact> sysReqs;
   private Artifact[] allSubsystems;
   private final HashCollection<Artifact, Artifact> subsystemToRequirements;

   @Override
   public String getName() {
      return "Publish System Level SSDD";
   }

   public PublishSystemLevelSSDD() {
      subsystemToRequirements = new HashCollection<Artifact, Artifact>(false, LinkedList.class);
   }

   private void init() throws IOException {
      charBak = new CharBackedInputStream();
      excelWriter = new ExcelXmlWriter(charBak.getWriter());
      subsystemToRequirements.clear();
   }

   @Override
   public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws Exception {
      monitor.beginTask("Generating System Level SSDD", 100);

      IOseeBranch branch = variableMap.getBranch("Branch");

      init();

      monitor.subTask("Aquiring System Components"); // bulk load for performance reasons
      ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.Component, branch);

      monitor.subTask("Aquiring System Requirements");
      ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.SystemRequirement, branch);

      Artifact root = OseeSystemArtifacts.getDefaultHierarchyRootArtifact(branch);
      sysReqs = root.getChild(Requirements.SYSTEM_REQUIREMENTS).getDescendants();

      getSubsystemList();

      monitor.subTask("5.2 System Requirement Allocation To Subsystems");
      writeSystemRequirementAllocationToSubsystems();
      for (Artifact subsystem : allSubsystems) {
         writeSystemRequirementAllocationBySubsystem(subsystem);
      }

      excelWriter.endWorkbook();
      IFile iFile = OseeData.getIFile("SystemLevelSSDD_" + Lib.getDateTimeString() + ".xml");
      AIFile.writeToFile(iFile, charBak);
      Program.launch(iFile.getLocation().toOSString());
   }

   private void getSubsystemList() throws OseeCoreException {
      for (Artifact systemRequirement : sysReqs) {
         for (Artifact subsystem : systemRequirement.getRelatedArtifacts(CoreRelationTypes.Allocation__Component)) {
            subsystemToRequirements.put(subsystem, systemRequirement);
         }
      }
      Set<Artifact> subsystemsSet = subsystemToRequirements.keySet();
      allSubsystems = new Artifact[subsystemsSet.size()];
      subsystemsSet.toArray(allSubsystems);
      Arrays.sort(allSubsystems);
   }

   private void writeSystemRequirementAllocationToSubsystems() throws IOException, OseeCoreException {
      excelWriter.startSheet("5.2", 200);

      excelWriter.writeCell("Paragraph Number");
      excelWriter.writeCell(CoreArtifactTypes.Component.getName());
      for (Artifact subsystem : allSubsystems) {
         excelWriter.writeCell(subsystem.getName());
      }
      excelWriter.endRow();

      excelWriter.writeRow("5.2 System Requirement Allocation to Subsystems");
      for (Artifact systemRequirement : sysReqs) {
         writeSystemRequirementAllocation(systemRequirement);
      }
      excelWriter.endSheet();
   }

   private void writeSystemRequirementAllocationBySubsystem(Artifact subsystem) throws IOException, OseeCoreException {
      excelWriter.startSheet(subsystem.getName(), 200);
      excelWriter.writeRow("System Requirements Allocated to the " + subsystem.getName());
      excelWriter.writeRow("Paragraph Number", CoreArtifactTypes.SystemRequirement.getName(), "Notes <rationale>");

      for (Artifact systemRequirement : subsystemToRequirements.getValues(subsystem)) {
         for (Artifact component : systemRequirement.getRelatedArtifacts(CoreRelationTypes.Allocation__Component)) {
            if (component.equals(subsystem)) {
               String rationale =
                  systemRequirement.getRelationRationale(component, CoreRelationTypes.Allocation__Component);
               if (rationale.equals("")) {
                  rationale = null;
               }
               excelWriter.writeRow(systemRequirement.getSoleAttributeValue(CoreAttributeTypes.ParagraphNumber, ""),
                  systemRequirement.getName(), rationale);
            }
         }
      }

      excelWriter.endSheet();
   }

   private void writeSystemRequirementAllocation(Artifact systemRequirement) throws IOException, OseeCoreException {
      excelWriter.writeCell(systemRequirement.getSoleAttributeValue(CoreAttributeTypes.ParagraphNumber, ""));
      excelWriter.writeCell(systemRequirement.getName());

      List<Artifact> allocatedSubsystems =
         new ArrayList<Artifact>(systemRequirement.getRelatedArtifacts(CoreRelationTypes.Allocation__Component));
      Collections.sort(allocatedSubsystems);
      for (Artifact allocatedSubsystem : allocatedSubsystems) {
         excelWriter.writeCell("X", Arrays.binarySearch(allSubsystems, allocatedSubsystem) + 2);
      }
      excelWriter.endRow();
   }

   @Override
   public String getDescriptionUsage() {
      return "Generate Traceability tables for the System Level SSDD";
   }

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

Back to the top