Package org.geotools.data

Examples of org.geotools.data.FeatureDiff


            Set insertedIds = new HashSet();
            Set updatedIds = new HashSet();
            Set deletedIds = new HashSet();
            while (reader.hasNext()) {
                FeatureDiff fd = reader.next();

                if (fd.getState() == FeatureDiff.INSERTED) {
                    inserted++;

                    InsertedFeatureType insertedFeature = WfsFactory.eINSTANCE
                            .createInsertedFeatureType();
                    insertedFeature.setHandle(rollback.getHandle());
                    insertedFeature.getFeatureId().add(filterFactory.featureId(fd.getID()));
                    response.getInsertResults().getFeature().add(insertedFeature);
                    // accumulate fids for transaction event handling
                    insertedIds.add(filterFactory.featureId(fd.getID()));
                } else if (fd.getState() == FeatureDiff.UPDATED) {
                    updated++;
                    // accumulate fids for transaction event handling
                    updatedIds.add(filterFactory.featureId(fd.getID()));
                } else if (fd.getState() == FeatureDiff.DELETED) {
                    deleted++;
                    // accumulate fids for transaction event handling
                    deletedIds.add(filterFactory.featureId(fd.getID()));
                }
            }

            // build filters
            Filter insertedFilter = filterFactory.id(insertedIds);
View Full Code Here


        final QName typeName = new QName(schema.getName().getNamespaceURI(), schema.getTypeName());
        final Set deletedIds = new HashSet();
        final InsertElementType insert = WfsFactory.eINSTANCE.createInsertElementType();

        while (diffReader.hasNext()) {
            FeatureDiff diff = diffReader.next();

            switch (diff.getState()) {
            case FeatureDiff.INSERTED:
                insert.getFeature().add(diff.getFeature());

                break;

            case FeatureDiff.DELETED:
                deletedIds.add(filterFactory.featureId(diff.getID()));

                break;

            case FeatureDiff.UPDATED:

                final UpdateElementType update = WfsFactory.eINSTANCE.createUpdateElementType();
                final EList properties = update.getProperty();

                SimpleFeature f = diff.getFeature();

                for (Iterator it = diff.getChangedAttributes().iterator(); it.hasNext();) {
                    final PropertyType property = WfsFactory.eINSTANCE.createPropertyType();
                    String name = (String) it.next();
                    property.setName(new QName(name));
                    property.setValue(f.getAttribute(name));
                    properties.add(property);
                }

                FeatureId featureId = filterFactory.featureId(diff.getID());
                final Filter filter = filterFactory.id(Collections.singleton(featureId));
                update.setFilter(filter);
                update.setTypeName(typeName);
                transaction.getUpdate().add(update);

                break;

            default:
                throw new WFSException("Could not handle diff type " + diff.getState());
            }
        }
        diffReader.close();

        // create insert and delete elements if needed
View Full Code Here

                    String newLocalRevisionId = String.valueOf(newLocalRevision);
                    String lastLocalRevisionId = lastLocalRevision != -1 ? String.valueOf(lastLocalRevision) : "FIRST";
                    FeatureDiffReader localChanges = fs.getDifferences(lastLocalRevisionId,
                            newLocalRevisionId, ff.id(changedFids), null);
                    while (localChanges.hasNext()) {
                        FeatureDiff fd = localChanges.next();
                        FeatureId diffFeatureId = ff.featureId(fd.getID());
                        if (fd.getState() == FeatureDiff.INSERTED) {
                            throw new GSSException(
                                    "A new locally inserted feature has the same "
                                            + "id as a modified feature coming from Central, this is impossible, "
                                            + "there is either a bug in ID generation or someone manually tampered with it!");
                        } else if (fd.getState() == FeatureDiff.DELETED) {
                            if (deletedFids.contains(diffFeatureId)) {
                                saveCleanMergeMarker(fs, conflicts, lastLocalRevisionId,
                                        newLocalRevision, fd.getID());
                            } else {
                                handleDeletionConflict(fs, conflicts, lastLocalRevisionId,
                                        newLocalRevision, fd.getID());
                            }
                        } else {
                            if (updatedFids.contains(diffFeatureId)) {
                                if (isSameUpdate(fd, findUpdate(fd.getID(), updates))) {
                                    saveCleanMergeMarker(fs, conflicts, lastLocalRevisionId,
                                            newLocalRevision, fd.getID());
                                } else {
                                    handleUpdateConflict(fs, conflicts, lastLocalRevisionId,
                                            newLocalRevision, fd.getID());
                                }
                            } else {
                                handleUpdateConflict(fs, conflicts, lastLocalRevisionId,
                                        newLocalRevision, fd.getID());
                            }
                        }
                    }
                    localChanges.close();
                }
