Search in sources :

Example 46 with InstanceCollection

use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.

the class OrientInstanceService method performTransformation.

/**
 * Perform the transformation
 *
 * @return if the transformation was successful
 */
protected boolean performTransformation() {
    final TransformationService ts = getTransformationService();
    if (ts == null) {
        log.userError("No transformation service available");
        return false;
    }
    final AtomicBoolean transformationFinished = new AtomicBoolean(false);
    final AtomicBoolean transformationCanceled = new AtomicBoolean(false);
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                Alignment alignment = getAlignmentService().getAlignment();
                if (alignment.getActiveTypeCells().isEmpty()) {
                    // early exit if there are no type relations
                    return;
                }
                // determine if there are any active type cells w/o source
                boolean transformEmpty = false;
                for (Cell cell : alignment.getActiveTypeCells()) {
                    if (cell.getSource() == null || cell.getSource().isEmpty()) {
                        transformEmpty = true;
                        break;
                    }
                }
                InstanceCollection sources = getInstances(DataSet.SOURCE);
                if (!transformEmpty && sources.isEmpty()) {
                    return;
                }
                HaleOrientInstanceSink sink = new HaleOrientInstanceSink(transformed, true);
                TransformationReport report;
                ATransaction trans = log.begin("Instance transformation");
                try {
                    report = ts.transform(alignment, sources, sink, HaleUI.getServiceProvider(), new ProgressMonitorIndicator(monitor));
                    // publish report
                    ReportService rs = PlatformUI.getWorkbench().getService(ReportService.class);
                    rs.addReport(report);
                } finally {
                    try {
                        sink.close();
                    } catch (IOException e) {
                    // ignore
                    }
                    trans.end();
                }
            } finally {
                // remember if canceled
                if (monitor.isCanceled()) {
                    transformationCanceled.set(true);
                }
                // transformation finished
                transformationFinished.set(true);
            }
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, ts.isCancelable());
    } catch (Throwable e) {
        log.error("Error starting transformation process", e);
    }
    // wait for transformation to complete
    HaleUI.waitFor(transformationFinished);
    return !transformationCanceled.get();
}
Also used : TransformationReport(eu.esdihumboldt.hale.common.align.transformation.report.TransformationReport) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) BrowseOrientInstanceCollection(eu.esdihumboldt.hale.common.instance.orient.storage.BrowseOrientInstanceCollection) FilteredInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.FilteredInstanceCollection) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) ATransaction(de.fhg.igd.slf4jplus.ATransaction) TransformationService(eu.esdihumboldt.hale.common.align.transformation.service.TransformationService) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 47 with InstanceCollection

use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.

the class HaleServiceFactory method create.

/**
 * @see AbstractServiceFactory#create(Class, IServiceLocator,
 *      IServiceLocator)
 */
