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;
}
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);
}
}
}
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);
}
}
}
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);
}
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);
}
Aggregations