use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class XPathPropertyDefinitionDialog method getInputDefinition.
private static TypeDefinition getInputDefinition(EntityDefinition entityDef) {
if (entityDef.getPropertyPath() == null || entityDef.getPropertyPath().isEmpty()) {
// types?
return entityDef.getType();
} else {
PropertyDefinition def = (PropertyDefinition) entityDef.getDefinition();
// create a dummy type for the input
TypeDefinition dummyType = new DefaultTypeDefinition(new QName("ValueFilterDummy"));
TypeDefinition emptyType = new DefaultTypeDefinition(new QName("EmptyDummy"));
// with .. as parent link
new DefaultPropertyDefinition(PARENT_NAME, dummyType, emptyType);
// and the value property added as itself
dummyType.addChild(def);
return dummyType;
}
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class XLSSchemaReader method loadFromSource.
@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
sheetNum = getParameter(InstanceTableIOConstants.SHEET_INDEX).as(int.class, 0);
progress.begin("Load XLS/XLSX schema", ProgressIndicator.UNKNOWN);
String namespace = "http://www.esdi-humboldt.eu/hale/xls";
DefaultSchema schema = new DefaultSchema(namespace, getSource().getLocation());
AnalyseXLSSchemaTable analyser;
try {
analyser = new AnalyseXLSSchemaTable(getSource().getLocation(), sheetNum);
header = analyser.getHeader();
// create type definition
String typename = getParameter(CommonSchemaConstants.PARAM_TYPENAME).as(String.class);
if (typename == null || typename.isEmpty()) {
reporter.setSuccess(false);
reporter.error(new IOMessageImpl("No Typename was set", null));
return null;
}
DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(typename));
// constraints on main type
type.setConstraint(MappingRelevantFlag.ENABLED);
type.setConstraint(MappableFlag.ENABLED);
type.setConstraint(HasValueFlag.DISABLED);
type.setConstraint(AbstractFlag.DISABLED);
// set metadata for main type
type.setLocation(getSource().getLocation());
StringBuffer defaultPropertyTypeBuffer = new StringBuffer();
String[] comboSelections;
if (getParameter(PARAM_PROPERTYTYPE).isEmpty()) {
for (int i = 0; i < header.size(); i++) {
defaultPropertyTypeBuffer.append("java.lang.String");
defaultPropertyTypeBuffer.append(",");
}
defaultPropertyTypeBuffer.deleteCharAt(defaultPropertyTypeBuffer.lastIndexOf(","));
String combs = defaultPropertyTypeBuffer.toString();
comboSelections = combs.split(",");
} else {
comboSelections = getParameter(PARAM_PROPERTYTYPE).as(String.class).split(",");
}
String[] properties;
if (getParameter(PARAM_PROPERTY).isEmpty()) {
properties = header.toArray(new String[0]);
} else {
properties = getParameter(PARAM_PROPERTY).as(String.class).split(",");
}
// than the entries in the first line
if ((header.size() != properties.length && properties.length != 0) || (header.size() != comboSelections.length && comboSelections.length != 0)) {
fail("Not the same number of entries for property names, property types and words in the first line of the file");
}
for (int i = 0; i < comboSelections.length; i++) {
PropertyType propertyType = PropertyTypeExtension.getInstance().getFactory(comboSelections[i]).createExtensionObject();
DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(properties[i]), type, propertyType.getTypeDefinition());
configureProperty(property);
}
boolean skipFirst = Arrays.equals(properties, header.toArray(new String[0]));
type.setConstraint(new CSVConfiguration(CSVUtil.getSep(this), CSVUtil.getQuote(this), CSVUtil.getEscape(this), skipFirst ? 1 : 0));
schema.addType(type);
} catch (Exception e) {
reporter.error(new IOMessageImpl("Cannot load xls/xlsx schema", e));
reporter.setSuccess(false);
return null;
}
reporter.setSuccess(true);
return schema;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class FilterTest method simpleFilterTestCQL.
@Test
public void simpleFilterTestCQL() throws CQLException {
DefaultTypeDefinition stringType = new DefaultTypeDefinition(new QName("StringType"));
stringType.setConstraint(Binding.get(String.class));
DefaultTypeDefinition personDef = new DefaultTypeDefinition(new QName("PersonType"));
personDef.addChild(new DefaultPropertyDefinition(new QName("Name"), personDef, stringType));
DefaultTypeDefinition autoDef = new DefaultTypeDefinition(new QName("AutoType"));
autoDef.addChild(new DefaultPropertyDefinition(new QName("Name"), autoDef, stringType));
autoDef.addChild(new DefaultPropertyDefinition(new QName("Besitzer"), autoDef, personDef));
MutableInstance auto = new DefaultInstance(autoDef, null);
auto.addProperty(new QName("Name"), "Mein Porsche");
MutableInstance ich = new DefaultInstance(personDef, null);
ich.addProperty(new QName("Name"), "Ich");
auto.addProperty(new QName("Besitzer"), ich);
Filter filter;
filter = new FilterGeoCqlImpl("Name = 'Mein Porsche'");
assertTrue(filter.match(auto));
Filter filter1 = new FilterGeoCqlImpl("Name like 'Porsche'");
assertFalse(filter1.match(auto));
Filter filter2 = new FilterGeoCqlImpl("Name like '%Porsche'");
assertTrue(filter2.match(auto));
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class ShapeSchemaReader method getTypeFromAttributeType.
/**
* Create a type definition for a simple attribute type
*
* @param type the attribute type
* @param schema the schema
* @param namespace the namespace to use for the type definition
* @return the type definition
*/
private TypeDefinition getTypeFromAttributeType(AttributeType type, DefaultSchema schema, String namespace) {
QName typeName = new QName(namespace, type.getName().getLocalPart());
TypeDefinition result = null;
// check shared types
if (getSharedTypes() != null) {
result = getSharedTypes().getType(typeName);
}
if (result == null) {
// get type from schema
result = schema.getType(typeName);
}
if (result == null) {
// create new type
DefaultTypeDefinition typeDef = new DefaultTypeDefinition(typeName);
// set constraints
// not mappable
typeDef.setConstraint(MappingRelevantFlag.DISABLED);
typeDef.setConstraint(MappableFlag.DISABLED);
// binding
if (Geometry.class.isAssignableFrom(type.getBinding())) {
// create geometry binding
typeDef.setConstraint(Binding.get(GeometryProperty.class));
} else {
typeDef.setConstraint(Binding.get(type.getBinding()));
}
// simple type
typeDef.setConstraint(HasValueFlag.ENABLED);
// set metadata
typeDef.setLocation(getSource().getLocation());
if (type.getDescription() != null) {
typeDef.setDescription(type.getDescription().toString());
}
result = typeDef;
schema.addType(result);
}
return result;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition in project hale by halestudio.
the class ShapeSchemaReader method loadFromSource.
@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
// $NON-NLS-1$
progress.begin(Messages.getString("ShapeSchemaProvider.1"), ProgressIndicator.UNKNOWN);
// DataStore store = new ShapefileDataStoreFactory().createDataStore(location.toURL());
// DataStore store = FileDataStoreFinder.getDataStore(getSource().getLocation().toURL());
ShapefileDataStore store = new ShapefileDataStore(getSource().getLocation().toURL());
store.setCharset(getCharset());
// TODO namespace from configuration parameter?!
String namespace = ShapefileConstants.SHAPEFILE_NS;
DefaultSchema schema = new DefaultSchema(namespace, getSource().getLocation());
// $NON-NLS-1$
progress.setCurrentTask(Messages.getString("ShapeSchemaProvider.2"));
// create type for augmented filename property
TypeDefinition filenameType = null;
if (isAddFilenameAttribute()) {
QName filenameTypeName = new QName(SHAPEFILE_AUGMENT_NS, "filenameType");
if (getSharedTypes() != null) {
filenameType = getSharedTypes().getType(filenameTypeName);
}
if (filenameType == null) {
DefaultTypeDefinition fnt = new DefaultTypeDefinition(filenameTypeName);
fnt.setConstraint(MappableFlag.DISABLED);
fnt.setConstraint(MappingRelevantFlag.DISABLED);
fnt.setConstraint(Binding.get(String.class));
fnt.setConstraint(HasValueFlag.ENABLED);
filenameType = fnt;
}
}
// build type definitions based on Schema extracted by geotools
for (Name name : store.getNames()) {
SimpleFeatureType sft = store.getSchema(name);
try {
// create type definition
DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(namespace, sft.getName().getLocalPart()));
// constraints on main type
type.setConstraint(MappingRelevantFlag.ENABLED);
type.setConstraint(MappableFlag.ENABLED);
type.setConstraint(HasValueFlag.DISABLED);
type.setConstraint(AbstractFlag.DISABLED);
type.setConstraint(Binding.get(Instance.class));
for (AttributeDescriptor ad : sft.getAttributeDescriptors()) {
DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(ad.getLocalName()), type, getTypeFromAttributeType(ad.getType(), schema, namespace));
// set constraints on property
// nillable
property.setConstraint(NillableFlag.get(ad.isNillable()));
// cardinality
property.setConstraint(Cardinality.get(ad.getMinOccurs(), ad.getMaxOccurs()));
// set metadata
property.setLocation(getSource().getLocation());
}
// add additional filename property
if (filenameType != null) {
// String filename = sft.getName().getLocalPart();
DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(SHAPEFILE_AUGMENT_NS, AUGMENTED_PROPERTY_FILENAME), type, filenameType);
property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
property.setConstraint(NillableFlag.ENABLED);
}
schema.addType(type);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
progress.setCurrentTask(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("ShapeSchemaProvider.7"), sft.getTypeName()));
}
reporter.setSuccess(true);
return schema;
}
Aggregations