Search in sources :

Example 11 with Resource

use of eu.esdihumboldt.hale.common.core.io.project.model.Resource 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)

Example 12 with Resource

use of eu.esdihumboldt.hale.common.core.io.project.model.Resource 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

Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)12 IOAction (eu.esdihumboldt.hale.common.core.io.IOAction)5 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)5 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)5 ArrayList (java.util.ArrayList)4 IOConfigurationResource (eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)3 ActionUI (eu.esdihumboldt.hale.ui.io.action.ActionUI)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URI (java.net.URI)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 StyledString (org.eclipse.jface.viewers.StyledString)2 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)1 CellType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 ProjectInfo (eu.esdihumboldt.hale.common.core.io.project.ProjectInfo)1 LocationUpdater (eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater)1 ReportFile (eu.esdihumboldt.hale.common.headless.report.ReportFile)1 DataSet (eu.esdihumboldt.hale.common.instance.model.DataSet)1 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)1