Roberto Sánchez
2014-09-19 071a008cf28e733ca3aaafa57e675fd54a5ea33b
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
....@@ -33,9 +33,9 @@
3333 import net.curisit.securis.security.Securable;
3434 import net.curisit.securis.utils.TokenHelper;
3535
36
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
37
-import org.apache.logging.log4j.Logger;
3836 import org.apache.logging.log4j.LogManager;
37
+import org.apache.logging.log4j.Logger;
38
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
3939
4040 import com.google.inject.persist.Transactional;
4141
....@@ -53,7 +53,8 @@
5353 @Inject
5454 private Provider<EntityManager> emProvider;
5555
56
- public OrganizationResource() {}
56
+ public OrganizationResource() {
57
+ }
5758
5859 /**
5960 *
....@@ -61,7 +62,9 @@
6162 */
6263 @GET
6364 @Path("/")
64
- @Produces({ MediaType.APPLICATION_JSON })
65
+ @Produces({
66
+ MediaType.APPLICATION_JSON
67
+ })
6568 @Securable
6669 public Response index(@Context BasicSecurityContext bsc) {
6770 LOG.info("Getting organizations list ");
....@@ -88,7 +91,9 @@
8891 */
8992 @GET
9093 @Path("/{orgid}")
91
- @Produces({ MediaType.APPLICATION_JSON })
94
+ @Produces({
95
+ MediaType.APPLICATION_JSON
96
+ })
9297 @Securable
9398 public Response get(@PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
9499 LOG.info("Getting organization data for id: {}: ", orgid);
....@@ -120,7 +125,9 @@
120125 @POST
121126 @Path("/")
122127 @Consumes(MediaType.APPLICATION_JSON)
123
- @Produces({ MediaType.APPLICATION_JSON })
128
+ @Produces({
129
+ MediaType.APPLICATION_JSON
130
+ })
124131 @Transactional
125132 @Securable
126133 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
....@@ -136,7 +143,7 @@
136143
137144 List<User> users = null;
138145 List<String> usersIds = org.getUsersIds();
139
- if (usersIds != null && usersIds.size() > 0) {
146
+ if (usersIds != null && !usersIds.isEmpty()) {
140147 users = new ArrayList<>();
141148 for (String username : usersIds) {
142149 User user = em.find(User.class, username);
....@@ -171,7 +178,7 @@
171178
172179 private void setOrgUsers(Organization org, List<String> usersIds, EntityManager em) throws SeCurisException {
173180 List<User> users = null;
174
- if (usersIds != null && usersIds.size() > 0) {
181
+ if (usersIds != null && !usersIds.isEmpty()) {
175182 users = new ArrayList<>();
176183 for (String username : usersIds) {
177184 User user = em.find(User.class, username);
....@@ -191,7 +198,9 @@
191198 @Path("/{orgid}")
192199 @Transactional
193200 @Consumes(MediaType.APPLICATION_JSON)
194
- @Produces({ MediaType.APPLICATION_JSON })
201
+ @Produces({
202
+ MediaType.APPLICATION_JSON
203
+ })
195204 @Securable
196205 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
197206 public Response modify(Organization org, @PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
....@@ -208,16 +217,13 @@
208217 } catch (SeCurisException e) {
209218 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
210219 }
211
- if (org.getParentOrganization() != null) {
212
- if (isCyclicalRelationship(currentOrg.getId(), org.getParentOrganization())) {
213
- LOG.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(),
214
- currentOrg.getId());
215
- return Response
216
- .status(Status.FORBIDDEN)
217
- .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
218
- "Cyclical relationships are not allowed, please change the parent organization, current Parent: "
219
- + org.getParentOrganization().getName()).build();
220
- }
220
+ if (org.getParentOrganization() != null && (isCyclicalRelationship(currentOrg.getId(), org.getParentOrganization()))) {
221
+ LOG.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId());
222
+ return Response
223
+ .status(Status.FORBIDDEN)
224
+ .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
225
+ "Cyclical relationships are not allowed, please change the parent organization, current Parent: "
226
+ + org.getParentOrganization().getName()).build();
221227 }
222228
223229 try {
....@@ -237,7 +243,9 @@
237243 @DELETE
238244 @Path("/{orgid}")
239245 @Transactional
240
- @Produces({ MediaType.APPLICATION_JSON })
246
+ @Produces({
247
+ MediaType.APPLICATION_JSON
248
+ })
241249 @Securable
242250 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
243251 public Response delete(@PathParam("orgid") String orgid, @Context HttpServletRequest request) {
....@@ -249,7 +257,7 @@
249257 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization was not found, ID: " + orgid)
250258 .build();
251259 }
252
- if (org.getChildOrganizations() != null && org.getChildOrganizations().size() > 0) {
260
+ if (org.getChildOrganizations() != null && !org.getChildOrganizations().isEmpty()) {
253261 LOG.error("Organization has children and can not be deleted, ID: " + orgid);
254262 return Response.status(Status.FORBIDDEN)
255263 .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization has children and can not be deleted, ID: " + orgid).build();