/**
   * Test method for {@link cpath.converter.internal.UniprotCleanerImpl#cleane(java.lang.String)}.
   *
   * @throws IOException
   */
  @Test
  public void testCleaner() throws IOException {
    // read data from file and look for accessions before being cleaned
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    CPathUtils.unzip(
        new ZipInputStream(
            CPathUtils.LOADER.getResource("/test_uniprot_data.dat.zip").getInputStream()),
        os);
    byte[] bytes = os.toByteArray();
    String data = new String(bytes);
    assertTrue(data.indexOf(CALR3_HUMAN_BEFORE) != -1);
    assertTrue(data.indexOf(CALRL_HUMAN_BEFORE) != -1);

    Cleaner cleaner = new UniProtCleanerImpl();
    os.reset();
    cleaner.clean(new ByteArrayInputStream(bytes), os);
    bytes = os.toByteArray();

    data = new String(bytes);
    assertTrue(data.indexOf(CALR3_HUMAN_AFTER) != -1);
    assertTrue(data.indexOf(CALRL_HUMAN_AFTER) != -1);

    // dump owl for review
    String outFilename =
        getClass().getClassLoader().getResource("").getPath()
            + File.separator
            + "testCleanUniProt.out.dat";
    Writer out = new OutputStreamWriter(new FileOutputStream(outFilename));
    out.write(data);
    out.close();
  }
Esempio n. 2
0
  // Upload (and replace if exists) a data archive for the existing data source
  @RequestMapping(value = "/admin/datasources/{identifier}/file", method = RequestMethod.POST)
  public void uploadDataArchive(
      @PathVariable String identifier,
      MultipartHttpServletRequest multiRequest,
      HttpServletResponse response)
      throws IOException {
    Metadata m = service.metadata().findByIdentifier(identifier);
    if (m == null) {
      response.sendError(
          Status.NO_RESULTS_FOUND.getErrorCode(),
          Status.NO_RESULTS_FOUND.getErrorMsg()
              + "; Metadata object with identifier: "
              + identifier
              + " not found.");
    }

    Map<String, MultipartFile> files = multiRequest.getFileMap();
    Assert.state(!files.isEmpty(), "No files to validate");
    String filename = files.keySet().iterator().next();
    MultipartFile file = files.get(filename);
    String origFilename = file.getOriginalFilename();
    if (file.getBytes().length == 0
        || filename == null
        || "".equals(filename)
        || !origFilename.endsWith(".zip")) {
      log.error("uploadDataArchive(), empty data file or null: " + origFilename);
      response.sendError(
          Status.BAD_REQUEST.getErrorCode(),
          "File (" + origFilename + ") UPLOAD failed; id:" + identifier);
    } else {
      // create or update the input source data file (must be ZIP archive!)
      CPathUtils.write(file.getBytes(), m.getDataArchiveName());
      log.info(
          "uploadDataArchive(), saved uploaded file:"
              + origFilename
              + " as "
              + m.getDataArchiveName());
    }
  }