Add missing db scripts

remotes/1729253769841084517/master
shamalka 2 years ago
parent b75cabfce7
commit 994f49db16

@ -425,59 +425,6 @@ public interface DeviceManagementService {
@QueryParam("limit")
int limit);
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting Details of Registered Devices Owned by an Authenticated User to generate token for Traccar",
notes = "Provides details of devices enrolled by authenticated users to generate token for Traccar.",
tags = "Device Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.",
response = DeviceList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client already has the latest version of " +
"the requested resource.\n"),
@ApiResponse(
code = 400,
message = "The incoming request has more than one selection criteria defined via the query parameters.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "The search criteria did not match any device registered with the server.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
response = ErrorResponse.class)
})
@Path("/traccar-user-token")
Response getTraccarUserToken();
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{groupId}/location-history")

@ -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.
*

@ -132,27 +132,8 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
this.groupDAO.addGroupProperties(deviceGroup, updatedGroupID, tenantId);
}
GroupManagementDAOFactory.commitTransaction();
//add new group in traccar
if (HttpReportingUtil.isTrackerEnabled()) {
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.addGroup(deviceGroup, updatedGroupID, tenantId);
}
//add new group in traccar
} else {
// add a group if not exist in traccar starts
if (HttpReportingUtil.isTrackerEnabled()){
existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId);
int groupId = existingGroup.getGroupId();
try {
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.addGroup(deviceGroup, groupId, tenantId);
} catch (TrackerAlreadyExistException e) {
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
}
} else {
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
}
throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName());
}
} catch (GroupManagementDAOException e) {
GroupManagementDAOFactory.rollbackTransaction();
@ -234,13 +215,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
this.groupDAO.updateGroupProperties(deviceGroup, groupId, tenantId);
}
//procees to update a group in traccar starts
if (HttpReportingUtil.isTrackerEnabled()) {
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.updateGroup(deviceGroup, groupId, tenantId);
}
//procees to update a group in traccar starts
GroupManagementDAOFactory.commitTransaction();
} else {
throw new GroupNotExistException("Group with ID - '" + groupId + "' doesn't exists!");
@ -300,21 +274,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
}
}
//procees to delete a group from traccar starts
if (HttpReportingUtil.isTrackerEnabled()) {
try {
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.deleteGroup(groupId, tenantId);
} catch (TrackerManagementDAOException e) {
String msg = "Failed while deleting traccar group " + groupId;
log.error(msg, e);
} catch (ExecutionException | InterruptedException e) {
String msg = "Failed while deleting traccar group "+groupId+" due to concurrent execution failure";
log.error(msg, e);
}
}
//procees to delete a group from traccar ends
if (isDeleteChildren) {
groupIdsToDelete.add(groupId);
groupDAO.deleteGroupsMapping(groupIdsToDelete, tenantId);

@ -754,4 +754,17 @@ CREATE TABLE DYNAMIC_TASK_PROPERTIES (
CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES
DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE
);
-- END OF DYNAMIC TASK TABLE--
-- END OF DYNAMIC TASK TABLE--
-- DM_TRACCAR_UNSYNCED_DEVICES TABLE --
CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES (
ID INT NOT NULL IDENTITY(1,1),
DEVICE_NAME VARCHAR(100) NOT NULL,
IOTS_DEVICE_IDENTIFIER VARCHAR(300) NULL UNIQUE,
TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL,
TRACCAR_USENAME VARCHAR(100) NULL,
STATUS VARCHAR(100) NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --

@ -851,3 +851,16 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
-- END OF DYNAMIC TASK TABLE--
-- DM_TRACCAR_UNSYNCED_DEVICES TABLE --
CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_NAME VARCHAR(100) NOT NULL,
IOTS_DEVICE_IDENTIFIER VARCHAR(300) DEFAULT NULL UNIQUE,
TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL,
TRACCAR_USENAME VARCHAR(100) NULL,
STATUS VARCHAR(100) NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --

@ -1119,3 +1119,16 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
-- END OF DYNAMIC TASK TABLE--
-- DM_TRACCAR_UNSYNCED_DEVICES TABLE --
CREATE TABLE DM_TRACCAR_UNSYNCED_DEVICES (
ID NUMBER(10) NOT NULL,
DEVICE_NAME VARCHAR2(100) NOT NULL,
IOTS_DEVICE_IDENTIFIER VARCHAR2(300) UNIQUE,
TRACCAR_DEVICE_UNIQUE_ID NUMBER(10) NOT NULL,
TRACCAR_USENAME VARCHAR2(100),
STATUS VARCHAR2(100),
TENANT_ID NUMBER(10) DEFAULT 0,
CONSTRAINT DM_TRACCAR_UNSYNCED_DEVICES_PK PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --

@ -772,3 +772,16 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
-- END OF DYNAMIC TASK TABLE--
-- DM_TRACCAR_UNSYNCED_DEVICES TABLE --
CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES (
ID SERIAL NOT NULL,
DEVICE_NAME VARCHAR(100) NOT NULL,
IOTS_DEVICE_IDENTIFIER VARCHAR(300) UNIQUE,
TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL,
TRACCAR_USENAME VARCHAR(100),
STATUS VARCHAR(100),
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --

Loading…
Cancel
Save