Add missing error logs and fix formatting issues

feature/traccar-sync
shamalka 2 years ago
parent 5ff9ef7782
commit 31bb87db41

@ -132,7 +132,15 @@ import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.ws.rs.*; import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
@ -534,7 +542,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
for (int i = 0; i < devices.getCount(); i++) { for (int i = 0; i < devices.getCount(); i++) {
TrackerDeviceInfo trackerDevice = DeviceAPIClientServiceImpl.getTrackerDevice( TrackerDeviceInfo trackerDevice = DeviceAPIClientServiceImpl.getTrackerDevice(
devices.getList().get(i).getId(), tenantId); devices.getList().get(i).getId(), tenantId);
int traccarDeviceId = trackerDevice.getTraccarDeviceId(); int traccarDeviceId = trackerDevice.getTraccarDeviceId();
boolean getPermission = DeviceAPIClientServiceImpl.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId); boolean getPermission = DeviceAPIClientServiceImpl.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId);
log.info("--------------------"); log.info("--------------------");
@ -547,7 +554,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceAPIClientServiceImpl.addTrackerUserDevicePermission(userId, traccarDeviceId); DeviceAPIClientServiceImpl.addTrackerUserDevicePermission(userId, traccarDeviceId);
} }
} }
//Remove neecessary //Remove neecessary
List<TrackerPermissionInfo> getAllUserDevices = List<TrackerPermissionInfo> getAllUserDevices =
DeviceAPIClientServiceImpl.getUserIdofPermissionByUserIdNIdList(userId, traccarValidIdList); DeviceAPIClientServiceImpl.getUserIdofPermissionByUserIdNIdList(userId, traccarValidIdList);
@ -557,26 +563,32 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
getAllUserDevice.getTraccarDeviceId(), getAllUserDevice.getTraccarDeviceId(),
TraccarHandlerConstants.Types.REMOVE_TYPE_SINGLE); TraccarHandlerConstants.Types.REMOVE_TYPE_SINGLE);
} }
} catch (JSONException e) { } catch (JSONException e) {
String msg = "not a JSONObject, "; String msg = "not a JSONObject, ";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while fetching all enrolled devices"; String msg = "Error occurred while fetching all enrolled devices";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
String msg = "Error occurred while checking device access authorization"; String msg = "Error occurred while checking device access authorization";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (TrackerManagementDAOException e) { } catch (TrackerManagementDAOException e) {
String msg = "Error occurred while mapping with deviceId ."; String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.error("ExecutionException : " + e); String msg = "ExecutionException occured ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("InterruptedException : " + e); String msg = "InterruptedException occured ";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
/*Get Device Id List*/ /*Get Device Id List*/
return Response.status(Response.Status.OK).entity(obj.getString("token")).build(); return Response.status(Response.Status.OK).entity(obj.getString("token")).build();
} }
} else { } else {

@ -18,6 +18,8 @@
package org.wso2.carbon.device.mgt.core.dao.impl.tracker; package org.wso2.carbon.device.mgt.core.dao.impl.tracker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo; import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo;
import org.wso2.carbon.device.mgt.common.TrackerGroupInfo; import org.wso2.carbon.device.mgt.common.TrackerGroupInfo;
import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo; import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo;
@ -36,6 +38,8 @@ import java.util.List;
public class TrackerDAOImpl implements TrackerDAO { public class TrackerDAOImpl implements TrackerDAO {
private static final Log log = LogFactory.getLog(TrackerDAOImpl.class);
@Override @Override
public Boolean addTrackerDevice(int traccarDeviceId, int deviceId, int tenantId) public Boolean addTrackerDevice(int traccarDeviceId, int deviceId, int tenantId)
throws TrackerManagementDAOException { throws TrackerManagementDAOException {
@ -51,7 +55,9 @@ public class TrackerDAOImpl implements TrackerDAO {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while adding on trackerDevice mapping table", e); String msg = "Error occurred while adding on trackerDevice mapping table";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -74,6 +80,7 @@ public class TrackerDAOImpl implements TrackerDAO {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating status on trackerDevice mapping table"; String msg = "Error occurred while updating status on trackerDevice mapping table";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e); throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
@ -98,7 +105,9 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
return status; return status;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while removing on trackerDevice table", e); String msg = "Error occurred while removing on trackerDevice table";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -122,7 +131,9 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
return trackerDeviceInfo; return trackerDeviceInfo;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while retrieving data from the trackerDevice table ", e); String msg = "Error occurred while retrieving data from the trackerDevice table ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, rs); TrackerManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -146,6 +157,7 @@ public class TrackerDAOImpl implements TrackerDAO {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while adding on traccarGroup mapping table"; String msg = "Error occurred while adding on traccarGroup mapping table";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e); throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
@ -169,6 +181,7 @@ public class TrackerDAOImpl implements TrackerDAO {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating status on traccarGroup mapping table"; String msg = "Error occurred while updating status on traccarGroup mapping table";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e); throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
@ -192,7 +205,9 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
return status; return status;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while removing from traccarGroup mapping table", e); String msg = "Error occurred while removing from traccarGroup mapping table";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -216,7 +231,9 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
return trackerGroupInfo; return trackerGroupInfo;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while retrieving data from the traccarGroup mapping table ", e); String msg = "Error occurred while retrieving data from the traccarGroup mapping table ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, rs); TrackerManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -236,7 +253,9 @@ public class TrackerDAOImpl implements TrackerDAO {
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while adding permission on permissions mapping table", e); String msg = "Error occurred while adding permission on permissions mapping table";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -258,10 +277,11 @@ public class TrackerDAOImpl implements TrackerDAO {
stmt.setInt(2, userId); stmt.setInt(2, userId);
} }
stmt.execute(); stmt.execute();
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while removing permission from permissions mapping table", e); String msg = "Error occurred while removing permission from permissions mapping table";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -287,7 +307,9 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
return trackerPermissionInfo; return trackerPermissionInfo;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while retrieving permissions data from permissions mapping table ", e); String msg = "Error occurred while retrieving permissions data from permissions mapping table ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, rs); TrackerManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -325,6 +347,7 @@ public class TrackerDAOImpl implements TrackerDAO {
return trackerPermissionInfo; return trackerPermissionInfo;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while retrieving data from the permissions mapping table "; String msg = "Error occurred while retrieving data from the permissions mapping table ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e); throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, rs); TrackerManagementDAOUtil.cleanupResources(stmt, rs);
@ -335,7 +358,6 @@ public class TrackerDAOImpl implements TrackerDAO {
public Boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) throws TrackerManagementDAOException { public Boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) throws TrackerManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
TrackerPermissionInfo trackerPermissionInfo = null;
try { try {
Connection conn = TrackerManagementDAOFactory.getConnection(); Connection conn = TrackerManagementDAOFactory.getConnection();
String sql = "SELECT TRACCAR_DEVICE_ID, TRACCAR_USER_ID FROM DM_EXT_PERMISSION_MAPPING WHERE " + String sql = "SELECT TRACCAR_DEVICE_ID, TRACCAR_USER_ID FROM DM_EXT_PERMISSION_MAPPING WHERE " +
@ -347,7 +369,9 @@ public class TrackerDAOImpl implements TrackerDAO {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
return rs.next(); return rs.next();
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while retrieving permissions data from permissions mapping table ", e); String msg = "Error occurred while retrieving permissions data from permissions mapping table ";
log.error(msg, e);
throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, rs); TrackerManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -95,7 +95,9 @@ public final class TrackerManagementDAOUtil {
final InitialContext context = new InitialContext(jndiProperties); final InitialContext context = new InitialContext(jndiProperties);
return (DataSource) context.lookup(dataSourceName); return (DataSource) context.lookup(dataSourceName);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); String msg = "Error in looking up data source: " + e.getMessage();
log.error(msg, e);
throw new RuntimeException(msg, e);
} }
} }
@ -129,11 +131,11 @@ public final class TrackerManagementDAOUtil {
public static String buildDeviceIdNotInQuery(List<Integer> DeviceIdList) throws TrackerManagementDAOException { public static String buildDeviceIdNotInQuery(List<Integer> DeviceIdList) throws TrackerManagementDAOException {
if (DeviceIdList == null || DeviceIdList.isEmpty()) { if (DeviceIdList == null || DeviceIdList.isEmpty()) {
String msg = "SQL query build for Device Id list failed. Device Id list cannot be empty or null"; String msg = "SQL query build for Device Id list failed. Device Id list cannot be empty or null";
log.error(msg);
throw new TrackerManagementDAOException(msg); throw new TrackerManagementDAOException(msg);
} }
StringJoiner joiner = new StringJoiner(",", " AND TRACCAR_DEVICE_ID NOT IN(", ")"); StringJoiner joiner = new StringJoiner(",", " AND TRACCAR_DEVICE_ID NOT IN(", ")");
DeviceIdList.stream().map(status -> "?").forEach(joiner::add); DeviceIdList.stream().map(status -> "?").forEach(joiner::add);
return joiner.toString(); return joiner.toString();
} }
} }