View Full Code Here

        int count = 0;
        Set<Integer> states = new HashSet<Integer>();
        while (reader.hasNext()) {
            assertTrue(merge.hasNext());
            FeatureDiff fd = reader.next();
            FeatureDiff fdm = merge.next();
            assertEquals(fd, fdm);
            count++;
            states.add(fd.getState());
        }
        reader.close();
View Full Code Here

        // build a merging one, it should report the same resuls
        MergingFeatureDiffReader merge = new MergingFeatureDiffReader(r1, r2);
       
        assertTrue(merge.hasNext());
        FeatureDiff fd = merge.next();
        assertEquals(2, fd.getChangedAttributes().size());
        assertEquals(-48l, fd.getFeature().getAttribute("cat"));
        assertTrue(g.equals((Geometry) fd.getFeature().getAttribute("the_geom")));
        assertFalse(merge.hasNext());
        merge.close();
    }
View Full Code Here

    public FeatureDiff next() throws IOException, NoSuchElementException {
        if (!hasNext()) {
            throw new NoSuchElementException("No more feature diffs in this reader");
        }

        FeatureDiff result = nextDifference;
        nextDifference = null;

        return result;
    }
View Full Code Here

        // updates -> the set of changes has to be rebuilt
        SimpleFeature from = null;
        SimpleFeature to = null;
        boolean removed = false;
        for (int i = 0; i < history.length; i++) {
            FeatureDiff diff = history[i];
            if (diff != null) {
                if (diff.getState() == FeatureDiff.INSERTED) {
                    // is this the rollback of a removal?
                    if(removed == true) {
                        from = null;
                        to = null;
                    } else {
                        from = null;
                        to = diff.getFeature();
                    }
                    removed = false;
                } else if (diff.getState() == FeatureDiff.DELETED) {
                    if (from == null) {
                        from = diff.getOldFeature();
                    }
                    to = null;
                    removed = true;
                } else {
                    // might we have a removed flag before this update? Maybe... if Central
                    // for some reason reinserted the feature (remember we're skipping
                    // changes coming from Central. But in that case we start over fresh
                    if (removed) {
                        removed = false;
                        from = diff.getOldFeature();
                    }

                    // is this the first diff or we have a history?
                    if (from == null) {
                        from = diff.getOldFeature();
                    }
                    to = diff.getFeature();
                }
            }
        }
       
        if(from == null && to == null) {
View Full Code Here

        for (int i = 0; i < delegates.length; i++) {
            if (delegates[i] != null && !featureRead[i]) {
                // read the next diff that is not linked to a conflicting feature
                while (delegates[i].hasNext()) {
                    // grab a new feature diff
                    FeatureDiff fd = delegates[i].next();
                    String fid = fd.getID();
                   
                    // is it about a feature id we already know about?
                    FeatureDiff[] history;
                    if (sortedFids.contains(fid)) {
                        history = diffHistory.get(fid);
View Full Code Here

        int count = 0;
        Set<Integer> states = new HashSet<Integer>();
        while (reader.hasNext()) {
            assertTrue(merge.hasNext());
            FeatureDiff fd = reader.next();
            FeatureDiff fdm = merge.next();
            assertEquals(fd, fdm);
            count++;
            states.add(fd.getState());
        }
        reader.close();
View Full Code Here

        // build a merging one, it should report the same resuls
        MergingFeatureDiffReader merge = new MergingFeatureDiffReader(r1, r2);
       
        assertTrue(merge.hasNext());
        FeatureDiff fd = merge.next();
        assertEquals(2, fd.getChangedAttributes().size());
        assertEquals(-48l, fd.getFeature().getAttribute("cat"));
        assertTrue(g.equals((Geometry) fd.getFeature().getAttribute("the_geom")));
        assertFalse(merge.hasNext());
        merge.close();
    }
View Full Code Here

TOP

Related Classes of org.geotools.data.FeatureDiff

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.