@Override
public Object create(@SuppressWarnings("rawtypes") Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) {
    if (AlignmentService.class.equals(serviceInterface)) {
        return new AlignmentServiceUndoSupport(new AlignmentServiceImpl(locator.getService(ProjectService.class)));
    }
    if (CompatibilityService.class.equals(serviceInterface)) {
        return new CompatibilityServiceImpl();
    }
    if (EntityDefinitionService.class.equals(serviceInterface)) {
        return new EntityDefinitionServiceUndoSupport(new EntityDefinitionServiceImpl(locator.getService(AlignmentService.class), locator.getService(ProjectService.class)));
    }
    if (EntityResolver.class.equals(serviceInterface)) {
        return new UserFallbackEntityResolver();
    }
    if (FunctionService.class.equals(serviceInterface)) {
        return new HaleFunctionService(locator.getService(AlignmentService.class));
    }
    if (GeometrySchemaService.class.equals(serviceInterface)) {
        return new ProjectGeometrySchemaService(locator.getService(ProjectService.class));
    }
    if (GroovyService.class.equals(serviceInterface)) {
        return new PreferencesGroovyService(locator.getService(ProjectService.class), locator.getService(AlignmentService.class));
    }
    if (InstanceSampleService.class.equals(serviceInterface)) {
        return new InstanceSampleServiceImpl();
    }
    if (InstanceService.class.equals(serviceInterface)) {
        final InstanceService is = OrientInstanceService.getInstance(locator.getService(SchemaService.class), locator.getService(ProjectService.class), locator.getService(AlignmentService.class), locator.getService(GroovyService.class));
        // Add a listener to close all InstanceProcessors when source data
        // is cleared
        // XXX There may a better place to add this listener
        is.addListener(new InstanceServiceAdapter() {

            @Override
            public void datasetChanged(DataSet type) {
                if (type != DataSet.SOURCE) {
                    return;
                }
                InstanceCollection instances = is.getInstances(type);
                if (instances.isEmpty()) {
                    // data was cleared, close instance
                    // processors
                    final InstanceProcessingExtension ext = new InstanceProcessingExtension(HaleUI.getServiceProvider());
                    for (InstanceProcessor processor : ext.getInstanceProcessors()) {
                        try {
                            processor.close();
                        } catch (IOException e) {
                        // Ignore
                        }
                    }
                }
            }
        });
        return is;
    }
    if (InstanceValidationService.class.equals(serviceInterface))
        return new InstanceValidationServiceImpl(locator.getService(InstanceService.class), locator.getService(ReportService.class));
    if (InstanceViewService.class.equals(serviceInterface)) {
        return new InstanceViewServiceImpl(locator.getService(ProjectService.class));
    }
    if (OccurringValuesService.class.equals(serviceInterface)) {
        return new OccurringValuesServiceImpl(locator.getService(InstanceService.class), locator.getService(ProjectService.class));
    }
    if (PopulationService.class.equals(serviceInterface)) {
        return new PopulationServiceImpl(locator.getService(InstanceService.class));
    }
    if (ProjectService.class.equals(serviceInterface)) {
        return new ProjectServiceImpl();
    }
    if (ProjectInfoService.class.equals(serviceInterface)) {
        return locator.getService(ProjectService.class);
    }
    if (RecentProjectsService.class.equals(serviceInterface)) {
        return new RecentProjectsServiceImpl();
    }
    if (RecentResources.class.equals(serviceInterface)) {
        return new RecentResourcesService(locator.getService(ProjectService.class));
    }
    if (ReportService.class.equals(serviceInterface)) {
        return new ReportServiceImpl();
    }
    if (SchemaService.class.equals(serviceInterface)) {
        return new SchemaServiceImpl(locator.getService(ProjectService.class));
    }
    if (TaskService.class.equals(serviceInterface)) {
        return new TaskServiceImpl();
    }
    if (TransformationFunctionService.class.equals(serviceInterface)) {
        return new HaleTransformationFunctionService(locator.getService(AlignmentService.class));
    }
    if (TransformationSchemas.class.equals(serviceInterface)) {
        return locator.getService(SchemaService.class);
    }
    return null;
}
Also used : UserFallbackEntityResolver(eu.esdihumboldt.hale.ui.service.align.resolver.UserFallbackEntityResolver) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) TaskServiceImpl(eu.esdihumboldt.hale.ui.service.tasks.internal.TaskServiceImpl) CompatibilityServiceImpl(eu.esdihumboldt.hale.ui.compatibility.extension.impl.CompatibilityServiceImpl) EntityDefinitionServiceUndoSupport(eu.esdihumboldt.hale.ui.service.entity.internal.EntityDefinitionServiceUndoSupport) AlignmentServiceUndoSupport(eu.esdihumboldt.hale.ui.service.align.internal.AlignmentServiceUndoSupport) PreferencesGroovyService(eu.esdihumboldt.hale.ui.service.groovy.internal.PreferencesGroovyService) GroovyService(eu.esdihumboldt.util.groovy.sandbox.GroovyService) ProjectServiceImpl(eu.esdihumboldt.hale.ui.service.project.internal.ProjectServiceImpl) InstanceViewServiceImpl(eu.esdihumboldt.hale.ui.service.instance.sample.internal.InstanceViewServiceImpl) PopulationServiceImpl(eu.esdihumboldt.hale.ui.service.population.internal.PopulationServiceImpl) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) InstanceSampleServiceImpl(eu.esdihumboldt.hale.ui.service.instance.sample.internal.InstanceSampleServiceImpl) SchemaServiceImpl(eu.esdihumboldt.hale.ui.service.schema.internal.SchemaServiceImpl) InstanceProcessor(eu.esdihumboldt.hale.common.instance.processing.InstanceProcessor) RecentResourcesService(eu.esdihumboldt.hale.ui.service.project.internal.resources.RecentResourcesService) InstanceServiceAdapter(eu.esdihumboldt.hale.ui.service.instance.InstanceServiceAdapter) PreferencesGroovyService(eu.esdihumboldt.hale.ui.service.groovy.internal.PreferencesGroovyService) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) InstanceValidationServiceImpl(eu.esdihumboldt.hale.ui.service.instance.validation.internal.InstanceValidationServiceImpl) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) IOException(java.io.IOException) ReportServiceImpl(eu.esdihumboldt.hale.ui.service.report.internal.ReportServiceImpl) RecentProjectsServiceImpl(eu.esdihumboldt.hale.ui.service.project.internal.RecentProjectsServiceImpl) EntityDefinitionServiceImpl(eu.esdihumboldt.hale.ui.service.entity.internal.EntityDefinitionServiceImpl) InstanceProcessingExtension(eu.esdihumboldt.hale.common.instance.processing.InstanceProcessingExtension) AlignmentServiceImpl(eu.esdihumboldt.hale.ui.service.align.internal.AlignmentServiceImpl) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ProjectGeometrySchemaService(eu.esdihumboldt.hale.ui.service.geometry.ProjectGeometrySchemaService) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService) OrientInstanceService(eu.esdihumboldt.hale.ui.service.instance.internal.orient.OrientInstanceService) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) OccurringValuesServiceImpl(eu.esdihumboldt.hale.ui.service.values.internal.OccurringValuesServiceImpl) ProjectGeometrySchemaService(eu.esdihumboldt.hale.ui.service.geometry.ProjectGeometrySchemaService)

Example 48 with InstanceCollection

use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.

