Revert global exception msg

merge-requests/915/head
shamalka 2 years ago
parent 87ef31ab1b
commit d61814329c

@ -497,7 +497,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj.getString("error")).build();
} else {
int userId = obj.getInt("id");
String msg = "";
List<Integer> traccarValidIdList = new ArrayList<>();
/*Get Device Id List*/
try {
@ -560,27 +559,27 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
TraccarHandlerConstants.Types.REMOVE_TYPE_SINGLE);
}
} catch (JSONException e) {
msg = "not a JSONObject. ";
String msg = "not a JSONObject. ";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (DeviceManagementException e) {
msg = "Error occurred while fetching all enrolled devices. ";
String msg = "Error occurred while fetching all enrolled devices. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (DeviceAccessAuthorizationException e) {
msg = "Error occurred while checking device access authorization. ";
String msg = "Error occurred while checking device access authorization. ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (TrackerManagementDAOException e) {
msg = "Error occurred while mapping with deviceId .";
String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ExecutionException e) {
msg = "ExecutionException occurred ";
String msg = "ExecutionException occurred ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (InterruptedException e) {
msg = "InterruptedException occurred ";
String msg = "InterruptedException occurred ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}

@ -259,20 +259,19 @@ public class TraccarClientImpl implements TraccarClient {
serverUrl(HttpReportingUtil.trackerServer())));
String result = res.get();
if(result==""){
String msg = "";
if (result.equals("")) {
try {
TrackerManagementDAOFactory.beginTransaction();
trackerDAO.addTrackerUserDevicePermission(userId, deviceId);
TrackerManagementDAOFactory.commitTransaction();
} catch (TrackerManagementDAOException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred while mapping with deviceId .";
String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (TransactionManagementException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred establishing the DB connection .";
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -298,19 +297,18 @@ public class TraccarClientImpl implements TraccarClient {
String result = res.get();
if (result != null) {
String msg = "";
try {
TrackerManagementDAOFactory.beginTransaction();
trackerDAO.removeTrackerUserDevicePermission(deviceId, userId, removeType);
TrackerManagementDAOFactory.commitTransaction();
} catch (TrackerManagementDAOException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred while mapping with deviceId .";
String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (TransactionManagementException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred establishing the DB connection .";
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -321,17 +319,16 @@ public class TraccarClientImpl implements TraccarClient {
public List<TrackerPermissionInfo> getUserIdofPermissionByUserIdNIdList(int userId, List<Integer> NotInDeviceIdList)
throws TrackerManagementDAOException {
String msg = "";
try {
TrackerManagementDAOFactory.openConnection();
return trackerDAO.getUserIdofPermissionByUserIdNIdList(userId, NotInDeviceIdList);
} catch (TrackerManagementDAOException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred while mapping with deviceId .";
String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (SQLException e) {
msg = "Error occurred establishing the DB connection .";
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -340,16 +337,15 @@ public class TraccarClientImpl implements TraccarClient {
}
public TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException {
String msg = "";
try {
TrackerManagementDAOFactory.openConnection();
return trackerDAO.getTrackerDevice(deviceId, tenantId);
} catch (SQLException e) {
msg = "Error occurred establishing the DB connection .";
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (TrackerManagementDAOException e) {
msg="Could not add new device location";
String msg = "Could not add new device location";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -360,16 +356,15 @@ public class TraccarClientImpl implements TraccarClient {
public boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId)
throws TrackerManagementDAOException {
Boolean result = false;
String msg = "";
try {
TrackerManagementDAOFactory.openConnection();
result = trackerDAO.getUserIdofPermissionByDeviceIdNUserId(deviceId, userId);
} catch (TrackerManagementDAOException e) {
msg = "Error occurred while mapping with deviceId .";
String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (SQLException e) {
msg = "Error occurred establishing the DB connection .";
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -380,6 +375,7 @@ public class TraccarClientImpl implements TraccarClient {
/**
* Add Traccar Device operation.
*
* @param traccarDevice with DeviceName UniqueId, Status, Disabled LastUpdate, PositionId, GroupId
* Model, Contact, Category, fenceIds
* @throws TrackerManagementDAOException Failed while add Traccar Device the operation
@ -387,21 +383,20 @@ public class TraccarClientImpl implements TraccarClient {
public void addDevice(TraccarDevice traccarDevice, int tenantId) throws
TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException {
TrackerDeviceInfo trackerDeviceInfo = null;
String msg = "";
try {
TrackerManagementDAOFactory.openConnection();
trackerDeviceInfo = trackerDAO.getTrackerDevice(traccarDevice.getId(), tenantId);
if (trackerDeviceInfo != null) {
msg = "The device already exist";
String msg = "The device already exist";
log.error(msg);
throw new TrackerAlreadyExistException(msg);
}
} catch (TrackerManagementDAOException e) {
msg = "Error occurred while mapping with deviceId .";
String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (SQLException e) {
msg = "Error occurred establishing the DB connection .";
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -434,12 +429,12 @@ public class TraccarClientImpl implements TraccarClient {
TrackerManagementDAOFactory.commitTransaction();
} catch (TrackerManagementDAOException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred while mapping with deviceId .";
String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (TransactionManagementException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred establishing the DB connection .";
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -455,21 +450,21 @@ public class TraccarClientImpl implements TraccarClient {
/**
* Add Device GPS Location operation.
*
* @param deviceInfo with DeviceIdentifier, Timestamp, Lat, Lon, Bearing, Speed, ignition
*/
public void updateLocation(TraccarDevice device, TraccarPosition deviceInfo, int tenantId) throws
TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException {
TrackerDeviceInfo trackerDeviceInfo = null;
String msg = "";
try {
TrackerManagementDAOFactory.openConnection();
trackerDeviceInfo = trackerDAO.getTrackerDevice(device.getId(), tenantId);
} catch (SQLException e) {
msg = "Error occurred establishing the DB connection .";
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (TrackerManagementDAOException e) {
msg = "Could not add new device location";
String msg = "Could not add new device location";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -497,14 +492,13 @@ public class TraccarClientImpl implements TraccarClient {
/**
* Dis-enroll a Device operation.
*
* @param deviceId identified via deviceIdentifier
* @throws TrackerManagementDAOException Failed while dis-enroll a Traccar Device operation
*/
public void disEnrollDevice(int deviceId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException {
TrackerDeviceInfo trackerDeviceInfo = null;
List<TrackerPermissionInfo> trackerPermissionInfo = null;
String msg = "";
try {
TrackerManagementDAOFactory.beginTransaction();
trackerDeviceInfo = trackerDAO.getTrackerDevice(deviceId, tenantId);
@ -519,18 +513,17 @@ public class TraccarClientImpl implements TraccarClient {
}
} catch (TransactionManagementException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred establishing the DB connection";
String msg = "Error occurred establishing the DB connection";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (TrackerManagementDAOException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred while mapping with deviceId";
String msg = "Error occurred while mapping with deviceId";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
TrackerManagementDAOFactory.closeConnection();
}
log.info("--------Disenrolling Device--------");
//Delete from traccar
if (trackerDeviceInfo != null) {
@ -556,27 +549,27 @@ public class TraccarClientImpl implements TraccarClient {
/**
* Add Traccar Device operation.
*
* @param groupInfo with groupName
* @throws TrackerManagementDAOException Failed while add Traccar Device the operation
*/
public void addGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws
TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException {
TrackerGroupInfo trackerGroupInfo = null;
String msg = "";
try {
TrackerManagementDAOFactory.openConnection();
trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId);
if (trackerGroupInfo != null) {
msg = "The group already exit";
String msg = "The group already exit";
log.error(msg);
throw new TrackerAlreadyExistException(msg);
}
} catch (TrackerManagementDAOException e) {
msg = "Error occurred while mapping with groupId.";
String msg = "Error occurred while mapping with groupId.";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (SQLException e) {
msg = "Error occurred establishing the DB connection.";
String msg = "Error occurred establishing the DB connection.";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -608,12 +601,12 @@ public class TraccarClientImpl implements TraccarClient {
trackerDAO.updateTrackerGroupIdANDStatus(trackerGroupInfo.getTraccarGroupId(), groupId, tenantId, 1);
}
} catch (TrackerManagementDAOException e) {
msg = "Error occurred while mapping with deviceId. ";
String msg = "Error occurred while mapping with deviceId. ";
log.error(msg, e);
TrackerManagementDAOFactory.rollbackTransaction();
throw new TrackerManagementDAOException(msg, e);
} catch (TransactionManagementException e) {
msg = "Error occurred establishing the DB connection. ";
String msg = "Error occurred establishing the DB connection. ";
log.error(msg, e);
TrackerManagementDAOFactory.rollbackTransaction();
throw new TrackerManagementDAOException(msg, e);
@ -630,21 +623,21 @@ public class TraccarClientImpl implements TraccarClient {
/**
* update Traccar Group operation.
*
* @param groupInfo with groupName
* @throws TrackerManagementDAOException Failed while add Traccar Device the operation
*/
public void updateGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws
TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException {
TrackerGroupInfo res = null;
String msg = "";
try {
TrackerManagementDAOFactory.openConnection();
res = trackerDAO.getTrackerGroup(groupId, tenantId);
} catch (SQLException e) {
msg = "Error occurred establishing the DB connection. ";
String msg = "Error occurred establishing the DB connection. ";
log.error(msg, e);
} catch (TrackerManagementDAOException e) {
msg="Could not find traccar group details. ";
String msg = "Could not find traccar group details. ";
log.error(msg, e);
} finally {
TrackerManagementDAOFactory.closeConnection();
@ -661,12 +654,12 @@ public class TraccarClientImpl implements TraccarClient {
TrackerManagementDAOFactory.commitTransaction();
} catch (TrackerManagementDAOException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg="Could not update the traccar group. ";
String msg = "Could not update the traccar group. ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (TransactionManagementException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred establishing the DB connection. ";
String msg = "Error occurred establishing the DB connection. ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {
@ -690,13 +683,13 @@ public class TraccarClientImpl implements TraccarClient {
/**
* Add Traccar Device operation.
*
* @param groupId
* @throws TrackerManagementDAOException Failed while add Traccar Device the operation
*/
public void deleteGroup(int groupId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException {
TrackerGroupInfo res = null;
JSONObject obj = null;
String msg = "";
try {
TrackerManagementDAOFactory.beginTransaction();
res = trackerDAO.getTrackerGroup(groupId, tenantId);
@ -716,12 +709,12 @@ public class TraccarClientImpl implements TraccarClient {
}
} catch (TransactionManagementException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred establishing the DB connection. ";
String msg = "Error occurred establishing the DB connection. ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} catch (TrackerManagementDAOException e) {
TrackerManagementDAOFactory.rollbackTransaction();
msg = "Error occurred while mapping with groupId. ";
String msg = "Error occurred while mapping with groupId. ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally {

Loading…
Cancel
Save