Search in sources :

Example 16 with IOConfiguration

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()));
        }
    }
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) Value(eu.esdihumboldt.hale.common.core.io.Value) URI(java.net.URI)

Example 17 with IOConfiguration

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;
}
Also used : ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ValueType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ValueType) ElementValue(eu.esdihumboldt.hale.common.core.io.impl.ElementValue) Value(eu.esdihumboldt.hale.common.core.io.Value) PropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.PropertyType) ComplexPropertyType(eu.esdihumboldt.hale.common.core.io.project.model.internal.generated.ComplexPropertyType) ElementValue(eu.esdihumboldt.hale.common.core.io.impl.ElementValue)

Example 18 with IOConfiguration

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);
        }
    }
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) Value(eu.esdihumboldt.hale.common.core.io.Value) URI(java.net.URI)

Example 19 with IOConfiguration

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();
    }
}
Also used : LocationUpdater(eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) ActionProjectFile(eu.esdihumboldt.hale.common.core.io.project.extension.internal.ActionProjectFile)

Example 20 with IOConfiguration

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);
        }
    }
}
Also used : IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) InstanceWriter(eu.esdihumboldt.hale.common.instance.io.InstanceWriter) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Aggregations

IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)31 Value (eu.esdihumboldt.hale.common.core.io.Value)10 URI (java.net.URI)9 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)8 File (java.io.File)8 IOException (java.io.IOException)6 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)5 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)5 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)5 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ArrayList (java.util.ArrayList)5 IOConfigurationResource (eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)4 Project (eu.esdihumboldt.hale.common.core.io.project.model.Project)4 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)3 ProjectFile (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile)3 LocationUpdater (eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater)3