Ignore:
Timestamp:
2020-06-07T11:36:21+02:00 (4 years ago)
Author:
simon04
Message:

fix #19343 - DataIntegrityProblemException: report commands involving relevant primitives

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataIntegrityProblemException.java

    r12036 r16546  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.osm;
     3
     4import java.util.Arrays;
     5import java.util.function.Predicate;
     6import java.util.stream.Collectors;
     7import java.util.stream.Stream;
     8
     9import org.openstreetmap.josm.command.Command;
     10import org.openstreetmap.josm.data.UndoRedoHandler;
    311
    412/**
     
    2230     * @param message the detail message
    2331     * @param htmlMessage HTML-formatted error message. Can be null
     32     * @param p the primitive involved in this integrity problem (used for constructing a detailed message)
    2433     */
    25     public DataIntegrityProblemException(String message, String htmlMessage) {
    26         super(message);
     34    public DataIntegrityProblemException(String message, String htmlMessage, OsmPrimitive... p) {
     35        super(message + relevantCommands(p));
    2736        this.htmlMessage = htmlMessage;
    2837    }
     
    3544        return htmlMessage;
    3645    }
     46
     47    private static String relevantCommands(OsmPrimitive... p) {
     48        if (p == null || p.length == 0) {
     49            return "";
     50        }
     51        Predicate<Command> isParticipating = c -> Arrays.stream(p).anyMatch(c.getParticipatingPrimitives()::contains);
     52        Stream<String> undo = UndoRedoHandler.getInstance().getUndoCommands().stream()
     53                .filter(isParticipating)
     54                .map(c -> "[" + c.getDescriptionText() + "]");
     55        Stream<String> redo = UndoRedoHandler.getInstance().getRedoCommands().stream()
     56                .filter(isParticipating)
     57                .map(c -> "[" + c.getDescriptionText() + " (undone)]");
     58        return Stream.concat(undo, redo)
     59                .collect(Collectors.joining(", ", " (changed by the following commands: ", ")"));
     60    }
    3761}
Note: See TracChangeset for help on using the changeset viewer.