Search in sources :

Example 1 with NullProgressIndicator

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

the class ReprojectGeometryTest method transformData.

@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
    ConceptualSchemaTransformer transformer = new ConceptualSchemaTransformer();
    DefaultInstanceSink sink = new DefaultInstanceSink();
    final Map<Class<?>, Object> customServices = new HashMap<>();
    customServices.put(FunctionService.class, new AlignmentFunctionService(example.getAlignment()));
    customServices.put(TransformationFunctionService.class, new AlignmentTransformationFunctionService(example.getAlignment()));
    final ServiceProvider serviceProvider = new ServiceProvider() {

        private final ServiceProvider projectScope = new ServiceManager(ServiceManager.SCOPE_PROJECT);

        @SuppressWarnings("unchecked")
        @Override
        public <T> T getService(Class<T> serviceInterface) {
            if (customServices.containsKey(serviceInterface)) {
                return (T) customServices.get(serviceInterface);
            }
            // FIXME global scope not supported yet
            return projectScope.getService(serviceInterface);
        }
    };
    transformer.transform(example.getAlignment(), example.getSourceInstances(), sink, serviceProvider, new NullProgressIndicator());
    return sink.getInstances();
}
Also used : AlignmentTransformationFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentTransformationFunctionService) ConceptualSchemaTransformer(eu.esdihumboldt.cst.ConceptualSchemaTransformer) HashMap(java.util.HashMap) ServiceManager(eu.esdihumboldt.hale.common.core.service.ServiceManager) DefaultInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.DefaultInstanceSink) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator) AlignmentFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService)

Example 2 with NullProgressIndicator

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

the class GenerateDefaults method loadSchema.

private void loadSchema() throws IOProviderConfigurationException, IOException {
    System.out.println("Loading schema...");
    LocatableInputSupplier<? extends InputStream> schemaIn = new DefaultInputSupplier(context.getSchema());
    SchemaReader schemaReader = HaleIO.findIOProvider(SchemaReader.class, schemaIn, context.getSchema().getPath());
    schemaReader.setSource(schemaIn);
    IOReport report = schemaReader.execute(new NullProgressIndicator());
    if (!report.isSuccess() || !report.getErrors().isEmpty()) {
        throw new IllegalStateException("Failed to load schema");
    }
    schema = schemaReader.getSchema();
    resourceId = schemaReader.getResourceIdentifier();
}
Also used : SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator)

Example 3 with NullProgressIndicator

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

the class GenerateDefaults method writeAlignment.

private void writeAlignment() throws Exception {
    System.out.println("Writing alignment to " + context.getOut().getAbsolutePath());
    // create alignment writer
    IContentType contentType = HalePlatform.getContentTypeManager().getContentType(ALIGNMENT_CONTENT_TYPE);
    IOProviderDescriptor factory = HaleIO.findIOProviderFactory(AlignmentWriter.class, contentType, null);
    AlignmentWriter writer = (AlignmentWriter) factory.createExtensionObject();
    // configure alignment writer
    writer.setTargetSchema(new ResourceSchemaSpace().addSchema(resourceId, schema));
    writer.setTarget(new FileIOSupplier(context.getOut()));
    writer.setAlignment(alignment);
    IOReport report = writer.execute(new NullProgressIndicator());
    if (!report.isSuccess() || !report.getErrors().isEmpty()) {
        throw new IllegalStateException("Errors while writing the alignment.");
    } else {
        System.out.println("Completed successfully.");
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) ResourceSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.ResourceSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator) IContentType(org.eclipse.core.runtime.content.IContentType) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) AlignmentWriter(eu.esdihumboldt.hale.common.align.io.AlignmentWriter)

Example 4 with NullProgressIndicator

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

the class ConceptualSchemaTransformerTest method transformData.

