Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4000d860740de7cd6dc4d6259895f2d9a19836d3 (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
/*********************************************************************
 * Copyright (c) 2013 Boeing
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Boeing - initial API and implementation
 **********************************************************************/

package org.eclipse.osee.define.rest.internal;

import javax.ws.rs.DefaultValue;
import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.AbstractSoftwareRequirement;
import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Name;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.StreamingOutput;
import org.eclipse.osee.activity.api.ActivityLog;
import org.eclipse.osee.app.OseeAppletPage;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry;
import org.eclipse.osee.framework.jdk.core.type.Pair;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.search.QueryBuilder;

/**
 * @author Ryan D. Brooks
 * @author David W. Miller
 */
@Path("/")
public final class SystemSafetyResource {
   private final OrcsApi orcsApi;
   private final IResourceRegistry resourceRegistry;
   private final ActivityLog activityLog;

   public SystemSafetyResource(ActivityLog activityLog, IResourceRegistry resourceRegistry, OrcsApi orcsApi) {
      this.activityLog = activityLog;
      this.resourceRegistry = resourceRegistry;
      this.orcsApi = orcsApi;
   }

   /**
    * Produce the System Safety Report
    *
    * @param branchId The Branch to run the System Safety Report on.
    * @param codeRoot The root directory accessible on the server for the code traces.
    * @return Produces a streaming xml file containing the System Safety Report
    */
   @Path("safety")
   @GET
   @Produces(MediaType.APPLICATION_XML)
   public Response getSystemSafetyReport(@QueryParam("branch") BranchId branchId, @QueryParam("code_root") String codeRoot, @DefaultValue("on") @QueryParam("style") String validate) {
      StreamingOutput streamingOutput =
         new SafetyStreamingOutput(activityLog, orcsApi, branchId, ArtifactId.SENTINEL, codeRoot, validate);
      ResponseBuilder builder = Response.ok(streamingOutput);
      builder.header("Content-Disposition", "attachment; filename=" + "Safety_Report.xml");
      return builder.build();
   }

   /**
    * Produce the System Safety Report
    *
    * @param branchId The Branch to run the System Safety Report on.
    * @param codeRoot The root directory accessible on the server for the code traces.
    * @return Produces a streaming xml file containing the System Safety Report
    */
   @Path("view/safety")
   @GET
   @Produces(MediaType.APPLICATION_XML)
   public Response getSystemSafetyReportWithView(@QueryParam("branch") BranchId branchId, @QueryParam("code_root") String codeRoot, @QueryParam("view") ArtifactId view, @DefaultValue("on") @QueryParam("style") String validate) {
      StreamingOutput streamingOutput =
         new SafetyStreamingOutput(activityLog, orcsApi, branchId, view, codeRoot, validate);
      ResponseBuilder builder = Response.ok(streamingOutput);
      builder.header("Content-Disposition", "attachment; filename=" + "Safety_Report.xml");
      return builder.build();
   }

   /**
    * Provides the user interface for the System Safety Report
    */
   @Path("ui/safety")
   @GET
   @Produces(MediaType.TEXT_HTML)
   public String getApplet() {
      OseeAppletPage pageUtil = new OseeAppletPage(orcsApi.getQueryFactory().branchQuery());
      return pageUtil.realizeApplet(resourceRegistry, "systemSafetyReport.html", getClass());
   }
   }
   //   private static final String[] names = new String[] {"{COMM NCO PRESET NVM VALIDATION}", "{FM NVM VALIDATION}"};

   @Path("deep")
   @GET
   @Produces(MediaType.TEXT_HTML)
   public String deep(@QueryParam("branch") BranchId branch, @QueryParam("name") String nameIn) {
      StringBuilder strB = new StringBuilder(10000);
      String[] names = new String[] {nameIn};
      List<Pair<ArtifactId, String>> values =
         orcsApi.getQueryFactory().deepQuery().andIsOfType(AbstractSoftwareRequirement).collect(Name);
      for (String oldName : names) {
         String fuzzyName =
            "\\{?" + oldName.toUpperCase().trim().replaceAll("[_ ]", ".?").replaceAll("[{}]", "") + "\\}?";
         Matcher matcher = Pattern.compile(fuzzyName).matcher("");

         for (Pair<ArtifactId, String> entry : values) {
            String name = entry.getSecond().toUpperCase().trim();
            matcher.reset(name);
            if (matcher.matches()) {
               ArtifactId artifactId = entry.getFirst();
               QueryBuilder builder = orcsApi.getQueryFactory().fromBranch(branch);
               ArtifactReadable art = builder.andId(artifactId).getResults().getAtMostOneOrNull();
               if (art != null) {
                  strB.append(entry.getSecond() + ", " + artifactId + ", " + art.getName() + "<br/>");
               }
            }
         }
      }
      return strB.toString();
}

Back to the top