Improve endpoint-mgt functionalities

4.x.x
tcdlpds@gmail.com 4 years ago
parent 8493879151
commit ce81eac413

@ -33,15 +33,6 @@ public class DeviceInfo implements Serializable {
private static final long serialVersionUID = 1998101733L; private static final long serialVersionUID = 1998101733L;
// @ApiModelProperty(name = "deviceId", value = "Device Id.", required = false)
// private int deviceId;
//
// @ApiModelProperty(name = "deviceType", value = "Type of the device.", required = true)
// private String deviceType;
//
// @ApiModelProperty(name = "deviceId", value = "Device identifier.", required = true)
// private DeviceIdentifier deviceIdentifier;
@ApiModelProperty(name = "IMEI", value = "IMEI number of the device.", required = true) @ApiModelProperty(name = "IMEI", value = "IMEI number of the device.", required = true)
private String IMEI; private String IMEI;

@ -129,26 +129,4 @@ public interface DeviceDetailsDAO {
void updateDeviceInformation(int deviceId, int enrollmentId, DeviceInfo newDeviceInfo) throws DeviceDetailsMgtDAOException; void updateDeviceInformation(int deviceId, int enrollmentId, DeviceInfo newDeviceInfo) throws DeviceDetailsMgtDAOException;
void updateDeviceLocation(DeviceLocation deviceLocation, int enrollmentId) throws DeviceDetailsMgtDAOException; void updateDeviceLocation(DeviceLocation deviceLocation, int enrollmentId) throws DeviceDetailsMgtDAOException;
// /**
// * This method will add device application to database.
// * @param deviceApplication - Device application
// * @throws DeviceDetailsMgtDAOException
// */
// void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtDAOException;
//
// /**
// * This method will return the device application list once device id is provided.
// * @param deviceId
// * @return
// * @throws DeviceDetailsMgtDAOException
// */
// DeviceApplication getDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException;
//
// /**
// * This method will delete the application list from the database.
// * @param deviceId - Integer
// * @throws DeviceDetailsMgtDAOException
// */
// void deleteDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException;
} }

@ -41,7 +41,7 @@ import java.util.Map;
public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
private static Log log = LogFactory.getLog(DeviceDetailsDAOImpl.class); private static final Log log = LogFactory.getLog(DeviceDetailsDAOImpl.class);
@Override @Override
public void addDeviceInformation(int deviceId, int enrolmentId, DeviceInfo deviceInfo) public void addDeviceInformation(int deviceId, int enrolmentId, DeviceInfo deviceInfo)
@ -168,8 +168,6 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
// deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo = new DeviceInfo(); deviceInfo = new DeviceInfo();
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setVendor(rs.getString("VENDOR")); deviceInfo.setVendor(rs.getString("VENDOR"));
@ -180,9 +178,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
// deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
deviceInfo.setSsid(rs.getString("SSID")); deviceInfo.setSsid(rs.getString("SSID"));
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
@ -190,7 +186,6 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
} }
return deviceInfo; return deviceInfo;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceDetailsMgtDAOException("Error occurred while fetching the details of the registered devices.", e); throw new DeviceDetailsMgtDAOException("Error occurred while fetching the details of the registered devices.", e);
@ -508,21 +503,5 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
private Connection getConnection() throws SQLException { private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection(); return DeviceManagementDAOFactory.getConnection();
} }
// @Override
// public void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtDAOException {
//
// }
//
// @Override
// public DeviceApplication getDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException {
// return null;
// }
//
// @Override
// public void deleteDeviceApplications(int deviceId) throws DeviceDetailsMgtDAOException {
//
// }
} }

