示例#1
0
  public boolean run(String targetDirectory) throws Throwable {
    // Create a time stamp and use it for the project name
    String projectName = new Date().toString();
    log.info("Storing project: " + projectName);
    Project project = store.addProject(projectName, "");

    // Our root directory
    File projectDirectory = new File(targetDirectory);
    boolean status = false;
    if (!config.getRecurse()) {
      // Do not parse sub-directory - only import files in the target.
      String name = projectDirectory.getName();
      log.info("Storing dataset: " + name);
      Dataset dataset = store.addDataset(name, "", project);
      status = processDirectory(config.getPopulate(), projectDirectory, dataset);
    } else {
      // Parse the sub-directories - these will become our datasets
      for (File datasetDirectory : projectDirectory.listFiles()) {
        if (datasetDirectory.exists() && datasetDirectory.isDirectory()) {
          String name = datasetDirectory.getName();
          log.info("Storing dataset: " + name);
          Dataset dataset = store.addDataset(name, "", project);
          // In each sub-directory/dataset, import the images needed
          status = processDirectory(config.getPopulate(), datasetDirectory, dataset);
        }
      }
    }
    store.logout();
    return status;
  }
示例#2
0
 /**
  * Exits the JVM by calculating the proper exit code based on the number (and eventually type) of
  * errors and {@link TestEngineConfig#getErrorOn()}
  */
 public void exit() {
   ErrorOn err = ErrorOn.valueOf(config.getErrorOn());
   int returnCode = 0;
   switch (err) {
     case never:
       {
         break;
       }
     default:
       {
         returnCode = errors;
       }
   }
   System.err.println("Number of errors: " + errors);
   System.exit(returnCode);
 }
示例#3
0
  public TestEngine(TestEngineConfig config)
      throws CannotCreateSessionException, PermissionDeniedException, ServerError {
    this.config = config;
    ProxyFactory pf = new ProxyFactory(new OMEROMetadataStoreClient());
    pf.addAdvice(interceptor);
    pf.setProxyTargetClass(true);
    store = (OMEROMetadataStoreClient) pf.getProxy();
    wrapper = new OMEROWrapper(new ImportConfig());

    login_url = config.getFeedbackLoginUrl();
    login_username = config.getFeedbackLoginUsername();
    login_password = config.getFeedbackLoginPassword();
    message_url = config.getFeedbackMessageUrl();
    comment_url = config.getCommentUrl();

    // Login
    if (config.getSessionKey() != null) {
      store.initialize(config.getHostname(), config.getPort(), config.getSessionKey());
    } else {
      store.initialize(
          config.getUsername(), config.getPassword(), config.getHostname(), config.getPort());
    }
    importLibrary = new ImportLibrary(store, wrapper);
  }
示例#4
0
  /**
   * Command line application entry point which parses CLI arguments and passes them into the
   * importer. Return codes are:
   *
   * <ul>
   *   <li>0 on success
   *   <li>1 on argument parsing failure
   *   <li>2 on exception during import
   * </ul>
   *
   * @param args Command line arguments.
   */
  public static void main(String[] args) throws Throwable {
    LongOpt[] longOptions =
        new LongOpt[] {
          new LongOpt("error-on", LongOpt.REQUIRED_ARGUMENT, null, 'e'),
          new LongOpt("feedback", LongOpt.REQUIRED_ARGUMENT, null, 'f'),
          new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'),
          new LongOpt("no-recurse", LongOpt.OPTIONAL_ARGUMENT, null, 'r')
        };

    // First find our configuration file, if it has been provided.
    Getopt g = new Getopt(APP_NAME, args, "s:u:w:p:k:c:x", longOptions);
    int a;
    InputStream configFile = new ByteArrayInputStream(new byte[0]);
    while ((a = g.getopt()) != -1) {
      switch (a) {
        case 'c':
          {
            configFile = new FileInputStream(g.getOptarg());
            break;
          }
      }
    }
    // Second check for the configuration file on the CLASSPATH if we
    // haven't been given a configuration file on the command line.
    if (configFile instanceof ByteArrayInputStream) {
      InputStream fromClasspath =
          TestEngine.class.getClassLoader().getResourceAsStream("test_engine.ini");
      configFile = fromClasspath == null ? configFile : fromClasspath;
    }

    // Now parse our options.
    g = new Getopt(APP_NAME, args, "s:u:w:p:c:k:x", longOptions);
    TestEngineConfig config = new TestEngineConfig(configFile);
    while ((a = g.getopt()) != -1) {
      switch (a) {
        case 's':
          {
            config.setHostname(g.getOptarg());
            break;
          }
        case 'u':
          {
            config.setUsername(g.getOptarg());
            break;
          }
        case 'w':
          {
            config.setPassword(g.getOptarg());
            break;
          }
        case 'k':
          {
            config.setSessionKey(g.getOptarg());
            break;
          }
        case 'p':
          {
            config.setPort(Integer.parseInt(g.getOptarg()));
            break;
          }
        case 'x':
          {
            config.setPopulate(!config.getPopulate());
            break;
          }
        case 'r':
          {
            config.setRecurse(!config.getRecurse());
            break;
          }
        case 'e':
          {
            config.setErrorOn(g.getOptarg());
          }
        case 'f':
          {
            config.setFeedbackUrl(g.getOptarg());
            break;
          }
        case 'c':
          {
            // Ignore, we've dealt with this already.
            break;
          }
        default:
          {
            usage();
          }
      }
    }

    // Ensure that we have all of our required login arguments
    if (!config.validateLogin()) {
      usage();
    }

    // Ensure that we have a valid target path.
    String path = config.getTarget();
    if (args.length - g.getOptind() == 1) {
      path = args[g.getOptind()];
    } else if (path == null) {
      usage();
    }

    TestEngine engine = new TestEngine(config);
    engine.run(path);
    engine.exit();
  }