Search in sources :

Example 6 with DefaultTypeDefinition

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;
    }
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)

Example 7 with DefaultTypeDefinition

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;
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) AnalyseXLSSchemaTable(eu.esdihumboldt.hale.io.xls.AnalyseXLSSchemaTable) QName(javax.xml.namespace.QName) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) PropertyType(eu.esdihumboldt.hale.io.csv.PropertyType) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) CSVConfiguration(eu.esdihumboldt.hale.io.csv.reader.internal.CSVConfiguration) DefaultSchema(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)

Example 8 with DefaultTypeDefinition

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));
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) QName(javax.xml.namespace.QName) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Test(org.junit.Test)

Example 9 with DefaultTypeDefinition

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;
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) QName(javax.xml.namespace.QName) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 10 with DefaultTypeDefinition

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;
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Name(org.opengis.feature.type.Name) QName(javax.xml.namespace.QName) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DefaultSchema(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)

Aggregations

DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)28 QName (javax.xml.namespace.QName)23 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)18 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)7 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)5 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)4 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 DefaultGroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition)4 DefaultSchema (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)3 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)3 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)3 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)2