the class InstanceImportAdvisor method handleResults.

/**
 * @see IOAdvisor#handleResults(IOProvider)
 */
@Override
public void handleResults(InstanceReader provider) {
    // add instances to instance service
    InstanceService is = getService(InstanceService.class);
    InstanceCollection instances = provider.getInstances();
    ResourceIterator<Instance> it = instances.iterator();
    try {
        if (!it.hasNext()) {
            URI loc = provider.getSource().getLocation();
            if (loc != null) {
                log.warn(MessageFormat.format("No instances could be imported with the given configuration from {0}", loc.toString()));
            } else {
                log.warn("No instances could be imported with the given configuration.");
            }
        }
    } finally {
        it.close();
    }
    // apply sampling before adding to the instance service
    InstanceViewService ivs = PlatformUI.getWorkbench().getService(InstanceViewService.class);
    if (ivs != null) {
        instances = ivs.sample(instances);
    }
    is.addSourceInstances(instances);
    super.handleResults(provider);
}
Also used : InstanceViewService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceViewService) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) URI(java.net.URI)

Example 49 with InstanceCollection

use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.

the class AbstractInstancePainter method update.

/**
 * Do a complete update of the way-points. Existing way-points are
 * discarded.
 *
 * @param selection the current selection
 */
public void update(ISelection selection) {
    clearWaypoints();
    // XXX only mappable type instances for source?!
    InstanceCollection instances = instanceService.getInstances(dataSet);
    if (selection != null) {
        lastSelected = collectReferences(selection);
    }
    if (instances.isEmpty()) {
        return;
    }
    final AtomicBoolean updateFinished = new AtomicBoolean(false);
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            String taskName;
            switch(getDataSet()) {
                case SOURCE:
                    taskName = "Update source data in map";
                    break;
                case TRANSFORMED:
                default:
                    taskName = "Update transformed data in map";
                    break;
            }
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            // add way-points for instances
            InstanceCollection instances = instanceService.getInstances(dataSet);
            ResourceIterator<Instance> it = instances.iterator();
            try {
                while (it.hasNext()) {
                    Instance instance = it.next();
                    InstanceWaypoint wp = createWaypoint(instance, instanceService);
                    if (wp != null) {
                        if (lastSelected.contains(wp.getValue())) {
                            // refresh can be
                            wp.setSelected(true, null);
                        // ignored because
                        // it's done for
                        // addWaypoint
                        }
                        // no refresher, as
                        addWaypoint(wp, null);
                    // refreshAll is executed
                    }
                }
            } finally {
                it.close();
                monitor.done();
                updateFinished.set(true);
            }
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, false);
    } catch (Throwable e) {
        log.error("Error running painter update", e);
    }
    HaleUI.waitFor(updateFinished);
    refreshAll();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 50 with InstanceCollection

use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.

the class XsltTransformationTest method transformData.

@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
    // export alignment to XSLT
    XsltExport export = new XsltExport();
    export.setAlignment(example.getAlignment());
    export.setSourceSchema(new DefaultSchemaSpace().addSchema(example.getSourceSchema()));
    export.setTargetSchema(new DefaultSchemaSpace().addSchema(example.getTargetSchema()));
    export.setParameter(XsltExport.PARAM_ROOT_ELEMENT_NAMESPACE, Value.of(example.getTargetContainerNamespace()));
    export.setParameter(XsltExport.PARAM_ROOT_ELEMENT_NAME, Value.of(example.getTargetContainerName()));
    File tempXsltFile = File.createTempFile("xsltest", ".xsl");
    export.setTarget(new FileIOSupplier(tempXsltFile));
    IOReport res = export.execute(new LogProgressIndicator());
    assertTrue("XSLT export not successful", res.isSuccess());
    assertTrue("Errors during XSLT export", res.getErrors().isEmpty());
    // invoke XSLT on source file to produce target
    File target = File.createTempFile("xsltest", ".xml");
    executeXslt(example.getSourceDataInput(), tempXsltFile, target);
    // load target and return instances
    InstanceCollection instances = TestUtil.loadInstances(target.toURI(), example.getTargetSchema());
    List<Instance> list = new ArrayList<Instance>();
    ResourceIterator<Instance> it = instances.iterator();
    try {
        while (it.hasNext()) {
            list.add(it.next());
        }
    } finally {
        it.close();
    }
    // clean up
    tempXsltFile.delete();
    target.delete();
    return list;
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) ArrayList(java.util.ArrayList) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) File(java.io.File)

Aggregations

InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)151 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)131 Test (org.junit.Test)116 AbstractHandlerTest (eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)97 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)17 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)17 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)11 ArrayList (java.util.ArrayList)10 Geometry (com.vividsolutions.jts.geom.Geometry)9 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)9 IOException (java.io.IOException)9 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)8 Polygon (com.vividsolutions.jts.geom.Polygon)8 QName (javax.xml.namespace.QName)8 Coordinate (com.vividsolutions.jts.geom.Coordinate)7 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)7 DefaultInstanceCollection (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)6 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)6 TypeFilter (eu.esdihumboldt.hale.common.instance.model.TypeFilter)6