use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class HaleIO method createIOProvider.
/**
* Creates an I/O provider instance
*
* @param
* <P>
* the provider interface type
*
* @param providerType the provider type, usually an interface
* @param contentType the content type the provider must match, may be
* <code>null</code> if providerId is set
* @param providerId the id of the provider to use, may be <code>null</code>
* if contentType is set
* @return the I/O provider preconfigured with the content type if it was
* given or <code>null</code> if no matching I/O provider is found
*/
@SuppressWarnings("unchecked")
public static <P extends IOProvider> P createIOProvider(Class<P> providerType, IContentType contentType, String providerId) {
IOProviderDescriptor factory = findIOProviderFactory(providerType, contentType, providerId);
P result;
try {
result = (P) ((factory == null) ? (null) : (factory.createExtensionObject()));
} catch (Exception e) {
throw new RuntimeException("Could not create I/O provider", e);
}
if (result != null && contentType != null) {
result.setContentType(contentType);
}
return result;
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ProjectTransformationEnvironment method init.
/**
* Initialize the environment based on the loaded project.
*
* @param project the project
*/
protected void init(Project project) {
// export presets
for (Entry<String, IOConfiguration> preset : project.getExportConfigurations().entrySet()) {
IOConfiguration conf = preset.getValue();
if (InstanceIO.ACTION_SAVE_TRANSFORMED_DATA.equals(conf.getActionId())) {
// configuration for data export
IOConfiguration c = conf.clone();
// check provider
IOProviderDescriptor factory = HaleIO.findIOProviderFactory(InstanceWriter.class, null, c.getProviderId());
if (factory != null) {
String name = preset.getKey();
if (Strings.isNullOrEmpty(name)) {
name = factory.getDisplayName();
}
exportPresets.put(name, c);
} else {
log.error("I/O provider for export preset not found.");
}
}
}
// export templates
Collection<IOProviderDescriptor> writerFactories = HaleIO.getProviderFactories(InstanceWriter.class);
for (IOProviderDescriptor factory : writerFactories) {
try {
InstanceWriter writer = (InstanceWriter) factory.createExtensionObject();
writer.setTargetSchema(getTargetSchema());
writer.checkCompatibility();
IOConfiguration conf = new IOConfiguration();
conf.setActionId(InstanceIO.ACTION_SAVE_TRANSFORMED_DATA);
conf.setProviderId(factory.getIdentifier());
exportTemplates.put(factory.getDisplayName(), conf);
} catch (IOProviderConfigurationException e) {
// ignore
} catch (Exception e) {
log.error("Error initializing instance writer for testing compatibility", e);
}
}
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ExecTransformation method setupWriter.
private void setupWriter() {
String preset = context.getPreset();
String customProvider = context.getTargetProviderId();
if (preset == null && customProvider == null) {
fail("Please specify the name of a data export configuration preset or provide a specific provider ID for the instance writer");
}
// create I/O configuration
IOConfiguration conf = null;
if (preset != null) {
conf = env.getExportPresets().get(preset);
}
if (conf == null) {
if (customProvider == null) {
throw fail("Data export configration preset not found: " + preset + " (please make sure you created it and saved it as part of the project)");
} else {
conf = new IOConfiguration();
}
}
if (customProvider != null) {
conf.setProviderId(customProvider);
}
// apply custom settings to configuration
conf.getProviderConfiguration().putAll(context.getTargetSettings());
// create I/O provider
String writerId = conf.getProviderId();
target = HaleIO.createIOProvider(InstanceWriter.class, null, writerId);
target.setTarget(createTargetSupplier(context.getTarget()));
target.setTargetSchema(env.getTargetSchema());
// determine content type to use based on file extension
IOProviderDescriptor factory = HaleIO.findIOProviderFactory(InstanceWriter.class, null, writerId);
if (factory == null) {
throw fail("Instance writer with ID " + writerId + " not found");
}
String path = context.getTarget().getPath();
List<IContentType> cts;
if (path != null) {
cts = HaleIO.findContentTypesFor(factory.getSupportedTypes(), null, path);
} else {
cts = new ArrayList<>(factory.getSupportedTypes());
}
if (!cts.isEmpty()) {
target.setContentType(cts.get(0));
}
// apply configuration (may override content type)
target.loadConfiguration(conf.getProviderConfiguration());
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ProjectReference method getSupportedExtensions.
/**
* Get the supported file extensions for projects.
*
* @return the set of file extensions (with leading dot)
*/
protected Set<String> getSupportedExtensions() {
Collection<IOProviderDescriptor> providers = HaleIO.getProviderFactories(ProjectReader.class);
// collect supported content types
Set<String> supportedExtensions = new HashSet<String>();
for (IOProviderDescriptor factory : providers) {
for (IContentType type : factory.getSupportedTypes()) {
String[] extensions = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
if (extensions != null) {
for (String ext : extensions) {
supportedExtensions.add('.' + ext);
}
}
}
}
return supportedExtensions;
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ExportSelectProviderPage method createContent.
/**
* @see HaleWizardPage#createContent(Composite)
*/
@Override
protected void createContent(Composite page) {
page.setLayout(new GridLayout(1, false));
// create provider list viewer
providers = new ListViewer(page, SWT.BORDER);
providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
providers.setContentProvider(ArrayContentProvider.getInstance());
providers.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof IOProviderDescriptor) {
return ((IOProviderDescriptor) element).getDisplayName();
}
return "Custom configuration: " + super.getText(element);
}
});
factories = getWizard().getFactories();
List<Object> input = new ArrayList<>();
// check for presets
Collection<String> presets = getWizard().getPresets();
if (presets != null && !presets.isEmpty()) {
input.addAll(presets);
}
input.addAll(factories);
providers.setInput(input);
providers.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (canFlipToNextPage()) {
getContainer().showPage(getNextPage());
return;
}
}
});
// set initial selection
// if (!factories.isEmpty()) {
// providers.setSelection(new StructuredSelection(factories.iterator().next()), true);
// }
// process current selection
ISelection selection = providers.getSelection();
setPageComplete(!selection.isEmpty());
updateWizard(selection);
// process selection changes
providers.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
setPageComplete(!selection.isEmpty());
updateWizard(selection);
}
});
}
Aggregations