Search in sources :

Example 76 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class InterpolationHelper method getInterpolation.

/**
 * Get the interpolation algorithm for a given instance reader.
 *
 * @param instanceReader the instance reader
 * @param factory the geometry factory
 * @return the interpolation algorithm
 */
public static InterpolationAlgorithm getInterpolation(IOProvider instanceReader, GeometryFactory factory) {
    // FIXME weak cache based on reader?
    String algorithmId = instanceReader.getParameter(PARAMETER_INTERPOLATION_ALGORITHM).as(String.class, DEFAULT_ALGORITHM);
    InterpolationAlgorithmFactory fact = InterpolationExtension.getInstance().getFactory(algorithmId);
    if (fact == null) {
        log.warn("Could not find interpolation algorithm with ID " + algorithmId);
        fact = InterpolationExtension.getInstance().getFactory(DEFAULT_ALGORITHM);
    }
    if (fact == null) {
        throw new IllegalStateException("Default interpolation algorithm could not be found");
    }
    InterpolationAlgorithm result;
    try {
        result = fact.createExtensionObject();
    } catch (Exception e) {
        log.error("Interpolation algorithm could be created", e);
        result = new SplitInterpolation();
    }
    double maxPositionalError = getMaxPositionalError(instanceReader);
    // configure the algorithm
    Map<String, Value> configuration = new HashMap<>();
    instanceReader.storeConfiguration(configuration);
    Map<String, String> properties = new HashMap<>();
    for (Entry<String, Value> entry : configuration.entrySet()) {
        if (!entry.getValue().isRepresentedAsDOM()) {
            properties.put(entry.getKey(), entry.getValue().getStringRepresentation());
        }
    }
    result.configure(factory, maxPositionalError, properties);
    return result;
}
Also used : SplitInterpolation(eu.esdihumboldt.util.geometry.interpolation.split.SplitInterpolation) HashMap(java.util.HashMap) Value(eu.esdihumboldt.hale.common.core.io.Value) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

Example 77 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class InstanceViewPreferencePage method performOk.

@Override
public boolean performOk() {
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    if (changed) {
        if (!MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Reload source data", "Applying the new settings will result in the source data being reloaded.")) {
            return false;
        }
        // save the enabled state
        ps.getConfigurationService().setBoolean(InstanceViewPreferences.KEY_ENABLED, enabled.getSelection());
        // store the current editor value in the map
        if (currentEditor != null) {
            // store value for current sampler
            Value setting = currentEditor.getValue();
            samplerSettings.put(InstanceViewPreferences.SAMPLERS.inverse().get(currentSampler), setting);
        }
        // store the map in the configuration
        for (Entry<String, Value> entry : samplerSettings.entrySet()) {
            ps.getConfigurationService().setProperty(InstanceViewPreferences.KEY_SETTINGS_PREFIX + entry.getKey(), entry.getValue());
        }
        // store the selected sampler
        Sampler selectedSampler = null;
        if (!samplers.getSelection().isEmpty()) {
            selectedSampler = (Sampler) ((IStructuredSelection) samplers.getSelection()).getFirstElement();
        }
        if (selectedSampler != null) {
            ps.getConfigurationService().set(InstanceViewPreferences.KEY_SAMPLER, InstanceViewPreferences.SAMPLERS.inverse().get(selectedSampler));
        }
        // reload the data
        ps.reloadSourceData();
        changed = false;
    }
    if (ov_changed) {
        ps.getConfigurationService().setBoolean(InstanceViewPreferences.KEY_OCCURRING_VALUES_USE_EXTERNAL, occurringValuesComplete.getSelection());
        ov_changed = false;
    }
    return true;
}
Also used : Sampler(eu.esdihumboldt.hale.ui.service.instance.sample.Sampler) Value(eu.esdihumboldt.hale.common.core.io.Value) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 78 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class ProjectResourcesUtil method executeProvider.

/**
 * Execute the given I/O provider with the given I/O advisor.
 *
 * @param provider the I/O provider
 * @param advisor the I/O advisor
 * @param publishReport if the report should be published
 * @param cacheCallback call back that is notified on cache changes for the
 *            I/O provider, may be <code>null</code>
 * @return the future yielding the report on success
 */
