Package net.opengis.wfs

Examples of net.opengis.wfs.TransactionType


    @Override
    protected EObject createTransactionRequest(TransactionRequest request) throws IOException {
        final WfsFactory factory = WfsFactory.eINSTANCE;

        TransactionType tx = factory.createTransactionType();
        tx.setService("WFS");
        tx.setHandle(request.getHandle());
        tx.setVersion(getVersion());

        List<TransactionElement> transactionElements = request.getTransactionElements();
        if (transactionElements.isEmpty()) {
            requestInfo("Asked to perform transaction with no transaction elements");
            return tx;
        }

        @SuppressWarnings("unchecked")
        List<InsertElementType> inserts = tx.getInsert();
        @SuppressWarnings("unchecked")
        List<UpdateElementType> updates = tx.getUpdate();
        @SuppressWarnings("unchecked")
        List<DeleteElementType> deletes = tx.getDelete();

        try {
            for (TransactionElement elem : transactionElements) {
                if (elem instanceof TransactionRequest.Insert) {
                    InsertElementType insert = createInsert(factory, (Insert) elem);
View Full Code Here


            // skyrocket for nothing if there are frequent synchronisations)
            String tableName = request.getTypeName().getLocalPart();
            VersioningFeatureStore fs = (VersioningFeatureStore) ds.getFeatureSource(tableName);
            FeatureStore history = (FeatureStore) ds.getFeatureSource(SYNCH_HISTORY);
            PropertyIsEqualTo ftSyncRecord = ff.equals(ff.property("table_name"), ff.literal(tableName));
            TransactionType changes = request.getTransaction();
            int changesCount = core.countChanges(changes);
            // ... if we have no changes from remote
            if(changesCount == 0) {
                // ... and we have no changes locally
                String lastLocalRevisionId = lastLocalRevision != -1 ? String.valueOf(lastLocalRevision) : "FIRST";
                if(fs.getLog(lastLocalRevisionId, "LAST", null, null, 1).size() == 0) {
                    // add a new record without the need to grab a new local revision
                    // (if necessary, that is, if at least the Central revision changed or if
                    // we don't have a synch history at all)
                    long newCentralRevision = request.getToVersion();
                    if(lastCentralRevision != newCentralRevision || record == null) {
                        SimpleFeatureType hft = (SimpleFeatureType) history.getSchema();
                        SimpleFeature f = SimpleFeatureBuilder.build(hft, new Object[] { tableName,
                                lastLocalRevision, newCentralRevision }, null);
                        history.addFeatures(DataUtilities.collection(f));
                    }
                   
                    // ... let's just return directly, no need to store or do anything
                    return new PostDiffResponseType();
                }
            }
           
            // setup the commit message and author
            transaction.putProperty(VersioningDataStore.AUTHOR, "gss");
            transaction.putProperty(VersioningDataStore.MESSAGE, "Applying " + changesCount
                    + " changes coming from Central on layer '" + tableName + "'");

            // grab the feature stores and bind them all to the same transaction
            VersioningFeatureStore conflicts = (VersioningFeatureStore) ds
                    .getFeatureSource(SYNCH_CONFLICTS);
            conflicts.setTransaction(transaction);
            history.setTransaction(transaction);
            fs.setTransaction(transaction);

            // get a hold on a revision number early so that we don't get concurrent changes
            // from the user (the datastore will make it so that no new revision numbers will
            // be generated until we commit or rollback this transaction
            long newLocalRevision = Long.parseLong(conflicts.getVersion());

            // apply changes
            LOGGER.info("About to apply " + core.countChanges(changes)
                    + " changes coming from Central");
            if (core.countChanges(changes) > 0) {
                List<DeleteElementType> deletes = changes.getDelete();
                List<UpdateElementType> updates = changes.getUpdate();

                // We need to find conflicts: local changes occurred since last synchronisation
                // that hit the same features contained in this changeset. For those we need
                // to create a conflict record and revert the local changes so that we
                // can apply the central ones
View Full Code Here

            while (fi.hasNext()) {
                intervals.add((Long) fi.next().getAttribute("local_revision"));
            }
            fi.close();

            TransactionType transaction;
            if(intervals.size() > 1) {
                // gather the ids of the features still under conflict, we don't want to load their
                // diffs
                Filter nonConflictingFilter = getFidConflictFilter(tableName,
                        getActiveConflicts(tableName));
   
                // gather all of the diff readers for the non conflicting features
                VersioningFeatureSource fs = (VersioningFeatureSource) ds.getFeatureSource(tableName);
                FeatureDiffReader[] readers = new FeatureDiffReader[intervals.size() - 1];
                for (int i = 1; i < intervals.size(); i++) {
                    // mind we need to skip the actual synch points, so we subtract 1
                    // from the revision number
                    String fromVersion = String.valueOf(intervals.get(i - 1));
                    String toVersion = String.valueOf(intervals.get(i) - 1);
   
                    Filter filter = nonConflictingFilter;
                    // skip over all the clean merges
                    Filter cleanMerges = getFidConflictFilter(tableName, getCleanMerges(tableName,
                            intervals.get(i)));
                    if (cleanMerges != Filter.INCLUDE) {
                        if (filter != Filter.INCLUDE) {
                            filter = ff.and(cleanMerges, filter);
                        } else {
                            filter = cleanMerges;
                        }
                    }
   
                    readers[i - 1] = fs.getDifferences(fromVersion, toVersion, filter, null);
                }
   
                // now we need to merge the readers into a global set of changes, skip
                // the changes on the conflicting features, and turn everything into a
                // transaction (easy no?)
                FeatureDiffReader differences = new MergingFeatureDiffReader(readers);
                transaction = new VersioningTransactionConverter().convert(differences,
                        TransactionType.class);
            } else {
                // no local changes to return, it happens only if we never had local changes
                // in the current history
                transaction = WfsFactory.eINSTANCE.createTransactionType();
            }
            transaction.setReleaseAction(null);
            transaction.setVersion(null);
            transaction.setService(null);
            LOGGER.info("Sending back to Central " + core.countChanges(transaction) + " changes");

            GetDiffResponseType response = new GetDiffResponseType();
            response.setFromVersion(request.getFromVersion());
            response.setToVersion(lastPostRevision);
View Full Code Here

        QName typeName = new QName("http://www.openplans.org/spearfish", "restricted");
        PostDiffType postDiff = new PostDiffType();
        postDiff.setFromVersion(-1);
        postDiff.setToVersion(3);
        postDiff.setTypeName(typeName);
        TransactionType changes = WfsFactory.eINSTANCE.createTransactionType();
        DeleteElementType delete = WfsFactory.eINSTANCE.createDeleteElementType();
        delete.setTypeName(typeName);
        delete.setFilter(removeFilter);
        changes.getDelete().add(delete);
        postDiff.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));
View Full Code Here

        // 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));
View Full Code Here

                    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);
View Full Code Here

        assertEquals("acme:foo", data.getLayers().get(0));
    }
   
    @Test
    public void testWFSTransaction() throws Exception {
        TransactionType t = WfsFactory.eINSTANCE.createTransactionType();
       
        UpdateElementType ue = WfsFactory.eINSTANCE.createUpdateElementType();
        ue.setTypeName(new QName("http://acme.org", "foo", "acme"));
        t.getUpdate().add(ue);
       
        DeleteElementType de = WfsFactory.eINSTANCE.createDeleteElementType();
        de.setTypeName(new QName("http://acme.org", "bar", "acme"));
        t.getDelete().add(de);
       
        Operation op = op("Transaction", "WFS", "1.0.0", t);
        callback.operationDispatched(new Request(), op);
       
        assertEquals("acme:foo", data.getLayers().get(0));
View Full Code Here

        PropertyType property = wfs.createPropertyType();
        property.setName(new QName(SF_NAMESPACE, "cat"));
        property.setValue(-48);
        update.getProperty().add(property);
       
        TransactionType transaction = wfs.createTransactionType();
        transaction.getInsert().add(insert);
        transaction.getUpdate().add(update);
        transaction.getDelete().add(delete);
       
        PostDiffType postDiff = new PostDiffType();
        postDiff.setFromVersion(15);
        postDiff.setToVersion(47);
        postDiff.setTypeName(restricted);
View Full Code Here

        PropertyType property = wfs.createPropertyType();
        property.setName(new QName(SF_NAMESPACE, "cat"));
        property.setValue(-48);
        update.getProperty().add(property);

        TransactionType transaction = wfs.createTransactionType();
        transaction.getInsert().add(insert);
        transaction.getUpdate().add(update);
        transaction.getDelete().add(delete);

        GetDiffResponseType response = new GetDiffResponseType();
        response.setFromVersion(15);
        response.setToVersion(47);
        response.setTypeName(restricted);
View Full Code Here

        writer.write(indent + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
        writer.write(indent);
        writer.write("xsi:schemaLocation=\"http://www.opengis.net/wfs ");

        TransactionType req = (TransactionType)operation.getParameters()[0];
        String baseUrl = buildSchemaURL(req.getBaseUrl(), "wfs/1.0.0/WFS-transaction.xsd");

        writer.write(baseUrl);
        writer.write("\">");

        InsertResultsType insertResults = response.getInsertResults();
View Full Code Here

TOP

Related Classes of net.opengis.wfs.TransactionType

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.