Ticket #9624: 9624.patch

File 9624.patch, 4.7 KB (added by simon04, 8 years ago)
  • src/org/openstreetmap/josm/data/APIDataSet.java

    diff --git a/src/org/openstreetmap/josm/data/APIDataSet.java b/src/org/openstreetmap/josm/data/APIDataSet.java
    index 7ab1334..3352623 100644
    a b public class APIDataSet { 
    231231        newToAdd.addAll(noProblemRelations);
    232232        relationsToAdd.removeAll(noProblemRelations);
    233233
    234         RelationUploadDependencyGraph graph = new RelationUploadDependencyGraph(relationsToAdd);
     234        RelationUploadDependencyGraph graph = new RelationUploadDependencyGraph(relationsToAdd, true);
    235235        newToAdd.addAll(graph.computeUploadOrder());
    236236        toAdd = newToAdd;
     237
     238        LinkedList<OsmPrimitive> newToDelete = new LinkedList<OsmPrimitive>();
     239        newToDelete.addAll(Utils.filteredCollection(toDelete, Node.class));
     240        newToDelete.addAll(Utils.filteredCollection(toDelete, Way.class));
     241        graph = new RelationUploadDependencyGraph(Utils.filteredCollection(toDelete, Relation.class), false);
     242        newToDelete.addAll(graph.computeUploadOrder());
     243        toDelete = newToDelete;
    237244    }
    238245
    239246    /**
    public class APIDataSet { 
    267274     *
    268275     */
    269276    private static class RelationUploadDependencyGraph {
    270         private Map<Relation, Set<Relation>> children;
     277        private Map<Relation, Set<Relation>> children = new HashMap<Relation, Set<Relation>>();
    271278        private Collection<Relation> relations;
    272         private Set<Relation> visited;
     279        private Set<Relation> visited = new HashSet<Relation>();
    273280        private List<Relation> uploadOrder;
     281        private final boolean onlyNewOrUndeleted;
    274282
    275         public RelationUploadDependencyGraph() {
    276             this.children = new HashMap<Relation, Set<Relation>>();
    277             this.visited = new HashSet<Relation>();
    278         }
    279 
    280         public RelationUploadDependencyGraph(Collection<Relation> relations) {
    281             this();
     283        public RelationUploadDependencyGraph(Collection<Relation> relations, boolean onlyNewOrUndeleted) {
     284            this.onlyNewOrUndeleted = onlyNewOrUndeleted;
    282285            build(relations);
    283286        }
    284287
    285288        public void build(Collection<Relation> relations) {
    286289            this.relations = new HashSet<Relation>();
    287290            for(Relation relation: relations) {
    288                 if (!relation.isNewOrUndeleted() ) {
     291                if (onlyNewOrUndeleted && !relation.isNewOrUndeleted() ) {
    289292                    continue;
    290293                }
    291294                this.relations.add(relation);
    292295                for (RelationMember m: relation.getMembers()) {
    293                     if (m.isRelation() && m.getMember().isNewOrUndeleted()) {
     296                    if (m.isRelation() && (!onlyNewOrUndeleted || m.getMember().isNewOrUndeleted())) {
    294297                        addDependency(relation, (Relation)m.getMember());
    295298                    }
    296299                }
  • test/unit/org/openstreetmap/josm/data/osm/APIDataSetTest.java

    diff --git a/test/unit/org/openstreetmap/josm/data/osm/APIDataSetTest.java b/test/unit/org/openstreetmap/josm/data/osm/APIDataSetTest.java
    index 7f4820d..0fb3d7b 100644
    a b public class APIDataSetTest { 
    144144        assertEquals(true, toAdd.indexOf(r3) < toAdd.indexOf(r1));
    145145    }
    146146
     147    @Test // for ticket #9624
     148    public void deleteOneParentTwoNewChildren() {
     149        DataSet ds = new DataSet();
     150        Relation r1 = new Relation(1);
     151        ds.addPrimitive(r1);
     152        r1.put("name", "r1");
     153
     154        Relation r2 = new Relation(2);
     155        ds.addPrimitive(r2);
     156        r2.put("name", "r2");
     157
     158        Relation r3 = new Relation(3);
     159        ds.addPrimitive(r3);
     160        r3.put("name", "r3");
     161
     162        Relation r4 = new Relation(4);
     163        ds.addPrimitive(r4);
     164        r4.put("name", "unrelated");
     165
     166
     167        r1.addMember(new RelationMember("", r2));
     168        r1.addMember(new RelationMember("", r3));
     169
     170        r1.setDeleted(true);
     171        r2.setDeleted(true);
     172        r3.setDeleted(true);
     173        r4.setDeleted(true);
     174
     175
     176        APIDataSet apiDataSet = new APIDataSet();
     177        apiDataSet.init(ds);
     178        try {
     179            apiDataSet.adjustRelationUploadOrder();
     180        } catch(CyclicUploadDependencyException e) {
     181            fail("unexpected exception:" + e);
     182        }
     183        List<OsmPrimitive> toDelete = apiDataSet.getPrimitivesToDelete();
     184
     185        assertEquals(4, toDelete.size());
     186        assertEquals(true, toDelete.indexOf(r2) < toDelete.indexOf(r1));
     187        assertEquals(true, toDelete.indexOf(r3) < toDelete.indexOf(r1));
     188        assertEquals(true, toDelete.indexOf(r3) < toDelete.indexOf(r1));
     189    }
     190
    147191    @Test
    148192    public void oneCycle() {
    149193        DataSet ds = new DataSet();