use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ProjectIO method getSupportedExtensions.
/**
* Get the supported file extensions for projects.
*
* @return the set of file extensions (with leading dot)
*/
private static 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 HeadlessIO method loadProvider.
/**
* Load and configure the I/O provider specified by the given I/O
* configuration.
*
* @param conf the I/O configuration
* @return the provider or <code>null</code> if it was not found or could
* not be created
*/
public static IOProvider loadProvider(IOConfiguration conf) {
IOProvider provider = null;
IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (descriptor != null) {
try {
provider = descriptor.createExtensionObject();
// configure settings
provider.loadConfiguration(conf.getProviderConfiguration());
if (provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setCache(conf.getCache());
}
} catch (Exception e) {
log.error("Could not instantiate I/O provider.", e);
}
}
return provider;
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ProjectParser method load.
private void load(URI source, String actionId, String msgCT, String msgIO, @SuppressWarnings("rawtypes") Class clazz) {
// create IOConfiguration for source data
IOConfiguration conf = new IOConfiguration();
// populate IOConfiguration
// set action ID
conf.setActionId(actionId);
// find provider
File file;
try {
file = new File(source);
} catch (IllegalArgumentException e) {
file = null;
}
@SuppressWarnings("unchecked") IContentType ct = HaleIO.findContentType(clazz, new DefaultInputSupplier(source), (file == null) ? (null) : (file.getAbsolutePath()));
if (ct == null) {
report.error(new IOMessageImpl(msgCT, null, -1, -1, source));
return;
}
@SuppressWarnings("unchecked") IOProviderDescriptor srf = HaleIO.findIOProviderFactory(clazz, ct, null);
if (srf == null) {
report.error(new IOMessageImpl(msgIO, null, -1, -1, source));
return;
}
conf.setProviderId(srf.getIdentifier());
// provider configuration
// source
conf.getProviderConfiguration().put(AbstractImportProvider.PARAM_SOURCE, Value.of(source.toString()));
// content type
conf.getProviderConfiguration().put(AbstractImportProvider.PARAM_CONTENT_TYPE, Value.of(ct.getId()));
// no dependencies needed
// add configuration to project
project.getResources().add(conf);
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class AppSchemaFileWriterTest method loadTestProject.
@BeforeClass
public static void loadTestProject() {
try {
URL archiveLocation = AppSchemaFileWriterTest.class.getResource(PROJECT_LOCATION);
ArchiveProjectReader projectReader = new ArchiveProjectReader();
projectReader.setSource(new DefaultInputSupplier(archiveLocation.toURI()));
IOReport report = projectReader.execute(new LogProgressIndicator());
if (!report.isSuccess()) {
throw new RuntimeException("project reader execution failed");
}
tempDir = projectReader.getTemporaryFiles().iterator().next();
project = projectReader.getProject();
assertNotNull(project);
sourceSchemaSpace = new DefaultSchemaSpace();
targetSchemaSpace = new DefaultSchemaSpace();
// load schemas
List<IOConfiguration> resources = project.getResources();
for (IOConfiguration resource : resources) {
String actionId = resource.getActionId();
String providerId = resource.getProviderId();
// get provider
IOProvider provider = null;
IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(providerId);
if (descriptor == null) {
throw new RuntimeException("Could not load I/O provider with ID: " + resource.getProviderId());
}
provider = descriptor.createExtensionObject();
provider.loadConfiguration(resource.getProviderConfiguration());
prepareProvider(provider, project, tempDir.toURI());
IOReport providerReport = provider.execute(new LogProgressIndicator());
if (!providerReport.isSuccess()) {
throw new RuntimeException("I/O provider execution failed");
}
// TODO: could (should?) be done by an advisor
if (provider instanceof SchemaReader) {
Schema schema = ((SchemaReader) provider).getSchema();
if (actionId.equals(SchemaIO.ACTION_LOAD_SOURCE_SCHEMA)) {
sourceSchemaSpace.addSchema(schema);
} else if (actionId.equals(SchemaIO.ACTION_LOAD_TARGET_SCHEMA)) {
targetSchemaSpace.addSchema(schema);
}
}
}
// load alignment
List<ProjectFileInfo> projectFiles = project.getProjectFiles();
for (ProjectFileInfo projectFile : projectFiles) {
if (projectFile.getName().equals(AlignmentIO.PROJECT_FILE_ALIGNMENT)) {
AlignmentReader alignReader = new JaxbAlignmentReader();
alignReader.setSource(new DefaultInputSupplier(projectFile.getLocation()));
alignReader.setSourceSchema(sourceSchemaSpace);
alignReader.setTargetSchema(targetSchemaSpace);
alignReader.setPathUpdater(new PathUpdate(null, null));
IOReport alignReport = alignReader.execute(new LogProgressIndicator());
if (!alignReport.isSuccess()) {
throw new RuntimeException("alignment reader execution failed");
}
alignment = alignReader.getAlignment();
assertNotNull(alignment);
break;
}
}
} catch (Exception e) {
log.error("Exception occurred", e);
fail("Test project could not be loaded: " + e.getMessage());
}
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class ExamplesContent method executeProvider.
/**
* Execute the I/O provider given or specified by the given provider ID.
*
* @param advisor the advisor to use for configuration of the provider and
* handling the results
* @param providerId the ID of the provider to execute, may be
* <code>null</code> if provider is set
* @param provider the provider to execute
* @throws Exception if executing the provider fails or if a provider with
* the given ID is not found
*/
@SuppressWarnings("unchecked")
private void executeProvider(@SuppressWarnings("rawtypes") IOAdvisor advisor, String providerId, IOProvider provider) throws Exception {
if (provider == null) {
// find and create the provider
IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(providerId);
if (descriptor != null) {
provider = descriptor.createExtensionObject();
} else {
throw new IllegalStateException("I/O provider with ID " + providerId + " not found");
}
}
// use advisor to configure provider
advisor.prepareProvider(provider);
advisor.updateConfiguration(provider);
// execute
IOReport report = provider.execute(null);
// handle results
if (report.isSuccess()) {
advisor.handleResults(provider);
}
}
Aggregations