@ -428,9 +428,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.error("ExecutionException : " + e); log.error("ExecutionException : " + e);
//throw new RuntimeException(e); //throw new RuntimeException(e);
//Exception was not thrown due to being conflicted with non-traccar features
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("InterruptedException : " + e); log.error("InterruptedException : " + e);
//throw new RuntimeException(e); //throw new RuntimeException(e);
//Exception was not thrown due to being conflicted with non-traccar features
} }
} }
//enroll Traccar device //enroll Traccar device
@ -614,10 +616,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
String msg = "Error occurred while initiating transaction"; String msg = "Error occurred while initiating transaction";
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} catch (Exception e) {
String msg = "Error occurred while dis-enrolling device: " + deviceId.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
@ -3969,9 +3967,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
deviceLocation.setSpeed(Float.parseFloat(speed)); deviceLocation.setSpeed(Float.parseFloat(speed));
deviceLocation.setBearing(Float.parseFloat(bearing)); deviceLocation.setBearing(Float.parseFloat(bearing));
deviceInformationManager.addDeviceLocation(device, deviceLocation); deviceInformationManager.addDeviceLocation(device, deviceLocation);
} catch (Exception e) { } catch (DeviceDetailsMgtException e) {
//We are not failing the execution since this is not critical for the functionality. But logging as //We are not failing the execution since this is not critical for the functionality. But logging as
// a warning for reference. // a warning for reference.
//Exception was not thrown due to being conflicted with non-traccar features
log.warn("Error occurred while trying to add '" + device.getType() + "' device '" + log.warn("Error occurred while trying to add '" + device.getType() + "' device '" +
device.getDeviceIdentifier() + "' (id:'" + device.getId() + "') location (lat:" + latitude + device.getDeviceIdentifier() + "' (id:'" + device.getId() + "') location (lat:" + latitude +
", lon:" + longitude + ", altitude: " + altitude + ", lon:" + longitude + ", altitude: " + altitude +

@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo; import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo;
import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo; import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException;
import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException;

Loading…
Cancel
Save