|
|
@ -353,103 +353,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Path("/traccar-user-token")
|
|
|
|
|
|
|
|
public Response getTraccarUserToken() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (HttpReportingUtil.isTrackerEnabled()) {
|
|
|
|
|
|
|
|
String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
|
|
|
DeviceAPIClientService deviceAPIClientService = DeviceMgtAPIUtils.getDeviceAPIClientService();
|
|
|
|
|
|
|
|
JSONObject obj = new JSONObject(deviceAPIClientService.returnUser(currentUser));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (obj.has("error")) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj.getString("error")).build();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
int userId = obj.getInt("id");
|
|
|
|
|
|
|
|
List<Integer> traccarValidIdList = new ArrayList<>();
|
|
|
|
|
|
|
|
/*Get Device Id List*/
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
|
|
|
|
|
|
|
|
DeviceMgtAPIUtils.getDeviceAccessAuthorizationService();
|
|
|
|
|
|
|
|
PaginationRequest request = new PaginationRequest(0, 0);
|
|
|
|
|
|
|
|
PaginationResult result;
|
|
|
|
|
|
|
|
DeviceList devices = new DeviceList();
|
|
|
|
|
|
|
|
List<String> status = new ArrayList<>();
|
|
|
|
|
|
|
|
status.add("ACTIVE");
|
|
|
|
|
|
|
|
status.add("INACTIVE");
|
|
|
|
|
|
|
|
status.add("CREATED");
|
|
|
|
|
|
|
|
status.add("UNREACHABLE");
|
|
|
|
|
|
|
|
request.setStatusList(status);
|
|
|
|
|
|
|
|
// this is the user who initiates the request
|
|
|
|
|
|
|
|
String authorizedUser = MultitenantUtils.getTenantAwareUsername(currentUser);
|
|
|
|
|
|
|
|
// check whether the user is device-mgt admin
|
|
|
|
|
|
|
|
if (!deviceAccessAuthorizationService.isDeviceAdminUser()) {
|
|
|
|
|
|
|
|
request.setOwner(authorizedUser);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = dms.getAllDevicesIds(request);
|
|
|
|
|
|
|
|
if (result == null || result.getData() == null || result.getData().isEmpty()) {
|
|
|
|
|
|
|
|
devices.setList(new ArrayList<Device>());
|
|
|
|
|
|
|
|
devices.setCount(0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
devices.setList((List<Device>) result.getData());
|
|
|
|
|
|
|
|
devices.setCount(result.getRecordsTotal());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
TrackerDeviceInfo trackerDevice;
|
|
|
|
|
|
|
|
for (Device device : devices.getList()) {
|
|
|
|
|
|
|
|
trackerDevice = deviceAPIClientService.getTrackerDevice(device.getId(), tenantId);
|
|
|
|
|
|
|
|
if(trackerDevice != null) {
|
|
|
|
|
|
|
|
int traccarDeviceId = trackerDevice.getTraccarDeviceId();
|
|
|
|
|
|
|
|
boolean getPermission = deviceAPIClientService.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId);
|
|
|
|
|
|
|
|
traccarValidIdList.add(traccarDeviceId);
|
|
|
|
|
|
|
|
if (!getPermission) {
|
|
|
|
|
|
|
|
deviceAPIClientService.addTrackerUserDevicePermission(userId, traccarDeviceId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Remove necessary
|
|
|
|
|
|
|
|
List<TrackerPermissionInfo> getAllUserDevices =
|
|
|
|
|
|
|
|
deviceAPIClientService.getUserIdofPermissionByUserIdNIdList(userId, traccarValidIdList);
|
|
|
|
|
|
|
|
for (TrackerPermissionInfo getAllUserDevice : getAllUserDevices) {
|
|
|
|
|
|
|
|
deviceAPIClientService.removeTrackerUserDevicePermission(
|
|
|
|
|
|
|
|
getAllUserDevice.getTraccarUserId(),
|
|
|
|
|
|
|
|
getAllUserDevice.getTraccarDeviceId(),
|
|
|
|
|
|
|
|
TraccarHandlerConstants.Types.REMOVE_TYPE_SINGLE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
String msg = "Execution error occurred handling traccar device permissions";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
String msg = "Interruption error occurred handling traccar device permissions";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Get Device Id List*/
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(obj.getString("token")).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity("Traccar is not enabled").build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Validate group Id and group Id greater than 0 and exist.
|
|
|
|
* Validate group Id and group Id greater than 0 and exist.
|
|
|
|
*
|
|
|
|
*
|
|
|
|