use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration in project hale by halestudio.
the class DefaultProjectWriter method updateRelativeResourcePaths.
private void updateRelativeResourcePaths(Iterable<IOConfiguration> resources, URI previousTarget, URI newTarget) {
// if the previous target is null, there cannot be relative paths
if (previousTarget == null)
return;
for (IOConfiguration resource : resources) {
Map<String, Value> providerConfig = resource.getProviderConfiguration();
URI pathUri = URI.create(providerConfig.get(ImportProvider.PARAM_SOURCE).as(String.class));
// update relative URIs
if (!pathUri.isAbsolute()) {
// resolve the resource's URI
pathUri = previousTarget.resolve(pathUri);
// try to get a relative path from the new project to the
// resource
URI relative = IOUtils.getRelativePath(pathUri, newTarget);
providerConfig.put(ImportProvider.PARAM_SOURCE, Value.of(relative.toString()));
}
}
}
use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration in project hale by halestudio.
the class JaxbToProject method toIOConfiguration.
/**
* Convert a JAXB representation to an {@link IOConfiguration}.
*
* @param config the JAXB representation
* @return the I/O configuration
*/
public static IOConfiguration toIOConfiguration(IOConfigurationType config) {
if (config == null) {
return null;
}
IOConfiguration result = new IOConfiguration();
result.setActionId(config.getActionId());
result.setProviderId(config.getProviderId());
for (JAXBElement<?> setting : config.getAbstractSetting()) {
Object value = setting.getValue();
if (value instanceof PropertyType) {
addProperty(result.getProviderConfiguration(), (PropertyType) value);
} else if (value instanceof ComplexPropertyType) {
addProperty(result.getProviderConfiguration(), (ComplexPropertyType) value);
}
}
// cache
ValueType cache = config.getCache();
if (cache != null) {
Value value = Value.NULL;
if (cache.getAny() != null) {
value = new ElementValue(cache.getAny(), null);
} else if (cache.getValue() != null) {
value = Value.of(cache.getValue());
}
result.setCache(value);
}
return result;
}
use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration in project hale by halestudio.
the class LocationUpdater method updateProject.
/**
* Update locations in the given project.
*
* @param keepRelative whether to keep working relative URIs as is or make
* them absolute
*/
public void updateProject(boolean keepRelative) {
if (project == null || getOldLocation() == null || getNewLocation() == null)
return;
IOConfiguration saveconfig = project.getSaveConfiguration();
// actually cannot be null here because then old location would be null
if (saveconfig == null)
return;
if (!getOldLocation().equals(getNewLocation()) || !keepRelative) {
// update save configuration
saveconfig.getProviderConfiguration().put(ExportProvider.PARAM_TARGET, Value.of(getNewLocation().toString()));
// update I/O configurations
List<IOConfiguration> configuration = project.getResources();
for (IOConfiguration providerconf : configuration) {
final Map<String, Value> conf = providerconf.getProviderConfiguration();
final URI uri = URI.create(conf.get(ImportProvider.PARAM_SOURCE).as(String.class));
URI resolved = findLocation(uri, true, true, keepRelative);
if (resolved != null)
conf.put(ImportProvider.PARAM_SOURCE, Value.of(resolved.toString()));
}
// update project file infos
for (ProjectFileInfo fileInfo : project.getProjectFiles()) {
URI location = fileInfo.getLocation();
/*
* Project files should always be next to the project file.
*
* Fallback wouldn't have an effect here because as it is used
* currently in the project service, project files are already
* loaded in the DefaultProjectReader.
*/
URI resolved = findLocation(location, false, false, keepRelative);
if (resolved != null)
fileInfo.setLocation(resolved);
}
}
}
use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration in project hale by halestudio.
the class HeadlessProjectAdvisor method handleResults.
@Override
public void handleResults(ProjectReader provider) {
project = provider.getProject();
projectLocation = provider.getSource().getLocation();
updater = new LocationUpdater(project, projectLocation);
// no need to keep relative paths in the headless environment
updater.updateProject(false);
// inject project into advisors (mappable types)
sourceSchemaAdvisor.setProject(project);
targetSchemaAdvisor.setProject(project);
// execute loaded I/O configurations
List<IOConfiguration> confs = new ArrayList<IOConfiguration>(project.getResources());
// but remove source data actions first
Iterator<IOConfiguration> it = confs.iterator();
while (it.hasNext()) {
if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(it.next().getActionId())) {
it.remove();
}
}
try {
HeadlessIO.executeConfigurations(confs, advisors, reportHandler, this);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
Map<String, ProjectFile> projectFiles = provider.getProjectFiles();
// apply remaining project files
for (ProjectFile file : projectFiles.values()) {
file.apply();
}
}
use of eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration 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);
}
}
}
Aggregations