Search in sources :

Example 1 with Schema

use of eu.esdihumboldt.hale.common.schema.model.Schema in project hale by halestudio.

the class ResourceSchemaSpace method removeSchema.

/**
 * Removes a schema.
 *
 * @param resourceId resource id of the schema.
 *
 * @return returns the schema to which this map previously associated the
 *         key, or null if the map contained no mapping for the key.
 */
public Schema removeSchema(String resourceId) {
    Schema removed = schemasMap.remove(resourceId);
    // re-initialize.
    allTypes = null;
    getTypes();
    mappingRelevantTypes = null;
    getMappingRelevantTypes();
    return removed;
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema)

Example 2 with Schema

use of eu.esdihumboldt.hale.common.schema.model.Schema in project hale by halestudio.

the class ResourceSchemaSpace method toggleMappingRelevant.

/**
 * @see eu.esdihumboldt.hale.common.schema.model.TypeIndex#toggleMappingRelevant(java.util.Collection)
 */
@Override
public void toggleMappingRelevant(Collection<? extends TypeDefinition> types) {
    synchronized (this) {
        for (TypeDefinition type : types) {
            Schema container = null;
            for (Schema schema : schemasMap.values()) if (schema.getTypes().contains(type)) {
                container = schema;
                break;
            }
            // toggle type in its schema
            if (container != null)
                container.toggleMappingRelevant(Collections.singletonList(type));
            else {
                // shouldn't happen, but to be safe toggle it in this case
                // too
                Definition<TypeConstraint> def = type;
                ((AbstractDefinition<TypeConstraint>) def).setConstraint(MappingRelevantFlag.get(!type.getConstraint(MappingRelevantFlag.class).isEnabled()));
            }
            // was toggled, update own list
            if (mappingRelevantTypes != null)
                if (type.getConstraint(MappingRelevantFlag.class).isEnabled())
                    mappingRelevantTypes.add(type);
                else
                    mappingRelevantTypes.remove(type);
        }
    }
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 3 with Schema

use of eu.esdihumboldt.hale.common.schema.model.Schema in project hale by halestudio.

the class DefaultSchemaSpace method toggleMappingRelevant.

/**
 * @see eu.esdihumboldt.hale.common.schema.model.TypeIndex#toggleMappingRelevant(java.util.Collection)
 */
@Override
public void toggleMappingRelevant(Collection<? extends TypeDefinition> types) {
    synchronized (this) {
        for (TypeDefinition type : types) {
            Schema container = null;
            for (Schema schema : schemas) if (schema.getTypes().contains(type)) {
                container = schema;
                break;
            }
            // toggle type in its schema
            if (container != null)
                container.toggleMappingRelevant(Collections.singletonList(type));
            else {
                // shouldn't happen, but to be safe toggle it in this case
                // too
                Definition<TypeConstraint> def = type;
                ((AbstractDefinition<TypeConstraint>) def).setConstraint(MappingRelevantFlag.get(!type.getConstraint(MappingRelevantFlag.class).isEnabled()));
            }
            // was toggled, update own list
            if (mappingRelevantTypes != null)
                if (type.getConstraint(MappingRelevantFlag.class).isEnabled())
                    mappingRelevantTypes.add(type);
                else
                    mappingRelevantTypes.remove(type);
        }
    }
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 4 with Schema

use of eu.esdihumboldt.hale.common.schema.model.Schema in project hale by halestudio.

the class SpatiaLiteTestSuite method schemaReaderTest.

/**
 * Test - reads a sample SpatiaLite schema
 *
 * @throws Exception if an error occurs
 */
public void schemaReaderTest() throws Exception {
    if (!isSpatiaLiteExtensionAvailable()) {
        log.info("Skipping test because SpatiaLite extension is not available");
        return;
    }
    Set<String> propertyNames = new HashSet<String>(Arrays.asList(SOUURCE_TYPE_PROPERTY_NAMES));
    SpatiaLiteSchemaReader schemaReader = new SpatiaLiteSchemaReader();
    schemaReader.setSource(new FileIOSupplier(new File(getSourceTempFilePath())));
    IOReport report = schemaReader.execute(new LogProgressIndicator());
    assertTrue(report.isSuccess());
    Schema schema = schemaReader.getSchema();
    assertEquals(1, schema.getMappingRelevantTypes().size());
    TypeDefinition type = schema.getMappingRelevantTypes().iterator().next();
    checkType(type, SOUURCE_TYPE_LOCAL_NAME, propertyNames);
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) SpatiaLiteSchemaReader(eu.esdihumboldt.hale.io.jdbc.spatialite.reader.internal.SpatiaLiteSchemaReader) 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) HashSet(java.util.HashSet) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 5 with Schema

use of eu.esdihumboldt.hale.common.schema.model.Schema in project hale by halestudio.

the class SpatiaLiteTestSuite method instanceWriterTest.

/**
 * Test - reads data from a source SpatiaLite database, writes them to a
 * target SpatiaLite database and checks the results.
 *
 * @throws Exception if an error occurs
 */
public void instanceWriterTest() throws Exception {
    if (!isSpatiaLiteExtensionAvailable()) {
        log.info("Skipping test because SpatiaLite extension is not available");
        return;
    }
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    for (int i = 0; i < SOUURCE_TYPE_PROPERTY_NAMES.length; i++) {
        String key = SOUURCE_TYPE_PROPERTY_NAMES[i];
        Object value = SOUURCE_TYPE_PROPERTY_VALUES[i];
        propertyMap.put(key, value);
    }
    // ****** read Schema ******//
    Schema schema = readSchema(getSourceTempFilePath());
    assertNotNull(schema);
    assertEquals(1, schema.getMappingRelevantTypes().size());
    // Test properties
    TypeDefinition schemaType = schema.getMappingRelevantTypes().iterator().next();
    // Check every property for their existence
    checkType(schemaType, SOUURCE_TYPE_LOCAL_NAME, propertyMap.keySet());
    // ****** read Instances ******//
    InstanceCollection instances = readInstances(schema, getSourceTempFilePath());
    assertTrue(instances.hasSize());
    assertEquals(SOURCE_INSTANCES_COUNT, instances.size());
    checkInstances(instances, propertyMap);
    // ****** write Instances ******//
    // check target DB is empty
    InstanceCollection targetInstances = readInstances(schema, getTargetTempFilePath());
    assertTrue(targetInstances.hasSize());
    assertEquals(0, targetInstances.size());
    writeInstances(schema, getTargetTempFilePath(), instances);
    // re-read instances to check they were written correctly
    targetInstances = readInstances(schema, getTargetTempFilePath());
    assertTrue(targetInstances.hasSize());
    assertEquals(SOURCE_INSTANCES_COUNT, targetInstances.size());
    checkInstances(targetInstances, propertyMap);
}
Also used : HashMap(java.util.HashMap) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

Schema (eu.esdihumboldt.hale.common.schema.model.Schema)60 Test (org.junit.Test)25 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)22 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)22 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)19 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)15 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)13 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)9 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)8 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)8 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)8 IOException (java.io.IOException)8 GmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)6 File (java.io.File)6 NoStreamInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)4 ShapeSchemaReader (eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader)4 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)3 Type (eu.esdihumboldt.hale.common.align.model.Type)3 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)3 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)3