public static ListenableFuture<IOReport> executeProvider(final IOProvider provider, @SuppressWarnings("rawtypes") final IOAdvisor advisor, final boolean publishReport, final CacheCallback cacheCallback) {
    final SettableFuture<IOReport> result = SettableFuture.create();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @SuppressWarnings("unchecked")
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            if (cacheCallback != null && provider instanceof CachingImportProvider) {
                // enable cache generation
                ((CachingImportProvider) provider).setProvideCache();
            }
            IOReporter reporter = provider.createReporter();
            ATransaction trans = log.begin(reporter.getTaskName());
            try {
                // use advisor to configure provider
                advisor.prepareProvider(provider);
                advisor.updateConfiguration(provider);
                // execute
                IOReport report = provider.execute(new ProgressMonitorIndicator(monitor));
                if (publishReport) {
                    // publish report
                    ReportService rs = PlatformUI.getWorkbench().getService(ReportService.class);
                    rs.addReport(report);
                }
                // handle cache update
                if (cacheCallback != null && provider instanceof CachingImportProvider) {
                    CachingImportProvider cip = (CachingImportProvider) provider;
                    if (cip.isCacheUpdate()) {
                        Value cache = cip.getCache();
                        cacheCallback.update(cache);
                    }
                }
                // handle results
                if (report.isSuccess()) {
                    advisor.handleResults(provider);
                }
                result.set(report);
            } catch (Exception e) {
                log.error("Error executing an I/O provider.", e);
                result.setException(e);
            } finally {
                trans.end();
            }
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, provider.isCancelable());
    } catch (Exception e) {
        log.error("Error executing an I/O provider.", e);
        result.setException(e);
    }
    return result;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) CachingImportProvider(eu.esdihumboldt.hale.common.core.io.CachingImportProvider) ATransaction(de.fhg.igd.slf4jplus.ATransaction) Value(eu.esdihumboldt.hale.common.core.io.Value) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 79 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class ProjectServiceImpl method executeConfiguration.

/**
 * Execute a single I/O configuration.
 *
 * @param conf the I/O configuration
 */
private void executeConfiguration(final IOConfiguration conf) {
    // work with a cloned configuration for the case that we make a relative
    // URI absolute
    IOConfiguration cloned = conf.clone();
    updater.updateIOConfiguration(cloned, false);
    ProjectResourcesUtil.executeConfiguration(cloned, new CacheCallback() {

        @Override
        public void update(Value cache) {
            // update the original configuration with the new cache value
            conf.setCache(cache);
            // set the project status to changed
            setChanged();
        }
    });
}
Also used : CacheCallback(eu.esdihumboldt.hale.ui.service.project.CacheCallback) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 80 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class ProjectServiceImpl method removeResource.

@Override
public void removeResource(String resourceId) {
    Resource removedResource = null;
    synchronized (this) {
        Iterator<IOConfiguration> iter = main.getResources().iterator();
        while (iter.hasNext()) {
            IOConfiguration conf = iter.next();
            Value idValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_RESOURCE_ID);
            if (idValue != null) {
                String id = idValue.as(String.class);
                if (resourceId.equals(id)) {
                    // match found, remove
                    iter.remove();
                    removedResource = new IOConfigurationResource(conf, projectLocation);
                    break;
                }
            }
        }
    }
    if (removedResource != null) {
        setChanged();
        notifyResourcesRemoved(removedResource.getActionId(), Collections.singletonList(removedResource));
    }
}
Also used : IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) Value(eu.esdihumboldt.hale.common.core.io.Value) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)

Aggregations

Value (eu.esdihumboldt.hale.common.core.io.Value)81 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)12 LookupTable (eu.esdihumboldt.hale.common.lookup.LookupTable)12 HashMap (java.util.HashMap)12 ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)11 LookupTableImpl (eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)11 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)10 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)8 Test (org.junit.Test)6 StyledString (org.eclipse.jface.viewers.StyledString)5 Composite (org.eclipse.swt.widgets.Composite)5 DefaultCustomPropertyFunction (eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)4 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)4 IOException (java.io.IOException)4 Locale (java.util.Locale)4