source: josm/trunk/src/org/openstreetmap/josm/data/osm/DataIntegrityProblemException.java

Last change on this file was 16546, checked in by simon04, 4 years ago

fix #19343 - DataIntegrityProblemException: report commands involving relevant primitives

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package 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;
11
12/**
13 * Exception thrown when a primitive or data set does not pass its integrity checks.
14 * @since 2399
15 */
16public class DataIntegrityProblemException extends RuntimeException {
17
18 private final String htmlMessage;
19
20 /**
21 * Constructs a new {@code DataIntegrityProblemException}.
22 * @param message the detail message
23 */
24 public DataIntegrityProblemException(String message) {
25 this(message, null);
26 }
27
28 /**
29 * Constructs a new {@code DataIntegrityProblemException}.
30 * @param message the detail message
31 * @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)
33 */
34 public DataIntegrityProblemException(String message, String htmlMessage, OsmPrimitive... p) {
35 super(message + relevantCommands(p));
36 this.htmlMessage = htmlMessage;
37 }
38
39 /**
40 * Returns the HTML-formatted error message.
41 * @return the HTML-formatted error message, or null
42 */
43 public String getHtmlMessage() {
44 return htmlMessage;
45 }
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 }
61}
Note: See TracBrowser for help on using the repository browser.