示例#1
0
  public static void handleArtifactUri(
      IResourceManager resourceManager, String request, String uri, HttpServletResponse response)
      throws OseeCoreException {
    boolean wasProcessed = false;
    if (Strings.isValid(uri)) {
      IResourceLocator locator = resourceManager.getResourceLocator(uri);
      PropertyStore options = new PropertyStore();
      options.put(StandardOptions.DecompressOnAquire.name(), true);
      IResource resource = resourceManager.acquire(locator, options);

      if (resource != null) {
        wasProcessed = true;

        InputStream inputStream = null;
        try {
          inputStream = resource.getContent();

          response.setStatus(HttpServletResponse.SC_OK);
          response.setContentLength(inputStream.available());
          response.setCharacterEncoding("ISO-8859-1");
          String mimeType = URLConnection.guessContentTypeFromStream(inputStream);
          if (mimeType == null) {
            mimeType = URLConnection.guessContentTypeFromName(resource.getLocation().toString());
            if (mimeType == null) {
              mimeType = "application/*";
            }
          }
          response.setContentType(mimeType);
          if (!mimeType.equals("text/html")) {
            response.setHeader("Content-Disposition", "attachment; filename=" + resource.getName());
          }
          Lib.inputStreamToOutputStream(inputStream, response.getOutputStream());
          response.flushBuffer();
        } catch (IOException ex) {
          OseeExceptions.wrapAndThrow(ex);
        } finally {
          Lib.close(inputStream);
        }
      }
    }
    if (!wasProcessed) {
      response.setStatus(HttpServletResponse.SC_NOT_FOUND);
      response.setContentType("text/plain");
      try {
        response.getWriter().write(String.format("Unable to find resource: [%s]", request));
      } catch (IOException ex) {
        OseeExceptions.wrapAndThrow(ex);
      }
    }
  }
