Skip to content

Commit

Permalink
refactor: ♻️ sonar issue fixes iteration-1
Browse files Browse the repository at this point in the history
  • Loading branch information
prakhar-s committed Nov 4, 2023
1 parent a20ec6c commit 72aaccf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 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,7 @@ 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) {
Expand All @@ -236,7 +238,7 @@ public Response createObservationUserGroupMappingDatatable(@Context HttpServletR
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.CONFLICT).entity(ERROR_OCCURED_IN_TRANSACTION).build();
return Response.status(Status.CREATED).entity(result).build();

} catch (Exception e) {
Expand Down Expand Up @@ -1257,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
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +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);
public List<UserGroupIbp> removeUserGroupObervationForDatatable(HttpServletRequest request, Long obvId, Long ugId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2224,14 +2224,14 @@ public List<UserGroupIbp> removeUserGroupObervation(HttpServletRequest request,
}

@Override
public List<UserGroupIbp> removeUserGroupObervationForDatatable(HttpServletRequest request, Long ObvId, Long ugId) {
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);
UserGroupObservation ugObvMapping = ugObvDao.checkObservationUGMApping(obvId, ugId);

try {
if (ugObvMapping != null) {
Expand All @@ -2241,7 +2241,7 @@ public List<UserGroupIbp> removeUserGroupObervationForDatatable(HttpServletReque
} catch (Exception e) {
logger.error(e.getMessage());
}
return fetchByObservationId(ObvId);
return fetchByObservationId(obvId);
}

return null;
Expand Down

0 comments on commit 72aaccf

Please sign in to comment.