| .. | .. |
|---|
| 33 | 33 | import net.curisit.securis.security.Securable; |
|---|
| 34 | 34 | import net.curisit.securis.utils.TokenHelper; |
|---|
| 35 | 35 | |
|---|
| 36 | | -import org.jboss.resteasy.spi.ResteasyProviderFactory; |
|---|
| 37 | | -import org.apache.logging.log4j.Logger; |
|---|
| 38 | 36 | import org.apache.logging.log4j.LogManager; |
|---|
| 37 | +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 | |
|---|
| .. | .. |
|---|
| 53 | 53 | @Inject |
|---|
| 54 | 54 | private Provider<EntityManager> emProvider; |
|---|
| 55 | 55 | |
|---|
| 56 | | - public OrganizationResource() {} |
|---|
| 56 | + public OrganizationResource() { |
|---|
| 57 | + } |
|---|
| 57 | 58 | |
|---|
| 58 | 59 | /** |
|---|
| 59 | 60 | * |
|---|
| .. | .. |
|---|
| 61 | 62 | */ |
|---|
| 62 | 63 | @GET |
|---|
| 63 | 64 | @Path("/") |
|---|
| 64 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 65 | + @Produces({ |
|---|
| 66 | + MediaType.APPLICATION_JSON |
|---|
| 67 | + }) |
|---|
| 65 | 68 | @Securable |
|---|
| 66 | 69 | public Response index(@Context BasicSecurityContext bsc) { |
|---|
| 67 | 70 | LOG.info("Getting organizations list "); |
|---|
| .. | .. |
|---|
| 88 | 91 | */ |
|---|
| 89 | 92 | @GET |
|---|
| 90 | 93 | @Path("/{orgid}") |
|---|
| 91 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 94 | + @Produces({ |
|---|
| 95 | + MediaType.APPLICATION_JSON |
|---|
| 96 | + }) |
|---|
| 92 | 97 | @Securable |
|---|
| 93 | 98 | public Response get(@PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { |
|---|
| 94 | 99 | LOG.info("Getting organization data for id: {}: ", orgid); |
|---|
| .. | .. |
|---|
| 120 | 125 | @POST |
|---|
| 121 | 126 | @Path("/") |
|---|
| 122 | 127 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 123 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 128 | + @Produces({ |
|---|
| 129 | + MediaType.APPLICATION_JSON |
|---|
| 130 | + }) |
|---|
| 124 | 131 | @Transactional |
|---|
| 125 | 132 | @Securable |
|---|
| 126 | 133 | @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| .. | .. |
|---|
| 136 | 143 | |
|---|
| 137 | 144 | List<User> users = null; |
|---|
| 138 | 145 | List<String> usersIds = org.getUsersIds(); |
|---|
| 139 | | - if (usersIds != null && usersIds.size() > 0) { |
|---|
| 146 | + if (usersIds != null && !usersIds.isEmpty()) { |
|---|
| 140 | 147 | users = new ArrayList<>(); |
|---|
| 141 | 148 | for (String username : usersIds) { |
|---|
| 142 | 149 | User user = em.find(User.class, username); |
|---|
| .. | .. |
|---|
| 171 | 178 | |
|---|
| 172 | 179 | private void setOrgUsers(Organization org, List<String> usersIds, EntityManager em) throws SeCurisException { |
|---|
| 173 | 180 | List<User> users = null; |
|---|
| 174 | | - if (usersIds != null && usersIds.size() > 0) { |
|---|
| 181 | + if (usersIds != null && !usersIds.isEmpty()) { |
|---|
| 175 | 182 | users = new ArrayList<>(); |
|---|
| 176 | 183 | for (String username : usersIds) { |
|---|
| 177 | 184 | User user = em.find(User.class, username); |
|---|
| .. | .. |
|---|
| 191 | 198 | @Path("/{orgid}") |
|---|
| 192 | 199 | @Transactional |
|---|
| 193 | 200 | @Consumes(MediaType.APPLICATION_JSON) |
|---|
| 194 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 201 | + @Produces({ |
|---|
| 202 | + MediaType.APPLICATION_JSON |
|---|
| 203 | + }) |
|---|
| 195 | 204 | @Securable |
|---|
| 196 | 205 | @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| 197 | 206 | public Response modify(Organization org, @PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { |
|---|
| .. | .. |
|---|
| 208 | 217 | } catch (SeCurisException e) { |
|---|
| 209 | 218 | return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build(); |
|---|
| 210 | 219 | } |
|---|
| 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(); |
|---|
| 221 | 227 | } |
|---|
| 222 | 228 | |
|---|
| 223 | 229 | try { |
|---|
| .. | .. |
|---|
| 237 | 243 | @DELETE |
|---|
| 238 | 244 | @Path("/{orgid}") |
|---|
| 239 | 245 | @Transactional |
|---|
| 240 | | - @Produces({ MediaType.APPLICATION_JSON }) |
|---|
| 246 | + @Produces({ |
|---|
| 247 | + MediaType.APPLICATION_JSON |
|---|
| 248 | + }) |
|---|
| 241 | 249 | @Securable |
|---|
| 242 | 250 | @RolesAllowed(BasicSecurityContext.ROL_ADMIN) |
|---|
| 243 | 251 | public Response delete(@PathParam("orgid") String orgid, @Context HttpServletRequest request) { |
|---|
| .. | .. |
|---|
| 249 | 257 | return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization was not found, ID: " + orgid) |
|---|
| 250 | 258 | .build(); |
|---|
| 251 | 259 | } |
|---|
| 252 | | - if (org.getChildOrganizations() != null && org.getChildOrganizations().size() > 0) { |
|---|
| 260 | + if (org.getChildOrganizations() != null && !org.getChildOrganizations().isEmpty()) { |
|---|
| 253 | 261 | LOG.error("Organization has children and can not be deleted, ID: " + orgid); |
|---|
| 254 | 262 | return Response.status(Status.FORBIDDEN) |
|---|
| 255 | 263 | .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization has children and can not be deleted, ID: " + orgid).build(); |
|---|