@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
    ConceptualSchemaTransformer transformer = new ConceptualSchemaTransformer();
    ThreadSafeInstanceSink<DefaultInstanceSink> sink = new ThreadSafeInstanceSink<>(new DefaultInstanceSink());
    final Map<Class<?>, Object> customServices = new HashMap<>();
    customServices.put(FunctionService.class, new AlignmentFunctionService(example.getAlignment()));
    customServices.put(TransformationFunctionService.class, new AlignmentTransformationFunctionService(example.getAlignment()));
    InstanceIndexServiceImpl indexService = new InstanceIndexServiceImpl();
    customServices.put(InstanceIndexService.class, indexService);
    final ServiceProvider serviceProvider = new ServiceProvider() {

        private final ServiceProvider projectScope = new ServiceManager(ServiceManager.SCOPE_PROJECT);

        @SuppressWarnings("unchecked")
        @Override
        public <T> T getService(Class<T> serviceInterface) {
            if (customServices.containsKey(serviceInterface)) {
                return (T) customServices.get(serviceInterface);
            }
            // FIXME global scope not supported yet
            return projectScope.getService(serviceInterface);
        }
    };
    indexService.addPropertyMappings(example.getAlignment().getActiveTypeCells(), serviceProvider);
    InstanceCollection source = example.getSourceInstances();
    try (ResourceIterator<Instance> it = source.iterator()) {
        while (it.hasNext()) {
            indexService.add(it.next(), source);
        }
    }
    transformer.transform(example.getAlignment(), source, sink, serviceProvider, new NullProgressIndicator());
    return sink.getDecoratee().getInstances();
}
Also used : AlignmentTransformationFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentTransformationFunctionService) HashMap(java.util.HashMap) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.DefaultInstanceSink) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator) AlignmentFunctionService(eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService) InstanceIndexServiceImpl(eu.esdihumboldt.hale.common.instance.index.InstanceIndexServiceImpl) ConceptualSchemaTransformer(eu.esdihumboldt.cst.ConceptualSchemaTransformer) ServiceManager(eu.esdihumboldt.hale.common.core.service.ServiceManager) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) ThreadSafeInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.ThreadSafeInstanceSink)

Example 5 with NullProgressIndicator

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

the class GenerateDuplicates method writeAlignment.

private void writeAlignment() throws Exception {
    System.out.println("Writing alignment to " + context.getOut().getAbsolutePath());
    // create alignment writer
    IContentType contentType = HalePlatform.getContentTypeManager().getContentType(ALIGNMENT_CONTENT_TYPE);
    IOProviderDescriptor factory = HaleIO.findIOProviderFactory(AlignmentWriter.class, contentType, null);
    AlignmentWriter writer = (AlignmentWriter) factory.createExtensionObject();
    // configure alignment writer
    writer.setSourceSchema(sourceSchema);
    writer.setTargetSchema(targetSchema);
    writer.setTarget(new FileIOSupplier(context.getOut()));
    writer.setAlignment(alignment);
    IOReport report = writer.execute(new NullProgressIndicator());
    if (!report.isSuccess() || !report.getErrors().isEmpty()) {
        throw new IllegalStateException("Errors while writing the alignment.");
    } else {
        System.out.println("Completed successfully.");
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator) IContentType(org.eclipse.core.runtime.content.IContentType) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) AlignmentWriter(eu.esdihumboldt.hale.common.align.io.AlignmentWriter)

Aggregations

NullProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator)7 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)5 AlignmentWriter (eu.esdihumboldt.hale.common.align.io.AlignmentWriter)3 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)3 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)3 IContentType (org.eclipse.core.runtime.content.IContentType)3 ConceptualSchemaTransformer (eu.esdihumboldt.cst.ConceptualSchemaTransformer)2 AlignmentFunctionService (eu.esdihumboldt.hale.common.align.service.impl.AlignmentFunctionService)2 AlignmentTransformationFunctionService (eu.esdihumboldt.hale.common.align.service.impl.AlignmentTransformationFunctionService)2 DefaultInstanceSink (eu.esdihumboldt.hale.common.align.transformation.service.impl.DefaultInstanceSink)2 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)2 ServiceManager (eu.esdihumboldt.hale.common.core.service.ServiceManager)2 ServiceProvider (eu.esdihumboldt.hale.common.core.service.ServiceProvider)2 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)2 HashMap (java.util.HashMap)2 ThreadSafeInstanceSink (eu.esdihumboldt.hale.common.align.transformation.service.impl.ThreadSafeInstanceSink)1 InstanceIndexServiceImpl (eu.esdihumboldt.hale.common.instance.index.InstanceIndexServiceImpl)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)1 ResourceSchemaSpace (eu.esdihumboldt.hale.common.schema.model.impl.ResourceSchemaSpace)1