device organization jax ws optimization

backup
Isuri Mendis 1 year ago
parent 3031f98319
commit 0385f35dab

@ -454,8 +454,10 @@ public interface DeviceOrganizationMgtService {
response = ErrorResponse.class)
})
Response isDeviceOrganizationExist(
@ApiParam(value = "The ID of the child device.", required = true)
@QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") Integer parentDeviceId);
@ApiParam(value = "The ID of the parent device.")
@QueryParam("parentDeviceId") String parentDeviceId);
/**
@ -517,8 +519,10 @@ public interface DeviceOrganizationMgtService {
response = ErrorResponse.class)
})
Response getDeviceOrganizationByUniqueKey(
@ApiParam(value = "The ID of the child device.", required = true)
@QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") Integer parentDeviceId);
@ApiParam(value = "The ID of the parent device.")
@QueryParam("parentDeviceId") String parentDeviceId);
/**
* Updates a device organization.

@ -137,10 +137,16 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
@Path("exists")
public Response isDeviceOrganizationExist(
@QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") Integer parentDeviceId) {
@QueryParam("parentDeviceId") String parentDeviceId) {
try {
DeviceOrganizationService deviceOrganizationService = DeviceOrgAPIUtils.getDeviceOrganizationService();
boolean exists = deviceOrganizationService.isDeviceOrganizationExist(deviceId, parentDeviceId);
boolean exists;
if (parentDeviceId.equals("null")) {
log.info("inside if");
exists = deviceOrganizationService.isDeviceOrganizationExist(deviceId, null);
} else {
exists = deviceOrganizationService.isDeviceOrganizationExist(deviceId, Integer.valueOf(parentDeviceId));
}
return Response.status(Response.Status.OK).entity(exists).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
@ -153,10 +159,15 @@ public class DeviceOrganizationMgtServiceImpl implements DeviceOrganizationMgtSe
@Path("organization")
public Response getDeviceOrganizationByUniqueKey(
@QueryParam("deviceId") int deviceId,
@QueryParam("parentDeviceId") Integer parentDeviceId) {
@QueryParam("parentDeviceId") String parentDeviceId) {
try {
DeviceOrganizationService deviceOrganizationService = DeviceOrgAPIUtils.getDeviceOrganizationService();
DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(deviceId, parentDeviceId);
DeviceOrganization organization;
if (parentDeviceId.equals("null")) {
organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(deviceId, null);
} else {
organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(deviceId, Integer.valueOf(parentDeviceId));
}
return Response.status(Response.Status.OK).entity(organization).build();
} catch (DeviceOrganizationMgtPluginException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();

@ -15,10 +15,10 @@ public class DeviceOrgAPIUtils {
private static final Log log = LogFactory.getLog(DeviceOrgAPIUtils.class);
/**
* Initializing and accessing method for WhiteLabelManagementService.
* Initializing and accessing method for DeviceOrganizationService.
*
* @return WhiteLabelManagementService instance
* @throws IllegalStateException if whiteLabelManagementService cannot be initialized
* @return DeviceOrganizationService instance
* @throws IllegalStateException if deviceOrganizationService cannot be initialized
*/
public static DeviceOrganizationService getDeviceOrganizationService() {
if (deviceOrganizationService == null) {
@ -28,7 +28,7 @@ public class DeviceOrgAPIUtils {
deviceOrganizationService = (DeviceOrganizationService) ctx.getOSGiService(
DeviceOrganizationService.class, null);
if (deviceOrganizationService == null) {
throw new IllegalStateException("Whitelabel Management service not initialized.");
throw new IllegalStateException("Device Organization Management service not initialized.");
}
}
}

@ -296,18 +296,21 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
public boolean isDeviceOrganizationExist(int deviceId, Integer parentDeviceId)
throws DeviceOrganizationMgtDAOException {
try {
String sql;
Connection conn = ConnectionManagerUtil.getDBConnection();
String sql = "SELECT 1 " +
"FROM DM_DEVICE_ORGANIZATION DO " +
"WHERE (DO.DEVICE_ID = ? AND DO.PARENT_DEVICE_ID = ?) " +
"LIMIT 1";
if (parentDeviceId != null) {
// If parentDeviceId is not null, use it in the query.
sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID = ? AND PARENT_DEVICE_ID = ?";
} else {
// If parentDeviceId is null, use a query that checks for null values.
sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID = ? AND PARENT_DEVICE_ID IS NULL";
}
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, deviceId);
if (parentDeviceId != null) {
stmt.setInt(2, parentDeviceId);
} else {
stmt.setNull(2, java.sql.Types.INTEGER);
}
try (ResultSet rs = stmt.executeQuery()) {

Loading…
Cancel
Save