diff --git a/src/main/java/org/caosdb/server/entity/Message.java b/src/main/java/org/caosdb/server/entity/Message.java index bdf6488d15a1d77b3038ece18541cab78ee9c805..63cf8210becc916447ac9e64cebcf094e179f865 100644 --- a/src/main/java/org/caosdb/server/entity/Message.java +++ b/src/main/java/org/caosdb/server/entity/Message.java @@ -21,6 +21,8 @@ */ package org.caosdb.server.entity; +import java.util.HashMap; +import java.util.Map; import org.caosdb.api.entity.v1.MessageCode; import org.caosdb.server.entity.xml.ToElementable; import org.jdom2.Element; @@ -32,6 +34,22 @@ public class Message extends Exception implements Comparable<Message>, ToElement private final String description; private final String body; + @Deprecated private static final Map<MessageCode, String> legacy_codes_mapping = new HashMap<>(); + + static { + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_ENTITY_HAS_BEEN_DELETED_SUCCESSFULLY, "10"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_ATOMICITY_ERROR, "12"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_ENTITY_DOES_NOT_EXIST, "101"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_PROPERTY_HAS_NO_DATA_TYPE, "110"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_ENTITY_HAS_UNQUALIFIED_PROPERTIES, "114"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_ENTITY_HAS_UNQUALIFIED_PARENTS, "116"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_WARNING_OCCURED, "128"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_ENTITY_NAME_IS_NOT_UNIQUE, "152"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_REQUIRED_BY_UNQUALIFIED, "192"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_REFERENCED_ENTITY_DOES_NOT_EXIST, "235"); + legacy_codes_mapping.put(MessageCode.MESSAGE_CODE_AUTHORIZATION_ERROR, "403"); + } + private static final long serialVersionUID = 1837110172902899264L; public enum MessageType { @@ -49,7 +67,7 @@ public class Message extends Exception implements Comparable<Message>, ToElement public String toString() { return this.type.toString() + " (" - + this.code.toString() + + (this.code != null ? this.code.toString() : "") + ") - " + (this.description != null ? this.description : ""); } @@ -129,8 +147,12 @@ public class Message extends Exception implements Comparable<Message>, ToElement public Element toElement() { final Element e = new Element(this.type); - if (this.code != null) { - e.setAttribute("code", this.code.toString()); + if (this.code != null && this.code != MessageCode.MESSAGE_CODE_UNKNOWN) { + if (legacy_codes_mapping.containsKey(this.code)) { + e.setAttribute("code", legacy_codes_mapping.get(this.code)); + } else { + e.setAttribute("code", Integer.toString(this.code.getNumber())); + } } if (this.description != null) { e.setAttribute("description", this.description);