bug[ats_ATS71838]: Make BuildTraceReport links relative

Change-Id: I53ef02c9698fb9426025603006aefea2dbb49505
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/ArchiveCollector.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/ArchiveCollector.java
index f806cdf..a1757c0 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/ArchiveCollector.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/ArchiveCollector.java
@@ -32,6 +32,7 @@
 import org.eclipse.osee.framework.jdk.core.type.Pair;
 import org.eclipse.osee.framework.jdk.core.util.Lib;
 import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.logger.Log;
 
 /**
  * @author John Misinco
@@ -43,17 +44,20 @@
    private final String serverData = OseeServerProperties.getOseeApplicationServerData(null);
    private final Map<String, String> urlToEntryName = new LinkedHashMap<String, String>();
    private final Set<String> pcrIds = new LinkedHashSet<String>();
-   private final String supportFilesUrl;
+   private final String baseUrl;
+   private final Log logger;
 
-   public ArchiveCollector(String supportFilesUrl) {
-      this.supportFilesUrl = supportFilesUrl;
+   public ArchiveCollector(String baseUrl, Log logger) {
+      this.baseUrl = baseUrl;
+      this.logger = logger;
    }
 
    public void onBuildToUrlPairs(String verifierName, List<Pair<String, String>> buildToUrlPairs) {
       for (Pair<String, String> pair : buildToUrlPairs) {
          String build = pair.getFirst();
          String url = pair.getSecond();
-         if (Strings.isValid(url)) {
+         if (Strings.isValid(url) && Strings.isValid(build)) {
+            url = baseUrl + url.replaceFirst("\\.\\.", "");
             String entryName = String.format(AtsElementData.ARCHIVE_SCRIPT_TEMPLATE, build, verifierName);
             urlToEntryName.put(url, entryName);
             //replace url with that of the local one
@@ -69,7 +73,7 @@
    public void writeArchive(ZipOutputStream zout) {
       InputStream inputStream = null;
       try {
-         URL url = new URL(supportFilesUrl);
+         URL url = new URL(baseUrl + "/supportFiles");
          inputStream = new BufferedInputStream(url.openStream());
 
          ZipInputStream zin = null;
@@ -103,12 +107,13 @@
                Lib.inputStreamToOutputStream(inputStream2, zout);
                zout.closeEntry();
             } catch (IOException ex) {
-               OseeExceptions.wrapAndThrow(ex);
+               // log and keep going 
+               logger.error(ex, "Error processing URL [%s]", url2.toString());
             } finally {
                Lib.close(inputStream2);
             }
          } catch (MalformedURLException ex1) {
-            OseeExceptions.wrapAndThrow(ex1);
+            logger.error(ex1, "Error processing URL [%s]", entry.getKey());
          }
       }
 
@@ -123,12 +128,12 @@
                Lib.inputStreamToOutputStream(fis, zout);
                zout.closeEntry();
             } catch (IOException ex) {
-               OseeExceptions.wrapAndThrow(ex);
+               // log and keep going
+               logger.error(ex, "Error processing file [%s]", file.getAbsolutePath());
             } finally {
                Lib.close(fis);
             }
          }
       }
    }
-
 }
\ No newline at end of file
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/BuildTraceReport.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/BuildTraceReport.java
index f8696dd..61ebcd6 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/BuildTraceReport.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/BuildTraceReport.java
@@ -21,7 +21,7 @@
 import java.util.Map;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 import org.eclipse.osee.ats.api.data.AtsAttributeTypes;
 import org.eclipse.osee.ats.core.util.AtsUtilCore;
@@ -65,9 +65,10 @@
       final ZipOutputStream zout = new ZipOutputStream(output);
 
       String supportFilesUrl =
-         uriInfo.getBaseUriBuilder().path(BuildTraceReportResource.RESOURCE_BASE).path("supportFiles").build().toString();
-      ArchiveCollector dataCollector = new ArchiveCollector(supportFilesUrl);
-      createTraceReport(buildId, programName, buildName, AtsElementData.ARCHIVE_REPORT_TEMPLATE, tableStream, uriInfo,
+         uriInfo.getBaseUriBuilder().path(BuildTraceReportResource.RESOURCE_BASE).host("localhost").build().toString();
+
+      ArchiveCollector dataCollector = new ArchiveCollector(supportFilesUrl, logger);
+      createTraceReport(buildId, programName, buildName, AtsElementData.ARCHIVE_REPORT_TEMPLATE, tableStream,
          dataCollector, orcsApi, logger);
       try {
          zout.putNextEntry(new ZipEntry(fileName + ".html"));
@@ -81,12 +82,12 @@
       }
    }
 
-   public void getBuildReport(OutputStream output, OrcsApi orcsApi, Log logger, String programId, String buildId, String programName, String buildName, @Context final UriInfo uriInfo) {
-      createTraceReport(buildId, programName, buildName, AtsElementData.CHANGE_REPORT_URL_TEMPLATE, output, uriInfo,
-         null, orcsApi, logger);
+   public void getBuildReport(OutputStream output, OrcsApi orcsApi, Log logger, String programId, String buildId, String programName, String buildName) {
+      createTraceReport(buildId, programName, buildName, AtsElementData.CHANGE_REPORT_URL_TEMPLATE, output, null,
+         orcsApi, logger);
    }
 
-   private void createTraceReport(final String buildId, final String programName, final String buildName, String urlTemplate, OutputStream output, final UriInfo uriInfo, final ArchiveCollector dataCollector, OrcsApi orcsApi, final Log logger) {
+   private void createTraceReport(final String buildId, final String programName, final String buildName, String urlTemplate, OutputStream output, final ArchiveCollector dataCollector, OrcsApi orcsApi, final Log logger) {
       final QueryFactory queryFactory = orcsApi.getQueryFactory(null);
       final IOseeBranch branch = getBaselineBranch(buildId, queryFactory);
       final List<Pair<String, String>> buildNamesToUrls = getBuildNameUrlPairs(buildId, queryFactory);
@@ -101,8 +102,8 @@
                for (Pair<String, String> buildToUrl : buildNamesToUrls) {
                   String url = String.format(buildToUrl.getSecond(), fullPath);
                   URI loadSourceResource =
-                     uriInfo.getBaseUriBuilder().path(BuildTraceReportResource.RESOURCE_BASE).path("sourceFile").queryParam(
-                        "url", url).queryParam("offline", dataCollector != null).build();
+                     UriBuilder.fromPath("..").path("sourceFile").queryParam("url", url).queryParam("offline",
+                        dataCollector != null).build();
                   toReturn.add(new Pair<String, String>(buildToUrl.getFirst(), loadSourceResource.toString()));
                }
             } else {
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/ProgramsAndBuildsTables.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/ProgramsAndBuildsTables.java
index d3d082a..979b5db 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/ProgramsAndBuildsTables.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/ProgramsAndBuildsTables.java
@@ -12,13 +12,12 @@
 
 import java.io.OutputStream;
 import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.UriBuilder;
 import org.eclipse.osee.ats.rest.internal.build.report.model.AtsBuildData;
 import org.eclipse.osee.ats.rest.internal.build.report.model.AtsProgramData;
 import org.eclipse.osee.ats.rest.internal.build.report.parser.AtsAbstractSAXParser.AtsDataHandler;
 import org.eclipse.osee.ats.rest.internal.build.report.parser.AtsBuildDataParser;
 import org.eclipse.osee.ats.rest.internal.build.report.parser.AtsProgramDataParser;
-import org.eclipse.osee.ats.rest.internal.build.report.resources.BuildTraceReportResource;
 import org.eclipse.osee.ats.rest.internal.build.report.table.UrlListTable;
 import org.eclipse.osee.ats.rest.internal.build.report.util.InputFilesUtil;
 import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
@@ -30,7 +29,7 @@
  */
 public class ProgramsAndBuildsTables {
 
-   public void getProgramsTable(final Log logger, OutputStream output, final UriInfo uriInfo) {
+   public void getProgramsTable(final Log logger, OutputStream output) {
       final UrlListTable table = new UrlListTable(output);
       try {
          table.initializeTable("Programs", "Programs");
@@ -40,8 +39,7 @@
             @Override
             public void handleData(AtsProgramData data) {
                String uri =
-                  uriInfo.getRequestUriBuilder().path("program").path(data.getProgramId()).queryParam("program",
-                     data.getProgramName()).build().toString();
+                  UriBuilder.fromPath("program").path(data.getProgramId()).queryParam("program", data.getProgramName()).build().toString();
                try {
                   Pair<String, String> pair = new Pair<String, String>(data.getProgramName(), uri);
                   table.addUrl(pair);
@@ -59,7 +57,7 @@
       }
    }
 
-   public void getBuildsTable(final Log logger, OutputStream output, final String programName, final String programId, final UriInfo uriInfo) {
+   public void getBuildsTable(final Log logger, OutputStream output, final String programName, final String programId) {
       final UrlListTable table = new UrlListTable(output);
       try {
          table.initializeTable("Builds", programName + " Builds", "Offline Download");
@@ -71,13 +69,12 @@
             public void handleData(AtsBuildData data) {
                if (data.getBuildProgramId().equals(programId)) {
                   String buildUri =
-                     uriInfo.getBaseUriBuilder().path(BuildTraceReportResource.RESOURCE_BASE).path(programId).queryParam(
-                        "program", programName).path(data.getBuildId()).queryParam("build", data.getBuildName()).build().toString();
+                     UriBuilder.fromPath("..").path(programId).queryParam("program", programName).path(
+                        data.getBuildId()).queryParam("build", data.getBuildName()).build().toString();
 
                   String archiveUri =
-                     uriInfo.getBaseUriBuilder().path(BuildTraceReportResource.RESOURCE_BASE).path("archive").path(
-                        programId).queryParam("program", programName).path(data.getBuildId()).queryParam("build",
-                        data.getBuildName()).build().toString();
+                     UriBuilder.fromPath("..").path("archive").path(programId).queryParam("program", programName).path(
+                        data.getBuildId()).queryParam("build", data.getBuildName()).build().toString();
                   try {
                      Pair<String, String> build = new Pair<String, String>(data.getBuildName(), buildUri);
                      Pair<String, String> offline = new Pair<String, String>("download", archiveUri);
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/resources/BuildTraceReportResource.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/resources/BuildTraceReportResource.java
index 171dc2b..77cdcd3 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/resources/BuildTraceReportResource.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/build/report/resources/BuildTraceReportResource.java
@@ -55,12 +55,12 @@
 
    @GET
    @Produces(MediaType.TEXT_HTML)
-   public Response getPrograms(@Context final UriInfo uriInfo) {
+   public Response getPrograms() {
       return Response.ok(new StreamingOutput() {
 
          @Override
          public void write(OutputStream output) throws WebApplicationException {
-            programsAndBuilds.getProgramsTable(logger, output, uriInfo);
+            programsAndBuilds.getProgramsTable(logger, output);
          }
       }).build();
    }
@@ -68,12 +68,12 @@
    @GET
    @Path("/program/{programId}")
    @Produces(MediaType.TEXT_HTML)
-   public Response getBuilds(@PathParam("programId") final String programId, @DefaultValue("UNKNOWN") @QueryParam("program") final String programName, @Context final UriInfo uriInfo) {
+   public Response getBuilds(@PathParam("programId") final String programId, @DefaultValue("UNKNOWN") @QueryParam("program") final String programName) {
       return Response.ok(new StreamingOutput() {
 
          @Override
          public void write(OutputStream output) throws WebApplicationException {
-            programsAndBuilds.getBuildsTable(logger, output, programName, programId, uriInfo);
+            programsAndBuilds.getBuildsTable(logger, output, programName, programId);
          }
       }).build();
    }
@@ -81,12 +81,12 @@
    @GET
    @Path("/{programId}/{buildId}")
    @Produces(MediaType.TEXT_HTML)
-   public Response getBuildReport(@PathParam("programId") final String programId, @PathParam("buildId") final String buildId, @DefaultValue("UNKNOWN") @QueryParam("program") final String programName, @DefaultValue("UNKNOWN") @QueryParam("build") final String buildName, @Context final UriInfo uriInfo) {
+   public Response getBuildReport(@PathParam("programId") final String programId, @PathParam("buildId") final String buildId, @DefaultValue("UNKNOWN") @QueryParam("program") final String programName, @DefaultValue("UNKNOWN") @QueryParam("build") final String buildName) {
       return Response.ok(new StreamingOutput() {
 
          @Override
          public void write(OutputStream output) throws WebApplicationException {
-            report.getBuildReport(output, orcsApi, logger, programId, buildId, programName, buildName, uriInfo);
+            report.getBuildReport(output, orcsApi, logger, programId, buildId, programName, buildName);
          }
       }).build();
    }