annotate src/main/java/de/intevation/lada/data/LProbeRepository.java @ 366:567ce7697fc7 0.5

Code documentation.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 10 Sep 2013 15:55:54 +0200
parents c96fcc4dd5fd
children ea4d2d685f32
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 *
366
567ce7697fc7 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 303
diff changeset
66 * @param filter The query filter
220
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 }
366
567ce7697fc7 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 303
diff changeset
102
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
103 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
104 * Get all objects.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
105 *
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
106 * @param clazz The object type. (unused)
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
107 * @return Response object.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
108 */
139
fda177c59d1f Updated service and repository to use the extended LProbeInfo object.
Raimund Renkert <rrenkert@intevation.de>
parents: 135
diff changeset
109 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
110 QueryBuilder<LProbeInfo> builder =
187
1a92e9ea68ba Get the entity manager from super class.
Raimund Renkert <rrenkert@intevation.de>
parents: 184
diff changeset
111 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
112 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
113 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
114 }
fda177c59d1f Updated service and repository to use the extended LProbeInfo object.
Raimund Renkert <rrenkert@intevation.de>
parents: 135
diff changeset
115
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
116 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
117 * Find object identified by its id.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
118 *
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
119 * @param clazz The object type.(unused)
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
120 * @param id The object id.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
121 * @return Response object.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
122 */
139
fda177c59d1f Updated service and repository to use the extended LProbeInfo object.
Raimund Renkert <rrenkert@intevation.de>
parents: 135
diff changeset
123 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
124 QueryBuilder<LProbeInfo> builder =
187
1a92e9ea68ba Get the entity manager from super class.
Raimund Renkert <rrenkert@intevation.de>
parents: 184
diff changeset
125 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
126 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
127 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
128 return filter(builder.getQuery());
35
f425150ea2b5 New filter option in LProbe GET request.
Raimund Renkert <rrenkert@intevation.de>
parents: 29
diff changeset
129 }
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
130
68
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
131 /**
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
132 * Validate and persist a new LProbe object.
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
133 *
366
567ce7697fc7 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 303
diff changeset
134 * @param object The new LProbe object
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
135 * @return Response.
68
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
136 */
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
137 public Response create(Object object) {
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
138 if (!(object instanceof LProbe)) {
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
139 return new Response(false, 602, object);
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
140 }
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
141 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
142 Response response = new Response(true, 200, probe);
68
9e34b7e872f9 Documentation and minor code cosmetics/renamings.
Raimund Renkert <rrenkert@intevation.de>
parents: 67
diff changeset
143 // Try to save the new LProbe.
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
144 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
145 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
146 manager.create(probe);
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
147 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
148 return response;
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
149 }
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
150 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
151 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
152 response.setMessage(601);
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
153 }
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
154 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
155 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
156 response.setMessage(602);
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
157 }
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
158 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
159 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
160 response.setMessage(603);
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
161 }
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
162 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
163 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
164 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
165 response.setErrors(ve.getErrors());
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
166 response.setWarnings(ve.getWarnings());
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
167 }
99
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
168 catch (EJBTransactionRolledbackException te) {
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
169 response.setSuccess(false);
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
170 response.setMessage(604);
bd5c69c4b769 Catch Rollback Exception.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 94
diff changeset
171 }
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
172 return response;
67
530a941dbf79 Updated the LProbeRepository and Service, Removed LProbeDetails
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
173 }
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
174
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
175 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
176 * Validate and update a LProbe object.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
177 *
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
178 * @param object The object to update.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
179 * @return Response object.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
180 */
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
181 public Response update(Object object) {
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
182 if (!(object instanceof LProbe)) {
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
183 return new Response(false, 602, object);
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
184 }
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 118
diff changeset
185 LProbe probe = (LProbe)object;
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
186 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
187 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
188 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
189 manager.update(probe);
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
190 response.setWarnings(warnings);
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
191 return response;
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
192 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
193 catch (EntityExistsException eee) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
194 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
195 response.setMessage(601);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
196 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
197 catch (IllegalArgumentException iae) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
198 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
199 response.setMessage(602);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
200 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
201 catch (TransactionRequiredException tre) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
202 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
203 response.setMessage(603);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
204 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
205 catch (ValidationException ve) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
206 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
207 response.setMessage(604);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
208 response.setErrors(ve.getErrors());
117
92b8b0e1e9fc Modified Validator interface and restructured the LProbe validation.
Raimund Renkert <rrenkert@intevation.de>
parents: 111
diff changeset
209 response.setWarnings(ve.getWarnings());
103
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
210 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
211 catch (EJBTransactionRolledbackException te) {
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
212 response.setSuccess(false);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
213 response.setMessage(604);
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
214 }
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
215 return response;
ffb008cf7c77 Added method to update a probe
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 99
diff changeset
216 }
191
253160854d79 Added new method to delete objects to repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 187
diff changeset
217
220
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
218 /**
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
219 * This class does not support this operation.
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
220 *
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
221 * @param object
f0482fa04e2b Code documentation and minor code style.
Raimund Renkert <rrenkert@intevation.de>
parents: 213
diff changeset
222 */
191
253160854d79 Added new method to delete objects to repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 187
diff changeset
223 public Response delete(Object object) {
253160854d79 Added new method to delete objects to repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 187
diff changeset
224 return null;
253160854d79 Added new method to delete objects to repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 187
diff changeset
225 }
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
226 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)