@ -165,52 +165,52 @@ public class OperationManagerImpl implements OperationManager {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("operation:[" + operation.toString() + "]"); log.debug("operation:[" + operation.toString() + "]");
for (DeviceIdentifier deviceIdentifier : deviceIds) { for (DeviceIdentifier deviceIdentifier : deviceIds) {
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType()
deviceIdentifier.getType() + "]"); + "]");
} }
} }
try {
DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
if (validDeviceIds.size() > 0) {
DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList();
if (authorizedDeviceIds.size() <= 0) {
log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list.");
Activity activity = new Activity();
//Send the operation statuses only for admin triggered operations
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
deviceAuthorizationResult));
return activity;
}
boolean isScheduledOperation = this.isTaskScheduledOperation(operation); DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
if (initiatedBy == null && isScheduledOperation) { if (!validDeviceIds.isEmpty()) {
if (log.isDebugEnabled()) { DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
log.debug("initiatedBy : " + SYSTEM); List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList();
} if (authorizedDeviceIds.isEmpty()) {
operation.setInitiatedBy(SYSTEM); log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list.");
} else { Activity activity = new Activity();
if (log.isDebugEnabled()) { //Send the operation statuses only for admin triggered operations
log.debug("initiatedBy : " + initiatedBy); activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
} return activity;
operation.setInitiatedBy(initiatedBy); }
}
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
OperationDAOUtil.convertOperation(operation); String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String operationCode = operationDto.getCode(); if (initiatedBy == null && isScheduledOperation) {
Map<Integer, Device> enrolments = new HashMap<>(); if (log.isDebugEnabled()) {
Device device; log.debug("initiatedBy : " + SYSTEM);
for (DeviceIdentifier deviceId : authorizedDeviceIds) { }
device = getDevice(deviceId); operation.setInitiatedBy(SYSTEM);
enrolments.put(device.getEnrolmentInfo().getId(), device); } else {
if (log.isDebugEnabled()) {
log.debug("initiatedBy : " + initiatedBy);
} }
operation.setInitiatedBy(initiatedBy);
}
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = OperationDAOUtil
.convertOperation(operation);
String operationCode = operationDto.getCode();
Map<Integer, Device> enrolments = new HashMap<>();
Device device;
for (DeviceIdentifier deviceId : authorizedDeviceIds) {
device = getDevice(deviceId);
enrolments.put(device.getEnrolmentInfo().getId(), device);
}
try {
OperationManagementDAOFactory.beginTransaction(); OperationManagementDAOFactory.beginTransaction();
if (operationDto.getControl() == if (operationDto.getControl()
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) { == org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
Map<Integer, Integer> pendingOperationIDs = operationDAO Map<Integer, Integer> pendingOperationIDs = operationDAO
.getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode); .getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
for (Integer enrolmentId : pendingOperationIDs.keySet()) { for (Integer enrolmentId : pendingOperationIDs.keySet()) {
@ -227,8 +227,8 @@ public class OperationManagerImpl implements OperationManager {
+ operationCode); + operationCode);
} }
Activity activity = new Activity(); Activity activity = new Activity();
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, activity.setActivityStatus(
deviceAuthorizationResult)); this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
return activity; return activity;
} }
} }
@ -242,20 +242,20 @@ public class OperationManagerImpl implements OperationManager {
activity.setType(Activity.Type.valueOf(operationDto.getType().toString())); activity.setType(Activity.Type.valueOf(operationDto.getType().toString()));
//For now set the operation statuses only for admin triggered operations //For now set the operation statuses only for admin triggered operations
if (!isScheduledOperation) { if (!isScheduledOperation) {
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, activity.setActivityStatus(
deviceAuthorizationResult)); this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
} }
return activity; return activity;
} else { } catch (OperationManagementDAOException e) {
throw new InvalidDeviceException("Invalid device Identifiers found."); OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException("Error occurred while adding operation", e);
} catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating the transaction", e);
} finally {
OperationManagementDAOFactory.closeConnection();
} }
} catch (OperationManagementDAOException e) { } else {
OperationManagementDAOFactory.rollbackTransaction(); throw new InvalidDeviceException("Invalid device Identifiers found.");
throw new OperationManagementException("Error occurred while adding operation", e);
} catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating the transaction", e);
} finally {
OperationManagementDAOFactory.closeConnection();
} }
} }

@ -75,7 +75,7 @@ public class DeviceStatusMonitoringTask implements Task {
Device device; Device device;
try { try {
operationEnrolmentMappings = this.getOperationEnrolmentMappings(); operationEnrolmentMappings = this.getOperationEnrolmentMappings();
if (operationEnrolmentMappings.size() > 0) { if (!operationEnrolmentMappings.isEmpty()) {
lastActivities = this.getLastDeviceActivities(); lastActivities = this.getLastDeviceActivities();
} }
} catch (DeviceStatusTaskException e) { } catch (DeviceStatusTaskException e) {
@ -107,7 +107,7 @@ public class DeviceStatusMonitoringTask implements Task {
} }
} }
if (enrolmentInfoTobeUpdated.size() > 0) { if (!enrolmentInfoTobeUpdated.isEmpty()) {
try { try {
this.updateDeviceStatus(enrolmentInfoTobeUpdated); this.updateDeviceStatus(enrolmentInfoTobeUpdated);
} catch (DeviceStatusTaskException e) { } catch (DeviceStatusTaskException e) {
@ -200,4 +200,4 @@ public class DeviceStatusMonitoringTask implements Task {
} }
return lastActivities; return lastActivities;
} }
} }

Loading…
Cancel
Save