Changeset 16407 in josm for trunk/src/org


Ignore:
Timestamp:
2020-05-13T15:24:14+02:00 (5 years ago)
Author:
GerdP
Message:

fix #18915: "Precondition violation" not fixable from within JOSM

  • correct handling of precondition failure responses that contain the word requires so that the correct objects are downloaded. The parents are needed, not the childern.
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/AbstractUploadTask.java

    r15586 r16407  
    88import java.net.HttpURLConnection;
    99import java.text.DateFormat;
     10import java.util.ArrayList;
    1011import java.util.Arrays;
    1112import java.util.Collection;
     
    264265        );
    265266        if (ret == 0) {
    266             DownloadReferrersAction.downloadReferrers(MainApplication.getLayerManager().getEditLayer(), Arrays.asList(conflict.a));
     267            if (msg.contains("to delete")) {
     268                DownloadReferrersAction.downloadReferrers(MainApplication.getLayerManager().getEditLayer(),
     269                        Arrays.asList(conflict.a));
     270            }
     271            if (msg.contains("to upload") && !conflict.b.isEmpty()) {
     272                MainApplication.worker.submit(new DownloadPrimitivesTask(
     273                        MainApplication.getLayerManager().getEditLayer(), new ArrayList<>(conflict.b), false));
     274            }
    267275        }
    268276    }
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r15089 r16407  
    2626import org.openstreetmap.josm.data.osm.Node;
    2727import org.openstreetmap.josm.data.osm.OsmPrimitive;
     28import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2829import org.openstreetmap.josm.data.osm.Relation;
    2930import org.openstreetmap.josm.data.osm.Way;
     
    135136            return Pair.create(n, refs);
    136137        }
    137         m = Pattern.compile(".*Way (\\d+) requires the nodes with id in " + ids + ".*").matcher(msg);
     138        m = Pattern.compile(".*Way ([-]*\\d+) requires the nodes with id in " + ids + ".*").matcher(msg);
    138139        // ... ", which either do not exist, or are not visible"
    139140        if (m.matches()) {
    140             OsmPrimitive n = new Way(Long.parseLong(m.group(1)));
     141            OsmPrimitive n = OsmPrimitiveType.WAY.newInstance(Long.parseLong(m.group(1)), true);
    141142            for (String s : m.group(2).split(",")) {
    142143                refs.add(new Node(Long.parseLong(s)));
     144            }
     145            return Pair.create(n, refs);
     146        }
     147        m = Pattern.compile(".*Relation ([-]*\\d+) requires the nodes with id in " + ids + ".*").matcher(msg);
     148        // ... ", which either do not exist, or are not visible"
     149        if (m.matches()) {
     150            OsmPrimitive n = OsmPrimitiveType.RELATION.newInstance(Long.parseLong(m.group(1)), true);
     151            for (String s : m.group(2).split(",")) {
     152                refs.add(new Node(Long.parseLong(s)));
     153            }
     154            return Pair.create(n, refs);
     155        }
     156        m = Pattern.compile(".*Relation ([-]*\\d+) requires the ways with id in " + ids + ".*").matcher(msg);
     157        // ... ", which either do not exist, or are not visible"
     158        if (m.matches()) {
     159            OsmPrimitive n = OsmPrimitiveType.RELATION.newInstance(Long.parseLong(m.group(1)), true);
     160            for (String s : m.group(2).split(",")) {
     161                refs.add(new Way(Long.parseLong(s)));
    143162            }
    144163            return Pair.create(n, refs);
     
    158177        if (conflict != null) {
    159178            OsmPrimitive firstRefs = conflict.b.iterator().next();
    160             String objId = Long.toString(conflict.a.getId());
     179            String objId = Long.toString(conflict.a.getUniqueId());
    161180            Collection<Long> refIds = Utils.transform(conflict.b, OsmPrimitive::getId);
    162181            String refIdsString = refIds.size() == 1 ? refIds.iterator().next().toString() : refIds.toString();
    163182            if (conflict.a instanceof Node) {
    164                 if (firstRefs instanceof Node) {
    165                     return "<html>" + trn(
    166                             "<strong>Failed</strong> to delete <strong>node {0}</strong>."
    167                             + " It is still referred to by node {1}.<br>"
    168                             + "Please load the node, remove the reference to the node, and upload again.",
    169                             "<strong>Failed</strong> to delete <strong>node {0}</strong>."
    170                             + " It is still referred to by nodes {1}.<br>"
    171                             + "Please load the nodes, remove the reference to the node, and upload again.",
    172                             conflict.b.size(), objId, refIdsString) + "</html>";
    173                 } else if (firstRefs instanceof Way) {
     183                if (firstRefs instanceof Way) {
    174184                    return "<html>" + trn(
    175185                            "<strong>Failed</strong> to delete <strong>node {0}</strong>."
     
    194204            } else if (conflict.a instanceof Way) {
    195205                if (firstRefs instanceof Node) {
     206                    // way p1 requires nodes
    196207                    return "<html>" + trn(
    197                             "<strong>Failed</strong> to delete <strong>way {0}</strong>."
    198                             + " It is still referred to by node {1}.<br>"
    199                             + "Please load the node, remove the reference to the way, and upload again.",
    200                             "<strong>Failed</strong> to delete <strong>way {0}</strong>."
    201                             + " It is still referred to by nodes {1}.<br>"
    202                             + "Please load the nodes, remove the reference to the way, and upload again.",
    203                             conflict.b.size(), objId, refIdsString) + "</html>";
    204                 } else if (firstRefs instanceof Way) {
    205                     return "<html>" + trn(
    206                             "<strong>Failed</strong> to delete <strong>way {0}</strong>."
    207                             + " It is still referred to by way {1}.<br>"
    208                             + "Please load the way, remove the reference to the way, and upload again.",
    209                             "<strong>Failed</strong> to delete <strong>way {0}</strong>."
    210                             + " It is still referred to by ways {1}.<br>"
    211                             + "Please load the ways, remove the reference to the way, and upload again.",
     208                            "<strong>Failed</strong> to upload <strong>way {0}</strong>."
     209                            + " It refers to deleted node {1}.<br>"
     210                            + "Please load the node, remove the reference in the way, and upload again.",
     211                            "<strong>Failed</strong> to upload <strong>way {0}</strong>."
     212                            + " It refers to deleted nodes {1}.<br>"
     213                            + "Please load the nodes, remove the reference in the way, and upload again.",
    212214                            conflict.b.size(), objId, refIdsString) + "</html>";
    213215                } else if (firstRefs instanceof Relation) {
     216                    // way is used by relation
    214217                    return "<html>" + trn(
    215218                            "<strong>Failed</strong> to delete <strong>way {0}</strong>."
     
    226229                if (firstRefs instanceof Node) {
    227230                    return "<html>" + trn(
    228                             "<strong>Failed</strong> to delete <strong>relation {0}</strong>."
    229                             + " It is still referred to by node {1}.<br>"
    230                             + "Please load the node, remove the reference to the relation, and upload again.",
    231                             "<strong>Failed</strong> to delete <strong>relation {0}</strong>."
    232                             + " It is still referred to by nodes {1}.<br>"
    233                             + "Please load the nodes, remove the reference to the relation, and upload again.",
     231                            "<strong>Failed</strong> to upload <strong>relation {0}</strong>."
     232                            + " it refers to deleted node {1}.<br>"
     233                            + "Please load the node, remove the reference in the relation, and upload again.",
     234                            "<strong>Failed</strong> to upload <strong>relation {0}</strong>."
     235                            + " it refers to deleted nodes {1}.<br>"
     236                            + "Please load the nodes, remove the reference in the relation, and upload again.",
    234237                            conflict.b.size(), objId, refIdsString) + "</html>";
    235238                } else if (firstRefs instanceof Way) {
    236239                    return "<html>" + trn(
    237                             "<strong>Failed</strong> to delete <strong>relation {0}</strong>."
    238                             + " It is still referred to by way {1}.<br>"
    239                             + "Please load the way, remove the reference to the relation, and upload again.",
    240                             "<strong>Failed</strong> to delete <strong>relation {0}</strong>."
    241                             + " It is still referred to by ways {1}.<br>"
    242                             + "Please load the ways, remove the reference to the relation, and upload again.",
     240                            "<strong>Failed</strong> to upload <strong>relation {0}</strong>."
     241                            + " It refers to deleted way {1}.<br>"
     242                            + "Please load the way, remove the reference in the relation, and upload again.",
     243                            "<strong>Failed</strong> to upload <strong>relation {0}</strong>."
     244                            + " It refers to deleted ways {1}.<br>"
     245                            + "Please load the ways, remove the reference in the relation, and upload again.",
    243246                            conflict.b.size(), objId, refIdsString) + "</html>";
    244247                } else if (firstRefs instanceof Relation) {
Note: See TracChangeset for help on using the changeset viewer.