| .. | .. |
|---|
| 1 | 1 | package net.curisit.securis.services; |
|---|
| 2 | 2 | |
|---|
| 3 | | -import java.util.ArrayList; |
|---|
| 4 | 3 | import java.util.Date; |
|---|
| 4 | +import java.util.HashSet; |
|---|
| 5 | 5 | import java.util.List; |
|---|
| 6 | +import java.util.Set; |
|---|
| 6 | 7 | |
|---|
| 7 | 8 | import javax.annotation.security.RolesAllowed; |
|---|
| 8 | 9 | import javax.inject.Inject; |
|---|
| .. | .. |
|---|
| 35 | 36 | |
|---|
| 36 | 37 | import org.apache.logging.log4j.LogManager; |
|---|
| 37 | 38 | import org.apache.logging.log4j.Logger; |
|---|
| 38 | | -import org.jboss.resteasy.spi.ResteasyProviderFactory; |
|---|
| 39 | 39 | |
|---|
| 40 | 40 | import com.google.inject.persist.Transactional; |
|---|
| 41 | 41 | |
|---|
| .. | .. |
|---|
| 69 | 69 | public Response index(@Context BasicSecurityContext bsc) { |
|---|
| 70 | 70 | LOG.info("Getting organizations list "); |
|---|
| 71 | 71 | |
|---|
| 72 | | - BasicSecurityContext bsc2 = ResteasyProviderFactory.getContextData(BasicSecurityContext.class); |
|---|
| 73 | | - LOG.debug("securityContext ROL_ADMIN?: {}", bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)); |
|---|
| 74 | 72 | EntityManager em = emProvider.get(); |
|---|
| 73 | + em.clear(); |
|---|
| 75 | 74 | TypedQuery<Organization> q; |
|---|
| 76 | 75 | if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) { |
|---|
| 77 | 76 | LOG.info("GEtting all orgs for user: " + bsc.getUserPrincipal()); |
|---|
| .. | .. |
|---|
| 103 | 102 | } |
|---|
| 104 | 103 | |
|---|
| 105 | 104 | EntityManager em = emProvider.get(); |
|---|
| 105 | + em.clear(); |
|---|
| 106 | 106 | Organization org = em.find(Organization.class, Integer.parseInt(orgid)); |
|---|
| 107 | 107 | if (org == null) { |
|---|
| 108 | 108 | LOG.error("Organization with id {} not found in DB", orgid); |
|---|
| .. | .. |
|---|
| 141 | 141 | return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build(); |
|---|
| 142 | 142 | } |
|---|
| 143 | 143 | |
|---|
| 144 | | - List<User> users = null; |
|---|
| 145 | | - List<String> usersIds = org.getUsersIds(); |
|---|
| 144 | + Set<User> users = null; |
|---|
| 145 | + Set<String> usersIds = org.getUsersIds(); |
|---|
| 146 | 146 | if (usersIds != null && !usersIds.isEmpty()) { |
|---|
| 147 | | - users = new ArrayList<>(); |
|---|
| 147 | + users = new HashSet<>(); |
|---|
| 148 | 148 | for (String username : usersIds) { |
|---|
| 149 | 149 | User user = em.find(User.class, username); |
|---|
| 150 | 150 | if (user == null) { |
|---|
| .. | .. |
|---|
| 176 | 176 | org.setParentOrganization(parentOrg); |
|---|
| 177 | 177 | } |
|---|
| 178 | 178 | |
|---|
| 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; |
|---|
| 181 | 181 | if (usersIds != null && !usersIds.isEmpty()) { |
|---|
| 182 | | - users = new ArrayList<>(); |
|---|
| 182 | + users = new HashSet<>(); |
|---|
| 183 | 183 | for (String username : usersIds) { |
|---|
| 184 | 184 | User user = em.find(User.class, username); |
|---|
| 185 | 185 | if (user == null) { |
|---|