예제 #1
0
  public String getBamIndexPath() {

    if (indexPath != null) return indexPath;

    if (path.toLowerCase().startsWith("http://") || path.toLowerCase().startsWith("https://")) {
      // See if bam file is specified by parameter
      try {
        URL url = new URL(path);
        String queryString = url.getQuery();
        if (queryString != null) {
          Map<String, String> parameters = HttpUtils.parseQueryString(queryString);
          if (parameters.containsKey("index")) {
            return parameters.get("index");
          } else if (parameters.containsKey("file")) {
            String bamFile = parameters.get("file");
            String bamIndexFile = bamFile + ".bai";
            String newQueryString = queryString.replace(bamFile, bamIndexFile);
            return path.replace(queryString, newQueryString);
          } else {
            String ip = path.replace(url.getPath(), url.getPath() + ".bai");
            return ip;
          }
        }
      } catch (MalformedURLException e) {
        log.error(e.getMessage(), e);
      }
    }

    return path + ".bai";
  }
예제 #2
0
  /**
   * Upload files to pre-configured url.
   *
   * @param uploadLocation the location we are uploading to.
   * @param fileName the filename we use for the resulting filename we upload.
   * @param params the optional parameter names.
   * @param values the optional parameter values.
   */
  static void uploadLogs(String uploadLocation, String fileName, String[] params, String[] values) {
    try {
      File tempDir = LoggingUtilsActivator.getFileAccessService().getTemporaryDirectory();
      File newDest = new File(tempDir, fileName);

      File optionalFile = null;

      // if we have some description params
      // save them to file and add it to archive
      if (params != null) {
        optionalFile =
            new File(
                LoggingUtilsActivator.getFileAccessService().getTemporaryDirectory(),
                "description.txt");
        OutputStream out = new FileOutputStream(optionalFile);
        for (int i = 0; i < params.length; i++) {
          out.write((params[i] + " : " + values[i] + "\r\n").getBytes("UTF-8"));
        }
        out.flush();
        out.close();
      }

      newDest = LogsCollector.collectLogs(newDest, optionalFile);

      // don't leave any unneeded information
      if (optionalFile != null) optionalFile.delete();

      if (uploadLocation == null) return;

      if (HttpUtils.postFile(uploadLocation, "logs", newDest) != null) {
        NotificationService notificationService = LoggingUtilsActivator.getNotificationService();

        if (notificationService != null) {
          ResourceManagementService resources = LoggingUtilsActivator.getResourceService();
          String bodyMsgKey = "plugin.loggingutils.ARCHIVE_MESSAGE_OK";

          notificationService.fireNotification(
              LOGFILES_ARCHIVED,
              resources.getI18NString("plugin.loggingutils.ARCHIVE_BUTTON"),
              resources.getI18NString(bodyMsgKey, new String[] {uploadLocation}),
              null);
        }
      }
    } catch (Throwable e) {
      logger.error("Cannot upload file", e);
    }
  }
예제 #3
0
  /**
   * Return a string suitable for determining file type based on extension May or may not be a full,
   * readable path. txt and gz extensions are stripped
   *
   * @return
   */
  public String getTypeString() {
    if (type != null) {
      return type;
    } else {

      String typeString = path.toLowerCase();
      if (path.startsWith("http://") || path.startsWith("https://")) {
        try {
          URL url = new URL(path);

          typeString = url.getPath().toLowerCase();
          String query = url.getQuery();
          if (query != null) {
            Map<String, String> queryMap = HttpUtils.parseQueryString(query);
            // If type is set explicitly use it
            if (queryMap.containsKey("dataformat")) {
              String format = queryMap.get("dataformat");
              if (format.contains("genomespace")) {
                typeString = GSUtils.parseDataFormatString(format);
              } else {
                typeString = format;
              }
            } else if (queryMap.containsKey("file")) {
              typeString = queryMap.get("file");
            }
          }

        } catch (MalformedURLException e) {
          log.error("Error interpreting url: " + path, e);
          typeString = path;
        }
      }

      // Strip .txt, .gz, and .xls extensions.  (So  foo.cn.gz => a .cn file)
      if ((typeString.endsWith(".txt")
          || typeString.endsWith(".xls")
          || typeString.endsWith(".gz")
          || typeString.endsWith(".bgz"))) {
        typeString = typeString.substring(0, typeString.lastIndexOf(".")).trim();
      }

      return typeString;
    }
  }