Search in sources :

Example 1 with IOProviderParameter

use of eu.esdihumboldt.hale.common.core.parameter.IOProviderParameter in project hale by halestudio.

the class IOReferenceContent method getIOProviderContent.

/**
 * @param providerId The id of the provider
 * @return The in input stream or null, if the given provider does not
 *         exist.
 * @throws Exception - if an error occurs
 */
private InputStream getIOProviderContent(String providerId) throws Exception {
    final String id = providerId;
    // try to get I/O provider
    IOProviderDescriptor providerDescriptor = HaleIO.findIOProviderFactory(IOProvider.class, null, providerId);
    if (providerDescriptor == null) {
        log.warn("I/O provider " + id + " does not exist.");
        return null;
    }
    final IOProviderDescriptor descriptor = providerDescriptor;
    return getContentFromTemplate(providerId, TEMPLATE_PROVIDER, new Callable<VelocityContext>() {

        @Override
        public VelocityContext call() throws Exception {
            VelocityContext context = new VelocityContext();
            // I/O provider descriptor
            context.put("descriptor", descriptor);
            // I/O provider type
            String type = (ImportProvider.class.isAssignableFrom(descriptor.getProviderType())) ? ("reader") : ("writer");
            context.put("providerType", type);
            // collect all optional parameter
            Collection<IOProviderParameter> parameter = new ArrayList<IOProviderParameter>();
            Map<String, String> example = new HashMap<String, String>();
            Map<String, String> defaults = new HashMap<String, String>();
            for (IOProviderParameter param : descriptor.getProviderParameter()) {
                parameter.add(param);
                // get example use of parameter
                if (param.getValueDescriptor() != null) {
                    // store sample value
                    Value sample = param.getValueDescriptor().getSampleData();
                    String displayValue = toDisplayValue(sample);
                    if (displayValue != null) {
                        example.put(param.getName(), displayValue);
                    }
                    // store default value
                    Value defaultValue = param.getValueDescriptor().getDefaultValue();
                    displayValue = toDisplayValue(defaultValue);
                    if (displayValue != null) {
                        defaults.put(param.getName(), displayValue);
                    }
                }
            }
            context.put("parameter", parameter);
            context.put("example", example);
            context.put("defaults", defaults);
            return context;
        }
    });
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) VelocityContext(org.apache.velocity.VelocityContext) ImportProvider(eu.esdihumboldt.hale.common.core.io.ImportProvider) TransformerException(javax.xml.transform.TransformerException) IOProviderParameter(eu.esdihumboldt.hale.common.core.parameter.IOProviderParameter) Value(eu.esdihumboldt.hale.common.core.io.Value) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ImportProvider (eu.esdihumboldt.hale.common.core.io.ImportProvider)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 IOProviderParameter (eu.esdihumboldt.hale.common.core.parameter.IOProviderParameter)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TransformerException (javax.xml.transform.TransformerException)1 VelocityContext (org.apache.velocity.VelocityContext)1