rsanchez
2014-12-12 4c13c7324a920f5cca9601154e5224e5d7484fa9
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
....@@ -1,8 +1,9 @@
11 package net.curisit.securis.services;
22
3
-import java.util.ArrayList;
43 import java.util.Date;
4
+import java.util.HashSet;
55 import java.util.List;
6
+import java.util.Set;
67
78 import javax.annotation.security.RolesAllowed;
89 import javax.inject.Inject;
....@@ -35,7 +36,6 @@
3536
3637 import org.apache.logging.log4j.LogManager;
3738 import org.apache.logging.log4j.Logger;
38
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
3939
4040 import com.google.inject.persist.Transactional;
4141
....@@ -69,9 +69,8 @@
6969 public Response index(@Context BasicSecurityContext bsc) {
7070 LOG.info("Getting organizations list ");
7171
72
- BasicSecurityContext bsc2 = ResteasyProviderFactory.getContextData(BasicSecurityContext.class);
73
- LOG.debug("securityContext ROL_ADMIN?: {}", bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN));
7472 EntityManager em = emProvider.get();
73
+ em.clear();
7574 TypedQuery<Organization> q;
7675 if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
7776 LOG.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
....@@ -103,6 +102,7 @@
103102 }
104103
105104 EntityManager em = emProvider.get();
105
+ em.clear();
106106 Organization org = em.find(Organization.class, Integer.parseInt(orgid));
107107 if (org == null) {
108108 LOG.error("Organization with id {} not found in DB", orgid);
....@@ -141,10 +141,10 @@
141141 return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
142142 }
143143
144
- List<User> users = null;
145
- List<String> usersIds = org.getUsersIds();
144
+ Set<User> users = null;
145
+ Set<String> usersIds = org.getUsersIds();
146146 if (usersIds != null && !usersIds.isEmpty()) {
147
- users = new ArrayList<>();
147
+ users = new HashSet<>();
148148 for (String username : usersIds) {
149149 User user = em.find(User.class, username);
150150 if (user == null) {
....@@ -176,10 +176,10 @@
176176 org.setParentOrganization(parentOrg);
177177 }
178178
179
- private void setOrgUsers(Organization org, List<String> usersIds, EntityManager em) throws SeCurisException {
180
- List<User> users = null;
179
+ private void setOrgUsers(Organization org, Set<String> usersIds, EntityManager em) throws SeCurisException {
180
+ Set<User> users = null;
181181 if (usersIds != null && !usersIds.isEmpty()) {
182
- users = new ArrayList<>();
182
+ users = new HashSet<>();
183183 for (String username : usersIds) {
184184 User user = em.find(User.class, username);
185185 if (user == null) {