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;
}
});
}
Aggregations