annotate src/main/java/de/intevation/lada/data/LProbeRepository.java @ 303:c96fcc4dd5fd

New filter method with free parameters and resultset.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 16 Aug 2013 14:39:27 +0200
parents 0de24f5e7c01
children 567ce7697fc7
rev   line source
29
c5930d01e0ab Package renaming and code cosmetics.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
1 package de.intevation.lada.data;
14
de959fc71eda Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
2
303
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
3 import java.util.ArrayList;
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
4 import java.util.HashMap;
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
5 import java.util.List;
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
6 import java.util.Map;
24
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
7
99
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
8 import javax.ejb.EJBTransactionRolledbackException;
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
9 import javax.enterprise.context.ApplicationScoped;
14
de959fc71eda Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
10 import javax.inject.Inject;
92
197257807428 Moved validation into the LProbeRepository.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 91
diff changeset
11 import javax.inject.Named;
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
12 import javax.persistence.EntityExistsException;
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
13 import javax.persistence.EntityManager;
303
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
14 import javax.persistence.Query;
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
15 import javax.persistence.TransactionRequiredException;
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
16 import javax.persistence.criteria.CriteriaQuery;
303
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
17 import javax.ws.rs.core.MultivaluedMap;
14
de959fc71eda Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
18
303
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
19 import de.intevation.lada.auth.Authorization;
171
8bf3054109ba Use the generic data manager in repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 148
diff changeset
20 import de.intevation.lada.manage.Manager;
29
c5930d01e0ab Package renaming and code cosmetics.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
21 import de.intevation.lada.model.LProbe;
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
22 import de.intevation.lada.model.LProbeInfo;
94
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
23 import de.intevation.lada.rest.Response;
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
24 import de.intevation.lada.validation.ValidationException;
92
197257807428 Moved validation into the LProbeRepository.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 91
diff changeset
25 import de.intevation.lada.validation.Validator;
14
de959fc71eda Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
26
39
e0a5477f657e Documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 36
diff changeset
27 /**
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
28 * This Container is an interface to read, write and update LProbe objects.
39
e0a5477f657e Documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 36
diff changeset
29 *
e0a5477f657e Documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 36
diff changeset
30 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
e0a5477f657e Documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 36
diff changeset
31 */
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
32 @ApplicationScoped
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
33 @Named("lproberepository")
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
34 public class LProbeRepository implements Repository{
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
35 /**
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
36 * The entitymanager managing the data.
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
37 */
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
38 @Inject
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
39 private EntityManager em;
29
c5930d01e0ab Package renaming and code cosmetics.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
40
39
e0a5477f657e Documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 36
diff changeset
41 /**
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
42 * The data manager providing database operations.
39
e0a5477f657e Documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 36
diff changeset
43 */
24
dc3bfcc5f717 Added functions to delete and create (stub) proben items. Currently are not working
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 23
diff changeset
44 @Inject
171
8bf3054109ba Use the generic data manager in repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 148
diff changeset
45 @Named("datamanager")
8bf3054109ba Use the generic data manager in repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 148
diff changeset
46 private Manager manager;
29
c5930d01e0ab Package renaming and code cosmetics.
Raimund Renkert <rrenkert@intevation.de>
parents: 24
diff changeset
47
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
48 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
49 * The validator used for LProbe objects.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
50 */
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
51 @Inject
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
52 @Named("lprobevalidator")
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
53 private Validator validator;
118
ffe3234a4590 Minor code styling.
Raimund Renkert <rrenkert@intevation.de>
parents: 117
diff changeset
54
303
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
55 @Inject
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
56 @Named("dataauthorization")
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
57 private Authorization authorization;
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
58
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
59 public EntityManager getEntityManager() {
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
60 return this.em;
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
61 }
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
62
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
63 /**
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
64 * Filter object list by the given criteria.
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
65 *
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
66 * @param criteria The query filter
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
67 * @return Response object.
213
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
68 */
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
69 public <T> Response filter(CriteriaQuery<T> filter) {
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
70 List<T> result = em.createQuery(filter).getResultList();
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
71 return new Response(true, 200, result);
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
72 }
8fdb699405aa Refactored repositories to avoid race conditions.
Raimund Renkert <rrenkert@intevation.de>
parents: 191
diff changeset
73
303
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
74 public Response filterFree(
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
75 String sql,
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
76 List<String> filters,
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
77 List<String> results,
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
78 MultivaluedMap<String, String> params) {
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
79 Query query = em.createNativeQuery(sql);
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
80 for (String filter: filters) {
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
81 query.setParameter(filter, params.get(filter));
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
82 }
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
83 List<Object[]> result = query.getResultList();
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
84 List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
85 for (Object[] row: result) {
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
86 Map<String, Object> set = new HashMap<String, Object>();
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
87 for (int i = 0; i < row.length; i++) {
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
88 set.put(results.get(i), row[i]);
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
89 if (results.get(i).equals("probeId")) {
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
90 if (authorization.isReadOnly((String)row[i])) {
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
91 set.put("readonly", Boolean.TRUE);
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
92 }
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
93 else {
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
94 set.put("readonly", Boolean.FALSE);
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
95 }
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
96 }
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
97 }
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
98 res.add(set);
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
99 }
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
100 return new Response(true, 200, res);
c96fcc4dd5fd New filter method with free parameters and resultset.
Raimund Renkert <rrenkert@intevation.de>
parents: 260
diff changeset
101 }
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
102 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
103 * Get all objects.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
104 *
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
105 * @param clazz The object type. (unused)
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
106 * @return Response object.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
107 */
139
fda177c59d1f Updated service and repository to use the extended LProbeInfo object.
Raimund Renkert <rrenkert@intevation.de>
parents: 135
diff changeset
108 public <T> Response findAll(Class<T> clazz) {
182
a2e04ab2cd44 Use the new filter and query builder and have authentication for LProbeInfo objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 171
diff changeset
109 QueryBuilder<LProbeInfo> builder =
187
1a92e9ea68ba Get the entity manager from super class.
Raimund Renkert <rrenkert@intevation.de>
parents: 184
diff changeset
110 new QueryBuilder<LProbeInfo>(this.getEntityManager(), LProbeInfo.class);
182
a2e04ab2cd44 Use the new filter and query builder and have authentication for LProbeInfo objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 171
diff changeset
111 builder.distinct();
a2e04ab2cd44 Use the new filter and query builder and have authentication for LProbeInfo objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 171
diff changeset
112 return filter(builder.getQuery());
139
fda177c59d1f Updated service and repository to use the extended LProbeInfo object.
Raimund Renkert <rrenkert@intevation.de>
parents: 135
diff changeset
113 }
fda177c59d1f Updated service and repository to use the extended LProbeInfo object.
Raimund Renkert <rrenkert@intevation.de>
parents: 135
diff changeset
114
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
115 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
116 * Find object identified by its id.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
117 *
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
118 * @param clazz The object type.(unused)
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
119 * @param id The object id.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
120 * @return Response object.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
121 */
139
fda177c59d1f Updated service and repository to use the extended LProbeInfo object.
Raimund Renkert <rrenkert@intevation.de>
parents: 135
diff changeset
122 public <T> Response findById(Class<T> clazz, String id) {
182
a2e04ab2cd44 Use the new filter and query builder and have authentication for LProbeInfo objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 171
diff changeset
123 QueryBuilder<LProbeInfo> builder =
187
1a92e9ea68ba Get the entity manager from super class.
Raimund Renkert <rrenkert@intevation.de>
parents: 184
diff changeset
124 new QueryBuilder<LProbeInfo>(this.getEntityManager(), LProbeInfo.class);
182
a2e04ab2cd44 Use the new filter and query builder and have authentication for LProbeInfo objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 171
diff changeset
125 builder.and("probeId", id);
a2e04ab2cd44 Use the new filter and query builder and have authentication for LProbeInfo objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 171
diff changeset
126 builder.distinct();
a2e04ab2cd44 Use the new filter and query builder and have authentication for LProbeInfo objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 171
diff changeset
127 return filter(builder.getQuery());
35
f425150ea2b5 New filter option in LProbe GET request.
Raimund Renkert <rrenkert@intevation.de>
parents: 29
diff changeset
128 }
53
3a00c8fd5a8e New path in 'proben' REST service: '/details/{id}'. Delivering more detials for a LProbe.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
129
68
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
130 /**
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
131 * Validate and persist a new LProbe object.
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
132 *
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
133 * @param probe The new LProbe object
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
134 * @return Response.
68
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
135 */
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
136 public Response create(Object object) {
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
137 if (!(object instanceof LProbe)) {
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
138 return new Response(false, 602, object);
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
139 }
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
140 LProbe probe = (LProbe)object;
94
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
141 Response response = new Response(true, 200, probe);
68
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
142 // Try to save the new LProbe.
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
143 try {
260
0de24f5e7c01 Added boolean parameter to validate method to test if update or create was triggered.
Raimund Renkert <rrenkert@intevation.de>
parents: 220
diff changeset
144 Map<String, Integer> warnings = validator.validate(probe, false);
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
145 manager.create(probe);
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
146 response.setWarnings(warnings);
94
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
147 return response;
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
148 }
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
149 catch (EntityExistsException eee) {
94
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
150 response.setSuccess(false);
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
151 response.setMessage(601);
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
152 }
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
153 catch (IllegalArgumentException iae) {
94
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
154 response.setSuccess(false);
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
155 response.setMessage(602);
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
156 }
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
157 catch (TransactionRequiredException tre) {
94
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
158 response.setSuccess(false);
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
159 response.setMessage(603);
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
160 }
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
161 catch (ValidationException ve) {
94
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
162 response.setSuccess(false);
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
163 response.setMessage(604);
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
164 response.setErrors(ve.getErrors());
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
165 response.setWarnings(ve.getWarnings());
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
166 }
99
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
167 catch (EJBTransactionRolledbackException te) {
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
168 response.setSuccess(false);
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
169 response.setMessage(604);
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
170 }
94
b84855915980 The create function of the repository now build the response object an returns
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 92
diff changeset
171 return response;
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
172 }
53
3a00c8fd5a8e New path in 'proben' REST service: '/details/{id}'. Delivering more detials for a LProbe.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
173
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
174 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
175 * Validate and update a LProbe object.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
176 *
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
177 * @param object The object to update.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
178 * @return Response object.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
179 */
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
180 public Response update(Object object) {
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
181 if (!(object instanceof LProbe)) {
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
182 return new Response(false, 602, object);
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
183 }
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
184 LProbe probe = (LProbe)object;
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
185 Response response = new Response(true, 200, probe);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
186 try {
260
0de24f5e7c01 Added boolean parameter to validate method to test if update or create was triggered.
Raimund Renkert <rrenkert@intevation.de>
parents: 220
diff changeset
187 Map<String, Integer> warnings = validator.validate(probe, true);
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
188 manager.update(probe);
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
189 response.setWarnings(warnings);
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
190 return response;
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
191 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
192 catch (EntityExistsException eee) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
193 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
194 response.setMessage(601);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
195 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
196 catch (IllegalArgumentException iae) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
197 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
198 response.setMessage(602);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
199 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
200 catch (TransactionRequiredException tre) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
201 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
202 response.setMessage(603);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
203 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
204 catch (ValidationException ve) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
205 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
206 response.setMessage(604);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
207 response.setErrors(ve.getErrors());
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
208 response.setWarnings(ve.getWarnings());
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
209 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
210 catch (EJBTransactionRolledbackException te) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
211 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
212 response.setMessage(604);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
213 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
214 return response;
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
215 }
191
253160854d79 Added new method to delete objects to repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 187
diff changeset
216
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
217 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
218 * This class does not support this operation.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
219 *
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
220 * @param object
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
221 */
191
253160854d79 Added new method to delete objects to repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 187
diff changeset
222 public Response delete(Object object) {
253160854d79 Added new method to delete objects to repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 187
diff changeset
223 return null;
253160854d79 Added new method to delete objects to repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 187
diff changeset
224 }
14
de959fc71eda Added class to handle getting values from the database for the LProben model.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
225 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)