Skip to content
Snippets Groups Projects
Verified Commit d8c00702 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Update Message class

parent 44c7aa5d
No related branches found
No related tags found
3 merge requests!44Release 0.6,!43Merge f-GRPC-main to dev,!42DEPS: Update proto and fix breaking changes
Pipeline #15816 passed
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment