Skip to content

Commit

Permalink
Datatable troubleshoot (#157)
Browse files Browse the repository at this point in the history
* experiment: ⚗️ disable single obs esupdate

* optimise: ⚡ optimised version of endpoints for datatable

* cleanup: ♻️ remove commented out code

* refactor: ♻️ sonar issue fixes iteration-1
  • Loading branch information
prakhar-s authored Nov 6, 2023
1 parent b859f0d commit 3f7fea8
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class UserGroupController {

@Inject
private UserGroupMemberService ugMemberService;

private static final String ERROR_OCCURED_IN_TRANSACTION = "Error occured in transaction";

@GET
@Path("/ping")
Expand Down Expand Up @@ -209,7 +211,34 @@ public Response createObservationUserGroupMapping(@Context HttpServletRequest re
List<Long> result = ugServices.createUserGroupObservationMapping(request, observationId, userGroupData,
true, userGroupData.getHasActivity() != null ? userGroupData.getHasActivity() : true);
if (result == null)
return Response.status(Status.CONFLICT).entity("Error occured in transaction").build();
return Response.status(Status.CONFLICT).entity(ERROR_OCCURED_IN_TRANSACTION).build();
return Response.status(Status.CREATED).entity(result).build();

} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}

@POST
@Path(ApiConstants.CREATE + "/datatable" + "/{obsId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

@ValidateUser
@ApiOperation(value = "Create Observation UserGroup Mapping", notes = "Returns List of UserGroup", response = Long.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 404, message = "UserGroup Not Found ", response = String.class),
@ApiResponse(code = 409, message = "UserGroup-Observation Mapping Cannot be Created", response = String.class) })

public Response createObservationUserGroupMappingDatatable(@Context HttpServletRequest request,
@PathParam("obsId") String obsId,
@ApiParam(name = "userGroupData") UserGroupMappingCreateData userGroupData) {
try {

Long observationId = Long.parseLong(obsId);
List<Long> result = ugServices.createUserGroupObservationMapping(request, observationId, userGroupData,
false, userGroupData.getHasActivity() != null ? userGroupData.getHasActivity() : true);
if (result == null)
return Response.status(Status.CONFLICT).entity(ERROR_OCCURED_IN_TRANSACTION).build();
return Response.status(Status.CREATED).entity(result).build();

} catch (Exception e) {
Expand Down Expand Up @@ -1230,7 +1259,7 @@ public Response createDatatableUserGroupMapping(@Context HttpServletRequest requ
List<Long> result = udDatatableService.createUserGroupDatatableMapping(request, datatableId,
userGroupData.getUserGroupIds());
if (result == null)
return Response.status(Status.CONFLICT).entity("Error occured in transaction").build();
return Response.status(Status.CONFLICT).entity(ERROR_OCCURED_IN_TRANSACTION).build();
return Response.status(Status.CREATED).entity(result).build();

} catch (Exception e) {
Expand Down Expand Up @@ -1331,4 +1360,30 @@ public Response removeObservationUserGroup(@Context HttpServletRequest request,
}
}

@DELETE
@Path(ApiConstants.REMOVE + "/datatable" + "/{obsId}/{ugId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

@ValidateUser
@ApiOperation(value = "Create Observation UserGroup Mapping", notes = "Returns UserGroup Observation", response = UserGroupIbp.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 404, message = "UserGroup Not Found ", response = String.class),
@ApiResponse(code = 409, message = "UserGroup-Observation Mapping Cannot be Created", response = String.class) })

public Response removeObservationUserGroupDatatable(@Context HttpServletRequest request,
@PathParam("obsId") String obsId, @PathParam("ugId") String ugId) {
try {

Long observationId = Long.parseLong(obsId);
Long userGroupId = Long.parseLong(ugId);

List<UserGroupIbp> result = ugServices.removeUserGroupObervationForDatatable(request, observationId,
userGroupId);
return Response.status(Status.OK).entity(result).build();

} catch (Exception e) {
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ public List<UserGroupIbp> updateUGSpeciesMapping(HttpServletRequest request, Lon

public List<UserGroupIbp> removeUserGroupObervation(HttpServletRequest request, Long ObvId, Long ugId);

public List<UserGroupIbp> removeUserGroupObervationForDatatable(HttpServletRequest request, Long obvId, Long ugId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2223,4 +2223,28 @@ public List<UserGroupIbp> removeUserGroupObervation(HttpServletRequest request,
return null;
}

@Override
public List<UserGroupIbp> removeUserGroupObervationForDatatable(HttpServletRequest request, Long obvId, Long ugId) {

CommonProfile profile = AuthUtil.getProfileFromRequest(request);
JSONArray roles = (JSONArray) profile.getAttribute("roles");
Long userId = Long.parseLong(profile.getId());
Boolean eligible = ugMemberService.checkUserGroupMember(userId, ugId);
if (roles.contains(roleAdmin) || Boolean.TRUE.equals(eligible)) {
UserGroupObservation ugObvMapping = ugObvDao.checkObservationUGMApping(obvId, ugId);

try {
if (ugObvMapping != null) {
ugObvDao.delete(ugObvMapping);
}

} catch (Exception e) {
logger.error(e.getMessage());
}
return fetchByObservationId(obvId);
}

return null;
}

}

0 comments on commit 3f7fea8

Please sign in to comment.