Subject: [PATCH] Multiple revert
---
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/plugins/reverter/src/reverter/RevertChangesetHandler.java b/plugins/reverter/src/reverter/RevertChangesetHandler.java
|
a
|
b
|
|
| 7 | 7 | import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; |
| 8 | 8 | import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler; |
| 9 | 9 | |
| | 10 | import java.util.List; |
| | 11 | import java.util.ArrayList; |
| | 12 | |
| 10 | 13 | public class RevertChangesetHandler extends RequestHandler { |
| 11 | 14 | public static final String command = "revert_changeset"; |
| 12 | 15 | public static final String permissionKey = "remotecontrol.permission.revert_changeset"; |
| 13 | 16 | public static final boolean permissionDefault = true; |
| 14 | 17 | |
| 15 | 18 | private int changesetId; |
| | 19 | private List<Integer> changesetIds = null; |
| 16 | 20 | |
| 17 | 21 | @Override |
| 18 | 22 | protected void handleRequest() throws RequestHandlerErrorException, |
| 19 | 23 | RequestHandlerBadRequestException { |
| 20 | 24 | try { |
| 21 | | MainApplication.worker.submit(new RevertChangesetTask(changesetId, ChangesetReverter.RevertType.FULL, true)); |
| | 25 | if (changesetIds == null) { |
| | 26 | MainApplication.worker.submit(new RevertChangesetTask(changesetId, ChangesetReverter.RevertType.FULL, true)); |
| | 27 | } else { |
| | 28 | MainApplication.worker.submit(new RevertChangesetTask(changesetIds, ChangesetReverter.RevertType.FULL, true, false)); |
| | 29 | } |
| 22 | 30 | } catch (Exception ex) { |
| 23 | 31 | System.out.println("RemoteControl: Error parsing revert_changeset remote control request:"); |
| 24 | 32 | ex.printStackTrace(); |
| … |
… |
|
| 28 | 36 | |
| 29 | 37 | @Override |
| 30 | 38 | public String[] getMandatoryParams() { |
| 31 | | return new String[] {"id"}; |
| | 39 | return new String[0]; |
| | 40 | } |
| | 41 | @Override |
| | 42 | public String[] getOptionalParams() { |
| | 43 | return new String[] {"id", "ids"}; |
| 32 | 44 | } |
| 33 | 45 | |
| 34 | 46 | @Override |
| … |
… |
|
| 43 | 55 | |
| 44 | 56 | @Override |
| 45 | 57 | protected void validateRequest() throws RequestHandlerBadRequestException { |
| 46 | | try { |
| 47 | | changesetId = Integer.parseInt(args.get("id")); |
| 48 | | } catch (NumberFormatException e) { |
| 49 | | throw new RequestHandlerBadRequestException("NumberFormatException: "+e.getMessage()); |
| | 58 | if (args.containsKey("id")) { |
| | 59 | try { |
| | 60 | changesetId = Integer.parseInt(args.get("id")); |
| | 61 | } catch (NumberFormatException e) { |
| | 62 | throw new RequestHandlerBadRequestException("NumberFormatException: " + e.getMessage()); |
| | 63 | } |
| | 64 | } else if (args.get("ids") != null) { |
| | 65 | try { |
| | 66 | changesetIds = new ArrayList<>(); |
| | 67 | for (String id : args.get("ids").split(",")) { |
| | 68 | changesetIds.add(Integer.parseInt(id)); |
| | 69 | } |
| | 70 | } catch (NumberFormatException e) { |
| | 71 | throw new RequestHandlerBadRequestException("NumberFormatException: " + e.getMessage()); |
| | 72 | } |
| | 73 | } else { |
| | 74 | throw new RequestHandlerBadRequestException(String.format("At least one of the optional arguments must be specified (%s)", |
| | 75 | String.join(", ", getOptionalParams()))); |
| 50 | 76 | } |
| 51 | 77 | } |
| 52 | 78 | } |