Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/util/rest/Response.java @ 539:deb3fec601ed
Use multivalued map for errors and warnings to be able to store more than one
error/warning per item.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 24 Feb 2015 14:56:46 +0100 |
parents | 8751d2135364 |
children | 3ec358698b4d |
comparison
equal
deleted
inserted
replaced
538:fd927b584c54 | 539:deb3fec601ed |
---|---|
8 package de.intevation.lada.util.rest; | 8 package de.intevation.lada.util.rest; |
9 | 9 |
10 import java.io.Serializable; | 10 import java.io.Serializable; |
11 import java.util.HashMap; | 11 import java.util.HashMap; |
12 import java.util.Map; | 12 import java.util.Map; |
13 | |
14 import javax.ws.rs.core.MultivaluedHashMap; | |
15 import javax.ws.rs.core.MultivaluedMap; | |
13 | 16 |
14 | 17 |
15 /** | 18 /** |
16 * Response object storing information about success, warnings, errors and | 19 * Response object storing information about success, warnings, errors and |
17 * the data object. This class is used as return value in REST services. | 20 * the data object. This class is used as return value in REST services. |
23 private static final long serialVersionUID = 1L; | 26 private static final long serialVersionUID = 1L; |
24 | 27 |
25 private Boolean success; | 28 private Boolean success; |
26 private String message; | 29 private String message; |
27 private Object data; | 30 private Object data; |
28 private Map<String, String> errors; | 31 private MultivaluedMap<String, Integer> errors; |
29 private Map<String, String> warnings; | 32 private MultivaluedMap<String, Integer> warnings; |
30 private Boolean readonly; | 33 private Boolean readonly; |
31 private int totalCount; | 34 private int totalCount; |
32 | 35 |
33 /** | 36 /** |
34 * Constructor to create a basic Response object. | 37 * Constructor to create a basic Response object. |
39 */ | 42 */ |
40 public Response(boolean success, int code, Object data) { | 43 public Response(boolean success, int code, Object data) { |
41 this.success = success; | 44 this.success = success; |
42 this.message = Integer.toString(code); | 45 this.message = Integer.toString(code); |
43 this.data = data; | 46 this.data = data; |
44 this.errors = new HashMap<String, String>(); | 47 this.errors = new MultivaluedHashMap<String, Integer>(); |
45 this.warnings = new HashMap<String, String>(); | 48 this.warnings = new MultivaluedHashMap<String, Integer>(); |
46 this.readonly = Boolean.FALSE; | 49 this.readonly = Boolean.FALSE; |
47 this.totalCount = 0; | 50 this.totalCount = 0; |
48 } | 51 } |
49 | 52 |
50 /** | 53 /** |
56 */ | 59 */ |
57 public Response(boolean success, int code, Object data, int totalCount) { | 60 public Response(boolean success, int code, Object data, int totalCount) { |
58 this.success = success; | 61 this.success = success; |
59 this.message = Integer.toString(code); | 62 this.message = Integer.toString(code); |
60 this.data = data; | 63 this.data = data; |
61 this.errors = new HashMap<String, String>(); | 64 this.errors = new MultivaluedHashMap<String, Integer>(); |
62 this.warnings = new HashMap<String, String>(); | 65 this.warnings = new MultivaluedHashMap<String, Integer>(); |
63 this.readonly = Boolean.FALSE; | 66 this.readonly = Boolean.FALSE; |
64 this.totalCount = totalCount; | 67 this.totalCount = totalCount; |
65 } | 68 } |
66 | 69 |
67 public Boolean getSuccess() { | 70 public Boolean getSuccess() { |
86 | 89 |
87 public void setData(Object data) { | 90 public void setData(Object data) { |
88 this.data = data; | 91 this.data = data; |
89 } | 92 } |
90 | 93 |
91 public Map<String, String> getErrors() { | 94 public MultivaluedMap<String, Integer> getErrors() { |
92 return errors; | 95 return errors; |
93 } | 96 } |
94 | 97 |
95 public void setErrors(Map<String, Integer> errors) { | 98 public void setErrors(MultivaluedMap<String, Integer> errors) { |
96 this.errors = this.convertCodes(errors); | 99 this.errors.putAll(errors); |
100 // this.errors = this.convertCodes(errors); | |
97 } | 101 } |
98 | 102 |
99 public Map<String, String> getWarnings() { | 103 public MultivaluedMap<String, Integer> getWarnings() { |
100 return warnings; | 104 return warnings; |
101 } | 105 } |
102 | 106 |
103 public void setWarnings(Map<String, Integer> warnings) { | 107 public void setWarnings(MultivaluedMap<String, Integer> warnings) { |
104 this.warnings = this.convertCodes(warnings); | 108 this.warnings.putAll(warnings); |
109 //this.warnings = this.convertCodes(warnings); | |
105 } | 110 } |
106 | 111 |
107 public Boolean getReadonly() { | 112 public Boolean getReadonly() { |
108 return readonly; | 113 return readonly; |
109 } | 114 } |
124 */ | 129 */ |
125 public void setTotalCount(int totalCount) { | 130 public void setTotalCount(int totalCount) { |
126 this.totalCount = totalCount; | 131 this.totalCount = totalCount; |
127 } | 132 } |
128 | 133 |
134 @SuppressWarnings("unused") | |
129 private HashMap<String, String> convertCodes(Map<String, Integer> codes) { | 135 private HashMap<String, String> convertCodes(Map<String, Integer> codes) { |
130 HashMap<String, String> converted = new HashMap<String, String>(); | 136 HashMap<String, String> converted = new HashMap<String, String>(); |
131 if (codes == null || codes.isEmpty()) { | 137 if (codes == null || codes.isEmpty()) { |
132 return converted; | 138 return converted; |
133 } | 139 } |