Search in sources :

Example 1 with NameImpl

use of org.geotools.feature.NameImpl in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    factory = new FilterFactoryImpl();
    attrExpr = factory.property(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, UNMAPPED_PROPERTY, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    created = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, Core.CREATED, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    metacardType = CswQueryFactoryTest.getCswMetacardType();
    mockMetacardTypeList = new ArrayList<>();
    mockMetacardTypeList.add(metacardType);
    visitor = new CswRecordMapperFilterVisitor(metacardType, mockMetacardTypeList);
}
Also used : NameImpl(org.geotools.feature.NameImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) QName(javax.xml.namespace.QName) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) BeforeClass(org.junit.BeforeClass)

Example 2 with NameImpl

use of org.geotools.feature.NameImpl in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method testVisitPropertyIsGreaterThanTemporal.

@Test
public void testVisitPropertyIsGreaterThanTemporal() {
    Expression val = factory.literal(new Date(System.currentTimeMillis() - 1000));
    Expression test = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, "TestDate", CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    PropertyIsGreaterThan filter = factory.greater(test, val);
    Object obj = visitor.visit(filter, null);
    assertThat(obj, instanceOf(During.class));
    During duplicate = (During) obj;
    assertThat(duplicate.getExpression1(), is(test));
    assertThat(duplicate.getExpression2(), is(val));
}
Also used : NameImpl(org.geotools.feature.NameImpl) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) QName(javax.xml.namespace.QName) Date(java.util.Date) During(org.opengis.filter.temporal.During) PropertyIsGreaterThan(org.opengis.filter.PropertyIsGreaterThan) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 3 with NameImpl

use of org.geotools.feature.NameImpl in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method testVisitWithMappedName.

@Test
public void testVisitWithMappedName() {
    AttributeExpressionImpl propName = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, CswConstants.CSW_ALTERNATIVE, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    CswRecordMapperFilterVisitor visitor = new CswRecordMapperFilterVisitor(metacardType, mockMetacardTypeList);
    PropertyName propertyName = (PropertyName) visitor.visit(propName, null);
    assertThat(propertyName.getPropertyName(), is(Core.TITLE));
    assertThat(propertyName.getPropertyName(), not(is(CswConstants.CSW_ALTERNATIVE)));
}
Also used : NameImpl(org.geotools.feature.NameImpl) PropertyName(org.opengis.filter.expression.PropertyName) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) QName(javax.xml.namespace.QName) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 4 with NameImpl

use of org.geotools.feature.NameImpl in project GeoGig by boundlessgeo.

the class SQLServerExport method runInternal.

