Пример #1
0
  /**
   * Utility method loads all of the workflow form definitions from yaml files contained in the
   * workflow directory.
   *
   * @return
   */
  public static List<FormDefinition> loadWorkflowFormDefinitions() {
    //        List<FormDefinition> formDefs = new ArrayList<>();
    //
    //        URL path = Play.application().classloader().getResource(WORKFLOWS_PATH);
    //        try {
    //            File dir = new File(path.toURI());
    //
    //            File[] workflows = dir.listFiles(new FilenameFilter() {
    //                public boolean accept(File dir, String name) {
    //                    return name.toLowerCase().endsWith(".yaml");
    //                }
    //            });
    //
    //            for (File file : workflows) {
    //                formDefs.add(loadFormDefinition(file.getAbsolutePath()));
    //            }
    //        } catch (URISyntaxException e) { /* Should not occur */ }

    List<FormDefinition> formDefs = new ArrayList<>();

    Collection<config.WorkflowConfig> workflows = ConfigManager.getInstance().getWorkflowConfigs();

    for (config.WorkflowConfig workflow : workflows) {
      FormDefinition formDef = new FormDefinition();
      formDef.name = workflow.getName();
      formDef.title = workflow.getTitle();
      formDef.yamlFile = workflow.getYaml();
      formDef.documentation = workflow.getDocumentation();
      formDef.instructions = workflow.getInstructions();
      formDef.summary = workflow.getSummary();

      for (ParameterConfig parameter : workflow.getParameters()) {
        if (parameter.isTyped()) {
          String type = parameter.getType();

          switch (type) {
            case "text":
              TextField textField = new TextField();
              textField.name = parameter.getName();
              textField.label = parameter.getLabel();
              textField.tooltip = parameter.getDescription();
              formDef.addField(textField);
              break;
            case "select":
              SelectField selectField = new SelectField();
              selectField.name = parameter.getName();
              selectField.label = parameter.getLabel();
              selectField.options = parameter.getOptions();
              selectField.tooltip = parameter.getDescription();
              formDef.addField(selectField);
              break;
            case "upload":
              FileInput fileInput = new FileInput();
              fileInput.name = parameter.getName();
              fileInput.label = parameter.getLabel();
              fileInput.tooltip = parameter.getDescription();
              formDef.addField(fileInput);
              break;
          }
        }
      }

      formDefs.add(formDef);
    }
    return formDefs;
  }