示例#2
0
  @Override
  public InputStream getRenderInputStream(
      PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException {
    InputStream stream = null;
    try {
      if (artifacts.isEmpty()) {
        stream =
            Streams.convertStringToInputStream(
                WordWholeDocumentAttribute.getEmptyDocumentContent(), "UTF-8");
      } else {
        Artifact artifact = artifacts.iterator().next();
        String content =
            artifact.getOrInitializeSoleAttributeValue(CoreAttributeTypes.WholeWordContent);
        if (presentationType == PresentationType.DIFF
            && WordUtil.containsWordAnnotations(content)) {
          throw new OseeStateException(
              "Trying to diff the [%s] artifact on the [%s] branch, which has tracked changes turned on.  All tracked changes must be removed before the artifacts can be compared.",
              artifact.getName(), artifact.getBranch().getName());
        }

        LinkType linkType = LinkType.OSEE_SERVER_LINK;
        content = WordMlLinkHandler.link(linkType, artifact, content);

        String classification = WordRendererUtil.getDataRightsClassification(artifact);
        if (Strings.isValid(classification)) {
          content = addDataRights(content, classification, artifact);
        }

        stream = Streams.convertStringToInputStream(content, "UTF-8");
      }
    } catch (IOException ex) {
      OseeExceptions.wrapAndThrow(ex);
    }
    return stream;
  }
示例#3
0
 @Override
 public int getCount() throws OseeCoreException {
   Integer result = -1;
   try {
     result = createCount().call();
   } catch (Exception ex) {
     OseeExceptions.wrapAndThrow(ex);
   }
   return result;
 }
示例#4
0
 @Override
 public ResultSet<IOseeBranch> getResultsAsId() throws OseeCoreException {
   ResultSet<IOseeBranch> result = null;
   try {
     result = createSearchResultsAsIds().call();
   } catch (Exception ex) {
     OseeExceptions.wrapAndThrow(ex);
   }
   return result;
 }
示例#5
0
  private void consolidateTxsAddressing(
      ExchangeDataProcessor processor,
      ExportItem exportItem,
      List<Long> branchUuids,
      Map<Long, Long> artifactGammaToNetGammaId)
      throws OseeCoreException {
    File targetFile = processor.getDataProvider().getFile(exportItem);
    File tempFile = new File(Lib.changeExtension(targetFile.getPath(), "temp"));
    Writer fileWriter = null;
    HashCollection<Long, Address> addressMap = new HashCollection<>(false, TreeSet.class);
    V0_9_2TxsConsolidateParser transformer =
        new V0_9_2TxsConsolidateParser(artifactGammaToNetGammaId, addressMap);
    try {
      fileWriter = processor.startTransform(targetFile, tempFile, transformer);
      ExchangeUtil.readExchange(tempFile, transformer);

      for (long branchUuid : branchUuids) {
        transformer.setBranchId(branchUuid);
        ExchangeUtil.readExchange(tempFile, transformer);

        for (Long gammaId : addressMap.keySet()) {
          Collection<Address> addresses = addressMap.getValues(gammaId);
          fixAddressing(addresses);
          writeAddresses(transformer.getWriter(), addresses);
        }
        addressMap.clear();
      }
      tempFile.delete();
    } catch (Exception ex) {
      OseeExceptions.wrapAndThrow(ex);
    } finally {
      try {
        transformer.finish();
      } catch (Exception ex) {
        OseeExceptions.wrapAndThrow(ex);
      } finally {
        Lib.close(fileWriter);
      }
    }
  }
示例#6
0
 public static CoverageUnit createCodeUnit(
     URL url, ICoverageUnitFileContentsProvider fileContentsProvider) throws OseeCoreException {
   Conditions.checkNotNull(url, "url", "Valid filename must be specified");
   InputStream inputStream = null;
   CoverageUnit fileCoverageUnit = null;
   try {
     inputStream = url.openStream();
     Conditions.checkNotNull(inputStream, "input stream", "File doesn't exist [%s]", url);
     // Store file as CoverageUnit
     File file = new File(url.getFile());
     String filename = file.getCanonicalFile().getName();
     fileCoverageUnit =
         CoverageUnitFactory.createCoverageUnit(
             null, filename, url.getFile(), fileContentsProvider);
     String fileStr = Lib.inputStreamToString(inputStream);
     Matcher m = packagePattern.matcher(fileStr);
     if (m.find()) {
       fileCoverageUnit.setNamespace(m.group(1));
     } else {
       throw new OseeArgumentException("Can't find package for [%s]", url);
     }
     fileCoverageUnit.setFileContents(fileStr);
     CoverageUnit coverageUnit = null;
     int lineNum = 0;
     for (String line : fileStr.split("(\r\n|\n)")) {
       if (line.contains("IGNORE")) {
         continue;
       }
       lineNum++;
       // Determine if method; store as CoverageUnit
       m = methodPattern.matcher(line);
       if (m.find()) {
         String name = m.group(3);
         coverageUnit =
             CoverageUnitFactory.createCoverageUnit(
                 fileCoverageUnit, name, "Line " + lineNum, fileContentsProvider);
         // Note: CoverageUnit's orderNumber is set by executeLine match below
         fileCoverageUnit.addCoverageUnit(coverageUnit);
         // Duplicate this method as error case for importing
         if (filename.contains("AuxPowerUnit2") && name.equals("clear")) {
           CoverageUnit duplicateCoverageUnit =
               CoverageUnitFactory.createCoverageUnit(
                   fileCoverageUnit, name, "Line " + lineNum, fileContentsProvider);
           duplicateCoverageUnit.setOrderNumber("2");
           fileCoverageUnit.addCoverageUnit(duplicateCoverageUnit);
           CoverageItem item =
               new CoverageItem(duplicateCoverageUnit, CoverageOptionManager.Not_Covered, "1");
           item.setName("return super.getColumn(index)");
           duplicateCoverageUnit.addCoverageItem(item);
         }
       }
       // Determine if executable coverage line; store as CoverageItem
       m = executeLine.matcher(line);
       if (m.find()) {
         String lineText = m.group(1);
         String methodNum = m.group(2);
         String executeNum = m.group(3);
         String testUnits = m.group(4);
         boolean covered = !testUnits.equals("n");
         CoverageItem coverageItem =
             new CoverageItem(
                 coverageUnit,
                 covered ? CoverageOptionManager.Test_Unit : CoverageOptionManager.Not_Covered,
                 executeNum);
         coverageUnit.setOrderNumber(methodNum);
         coverageItem.setName(lineText);
         coverageItem.setOrderNumber(executeNum);
         coverageUnit.addCoverageItem(coverageItem);
         if (covered) {
           for (String testUnitName : testUnits.split("\\|")) {
             coverageItem.addTestUnitName(testUnitName);
           }
         }
       }
     }
   } catch (IOException ex) {
     OseeExceptions.wrapAndThrow(ex);
   }
   return fileCoverageUnit;
 }