예제 #1
0
  // TODO - also use this scheme in the GPF GUIs (nf, 2012-03-02)
  // See also [BEAM-1375] Allow gpt to use template variables in parameter files
  private Map<String, String> getRawParameterMap() throws Exception {
    Map<String, String> parameterMap;
    String parameterFilePath = commandLineArgs.getParameterFilePath();
    if (parameterFilePath != null) {
      // put command line parameters in the Velocity context so that we can reference them in the
      // parameters file
      VelocityContext velocityContext = metadataResourceEngine.getVelocityContext();
      velocityContext.put("parameters", commandLineArgs.getParameterMap());

      Resource parameterFile =
          metadataResourceEngine.readResource("parameterFile", parameterFilePath);
      Map<String, String> configFilemap = parameterFile.getMap();
      if (!parameterFile.isXml()) {
        configFilemap.putAll(commandLineArgs.getParameterMap());
      }
      parameterMap = configFilemap;
    } else {
      parameterMap = new HashMap<String, String>();
    }

    // CLI parameters shall always overwrite file parameters
    parameterMap.putAll(commandLineArgs.getParameterMap());
    metadataResourceEngine.getVelocityContext().put("parameters", parameterMap);
    return parameterMap;
  }
예제 #2
0
  private Map<String, Object> convertParameterMap(
      String operatorName, Map<String, String> parameterMap) throws ValidationException {
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    PropertyContainer container =
        ParameterDescriptorFactory.createMapBackedOperatorPropertyContainer(
            operatorName, parameters);
    // explicitly set default values for putting them into the backing map
    container.setDefaultValues();

    // handle xml parameters
    Object parametersObject = metadataResourceEngine.getVelocityContext().get("parameterFile");
    if (parametersObject instanceof Resource) {
      Resource paramatersResource = (Resource) parametersObject;
      if (paramatersResource.isXml()) {
        OperatorSpiRegistry operatorSpiRegistry = GPF.getDefaultInstance().getOperatorSpiRegistry();
        OperatorSpi operatorSpi = operatorSpiRegistry.getOperatorSpi(operatorName);
        Class<? extends Operator> operatorClass = operatorSpi.getOperatorClass();
        DefaultDomConverter domConverter =
            new DefaultDomConverter(operatorClass, new ParameterDescriptorFactory());

        DomElement parametersElement = createDomElement(paramatersResource.getContent());
        try {
          domConverter.convertDomToValue(parametersElement, container);
        } catch (ConversionException e) {
          String msgPattern = "Can not convert XML parameters for operator '%s'";
          throw new RuntimeException(String.format(msgPattern, operatorName));
        }
      }
    }

    for (Entry<String, String> entry : parameterMap.entrySet()) {
      String paramName = entry.getKey();
      String paramValue = entry.getValue();
      final Property property = container.getProperty(paramName);
      if (property != null) {
        property.setValueFromText(paramValue);
      } else {
        throw new RuntimeException(
            String.format("Parameter '%s' is not known by operator '%s'", paramName, operatorName));
      }
    }
    return parameters;
  }