Search in sources :

Example 1 with TransformDataImportAdvisor

use of eu.esdihumboldt.hale.ui.transformation.TransformDataImportAdvisor in project hale by halestudio.

the class OccurringValuesServiceImpl method updateOccuringValues.

/**
 * Update the occurring values for the given property entity.
 *
 * @param property the property entity definition
 * @param values the map containing the current occurring values
 * @return <code>true</code> if the task to update the information has been
 *         started, <code>false</code> if the information was up-to-date
 */
private boolean updateOccuringValues(PropertyEntityDefinition property, Map<PropertyEntityDefinition, OccurringValuesImpl> values) {
    synchronized (values) {
        OccurringValues ov = values.get(property);
        if (ov != null && ov.isUpToDate()) {
            return false;
        }
    }
    // determine occurring values
    // determine data set
    DataSet dataSet;
    switch(property.getSchemaSpace()) {
        case TARGET:
            dataSet = DataSet.TRANSFORMED;
            break;
        default:
            dataSet = DataSet.SOURCE;
    }
    // determine if external data should be used
    boolean useExternalData = false;
    if (dataSet.equals(DataSet.SOURCE)) {
        ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
        useExternalData = InstanceViewPreferences.occurringValuesUseExternalData(ps.getConfigurationService());
    }
    InstanceCollection collection;
    if (!useExternalData) {
        collection = instances.getInstances(dataSet);
    } else {
        // use complete project data sources
        final AtomicReference<InstanceCollection> source = new AtomicReference<>();
        IRunnableWithProgress op = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
                List<InstanceCollection> sources = new ArrayList<>();
                for (Resource resource : ps.getResources()) {
                    if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) {
                        // resource is source data
                        IOConfiguration conf = resource.copyConfiguration(true);
                        TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
                        ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null);
                        if (advisor.getInstances() != null) {
                            sources.add(advisor.getInstances());
                        }
                    }
                }
                source.set(new MultiInstanceCollection(sources));
            }
        };
        try {
            ThreadProgressMonitor.runWithProgressDialog(op, false);
            collection = source.get();
        } catch (Exception e) {
            log.error("Error initializing data sources", e);
            return true;
        }
    }
    // go through instances to determine occurring values
    Job job = new OccurringValuesJob(property, values, collection);
    job.schedule();
    return true;
}
Also used : DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) MultiInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) ArrayList(java.util.ArrayList) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MultiInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TransformDataImportAdvisor(eu.esdihumboldt.hale.ui.transformation.TransformDataImportAdvisor) OccurringValues(eu.esdihumboldt.hale.ui.service.values.OccurringValues) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)1 MultiInstanceCollection (eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection)1 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)1 OccurringValues (eu.esdihumboldt.hale.ui.service.values.OccurringValues)1 TransformDataImportAdvisor (eu.esdihumboldt.hale.ui.transformation.TransformDataImportAdvisor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1