Package org.geotools.data

Examples of org.geotools.data.VersioningFeatureStore


     * Sheer luck, the local changes are on the same feature, and are the same changes Central is pushing onto us
     * @throws Exception
     */
    public void testCleanMerge() throws Exception {
        // grab the datastore
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // make the same changes as in the post diff
        Id updateFilter = ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);
        // remove the third feature
        Id removeFilter = ff.id(singleton(ff.featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
        restricted.removeFeatures(removeFilter);
        assertEquals(3, restricted.getCount(Query.ALL));
       

        // get the response and do the basic checks
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
View Full Code Here


        assertEquals(0, gss.getActiveConflicts("restricted").size());
    }

    public void testDeleteConflict() throws Exception {
        // grab the datastore so that we can make some changes that will generate conflicts
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        restricted.removeFeatures(ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4"))));
        assertEquals(3, restricted.getCount(Query.ALL));
    
        // get the response and do the basic checks
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
        checkPostDiffSuccessResponse(response);
View Full Code Here

        assertNull(f.getAttribute("local_feature"));
    }
   
    public void testUpdateConflict() throws Exception {
        // grab the datastore so that we can make some changes that will generate conflicts
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        Id fidFilter = ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), 123456, fidFilter);
        assertEquals(4, restricted.getCount(Query.ALL));
    
        // get the response and do the basic checks
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
        checkPostDiffSuccessResponse(response);
View Full Code Here

public class MergingFeatureDiffReaderTest extends GSSTestSupport {

    public void testMergeSingle() throws Exception {
        // grab the datastore
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore
                .getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();

        // an update
        Id updateFilter = ff.id(singleton(ff
                .featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);
        // a delete
        Id removeFilter = ff.id(singleton(ff
                .featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
        restricted.removeFeatures(removeFilter);
        // and an insert
        WKTReader wkt = new WKTReader();
        SimpleFeature f = SimpleFeatureBuilder.build(schema, new Object[] { 123,
                wkt.read("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))") }, null);
        restricted.addFeatures(collection(f));

        // grab a diff reader
        FeatureDiffReader reader = restricted.getDifferences("FIRST", "LAST", null, null);
        FeatureDiffReader reader2 = restricted.getDifferences("FIRST", "LAST", null, null);

        // build a merging one, it should report the same resuls
        MergingFeatureDiffReader merge = new MergingFeatureDiffReader(reader2);

        int count = 0;
View Full Code Here

        assertEquals(3, states.size());
    }

    public void testDeleteReinsert() throws Exception {
        // grab the datastore
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore
                .getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();

        // remove
        Id removeFilter = ff.id(singleton(ff
                .featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
        Transaction t = new DefaultTransaction();
        restricted.setTransaction(t);
        restricted.removeFeatures(removeFilter);
        String v1 = restricted.getVersion();
        t.commit();

        // revert
        String v2 = restricted.getVersion();
        restricted.rollback("FIRST", null, null);
        t.commit();
        t.close();
       
        restricted.setTransaction(Transaction.AUTO_COMMIT);

        // grab the two readers, separate
        FeatureDiffReader r1 = restricted.getDifferences("FIRST", v1, null, null);
        FeatureDiffReader r2 = restricted.getDifferences(v1, v2, null, null);

        // build a merging one, it should report the same resuls
        MergingFeatureDiffReader merge = new MergingFeatureDiffReader(r1, r2);
       
        assertFalse(merge.hasNext());
View Full Code Here

        assertFalse((Boolean) f.getAttribute("errors"));
    }
   
    public void testLocalChanges() throws Exception {
        // apply a local change on Central so that we'll get a non empty transaction sent to the client
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // remove the third feature
        Id removeFilter = ff.id(singleton(ff.featureId("restricted.c15e76ab-e44b-423e-8f85-f6d9927b878a")));
        restricted.removeFeatures(removeFilter);
        assertEquals(3, restricted.getCount(Query.ALL));
       
        // build the expected PostDiff request
        QName typeName = new QName("http://www.openplans.org/spearfish", "restricted");
        PostDiffType postDiff = new PostDiffType();
        postDiff.setFromVersion(-1);
View Full Code Here

    }
   
   
    public void testRemoteChanges() throws Exception {
        // make sure we start with 4 features
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        assertEquals(4, restricted.getCount(Query.ALL));
       
        // build a "no local changes" postdiff
        QName typeName = new QName("http://www.openplans.org/spearfish", "restricted");
        PostDiffType postDiff = new PostDiffType();
        postDiff.setFromVersion(-1);
        postDiff.setToVersion(-1);
        postDiff.setTypeName(typeName);
        postDiff.setTransaction(WfsFactory.eINSTANCE.createTransactionType());
       
        // build the expected GetDiff object
        GetDiffType getDiff = new GetDiffType();
        getDiff.setTypeName(typeName);
        getDiff.setFromVersion(-1);
       
        // build a GetDiffResponse that will trigger a deletion
        GetDiffResponseType gdr = new GetDiffResponseType();
        gdr.setFromVersion(-1);
        gdr.setFromVersion(6);
        gdr.setTypeName(typeName);
        TransactionType changes = WfsFactory.eINSTANCE.createTransactionType();
        DeleteElementType delete = WfsFactory.eINSTANCE.createDeleteElementType();
        delete.setTypeName(typeName);
        Id removeFilter = ff.id(singleton(ff.featureId("restricted.c15e76ab-e44b-423e-8f85-f6d9927b878a")));
        delete.setFilter(removeFilter);
        changes.getDelete().add(delete);
        gdr.setTransaction(changes);
       
        // create mock objects that will check the calls are flowing as expected
        GSSClient client = createMock(GSSClient.class);
        expect(client.getCentralRevision((QName) anyObject())).andReturn(new Long(-1));
        client.postDiff(postDiff);
        expect(client.getDiff((GetDiffType) anyObject())).andReturn(gdr);
        replay(client);
        GSSClientFactory factory = createMock(GSSClientFactory.class);
        expect(factory.createClient(new URL("http://localhost:8081/geoserver/ows"), null, null))
                .andReturn(client);
        replay(factory);
       
        synch.clientFactory = factory;
       
        // perform synch
        Date start = new Date();
        synch.synchronizeOustandlingLayers();
        Date end = new Date();

        // check we stored the last synch marker
        SimpleFeature f = getSingleFeature(fsUnitTables, ff.equal(ff.property("table_id"), ff.literal(1), false));
        Date lastSynch = (Date) f.getAttribute("last_synchronization");
        assertNotNull(lastSynch);
        assertTrue(lastSynch.compareTo(start) >= 0 && lastSynch.compareTo(end) <= 0);
        assertNull(f.getAttribute("last_failure"));
       
        // check we marked the unit as succeded
        f = getSingleFeature(fsUnits, ff.equal(ff.property("unit_name"), ff.literal("unit1"), false));
        assertFalse((Boolean) f.getAttribute("errors"));
       
        // check the deletion actually happened locally
        assertEquals(3, restricted.getCount(Query.ALL));
        assertEquals(0, restricted.getCount(new DefaultQuery("restricted", removeFilter)));
    }
View Full Code Here

     * Local but not conflicting changes
     * @throws Exception
     */
    public void testLocalChangesNoConflict() throws Exception {
        // grab the datastore so that we can make some changes that will not generate conflicts
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // modify the fourth feature, change its cat from 400 to 450
        Id updateFilter = ff.id(singleton(ff.featureId("restricted.1b99be2b-2480-4742-ad52-95c294efda3b")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), 450, updateFilter);
        // remove the third feature
        Id removeFilter = ff.id(singleton(ff.featureId("restricted.c15e76ab-e44b-423e-8f85-f6d9927b878a")));
        restricted.removeFeatures(removeFilter);
        assertEquals(3, restricted.getCount(Query.ALL));
       

        // get the response and do the basic checks
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
        checkPostDiffSuccessResponse(response);
        checkPostDiffInitialChanges(restricted);

        // check there are no conflicts
        assertEquals(0, gss.getActiveConflicts("restricted").size());
       
        // check the local changes are still there
        assertEquals(0, restricted.getCount(new DefaultQuery(null, removeFilter)));
        FeatureIterator<SimpleFeature> fi;
        fi = restricted.getFeatures(updateFilter).features();
        assertTrue(fi.hasNext());
        SimpleFeature f = fi.next();
        fi.close();
        assertEquals(450l, f.getAttribute("cat"));
    }
View Full Code Here

        merge.close();
    }
   
    public void testMergeMulti() throws Exception {
        // grab the datastore
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore
                .getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();

        // first update
        Id updateFilter = ff.id(singleton(ff
                .featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        Transaction t = new DefaultTransaction();
        restricted.setTransaction(t);
        restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);
        String v1 = restricted.getVersion();
        t.commit();
       
        // second update
        WKTReader wkt = new WKTReader();
        Geometry g = wkt.read("MULTIPOLYGON(((0 0, 0 10, 10 10, 10 0, 0 0)))");
        restricted.modifyFeatures(schema.getDescriptor("the_geom"), g, updateFilter);
        String v2 = restricted.getVersion();
        t.commit();
       
        // clean up
        t.close();
        restricted.setTransaction(Transaction.AUTO_COMMIT);

        // grab the two readers, separate
        FeatureDiffReader r1 = restricted.getDifferences("FIRST", v1, null, null);
        FeatureDiffReader r2 = restricted.getDifferences(v1, v2, null, null);

        // build a merging one, it should report the same resuls
        MergingFeatureDiffReader merge = new MergingFeatureDiffReader(r1, r2);
       
        assertTrue(merge.hasNext());
View Full Code Here

                    long clientCentralRevision = client.getCentralRevision(layerName);

                    // compute the diff that we have to send the client. Notice that we have
                    // to skip over the local change occurred when we last performed a GetDiff
                    // against the client
                    VersioningFeatureStore fs = (VersioningFeatureStore) ds
                            .getFeatureSource(tableName);
                    fs.setTransaction(transaction);
                    String fromRevision = clientCentralRevision == -1 ? "FIRST" : String
                            .valueOf(clientCentralRevision);
                    TransactionType centralChanges;
                    LOGGER.log(Level.INFO, "About to compute PostDiff changes. Last central revision known to client " + clientCentralRevision + ", last GetDiff central revision " + getDiffCentralRevision);
                    if (getDiffCentralRevision == null || clientCentralRevision >= getDiffCentralRevision) {
                        // either first time or we don't need to make jumps
                        LOGGER.log(Level.INFO, "First PostDiff or clientRevion same as the last central one, computing diff from " + fromRevision +  " to LAST");
                        FeatureDiffReader fdr = fs.getDifferences(fromRevision, "LAST", null, null);
                        centralChanges = new VersioningTransactionConverter().convert(fdr,
                                TransactionType.class);
                    } else  {
                        // we need to jump over the last local changes
                        String before = String.valueOf(getDiffCentralRevision - 1);
                        String after = String.valueOf(getDiffCentralRevision);
                        LOGGER.log(Level.INFO, "Client revision lower than the server one, computing diff from " + fromRevision +  " to " + before + " and merging with diffs from " + after + " to LAST");
                        FeatureDiffReader fdr1 = fs.getDifferences(fromRevision, before, null, null);
                        FeatureDiffReader fdr2 = fs.getDifferences(after, "LAST", null, null);
                        FeatureDiffReader[] fdr = new FeatureDiffReader[] { fdr1, fdr2 };
                        centralChanges = new VersioningTransactionConverter().convert(fdr,
                                TransactionType.class);
                    }

                    // what is the latest change on this layer? (worst case it's the last GetDiff
                    // from this Unit)
                    long lastCentralRevision = clientCentralRevision;
                    li = fs.getLog("LAST", fromRevision, null, null, 1).features();
                    if (li.hasNext()) {
                        lastCentralRevision = (Long) li.next().getAttribute("revision");
                    }
                    li.close();

                    // finally run the PostDiff
                    PostDiffType postDiff = new PostDiffType();
                    postDiff.setTypeName(layerName);
                    postDiff.setFromVersion(clientCentralRevision);
                    postDiff.setToVersion(lastCentralRevision);
                    postDiff.setTransaction(centralChanges);
                    client.postDiff(postDiff);

                    // grab the changes from the client and apply them locally
                    GetDiffType getDiff = new GetDiffType();
                    getDiff.setFromVersion(lastUnitRevision == null ? -1 : lastUnitRevision);
                    getDiff.setTypeName(layerName);
                    GetDiffResponseType gdr = client.getDiff(getDiff);
                    TransactionType unitChanges = gdr.getTransaction();
                    core.applyChanges(unitChanges, fs);
                   
                    // mark down this layer as succesfully synchronised
                    FeatureStore<SimpleFeatureType, SimpleFeature> tuMetadata = (FeatureStore<SimpleFeatureType, SimpleFeature>) ds
                            .getFeatureSource(SYNCH_UNIT_TABLES);
                    tuMetadata.setTransaction(transaction);
                    SimpleFeatureType tuSchema = tuMetadata.getSchema();
                    int unitChangeCount = core.countChanges(unitChanges);
                    int centralChangeCount = core.countChanges(centralChanges);
                    if (unitChangeCount == 0 && centralChangeCount == 0) {
                        // just update the last_synch marker, as nothing else happened and
                        // this way we can avoid eating away central revision number (which
                        // might go up very rapidly otherwise)
                        AttributeDescriptor[] atts = new AttributeDescriptor[] { tuSchema
                                .getDescriptor("last_synchronization") };
                        Object[] values = new Object[] { new Date() };
                        Filter filter = ff.and(ff.equals(ff.property("table_id"), ff
                                .literal(tableId)), ff.equals(ff.property("unit_id"), ff
                                .literal(unitId)));
                        tuMetadata.modifyFeatures(atts, values, filter);
                    } else {
                        AttributeDescriptor[] atts = new AttributeDescriptor[] {
                                tuSchema.getDescriptor("last_synchronization"),
                                tuSchema.getDescriptor("getdiff_central_revision"),
                                tuSchema.getDescriptor("last_unit_revision") };
                        Object[] values = new Object[] { new Date(),
                                Long.parseLong(fs.getVersion()), gdr.getToVersion() };
                        Filter filter = ff.and(ff.equals(ff.property("table_id"), ff
                                .literal(tableId)), ff.equals(ff.property("unit_id"), ff
                                .literal(unitId)));
                        tuMetadata.modifyFeatures(atts, values, filter);
                    }
View Full Code Here

TOP

Related Classes of org.geotools.data.VersioningFeatureStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.