Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/util/auth/BaseAuthorizer.java @ 1028:1c41c7b8f7c2 schema-update
Updated server application to new database model. THIS IS STILL WIP!!!
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 08 Jul 2016 15:32:36 +0200 |
parents | d0a591b3eade |
children |
comparison
equal
deleted
inserted
replaced
1027:9971471d562c | 1028:1c41c7b8f7c2 |
---|---|
10 import java.util.List; | 10 import java.util.List; |
11 | 11 |
12 import javax.inject.Inject; | 12 import javax.inject.Inject; |
13 import javax.persistence.EntityManager; | 13 import javax.persistence.EntityManager; |
14 | 14 |
15 import de.intevation.lada.model.land.LMessung; | 15 import de.intevation.lada.model.land.Messung; |
16 import de.intevation.lada.model.land.LProbe; | 16 import de.intevation.lada.model.land.Probe; |
17 import de.intevation.lada.model.land.LStatusProtokoll; | 17 import de.intevation.lada.model.land.StatusProtokoll; |
18 import de.intevation.lada.model.stammdaten.StatusKombi; | |
18 import de.intevation.lada.util.annotation.RepositoryConfig; | 19 import de.intevation.lada.util.annotation.RepositoryConfig; |
19 import de.intevation.lada.util.data.QueryBuilder; | 20 import de.intevation.lada.util.data.QueryBuilder; |
20 import de.intevation.lada.util.data.Repository; | 21 import de.intevation.lada.util.data.Repository; |
21 import de.intevation.lada.util.data.RepositoryType; | 22 import de.intevation.lada.util.data.RepositoryType; |
22 import de.intevation.lada.util.rest.Response; | 23 import de.intevation.lada.util.rest.Response; |
34 * Get the authorization of a single probe. | 35 * Get the authorization of a single probe. |
35 * | 36 * |
36 * @param userInfo The user information. | 37 * @param userInfo The user information. |
37 * @param probe The probe to authorize. | 38 * @param probe The probe to authorize. |
38 */ | 39 */ |
39 protected boolean getAuthorization(UserInfo userInfo, LProbe probe) { | 40 protected boolean getAuthorization(UserInfo userInfo, Probe probe) { |
40 if (userInfo.getMessstellen().contains(probe.getMstId())) { | 41 if (userInfo.getMessstellen().contains(probe.getMstId())) { |
41 return true; | 42 return true; |
42 } | 43 } |
43 else { | 44 else { |
44 return false; | 45 return false; |
51 * @param probeId The probe Id. | 52 * @param probeId The probe Id. |
52 * @return True if the probe is readonly. | 53 * @return True if the probe is readonly. |
53 */ | 54 */ |
54 public boolean isProbeReadOnly(Integer probeId) { | 55 public boolean isProbeReadOnly(Integer probeId) { |
55 EntityManager manager = repository.entityManager("land"); | 56 EntityManager manager = repository.entityManager("land"); |
56 QueryBuilder<LMessung> builder = | 57 QueryBuilder<Messung> builder = |
57 new QueryBuilder<LMessung>( | 58 new QueryBuilder<Messung>( |
58 manager, | 59 manager, |
59 LMessung.class); | 60 Messung.class); |
60 builder.and("probeId", probeId); | 61 builder.and("probeId", probeId); |
61 Response response = repository.filter(builder.getQuery(), "land"); | 62 Response response = repository.filter(builder.getQuery(), "land"); |
62 @SuppressWarnings("unchecked") | 63 @SuppressWarnings("unchecked") |
63 List<LMessung> messungen = (List<LMessung>) response.getData(); | 64 List<Messung> messungen = (List<Messung>) response.getData(); |
64 for (int i = 0; i < messungen.size(); i++) { | 65 for (int i = 0; i < messungen.size(); i++) { |
65 if (messungen.get(i).getStatus() == null) { | 66 if (messungen.get(i).getStatus() == null) { |
66 continue; | 67 continue; |
67 } | 68 } |
68 LStatusProtokoll status = repository.getByIdPlain( | 69 StatusProtokoll status = repository.getByIdPlain( |
69 LStatusProtokoll.class, messungen.get(i).getStatus(), "land"); | 70 StatusProtokoll.class, messungen.get(i).getStatus(), "land"); |
70 if (status.getStatusWert() != 0 && status.getStatusWert() != 4) { | 71 StatusKombi kombi = repository.getByIdPlain( |
72 StatusKombi.class, status.getStatusKombi(), "stamm"); | |
73 if (kombi.getStatusWert().getId() != 0 && | |
74 kombi.getStatusWert().getId() != 4) { | |
71 return true; | 75 return true; |
72 } | 76 } |
73 } | 77 } |
74 return false; | 78 return false; |
75 } | 79 } |
76 | 80 |
77 public boolean isMessungReadOnly(Integer messungsId) { | 81 public boolean isMessungReadOnly(Integer messungsId) { |
78 LMessung messung = | 82 Messung messung = |
79 repository.getByIdPlain(LMessung.class, messungsId, "land"); | 83 repository.getByIdPlain(Messung.class, messungsId, "land"); |
80 if (messung.getStatus() == null) { | 84 if (messung.getStatus() == null) { |
81 return false; | 85 return false; |
82 } | 86 } |
83 LStatusProtokoll status = repository.getByIdPlain( | 87 StatusProtokoll status = repository.getByIdPlain( |
84 LStatusProtokoll.class, | 88 StatusProtokoll.class, |
85 messung.getStatus(), | 89 messung.getStatus(), |
86 "land"); | 90 "land"); |
87 return (status.getStatusWert() != 0 && status.getStatusWert() != 4); | 91 StatusKombi kombi = repository.getByIdPlain( |
92 StatusKombi.class, status.getStatusKombi(), "stamm"); | |
93 return (kombi.getStatusWert().getId() != 0 && | |
94 kombi.getStatusWert().getId() != 4); | |
88 } | 95 } |
89 | 96 |
90 } | 97 } |