Changeset 33190 in osm
- Timestamp:
- 2017-03-15T02:31:32+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/DetermineSdsModificationsUploadHook.java
r32705 r33190 52 52 53 53 // check modified primitives. 54 54 for (OsmPrimitive upd : apiDataSet.getPrimitivesToUpdate()) { 55 55 56 57 56 HashSet<String> allKeys = new HashSet<>(); 57 boolean specialTags = false; 58 58 59 // process tags of new object 60 for (String key : upd.keySet()) { 61 allKeys.add(key); 62 if (!specialTags && isSpecialKey(key)) specialTags = true; 59 // process tags of new object 60 for (String key : upd.keySet()) { 61 allKeys.add(key); 62 if (!specialTags && isSpecialKey(key)) specialTags = true; 63 } 64 65 // process tags of old object 66 IPrimitive old = plugin.getOriginalPrimitive(upd); 67 for (String key : old.keySet()) { 68 allKeys.add(key); 69 if (!specialTags && isSpecialKey(key)) specialTags = true; 70 } 71 72 // if neither has special tags, done with this object. 73 if (!specialTags) continue; 74 75 // special tags are involved. find out what, exactly, has changed. 76 boolean changeInSpecialTags = false; 77 boolean changeInOtherTags = false; 78 for (String key : allKeys) { 79 if (old.get(key) == null || upd.get(key) == null || !old.get(key).equals(upd.get(key))) { 80 if (isSpecialKey(key)) changeInSpecialTags = true; else changeInOtherTags = true; 81 if (changeInSpecialTags && changeInOtherTags) break; 63 82 } 83 } 64 84 65 // process tags of old object 66 IPrimitive old = plugin.getOriginalPrimitive(upd); 67 for (String key : old.keySet()) { 68 allKeys.add(key); 69 if (!specialTags && isSpecialKey(key)) specialTags = true; 70 } 85 // change *only* in standard tags - done with this object. 86 if (!changeInSpecialTags) continue; 71 87 72 // if neither has special tags, done with this object. 73 if (!specialTags) continue; 88 // assemble new set of special tags. might turn out to be empty. 89 HashMap<String, String> newSpecialTags = new HashMap<>(); 90 for (String key : upd.keySet()) { 91 if (isSpecialKey(key)) newSpecialTags.put(key, upd.get(key)); 92 } 74 93 75 // special tags are involved. find out what, exactly, has changed. 76 boolean changeInSpecialTags = false; 77 boolean changeInOtherTags = false; 78 for (String key : allKeys) { 79 if (old.get(key) == null || upd.get(key) == null || !old.get(key).equals(upd.get(key))) { 80 if (isSpecialKey(key)) changeInSpecialTags = true; else changeInOtherTags = true; 81 if (changeInSpecialTags && changeInOtherTags) break; 94 boolean uploadToOsm = changeInOtherTags; 95 96 // not done yet: if no changes in standard tags, we need to find out if 97 // there were changes in the other properties (node: lat/lon, way/relation: 98 // member list). If the answer is no, then the object must be removed from 99 // JOSM's normal upload queue, else we would be uploading a non-edit. 100 if (!changeInOtherTags) { 101 switch(old.getType()) { 102 case NODE: 103 INode nold = (INode) old; 104 INode nupd = (INode) upd; 105 uploadToOsm = !(nold.getCoor().equals(nupd.getCoor())); 106 break; 107 case WAY: 108 IWay wold = (IWay) old; 109 IWay wupd = (IWay) upd; 110 if (wold.getNodesCount() != wupd.getNodesCount()) { 111 uploadToOsm = true; 112 break; 82 113 } 83 } 84 85 // change *only* in standard tags - done with this object. 86 if (!changeInSpecialTags) continue; 87 88 // assemble new set of special tags. might turn out to be empty. 89 HashMap<String, String> newSpecialTags = new HashMap<>(); 90 for (String key : upd.keySet()) { 91 if (isSpecialKey(key)) newSpecialTags.put(key, upd.get(key)); 92 } 93 94 boolean uploadToOsm = changeInOtherTags; 95 96 // not done yet: if no changes in standard tags, we need to find out if 97 // there were changes in the other properties (node: lat/lon, way/relation: 98 // member list). If the answer is no, then the object must be removed from 99 // JOSM's normal upload queue, else we would be uploading a non-edit. 100 if (!changeInOtherTags) { 101 switch(old.getType()) { 102 case NODE: 103 INode nold = (INode) old; 104 INode nupd = (INode) upd; 105 uploadToOsm = !(nold.getCoor().equals(nupd.getCoor())); 106 break; 107 case WAY: 108 IWay wold = (IWay) old; 109 IWay wupd = (IWay) upd; 110 if (wold.getNodesCount() != wupd.getNodesCount()) { 114 for (int i = 0; i < wold.getNodesCount(); i++) { 115 if (wold.getNodeId(i) != wupd.getNodeId(i)) { 111 116 uploadToOsm = true; 112 117 break; 113 118 } 114 for (int i = 0; i < wold.getNodesCount(); i++) { 115 if (wold.getNodeId(i) != wupd.getNodeId(i)) { 116 uploadToOsm = true; 117 break; 118 } 119 } 119 } 120 break; 121 case RELATION: 122 IRelation rold = (IRelation) old; 123 IRelation rupd = (IRelation) upd; 124 if (rold.getMembersCount() != rupd.getMembersCount()) { 125 uploadToOsm = true; 120 126 break; 121 case RELATION:122 IRelation rold = (IRelation) old;123 IRelation rupd = (IRelation) upd;124 if (rold.getMembersCount() != rupd.getMembersCount()) {127 } 128 for (int i = 0; i < rold.getMembersCount(); i++) { 129 if (rold.getMemberType(i) != rupd.getMemberType(i) || 130 rold.getMemberId(i) != rupd.getMemberId(i)) { 125 131 uploadToOsm = true; 126 132 break; 127 133 } 128 for (int i = 0; i < rold.getMembersCount(); i++) {129 if (rold.getMemberType(i) != rupd.getMemberType(i) ||130 rold.getMemberId(i) != rupd.getMemberId(i)) {131 uploadToOsm = true;132 break;133 }134 }135 break;136 default: throw new AssertionError("unexpected case: " + old.getType());137 134 } 135 break; 136 default: throw new AssertionError("unexpected case: " + old.getType()); 138 137 } 138 } 139 139 140 141 140 // request that new set of special tags be uploaded 141 plugin.enqueueForUpload(upd, newSpecialTags, !uploadToOsm); 142 142 143 144 145 143 // we cannot remove from getPrimitivesToUpdate, this would result in a 144 // ConcurrentModificationException. 145 if (!uploadToOsm) droplist.add(upd); 146 146 147 147 } … … 149 149 apiDataSet.getPrimitivesToUpdate().removeAll(droplist); 150 150 151 152 153 154 155 156 157 158 151 // check added primitives. 152 for (OsmPrimitive add : apiDataSet.getPrimitivesToAdd()) { 153 // assemble new set of special tags. might turn out to be empty. 154 HashMap<String, String> newSpecialTags = new HashMap<>(); 155 for (String key : add.keySet()) { 156 if (isSpecialKey(key)) newSpecialTags.put(key, add.get(key)); 157 } 158 if (!newSpecialTags.isEmpty()) plugin.enqueueForUpload(add, newSpecialTags, false); 159 159 } 160 160 161 161 // FIXME it is possible that the list of OSM edits is totally empty. 162 162 return true; 163 163
Note:
See TracChangeset
for help on using the changeset viewer.