/** * 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()); }
@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(); } }