Ejemplo n.º 1
0
  /**
   * Start the workflow run asynchronously.
   *
   * @param name The name of the workflow
   * @return json response containing id
   */
  @Security.Authenticated(Secured.class)
  public Result runWorkflow(String name) {
    FormDefinition form = formDefinitionForWorkflow(name);

    // Process file upload first if present in form data
    Http.MultipartFormData body = request().body().asMultipartFormData();

    for (Object obj : body.getFiles()) {
      Http.MultipartFormData.FilePart filePart = (Http.MultipartFormData.FilePart) obj;
      UserUpload userUpload = uploadFile(filePart);

      BasicField fileInputField = form.getField(filePart.getKey());
      fileInputField.setValue(userUpload);
    }

    //  Set the form definition field values from the request data
    Map<String, String[]> data = body.asFormUrlEncoded();
    for (String key : data.keySet()) {
      BasicField field = form.getField(key);
      field.setValue(data.get(key));
    }

    // Transfer form field data to workflow settings map
    Map<String, Object> settings = new HashMap<>();

    for (BasicField field : form.fields) {
      settings.put(field.name, field.value());
    }

    settings.putAll(settingsFromConfig(form));

    // Update the workflow model object and persist to the db
    Workflow workflow = Workflow.find.where().eq("name", form.name).findUnique();

    if (workflow == null) {
      workflow = new Workflow();
    }

    workflow.name = form.name;
    workflow.title = form.title;
    workflow.yamlFile = form.yamlFile;

    workflow.save();

    // Run the workflow
    ObjectNode response = runYamlWorkflow(form.yamlFile, workflow, settings);

    return redirect(routes.Application.index());
  }
Ejemplo n.º 2
0
  /**
   * Helper method creates a temp file from the multipart form data and persists the upload file
   * metadata to the database
   *
   * @param filePart data from the form submission
   * @return an instance of UploadFile that has been persisted to the db
   */
  private static UserUpload uploadFile(Http.MultipartFormData.FilePart filePart) {
    File src = (File) filePart.getFile();
    File file = null;
    try {
      file = File.createTempFile(filePart.getFilename() + "-", ".csv");
      FileUtils.copyFile(src, file);
    } catch (IOException e) {
      throw new RuntimeException("Could not create temp file for upload", e);
    }

    UserUpload uploadFile = new UserUpload();
    uploadFile.absolutePath = file.getAbsolutePath();
    uploadFile.fileName = filePart.getFilename();
    uploadFile.user = Application.getCurrentUser();
    uploadFile.save();

    return uploadFile;
  }
Ejemplo n.º 3
0
  @Security.Authenticated(Secured.class)
  public Result deploy() {
    Http.MultipartFormData body = request().body().asMultipartFormData();
    Http.MultipartFormData.FilePart filePart = body.getFile("filename");

    if (filePart != null) {
      ConfigManager configManager = ConfigManager.getInstance();
      try {
        configManager.unpack((File) filePart.getFile());
      } catch (Exception e) {
        flash("error", "Could not verify package.");
        return redirect(routes.Workflows.uploadWorkflow());
      }

      flash("message", "Packages zip file was successfully deployed");
      return redirect(routes.Workflows.uploadWorkflow());
    } else {
      flash("error", "Missing file");
      return badRequest();
    }
  }