/**
     * Executes the export command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    if (args.isEmpty()) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    String path = args.get(0);
    String tableName = args.get(1);
    checkParameter(tableName != null && !tableName.isEmpty(), "No table name specified");
    DataStore dataStore = getDataStore();
    ObjectId featureTypeId = null;
    if (!Arrays.asList(dataStore.getTypeNames()).contains(tableName)) {
        SimpleFeatureType outputFeatureType;
        if (sFeatureTypeId != null) {
            // Check the feature type id string is a correct id
            Optional<ObjectId> id = cli.getGeogig().command(RevParse.class).setRefSpec(sFeatureTypeId).call();
            checkParameter(id.isPresent(), "Invalid feature type reference", sFeatureTypeId);
            TYPE type = cli.getGeogig().command(ResolveObjectType.class).setObjectId(id.get()).call();
            checkParameter(type.equals(TYPE.FEATURETYPE), "Provided reference does not resolve to a feature type: ", sFeatureTypeId);
            outputFeatureType = (SimpleFeatureType) cli.getGeogig().command(RevObjectParse.class).setObjectId(id.get()).call(RevFeatureType.class).get().type();
            featureTypeId = id.get();
        } else {
            try {
                SimpleFeatureType sft = getFeatureType(path, cli);
                outputFeatureType = new SimpleFeatureTypeImpl(new NameImpl(tableName), sft.getAttributeDescriptors(), sft.getGeometryDescriptor(), sft.isAbstract(), sft.getRestrictions(), sft.getSuper(), sft.getDescription());
            } catch (GeoToolsOpException e) {
                throw new CommandFailedException("No features to export.", e);
            }
        }
        try {
            dataStore.createSchema(outputFeatureType);
        } catch (IOException e) {
            throw new CommandFailedException("Cannot create new table in database", e);
        }
    } else {
        if (!overwrite) {
            throw new CommandFailedException("The selected table already exists. Use -o to overwrite");
        }
    }
    SimpleFeatureSource featureSource = dataStore.getFeatureSource(tableName);
    if (!(featureSource instanceof SimpleFeatureStore)) {
        throw new CommandFailedException("Can't write to the selected table");
    }
    SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
    if (overwrite) {
        try {
            featureStore.removeFeatures(Filter.INCLUDE);
        } catch (IOException e) {
            throw new CommandFailedException("Error accessing table: " + e.getMessage(), e);
        }
    }
    ExportOp op = cli.getGeogig().command(ExportOp.class).setFeatureStore(featureStore).setPath(path).setFilterFeatureTypeId(featureTypeId).setAlter(alter);
    if (defaultType) {
        op.exportDefaultFeatureType();
    }
    try {
        op.setProgressListener(cli.getProgressListener()).call();
    } catch (IllegalArgumentException iae) {
        throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
    } catch (GeoToolsOpException e) {
        switch(e.statusCode) {
            case MIXED_FEATURE_TYPES:
                throw new CommandFailedException("The selected tree contains mixed feature types. Use --defaulttype or --featuretype <feature_type_ref> to export.", e);
            default:
                throw new CommandFailedException("Could not export. Error:" + e.statusCode.name(), e);
        }
    }
    cli.getConsole().println(path + " exported successfully to " + tableName);
}
Also used : NameImpl(org.geotools.feature.NameImpl) ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) IOException(java.io.IOException) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) SimpleFeatureTypeImpl(org.geotools.feature.simple.SimpleFeatureTypeImpl) GeoToolsOpException(org.locationtech.geogig.geotools.plumbing.GeoToolsOpException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DataStore(org.geotools.data.DataStore) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) ExportOp(org.locationtech.geogig.geotools.plumbing.ExportOp) TYPE(org.locationtech.geogig.api.RevObject.TYPE)

Example 5 with NameImpl

use of org.geotools.feature.NameImpl in project GeoGig by boundlessgeo.

the class PGExport method runInternal.

/**
     * Executes the export command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    if (args.isEmpty()) {
        printUsage(cli);
        throw new CommandFailedException();
    }
    String path = args.get(0);
    String tableName = args.get(1);
    checkParameter(tableName != null && !tableName.isEmpty(), "No table name specified");
    DataStore dataStore = getDataStore();
    ObjectId featureTypeId = null;
    if (!Arrays.asList(dataStore.getTypeNames()).contains(tableName)) {
        SimpleFeatureType outputFeatureType;
        if (sFeatureTypeId != null) {
            // Check the feature type id string is a correct id
            Optional<ObjectId> id = cli.getGeogig().command(RevParse.class).setRefSpec(sFeatureTypeId).call();
            checkParameter(id.isPresent(), "Invalid feature type reference", sFeatureTypeId);
            TYPE type = cli.getGeogig().command(ResolveObjectType.class).setObjectId(id.get()).call();
            checkParameter(type.equals(TYPE.FEATURETYPE), "Provided reference does not resolve to a feature type: ", sFeatureTypeId);
            outputFeatureType = (SimpleFeatureType) cli.getGeogig().command(RevObjectParse.class).setObjectId(id.get()).call(RevFeatureType.class).get().type();
            featureTypeId = id.get();
        } else {
            try {
                SimpleFeatureType sft = getFeatureType(path, cli);
                outputFeatureType = new SimpleFeatureTypeImpl(new NameImpl(tableName), sft.getAttributeDescriptors(), sft.getGeometryDescriptor(), sft.isAbstract(), sft.getRestrictions(), sft.getSuper(), sft.getDescription());
            } catch (GeoToolsOpException e) {
                throw new CommandFailedException("No features to export.", e);
            }
        }
        try {
            dataStore.createSchema(outputFeatureType);
        } catch (IOException e) {
            throw new CommandFailedException("Cannot create new table in database", e);
        }
    } else {
        if (!overwrite) {
            throw new InvalidParameterException("The selected table already exists. Use -o to overwrite");
        }
    }
    SimpleFeatureSource featureSource;
    try {
        featureSource = dataStore.getFeatureSource(tableName);
    } catch (IOException e) {
        throw new CommandFailedException("Can't aquire the feature source", e);
    }
    if (featureSource instanceof SimpleFeatureStore) {
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        if (overwrite) {
            try {
                featureStore.removeFeatures(Filter.INCLUDE);
            } catch (IOException e) {
                throw new CommandFailedException("Error trying to remove features", e);
            }
        }
        ExportOp op = cli.getGeogig().command(ExportOp.class).setFeatureStore(featureStore).setPath(path).setFilterFeatureTypeId(featureTypeId).setAlter(alter);
        if (defaultType) {
            op.exportDefaultFeatureType();
        }
        try {
            op.setProgressListener(cli.getProgressListener()).call();
        } catch (IllegalArgumentException iae) {
            throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
        } catch (GeoToolsOpException e) {
            switch(e.statusCode) {
                case MIXED_FEATURE_TYPES:
                    throw new CommandFailedException("The selected tree contains mixed feature types. Use --defaulttype or --featuretype <feature_type_ref> to export.", e);
                default:
                    throw new CommandFailedException("Could not export. Error:" + e.statusCode.name(), e);
            }
        }
        cli.getConsole().println(path + " exported successfully to " + tableName);
    } else {
        throw new CommandFailedException("Can't write to the selected table");
    }
}
Also used : NameImpl(org.geotools.feature.NameImpl) ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) IOException(java.io.IOException) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) SimpleFeatureTypeImpl(org.geotools.feature.simple.SimpleFeatureTypeImpl) GeoToolsOpException(org.locationtech.geogig.geotools.plumbing.GeoToolsOpException) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DataStore(org.geotools.data.DataStore) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) ExportOp(org.locationtech.geogig.geotools.plumbing.ExportOp) TYPE(org.locationtech.geogig.api.RevObject.TYPE)

Aggregations

NameImpl (org.geotools.feature.NameImpl)32 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)13 QName (javax.xml.namespace.QName)9 Test (org.junit.Test)8 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)6 PropertyName (org.opengis.filter.expression.PropertyName)6 IOException (java.io.IOException)5 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)5 DataStore (org.geotools.data.DataStore)4 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)4 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)4 SimpleFeatureTypeImpl (org.geotools.feature.simple.SimpleFeatureTypeImpl)4 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)4 Name (org.opengis.feature.type.Name)4 Expression (org.opengis.filter.expression.Expression)4 Color (java.awt.Color)3 ObjectId (org.locationtech.geogig.api.ObjectId)3 TYPE (org.locationtech.geogig.api.RevObject.TYPE)3 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)3