mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Performance improvements
This commit is contained in:
parent
dc05306aa9
commit
be705ce81b
@ -102,7 +102,7 @@ public class Utils {
|
|||||||
|
|
||||||
final ProxySelector proxySelector = new ProxySelector() {
|
final ProxySelector proxySelector = new ProxySelector() {
|
||||||
@Override
|
@Override
|
||||||
public java.util.List<Proxy> select(URI uri) {
|
public List<Proxy> select(URI uri) {
|
||||||
List<Proxy> proxyList = new ArrayList<>();
|
List<Proxy> proxyList = new ArrayList<>();
|
||||||
String host = uri.getHost();
|
String host = uri.getHost();
|
||||||
|
|
||||||
|
|||||||
@ -94,7 +94,7 @@ public class AnnotationProcessor {
|
|||||||
private Class<io.swagger.annotations.Tag> tagClass;
|
private Class<io.swagger.annotations.Tag> tagClass;
|
||||||
private Class<io.swagger.annotations.Extension> extensionClass;
|
private Class<io.swagger.annotations.Extension> extensionClass;
|
||||||
private Class<io.swagger.annotations.ExtensionProperty> extensionPropertyClass;
|
private Class<io.swagger.annotations.ExtensionProperty> extensionPropertyClass;
|
||||||
private Class<io.swagger.annotations.ApiOperation> apiOperation;
|
private Class<ApiOperation> apiOperation;
|
||||||
private Class<org.wso2.carbon.apimgt.annotations.api.Scope> scopeClass;
|
private Class<org.wso2.carbon.apimgt.annotations.api.Scope> scopeClass;
|
||||||
private Class<org.wso2.carbon.apimgt.annotations.api.Scopes> scopesClass;
|
private Class<org.wso2.carbon.apimgt.annotations.api.Scopes> scopesClass;
|
||||||
private Map<String, ApiScope> apiScopes;
|
private Map<String, ApiScope> apiScopes;
|
||||||
@ -119,8 +119,8 @@ public class AnnotationProcessor {
|
|||||||
.loadClass(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName());
|
.loadClass(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName());
|
||||||
scopesClass = (Class<org.wso2.carbon.apimgt.annotations.api.Scopes>) classLoader
|
scopesClass = (Class<org.wso2.carbon.apimgt.annotations.api.Scopes>) classLoader
|
||||||
.loadClass(org.wso2.carbon.apimgt.annotations.api.Scopes.class.getName());
|
.loadClass(org.wso2.carbon.apimgt.annotations.api.Scopes.class.getName());
|
||||||
apiOperation = (Class<io.swagger.annotations.ApiOperation>)classLoader
|
apiOperation = (Class<ApiOperation>)classLoader
|
||||||
.loadClass((io.swagger.annotations.ApiOperation.class.getName()));
|
.loadClass((ApiOperation.class.getName()));
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
log.error("An error has occurred while loading classes ", e);
|
log.error("An error has occurred while loading classes ", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,7 +140,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
|
|||||||
@QueryParam("owner") String owner,
|
@QueryParam("owner") String owner,
|
||||||
List<String> deviceIdentifiers){
|
List<String> deviceIdentifiers){
|
||||||
try {
|
try {
|
||||||
if (DeviceMgtAPIUtils.getDeviceManagementService().updateEnrollment(owner, deviceIdentifiers)) {
|
if (DeviceMgtAPIUtils.getDeviceManagementService().updateEnrollment(owner, true, deviceIdentifiers)) {
|
||||||
String msg = "Device owner is updated successfully.";
|
String msg = "Device owner is updated successfully.";
|
||||||
return Response.status(Response.Status.OK).entity(msg).build();
|
return Response.status(Response.Status.OK).entity(msg).build();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,7 +52,6 @@ public class DeviceMgtAPITestHelper {
|
|||||||
deviceType.setName(name != null ? name : DEVICE_TYPE);
|
deviceType.setName(name != null ? name : DEVICE_TYPE);
|
||||||
|
|
||||||
DeviceTypeMetaDefinition deviceTypeMetaDefinition = new DeviceTypeMetaDefinition();
|
DeviceTypeMetaDefinition deviceTypeMetaDefinition = new DeviceTypeMetaDefinition();
|
||||||
deviceTypeMetaDefinition.setClaimable(true);
|
|
||||||
deviceTypeMetaDefinition.setDescription(DEVICE_TYPE_DESCRIPTION);
|
deviceTypeMetaDefinition.setDescription(DEVICE_TYPE_DESCRIPTION);
|
||||||
|
|
||||||
PushNotificationConfig pushNotificationConfig =
|
PushNotificationConfig pushNotificationConfig =
|
||||||
|
|||||||
@ -184,8 +184,6 @@ public interface DeviceManager {
|
|||||||
*/
|
*/
|
||||||
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
|
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
|
||||||
|
|
||||||
boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException;
|
|
||||||
|
|
||||||
boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
|
boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
|
||||||
EnrolmentInfo.Status status) throws DeviceManagementException;
|
EnrolmentInfo.Status status) throws DeviceManagementException;
|
||||||
|
|
||||||
|
|||||||
@ -40,6 +40,8 @@ public class EnrolmentInfo implements Serializable {
|
|||||||
@ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.",
|
@ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.",
|
||||||
required = true)
|
required = true)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
|
private boolean isTransferred;
|
||||||
@ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment. This value is not necessary.", required = false )
|
@ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment. This value is not necessary.", required = false )
|
||||||
private Long dateOfEnrolment;
|
private Long dateOfEnrolment;
|
||||||
@ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update. This value is not necessary.", required = false )
|
@ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update. This value is not necessary.", required = false )
|
||||||
@ -72,6 +74,14 @@ public class EnrolmentInfo implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTransferred() {
|
||||||
|
return isTransferred;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransferred(boolean transferred) {
|
||||||
|
isTransferred = transferred;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getDateOfEnrolment() {
|
public Long getDateOfEnrolment() {
|
||||||
return dateOfEnrolment;
|
return dateOfEnrolment;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ public class MonitoringOperation {
|
|||||||
|
|
||||||
private String taskName;
|
private String taskName;
|
||||||
private int recurrentTimes;
|
private int recurrentTimes;
|
||||||
|
private boolean responsePersistence = true;
|
||||||
|
|
||||||
public String getTaskName() {
|
public String getTaskName() {
|
||||||
return taskName;
|
return taskName;
|
||||||
@ -42,5 +43,21 @@ public class MonitoringOperation {
|
|||||||
this.recurrentTimes = recurrentTimes;
|
this.recurrentTimes = recurrentTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasResponsePersistence() {
|
||||||
|
return responsePersistence;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponsePersistence(boolean responsePersistence) {
|
||||||
|
this.responsePersistence = responsePersistence;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof MonitoringOperation) {
|
||||||
|
MonitoringOperation op = (MonitoringOperation) obj;
|
||||||
|
return taskName != null && taskName.equals(op.getTaskName());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.common;
|
package org.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,14 +34,14 @@ public class PaginationRequest {
|
|||||||
private int groupId;
|
private int groupId;
|
||||||
private String owner;
|
private String owner;
|
||||||
private String ownerPattern;
|
private String ownerPattern;
|
||||||
private List<String> statusList;
|
|
||||||
private String deviceType;
|
private String deviceType;
|
||||||
private String deviceName;
|
private String deviceName;
|
||||||
private String ownership;
|
private String ownership;
|
||||||
private String ownerRole;
|
private String ownerRole;
|
||||||
private Map<String, Object> property = new HashMap<>();
|
|
||||||
private Date since;
|
private Date since;
|
||||||
private String filter;
|
private String filter;
|
||||||
|
private Map<String, Object> property = new HashMap<>();
|
||||||
|
private List<String> statusList = new ArrayList<>();
|
||||||
|
|
||||||
public PaginationRequest(int start, int rowCount) {
|
public PaginationRequest(int start, int rowCount) {
|
||||||
this.startIndex = start;
|
this.startIndex = start;
|
||||||
|
|||||||
@ -45,6 +45,8 @@ public interface OperationManager {
|
|||||||
Activity addOperation(Operation operation, List<DeviceIdentifier> devices) throws OperationManagementException,
|
Activity addOperation(Operation operation, List<DeviceIdentifier> devices) throws OperationManagementException,
|
||||||
InvalidDeviceException;
|
InvalidDeviceException;
|
||||||
|
|
||||||
|
void addTaskOperation(String deviceType, Operation operation) throws OperationManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to retrieve the list of all operations to a device.
|
* Method to retrieve the list of all operations to a device.
|
||||||
*
|
*
|
||||||
@ -66,6 +68,17 @@ public interface OperationManager {
|
|||||||
*/
|
*/
|
||||||
PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request)
|
PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request)
|
||||||
throws OperationManagementException;
|
throws OperationManagementException;
|
||||||
|
/**
|
||||||
|
* Method to retrieve the list of operations placed for device with specified status.
|
||||||
|
*
|
||||||
|
* @param deviceId - Device Identifier of the device
|
||||||
|
* @param status - Status of the operation
|
||||||
|
* @return A List of operations applied to the given device-id.
|
||||||
|
* @throws OperationManagementException If some unusual behaviour is observed while fetching the
|
||||||
|
* operation list.
|
||||||
|
*/
|
||||||
|
List<? extends Operation> getOperations(DeviceIdentifier deviceId, Operation.Status status)
|
||||||
|
throws OperationManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to retrieve the list of available operations to a device.
|
* Method to retrieve the list of available operations to a device.
|
||||||
@ -86,7 +99,7 @@ public interface OperationManager {
|
|||||||
|
|
||||||
void updateOperation(DeviceIdentifier deviceId, Operation operation) throws OperationManagementException;
|
void updateOperation(DeviceIdentifier deviceId, Operation operation) throws OperationManagementException;
|
||||||
|
|
||||||
void updateOperation(int enrolmentId, Operation operation) throws OperationManagementException;
|
void updateOperation(int enrolmentId, Operation operation, DeviceIdentifier deviceId) throws OperationManagementException;
|
||||||
|
|
||||||
Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
|
Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
|
||||||
throws OperationManagementException;
|
throws OperationManagementException;
|
||||||
|
|||||||
@ -43,14 +43,6 @@ public class DeviceTypeMetaDefinition {
|
|||||||
this.features = features;
|
this.features = features;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClaimable() {
|
|
||||||
return claimable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClaimable(boolean isClaimable) {
|
|
||||||
this.claimable = isClaimable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PushNotificationConfig getPushNotificationConfig() {
|
public PushNotificationConfig getPushNotificationConfig() {
|
||||||
return pushNotificationConfig;
|
return pushNotificationConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,15 +56,15 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
|
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
|
||||||
|
|
||||||
private Map<DeviceTypeServiceIdentifier, DeviceManagementServiceHolder> providers;
|
private final Map<DeviceTypeServiceIdentifier, DeviceManagementServiceHolder> providers;
|
||||||
private boolean isInitiated;
|
private boolean isInitiated;
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagementPluginRepository.class);
|
private static final Log log = LogFactory.getLog(DeviceManagementPluginRepository.class);
|
||||||
private OperationManagerRepository operationManagerRepository;
|
private final OperationManagerRepository operationManagerRepository;
|
||||||
private static final long DEFAULT_UPDATE_TIMESTAMP = 900000L;
|
private static final long DEFAULT_UPDATE_TIMESTAMP = 900000L;
|
||||||
|
|
||||||
public DeviceManagementPluginRepository() {
|
public DeviceManagementPluginRepository() {
|
||||||
this.operationManagerRepository = new OperationManagerRepository();
|
this.operationManagerRepository = new OperationManagerRepository();
|
||||||
providers = Collections.synchronizedMap(new HashMap<DeviceTypeServiceIdentifier, DeviceManagementServiceHolder>());
|
providers = Collections.synchronizedMap(new HashMap<>());
|
||||||
DeviceManagementServiceComponent.registerStartupListener(this);
|
DeviceManagementServiceComponent.registerStartupListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,34 +18,34 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival;
|
package org.wso2.carbon.device.mgt.core.archival;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.archival.beans.*;
|
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.archival.dao.*;
|
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDestinationDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalSourceDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.archival.dao.DataDeletionDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ArchivalServiceImpl implements ArchivalService {
|
public class ArchivalServiceImpl implements ArchivalService {
|
||||||
private static Log log = LogFactory.getLog(ArchivalServiceImpl.class);
|
private static final Log log = LogFactory.getLog(ArchivalServiceImpl.class);
|
||||||
|
|
||||||
private ArchivalDAO archivalDAO;
|
private final ArchivalDAO archivalDAO;
|
||||||
private DataDeletionDAO dataDeletionDAO;
|
private final DataDeletionDAO dataDeletionDAO;
|
||||||
|
|
||||||
private static final int EXECUTION_BATCH_SIZE =
|
private static final int EXECUTION_BATCH_SIZE =
|
||||||
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
|
||||||
.getArchivalTaskConfiguration().getBatchSize();
|
.getArchivalTaskConfiguration().getBatchSize();
|
||||||
|
|
||||||
private static final boolean ARCHIVE_PENDING_OPERATIONS =
|
private static final int ARCHIVAL_LOCK_INTERVAL =
|
||||||
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
|
||||||
.getArchivalTaskConfiguration().isArchivePendingOperations();
|
.getArchivalTaskConfiguration().getArchivalLockInterval();
|
||||||
|
|
||||||
private String[] NOT_IN_PROGRESS_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED"};
|
|
||||||
private String[] NOT_PENDING_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED", "IN_PROGRESS"};
|
|
||||||
private String[] NOT_PENDING_IN_PROGRESS_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED"};
|
|
||||||
|
|
||||||
public ArchivalServiceImpl() {
|
public ArchivalServiceImpl() {
|
||||||
this.archivalDAO = ArchivalSourceDAOFactory.getDataPurgingDAO();
|
this.archivalDAO = ArchivalSourceDAOFactory.getDataPurgingDAO();
|
||||||
@ -54,187 +54,160 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void archiveTransactionalRecords() throws ArchivalException {
|
public void archiveTransactionalRecords() throws ArchivalException {
|
||||||
List<Integer> allOperations;
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArchivalSourceDAOFactory.openConnection();
|
|
||||||
ArchivalDestinationDAOFactory.openConnection();
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Fetching All Operations");
|
|
||||||
}
|
|
||||||
allOperations = archivalDAO.getAllOperations();
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Fetching All Pending Operations");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} catch (ArchivalDAOException e) {
|
|
||||||
// rollbackTransactions();
|
|
||||||
String msg = "Rollback the get all operations and get all pending operations";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ArchivalException(msg, e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "An error occurred while connecting to the archival database";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ArchivalException(msg, e);
|
|
||||||
} finally {
|
|
||||||
ArchivalSourceDAOFactory.closeConnection();
|
|
||||||
ArchivalDestinationDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Integer> candidates = allOperations;
|
|
||||||
log.info(allOperations.size() + " All Operations.");
|
|
||||||
|
|
||||||
if (!ARCHIVE_PENDING_OPERATIONS) {
|
|
||||||
try {
|
|
||||||
ArchivalSourceDAOFactory.openConnection();
|
|
||||||
ArchivalDestinationDAOFactory.openConnection();
|
|
||||||
List<Integer> pendingAndIPOperations = archivalDAO.getPendingAndInProgressOperations();
|
|
||||||
log.info(pendingAndIPOperations.size() +" P&IP Operations");
|
|
||||||
// Get the diff of operations
|
|
||||||
candidates.removeAll(pendingAndIPOperations);
|
|
||||||
} catch (ArchivalDAOException e) {
|
|
||||||
String msg = "Error occurred while retrieving the pending operations";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ArchivalException(msg, e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "An error occurred while connecting to the archival database";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ArchivalException(msg, e);
|
|
||||||
} finally {
|
|
||||||
ArchivalSourceDAOFactory.closeConnection();
|
|
||||||
ArchivalDestinationDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int total = candidates.size();
|
|
||||||
int batches = calculateNumberOfBatches(total);
|
|
||||||
log.info(total + " Operations ready for archiving. " + batches + " iterations to be done.");
|
|
||||||
int batchSize = EXECUTION_BATCH_SIZE;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug(total + " Operations ready for archiving. " + batches + " iterations to be done.");
|
|
||||||
log.debug(batchSize + " is the batch size");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 1; i <= batches; i++) {
|
|
||||||
int startIdx = batchSize * (i - 1);
|
|
||||||
int endIdx = batchSize * i;
|
|
||||||
if (i == batches) {
|
|
||||||
endIdx = startIdx + (total % batchSize);
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("\n\n############ Iterating over batch " + i + "[" +
|
|
||||||
startIdx + "," + endIdx + "] #######");
|
|
||||||
}
|
|
||||||
List<Integer> subList = candidates.subList(startIdx, endIdx);
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("SubList size is: " + subList.size());
|
|
||||||
if (subList.size() > 0) {
|
|
||||||
log.debug("First Element is: " + subList.get(0));
|
|
||||||
log.debug("Last Element is: " + subList.get(subList.size() - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
for (Integer val : subList) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Sub List Element: " + val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
beginTransactions();
|
|
||||||
prepareTempTable(subList);
|
|
||||||
commitTransactions();
|
|
||||||
} catch (Exception e) {
|
|
||||||
rollbackTransactions();
|
|
||||||
String msg = "Error occurred while preparing the operations.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ArchivalException(msg, e);
|
|
||||||
} finally {
|
|
||||||
ArchivalSourceDAOFactory.closeConnection();
|
|
||||||
ArchivalDestinationDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ArchiveOperationResponse> operationResponses = null;
|
|
||||||
List<ArchiveNotification> notification = null;
|
|
||||||
List<ArchiveCommandOperation> commandOperations = null;
|
|
||||||
List<ArchiveProfileOperation> profileOperations = null;
|
|
||||||
List<ArchiveEnrolmentOperationMap> enrollmentMapping = null;
|
|
||||||
List<ArchiveOperation> operations = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
openConnection();
|
|
||||||
operationResponses = archivalDAO.selectOperationResponses();
|
|
||||||
notification = archivalDAO.selectNotifications();
|
|
||||||
enrollmentMapping = archivalDAO.selectEnrolmentMappings();
|
|
||||||
operations = archivalDAO.selectOperations();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
String msg = "Error occurred while retrieving data.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ArchivalException(msg, e);
|
|
||||||
} finally {
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
beginTransactions();
|
beginTransactions();
|
||||||
|
Timestamp currentTime = new Timestamp(new Date().getTime());
|
||||||
|
|
||||||
//Purge the largest table, DM_DEVICE_OPERATION_RESPONSE
|
//Purge the largest table, DM_DEVICE_OPERATION_RESPONSE
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("## Archiving operation responses");
|
log.debug("## Archiving operation responses");
|
||||||
}
|
}
|
||||||
archivalDAO.moveOperationResponses(operationResponses);
|
|
||||||
|
int failAttempts;
|
||||||
|
|
||||||
|
List<Integer> nonRemovableMappings = archivalDAO.getNonRemovableOperationMappingIDs(currentTime);
|
||||||
|
int totalLargeOpResCount = archivalDAO.getLargeOperationResponseCount(currentTime, nonRemovableMappings);
|
||||||
|
|
||||||
|
if (totalLargeOpResCount > 0) {
|
||||||
|
int iterationCount = totalLargeOpResCount / EXECUTION_BATCH_SIZE;
|
||||||
|
int residualRecSize = 0;
|
||||||
|
if ((totalLargeOpResCount % EXECUTION_BATCH_SIZE) != 0) {
|
||||||
|
residualRecSize = totalLargeOpResCount % EXECUTION_BATCH_SIZE;
|
||||||
|
iterationCount++;
|
||||||
|
}
|
||||||
|
failAttempts = 0;
|
||||||
|
for (int iter = 0; iter < iterationCount; iter++) {
|
||||||
|
try {
|
||||||
|
if (iter == (iterationCount - 1)) {
|
||||||
|
archivalDAO.transferLargeOperationResponses(residualRecSize, currentTime, nonRemovableMappings);
|
||||||
|
archivalDAO.removeLargeOperationResponses(residualRecSize, currentTime, nonRemovableMappings);
|
||||||
|
} else {
|
||||||
|
archivalDAO.transferLargeOperationResponses(EXECUTION_BATCH_SIZE, currentTime, nonRemovableMappings);
|
||||||
|
archivalDAO.removeLargeOperationResponses(EXECUTION_BATCH_SIZE, currentTime, nonRemovableMappings);
|
||||||
|
}
|
||||||
|
commitTransactions();
|
||||||
|
failAttempts = 0;
|
||||||
|
} catch (ArchivalDAOException e) {
|
||||||
|
rollbackTransactions();
|
||||||
|
if (++failAttempts > 3) {
|
||||||
|
String msg = "Error occurred while trying to archive Large Operation Responses. Abort archiving.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ArchivalException(msg, e);
|
||||||
|
}
|
||||||
|
String msg = "Error occurred while trying to archive Large Operation Responses. " +
|
||||||
|
"Failed attempts: " + failAttempts + " Error: " + e.getMessage();
|
||||||
|
log.warn(msg);
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
Thread.sleep(ARCHIVAL_LOCK_INTERVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalOpResCount = archivalDAO.getOperationResponseCount(currentTime, nonRemovableMappings);
|
||||||
|
|
||||||
|
if (totalOpResCount > 0) {
|
||||||
|
int iterationCount = totalOpResCount / EXECUTION_BATCH_SIZE;
|
||||||
|
int residualRecSize = 0;
|
||||||
|
if ((totalOpResCount % EXECUTION_BATCH_SIZE) != 0) {
|
||||||
|
residualRecSize = totalOpResCount % EXECUTION_BATCH_SIZE;
|
||||||
|
iterationCount++;
|
||||||
|
}
|
||||||
|
failAttempts = 0;
|
||||||
|
for (int iter = 0; iter < iterationCount; iter++) {
|
||||||
|
try {
|
||||||
|
if (iter == (iterationCount - 1)) {
|
||||||
|
archivalDAO.transferOperationResponses(residualRecSize, currentTime, nonRemovableMappings);
|
||||||
|
archivalDAO.removeOperationResponses(residualRecSize, currentTime, nonRemovableMappings);
|
||||||
|
} else {
|
||||||
|
archivalDAO.transferOperationResponses(EXECUTION_BATCH_SIZE, currentTime, nonRemovableMappings);
|
||||||
|
archivalDAO.removeOperationResponses(EXECUTION_BATCH_SIZE, currentTime, nonRemovableMappings);
|
||||||
|
}
|
||||||
|
commitTransactions();
|
||||||
|
failAttempts = 0;
|
||||||
|
} catch (ArchivalDAOException e) {
|
||||||
|
rollbackTransactions();
|
||||||
|
if (++failAttempts > 3) {
|
||||||
|
String msg = "Error occurred while trying to archive Operation Responses. Abort archiving.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ArchivalException(msg, e);
|
||||||
|
}
|
||||||
|
String msg = "Error occurred while trying to archive Operation Responses. " +
|
||||||
|
"Failed attempts: " + failAttempts + " Error: " + e.getMessage();
|
||||||
|
log.warn(msg);
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
Thread.sleep(ARCHIVAL_LOCK_INTERVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Purge the notifications table, DM_NOTIFICATION
|
//Purge the notifications table, DM_NOTIFICATION
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("## Archiving notifications");
|
log.debug("## Archiving notifications");
|
||||||
}
|
}
|
||||||
archivalDAO.moveNotifications(notification);
|
archivalDAO.moveNotifications(currentTime);
|
||||||
|
commitTransactions();
|
||||||
//Purge the enrolment mappings table, DM_ENROLMENT_OP_MAPPING
|
//Purge the enrolment mappings table, DM_ENROLMENT_OP_MAPPING
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("## Archiving enrolment mappings");
|
log.debug("## Archiving enrolment mappings");
|
||||||
}
|
}
|
||||||
archivalDAO.moveEnrolmentMappings(enrollmentMapping);
|
int opMappingCount = archivalDAO.getOpMappingsCount(currentTime);
|
||||||
|
if (opMappingCount > 0) {
|
||||||
|
int iterationCount = opMappingCount / EXECUTION_BATCH_SIZE;
|
||||||
|
int residualRecSize = 0;
|
||||||
|
if ((opMappingCount % EXECUTION_BATCH_SIZE) != 0) {
|
||||||
|
residualRecSize = opMappingCount % EXECUTION_BATCH_SIZE;
|
||||||
|
iterationCount++;
|
||||||
|
}
|
||||||
|
failAttempts = 0;
|
||||||
|
for (int iter = 0; iter < iterationCount; iter++) {
|
||||||
|
try {
|
||||||
|
if (iter == (iterationCount - 1)) {
|
||||||
|
archivalDAO.transferEnrollmentOpMappings(residualRecSize, currentTime);
|
||||||
|
archivalDAO.removeEnrollmentOPMappings(residualRecSize, currentTime);
|
||||||
|
} else {
|
||||||
|
archivalDAO.transferEnrollmentOpMappings(EXECUTION_BATCH_SIZE, currentTime);
|
||||||
|
archivalDAO.removeEnrollmentOPMappings(EXECUTION_BATCH_SIZE, currentTime);
|
||||||
|
}
|
||||||
|
commitTransactions();
|
||||||
|
failAttempts = 0;
|
||||||
|
} catch (ArchivalDAOException e) {
|
||||||
|
rollbackTransactions();
|
||||||
|
if (++failAttempts > 3) {
|
||||||
|
String msg = "Error occurred while trying to archive Operation Enrollment Mappings. Abort archiving.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ArchivalException(msg, e);
|
||||||
|
}
|
||||||
|
String msg = "Error occurred while trying to archive Operation Enrollment Mappings. " +
|
||||||
|
"Failed attempts: " + failAttempts + " Error: " + e.getMessage();
|
||||||
|
log.warn(msg);
|
||||||
|
iter--;
|
||||||
|
}
|
||||||
|
Thread.sleep(ARCHIVAL_LOCK_INTERVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Finally, purge the operations table, DM_OPERATION
|
//Finally, purge the operations table, DM_OPERATION
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("## Archiving operations");
|
log.debug("## Archiving operations");
|
||||||
}
|
}
|
||||||
archivalDAO.moveOperations(operations);
|
|
||||||
|
archivalDAO.transferOperations();
|
||||||
|
archivalDAO.removeOperations();
|
||||||
commitTransactions();
|
commitTransactions();
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("End of Iteration : " + i);
|
|
||||||
}
|
|
||||||
} catch (ArchivalDAOException e) {
|
} catch (ArchivalDAOException e) {
|
||||||
rollbackTransactions();
|
rollbackTransactions();
|
||||||
String msg = "Error occurred while trying to archive data to the six tables";
|
String msg = "Error occurred while trying to archive data to the six tables";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new ArchivalException(msg, e);
|
throw new ArchivalException(msg, e);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
rollbackTransactions();
|
||||||
|
String msg = "Error while halting archival thread to free up table locks.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ArchivalException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
ArchivalSourceDAOFactory.closeConnection();
|
ArchivalSourceDAOFactory.closeConnection();
|
||||||
ArchivalDestinationDAOFactory.closeConnection();
|
ArchivalDestinationDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void prepareTempTable(List<Integer> subList) throws ArchivalDAOException {
|
|
||||||
//Clean up the DM_ARCHIVED_OPERATIONS table
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("## Truncating the temporary table");
|
|
||||||
}
|
|
||||||
archivalDAO.truncateOperationIDsForArchival();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("## Inserting into the temporary table");
|
|
||||||
}
|
|
||||||
archivalDAO.copyOperationIDsForArchival(subList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beginTransactions() throws ArchivalException {
|
private void beginTransactions() throws ArchivalException {
|
||||||
@ -247,28 +220,6 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openConnection() throws ArchivalException {
|
|
||||||
try {
|
|
||||||
ArchivalSourceDAOFactory.openConnection();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "An error occurred during opening connection";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ArchivalException(msg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeConnection() throws ArchivalException {
|
|
||||||
try {
|
|
||||||
ArchivalSourceDAOFactory.closeConnection();
|
|
||||||
} catch (Exception e) {
|
|
||||||
String msg = "An error occurred during opening connection";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ArchivalException(msg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void commitTransactions() {
|
private void commitTransactions() {
|
||||||
ArchivalSourceDAOFactory.commitTransaction();
|
ArchivalSourceDAOFactory.commitTransaction();
|
||||||
ArchivalDestinationDAOFactory.commitTransaction();
|
ArchivalDestinationDAOFactory.commitTransaction();
|
||||||
@ -279,22 +230,16 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|||||||
ArchivalDestinationDAOFactory.rollbackTransaction();
|
ArchivalDestinationDAOFactory.rollbackTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculateNumberOfBatches(int total) {
|
|
||||||
int batches = 0;
|
|
||||||
int batchSize = EXECUTION_BATCH_SIZE;
|
|
||||||
if ((total % batchSize) > 0) {
|
|
||||||
batches = (total / batchSize) + 1;
|
|
||||||
} else {
|
|
||||||
batches = total / batchSize;
|
|
||||||
}
|
|
||||||
return batches;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteArchivedRecords() throws ArchivalException {
|
public void deleteArchivedRecords() throws ArchivalException {
|
||||||
try {
|
try {
|
||||||
ArchivalDestinationDAOFactory.openConnection();
|
ArchivalDestinationDAOFactory.openConnection();
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("## Deleting Large operation responses");
|
||||||
|
}
|
||||||
|
dataDeletionDAO.deleteLargeOperationResponses();
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("## Deleting operation responses");
|
log.debug("## Deleting operation responses");
|
||||||
}
|
}
|
||||||
@ -305,16 +250,6 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|||||||
}
|
}
|
||||||
dataDeletionDAO.deleteNotifications();
|
dataDeletionDAO.deleteNotifications();
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("## Deleting command operations");
|
|
||||||
}
|
|
||||||
dataDeletionDAO.deleteCommandOperations();
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("## Deleting profile operations ");
|
|
||||||
}
|
|
||||||
dataDeletionDAO.deleteProfileOperations();
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("## Deleting enrolment mappings ");
|
log.debug("## Deleting enrolment mappings ");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.beans;
|
|
||||||
|
|
||||||
public class ArchiveCommandOperation {
|
|
||||||
|
|
||||||
|
|
||||||
private int operationId;
|
|
||||||
private int enabled;
|
|
||||||
|
|
||||||
public int getOperationId() {
|
|
||||||
return operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationId(int operationId) {
|
|
||||||
this.operationId = operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(int enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.beans;
|
|
||||||
|
|
||||||
public class ArchiveEnrolmentOperationMap {
|
|
||||||
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private int enrolmentId;
|
|
||||||
private int operationId;
|
|
||||||
private String status;
|
|
||||||
private int createdTimestamp;
|
|
||||||
private int updatedTimestamp;
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnrolmentId() {
|
|
||||||
return enrolmentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnrolmentId(int enrolmentId) {
|
|
||||||
this.enrolmentId = enrolmentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOperationId() {
|
|
||||||
return operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationId(int operationId) {
|
|
||||||
this.operationId = operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(String status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCreatedTimestamp() {
|
|
||||||
return createdTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreatedTimestamp(int createdTimestamp) {
|
|
||||||
this.createdTimestamp = createdTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getUpdatedTimestamp() {
|
|
||||||
return updatedTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdatedTimestamp(int updatedTimestamp) {
|
|
||||||
this.updatedTimestamp = updatedTimestamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.beans;
|
|
||||||
|
|
||||||
public class ArchiveNotification {
|
|
||||||
|
|
||||||
|
|
||||||
private int notificationId;
|
|
||||||
private int deviceId;
|
|
||||||
private int operationId;
|
|
||||||
private int tenantId;
|
|
||||||
private String status;
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
public int getNotificationId() {
|
|
||||||
return notificationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNotificationId(int notificationId) {
|
|
||||||
this.notificationId = notificationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(int deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOperationId() {
|
|
||||||
return operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationId(int operationId) {
|
|
||||||
this.operationId = operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTenantId() {
|
|
||||||
return tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTenantId(int tenantId) {
|
|
||||||
this.tenantId = tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(String status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.beans;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
|
|
||||||
public class ArchiveOperation {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private String type;
|
|
||||||
private Timestamp createdTimeStamp;
|
|
||||||
private Timestamp recievedTimeStamp;
|
|
||||||
private String operationCode;
|
|
||||||
|
|
||||||
private Object operationDetails;
|
|
||||||
private String initiatedBy;
|
|
||||||
private boolean enabled;
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timestamp getCreatedTimeStamp() {
|
|
||||||
return createdTimeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreatedTimeStamp(Timestamp createdTimeStamp) {
|
|
||||||
this.createdTimeStamp = createdTimeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timestamp getRecievedTimeStamp() {
|
|
||||||
return recievedTimeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRecievedTimeStamp(Timestamp recievedTimeStamp) {
|
|
||||||
this.recievedTimeStamp = recievedTimeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOperationCode() {
|
|
||||||
return operationCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationCode(String operationCode) {
|
|
||||||
this.operationCode = operationCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getOperationDetails() {
|
|
||||||
return operationDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationDetails(Object operationDetails) {
|
|
||||||
this.operationDetails = operationDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInitiatedBy() {
|
|
||||||
return initiatedBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInitiatedBy(String initiatedBy) {
|
|
||||||
this.initiatedBy = initiatedBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.beans;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
|
|
||||||
public class ArchiveOperationResponse {
|
|
||||||
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private int enrolmentId;
|
|
||||||
private int operationId;
|
|
||||||
private int enOpMapId;
|
|
||||||
private Object operationResponse;
|
|
||||||
private Timestamp receivedTimeStamp;
|
|
||||||
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnrolmentId() {
|
|
||||||
return enrolmentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnrolmentId(int enrolmentId) {
|
|
||||||
this.enrolmentId = enrolmentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOperationId() {
|
|
||||||
return operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationId(int operationId) {
|
|
||||||
this.operationId = operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnOpMapId() {
|
|
||||||
return enOpMapId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnOpMapId(int enOpMapId) {
|
|
||||||
this.enOpMapId = enOpMapId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getOperationResponse() {
|
|
||||||
return operationResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationResponse(Object operationResponse) {
|
|
||||||
this.operationResponse = operationResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timestamp getReceivedTimeStamp() {
|
|
||||||
return receivedTimeStamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReceivedTimeStamp(Timestamp receivedTimeStamp) {
|
|
||||||
this.receivedTimeStamp = receivedTimeStamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.beans;
|
|
||||||
|
|
||||||
public class ArchiveProfileOperation {
|
|
||||||
|
|
||||||
|
|
||||||
private int operationId;
|
|
||||||
private int enabled;
|
|
||||||
private Object operationDetails;
|
|
||||||
|
|
||||||
public int getOperationId() {
|
|
||||||
return operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationId(int operationId) {
|
|
||||||
this.operationId = operationId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(int enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getOperationDetails() {
|
|
||||||
return operationDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOperationDetails(Object operationDetails) {
|
|
||||||
this.operationDetails = operationDetails;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -18,9 +18,7 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.dao;
|
package org.wso2.carbon.device.mgt.core.archival.dao;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.archival.beans.*;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,34 +26,30 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface ArchivalDAO {
|
public interface ArchivalDAO {
|
||||||
|
|
||||||
int DEFAULT_BATCH_SIZE = 1000;
|
List<Integer> getNonRemovableOperationMappingIDs(Timestamp time) throws ArchivalDAOException;
|
||||||
|
|
||||||
List<Integer> getAllOperations() throws ArchivalDAOException;
|
int getLargeOperationResponseCount(Timestamp time, List<Integer> nonRemovableMappings) throws ArchivalDAOException;
|
||||||
|
|
||||||
List<Integer> getPendingAndInProgressOperations() throws ArchivalDAOException;
|
int getOpMappingsCount(Timestamp time) throws ArchivalDAOException;
|
||||||
|
|
||||||
void copyOperationIDsForArchival(List<Integer> operationIds) throws ArchivalDAOException;
|
int getOperationResponseCount(Timestamp time, List<Integer> nonRemovableMappings) throws ArchivalDAOException;
|
||||||
|
|
||||||
List<ArchiveOperationResponse> selectOperationResponses() throws ArchivalDAOException;
|
void transferOperationResponses(int batchSize, Timestamp time, List<Integer> nonRemovableMappings) throws ArchivalDAOException;
|
||||||
|
|
||||||
void moveOperationResponses(List<ArchiveOperationResponse> rs) throws ArchivalDAOException;
|
void transferLargeOperationResponses(int batchSize, Timestamp time, List<Integer> nonRemovableMappings) throws ArchivalDAOException;
|
||||||
|
|
||||||
List<ArchiveNotification> selectNotifications() throws ArchivalDAOException;
|
void removeLargeOperationResponses(int batchSize, Timestamp time, List<Integer> nonRemovableMappings) throws ArchivalDAOException;
|
||||||
|
|
||||||
void moveNotifications(List<ArchiveNotification> rs) throws ArchivalDAOException;
|
void removeOperationResponses(int batchSize, Timestamp time, List<Integer> nonRemovableMappings) throws ArchivalDAOException;
|
||||||
|
|
||||||
List<ArchiveCommandOperation> selectCommandOperations() throws ArchivalDAOException;
|
void moveNotifications(Timestamp time) throws ArchivalDAOException;
|
||||||
|
|
||||||
List<ArchiveProfileOperation> selectProfileOperations() throws ArchivalDAOException;
|
void transferEnrollmentOpMappings(int batchSize, Timestamp time) throws ArchivalDAOException;
|
||||||
|
|
||||||
List<ArchiveEnrolmentOperationMap> selectEnrolmentMappings() throws ArchivalDAOException;
|
void removeEnrollmentOPMappings(int batchSize, Timestamp time) throws ArchivalDAOException;
|
||||||
|
|
||||||
void moveEnrolmentMappings(List<ArchiveEnrolmentOperationMap> rs) throws ArchivalDAOException;
|
void transferOperations() throws ArchivalDAOException;
|
||||||
|
|
||||||
List<ArchiveOperation> selectOperations() throws ArchivalDAOException;
|
void removeOperations() throws ArchivalDAOException;
|
||||||
|
|
||||||
void moveOperations(List<ArchiveOperation> rs) throws ArchivalDAOException;
|
|
||||||
|
|
||||||
void truncateOperationIDsForArchival() throws ArchivalDAOException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,14 +57,4 @@ public class ArchivalDAOUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void cleanupResultSet(ResultSet rs) {
|
|
||||||
if (rs != null) {
|
|
||||||
try {
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Error occurred while closing the result set", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,8 +39,7 @@ public class ArchivalDestinationDAOFactory {
|
|||||||
private static final Log log = LogFactory.getLog(OperationManagementDAOFactory.class);
|
private static final Log log = LogFactory.getLog(OperationManagementDAOFactory.class);
|
||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
private static String databaseEngine;
|
private static String databaseEngine;
|
||||||
private static int retentionPeriod;
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<>();
|
||||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
|
||||||
|
|
||||||
public static DataDeletionDAO getDataDeletionDAO() {
|
public static DataDeletionDAO getDataDeletionDAO() {
|
||||||
return new DataDeletionDAOImpl(DeviceConfigurationManager.getInstance().getDeviceManagementConfig()
|
return new DataDeletionDAOImpl(DeviceConfigurationManager.getInstance().getDeviceManagementConfig()
|
||||||
@ -77,6 +76,16 @@ public class ArchivalDestinationDAOFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void beginTransaction(Connection conn) throws TransactionManagementException {
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
// currentConnection.set(conn);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new TransactionManagementException(
|
||||||
|
"Error occurred while retrieving config.datasource connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void openConnection() throws SQLException {
|
public static void openConnection() throws SQLException {
|
||||||
currentConnection.set(dataSource.getConnection());
|
currentConnection.set(dataSource.getConnection());
|
||||||
}
|
}
|
||||||
@ -102,6 +111,16 @@ public class ArchivalDestinationDAOFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void closeConnection(Connection conn) {
|
||||||
|
if (conn != null) {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while close the connection");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void commitTransaction() {
|
public static void commitTransaction() {
|
||||||
try {
|
try {
|
||||||
Connection conn = currentConnection.get();
|
Connection conn = currentConnection.get();
|
||||||
@ -118,6 +137,21 @@ public class ArchivalDestinationDAOFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void commitTransaction(Connection conn) {
|
||||||
|
try {
|
||||||
|
if (conn != null) {
|
||||||
|
conn.commit();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence commit " +
|
||||||
|
"has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while committing the transaction", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void rollbackTransaction() {
|
public static void rollbackTransaction() {
|
||||||
try {
|
try {
|
||||||
Connection conn = currentConnection.get();
|
Connection conn = currentConnection.get();
|
||||||
@ -153,7 +187,7 @@ public class ArchivalDestinationDAOFactory {
|
|||||||
}
|
}
|
||||||
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
|
||||||
if (jndiPropertyList != null) {
|
if (jndiPropertyList != null) {
|
||||||
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
Hashtable<Object, Object> jndiProperties = new Hashtable<>();
|
||||||
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
||||||
jndiProperties.put(prop.getName(), prop.getValue());
|
jndiProperties.put(prop.getName(), prop.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.dao;
|
package org.wso2.carbon.device.mgt.core.archival.dao;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException;
|
import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException;
|
||||||
|
|||||||
@ -23,16 +23,12 @@ package org.wso2.carbon.device.mgt.core.archival.dao;
|
|||||||
*/
|
*/
|
||||||
public interface DataDeletionDAO {
|
public interface DataDeletionDAO {
|
||||||
|
|
||||||
int DEFAULT_RETENTION_PERIOD = 364;
|
void deleteLargeOperationResponses() throws ArchivalDAOException;
|
||||||
|
|
||||||
void deleteOperationResponses() throws ArchivalDAOException;
|
void deleteOperationResponses() throws ArchivalDAOException;
|
||||||
|
|
||||||
void deleteNotifications() throws ArchivalDAOException;
|
void deleteNotifications() throws ArchivalDAOException;
|
||||||
|
|
||||||
void deleteCommandOperations() throws ArchivalDAOException;
|
|
||||||
|
|
||||||
void deleteProfileOperations() throws ArchivalDAOException;
|
|
||||||
|
|
||||||
void deleteEnrolmentMappings() throws ArchivalDAOException;
|
void deleteEnrolmentMappings() throws ArchivalDAOException;
|
||||||
|
|
||||||
void deleteOperations() throws ArchivalDAOException;
|
void deleteOperations() throws ArchivalDAOException;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -18,14 +18,13 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.archival.dao.impl;
|
package org.wso2.carbon.device.mgt.core.archival.dao.impl;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.archival.dao.DataDeletionDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDAOException;
|
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDAOUtil;
|
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDestinationDAOFactory;
|
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDestinationDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.task.impl.ArchivedDataDeletionTask;
|
import org.wso2.carbon.device.mgt.core.archival.dao.DataDeletionDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -34,7 +33,11 @@ import java.sql.SQLException;
|
|||||||
public class DataDeletionDAOImpl implements DataDeletionDAO {
|
public class DataDeletionDAOImpl implements DataDeletionDAO {
|
||||||
private static Log log = LogFactory.getLog(DataDeletionDAOImpl.class);
|
private static Log log = LogFactory.getLog(DataDeletionDAOImpl.class);
|
||||||
|
|
||||||
private int retentionPeriod = DataDeletionDAO.DEFAULT_RETENTION_PERIOD;
|
private int retentionPeriod;
|
||||||
|
|
||||||
|
private static final String DESTINATION_DB =
|
||||||
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
|
||||||
|
.getArchivalTaskConfiguration().getDbConfig().getDestinationDB();
|
||||||
|
|
||||||
public DataDeletionDAOImpl(int retentionPeriod) {
|
public DataDeletionDAOImpl(int retentionPeriod) {
|
||||||
this.retentionPeriod = retentionPeriod;
|
this.retentionPeriod = retentionPeriod;
|
||||||
@ -49,7 +52,26 @@ public class DataDeletionDAOImpl implements DataDeletionDAO {
|
|||||||
try {
|
try {
|
||||||
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE_ARCH " +
|
String sql = "DELETE FROM "+ DESTINATION_DB +".DM_DEVICE_OPERATION_RESPONSE_ARCH " +
|
||||||
|
"WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, this.retentionPeriod);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
conn.commit();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ArchivalDAOException("Error occurred while deleting operation responses", e);
|
||||||
|
} finally {
|
||||||
|
ArchivalDAOUtil.cleanupResources(stmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteLargeOperationResponses() throws ArchivalDAOException {
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
String sql = "DELETE FROM "+ DESTINATION_DB +".DM_DEVICE_OPERATION_RESPONSE_LARGE_ARCH " +
|
||||||
"WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
"WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, this.retentionPeriod);
|
stmt.setInt(1, this.retentionPeriod);
|
||||||
@ -68,7 +90,7 @@ public class DataDeletionDAOImpl implements DataDeletionDAO {
|
|||||||
try {
|
try {
|
||||||
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
String sql = "DELETE FROM DM_NOTIFICATION_ARCH" +
|
String sql = "DELETE FROM "+ DESTINATION_DB +".DM_NOTIFICATION_ARCH" +
|
||||||
" WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
" WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, this.retentionPeriod);
|
stmt.setInt(1, this.retentionPeriod);
|
||||||
@ -81,51 +103,13 @@ public class DataDeletionDAOImpl implements DataDeletionDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteCommandOperations() throws ArchivalDAOException {
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
|
||||||
conn.setAutoCommit(false);
|
|
||||||
String sql = "DELETE FROM DM_COMMAND_OPERATION_ARCH" +
|
|
||||||
" WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setInt(1, this.retentionPeriod);
|
|
||||||
stmt.executeUpdate();
|
|
||||||
conn.commit();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ArchivalDAOException("Error occurred while deleting command operations", e);
|
|
||||||
} finally {
|
|
||||||
ArchivalDAOUtil.cleanupResources(stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteProfileOperations() throws ArchivalDAOException {
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
|
||||||
conn.setAutoCommit(false);
|
|
||||||
String sql = "DELETE FROM DM_PROFILE_OPERATION_ARCH" +
|
|
||||||
" WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setInt(1, this.retentionPeriod);
|
|
||||||
stmt.executeUpdate();
|
|
||||||
conn.commit();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ArchivalDAOException("Error occurred while deleting profile operations", e);
|
|
||||||
} finally {
|
|
||||||
ArchivalDAOUtil.cleanupResources(stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteEnrolmentMappings() throws ArchivalDAOException {
|
public void deleteEnrolmentMappings() throws ArchivalDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING_ARCH WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
String sql = "DELETE FROM "+ DESTINATION_DB + ".DM_ENROLMENT_OP_MAPPING_ARCH WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, this.retentionPeriod);
|
stmt.setInt(1, this.retentionPeriod);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
@ -143,7 +127,7 @@ public class DataDeletionDAOImpl implements DataDeletionDAO {
|
|||||||
try {
|
try {
|
||||||
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
Connection conn = ArchivalDestinationDAOFactory.getConnection();
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
String sql = "DELETE FROM DM_OPERATION_ARCH WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
String sql = "DELETE FROM "+ DESTINATION_DB +".DM_OPERATION_ARCH WHERE ARCHIVED_AT < DATE_SUB(NOW(), INTERVAL ? DAY)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, this.retentionPeriod);
|
stmt.setInt(1, this.retentionPeriod);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|||||||
@ -269,16 +269,4 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori
|
|||||||
permission.setPath(PermissionUtils.getAbsolutePermissionPath(CDM_ADMIN_PERMISSION));
|
permission.setPath(PermissionUtils.getAbsolutePermissionPath(CDM_ADMIN_PERMISSION));
|
||||||
return PermissionUtils.putPermission(permission);
|
return PermissionUtils.putPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class PermissionMethod {
|
|
||||||
public static final String READ = "read";
|
|
||||||
public static final String WRITE = "write";
|
|
||||||
public static final String DELETE = "delete";
|
|
||||||
public static final String ACTION = "action";
|
|
||||||
public static final String UI_EXECUTE = "ui.execute";
|
|
||||||
|
|
||||||
private PermissionMethod() {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -28,8 +28,28 @@ public class ArchivalTaskConfiguration {
|
|||||||
private String taskClazz;
|
private String taskClazz;
|
||||||
private int retentionPeriod;
|
private int retentionPeriod;
|
||||||
private int batchSize;
|
private int batchSize;
|
||||||
|
private int archivalLockInterval;
|
||||||
private PurgingTaskConfiguration purgingTaskConfiguration;
|
private PurgingTaskConfiguration purgingTaskConfiguration;
|
||||||
private boolean archivePendingOperations;
|
private boolean archivePendingOperations;
|
||||||
|
private DBConfig dbConfig;
|
||||||
|
|
||||||
|
@XmlElement(name = "ArchivalLockInterval", required = true)
|
||||||
|
public int getArchivalLockInterval() {
|
||||||
|
return archivalLockInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArchivalLockInterval(int archivalLockInterval) {
|
||||||
|
this.archivalLockInterval = archivalLockInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "DBConfig", required = true)
|
||||||
|
public DBConfig getDbConfig() {
|
||||||
|
return dbConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDbConfig(DBConfig dbConfig) {
|
||||||
|
this.dbConfig = dbConfig;
|
||||||
|
}
|
||||||
|
|
||||||
@XmlElement(name = "Enabled", required = true)
|
@XmlElement(name = "Enabled", required = true)
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
|
|||||||
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.core.config.archival;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the information related to data archival configurations.
|
||||||
|
*/
|
||||||
|
@XmlRootElement(name = "DBConfig")
|
||||||
|
public class DBConfig {
|
||||||
|
|
||||||
|
private String destinationDB;
|
||||||
|
private String sourceDB;
|
||||||
|
|
||||||
|
@XmlElement(name = "DestinationDB", required = true)
|
||||||
|
public String getDestinationDB() {
|
||||||
|
return destinationDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestinationDB(String destinationDB) {
|
||||||
|
this.destinationDB = destinationDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "SourceDB", required = true)
|
||||||
|
public String getSourceDB() {
|
||||||
|
return sourceDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceDB(String sourceDB) {
|
||||||
|
this.sourceDB = sourceDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,23 +15,6 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -28,18 +28,12 @@ public interface EnrollmentDAO {
|
|||||||
|
|
||||||
EnrolmentInfo addEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId) throws DeviceManagementDAOException;
|
EnrolmentInfo addEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
int updateEnrollment(int deviceId, EnrolmentInfo enrolmentInfo,
|
int updateEnrollment(EnrolmentInfo enrolmentInfo, int tenantId) throws DeviceManagementDAOException;
|
||||||
int tenantId) throws DeviceManagementDAOException;
|
|
||||||
|
|
||||||
int updateEnrollment(EnrolmentInfo enrolmentInfo) throws DeviceManagementDAOException;
|
|
||||||
|
|
||||||
boolean updateEnrollmentStatus(List<EnrolmentInfo> enrolmentInfos) throws DeviceManagementDAOException;
|
boolean updateEnrollmentStatus(List<EnrolmentInfo> enrolmentInfos) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
int removeEnrollment(int deviceId, String currentOwner, int tenantId) throws DeviceManagementDAOException;
|
int removeEnrollment(int deviceId, String currentOwner, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
boolean setStatus(int enrolmentId, String currentOwner, Status status,
|
|
||||||
int tenantId) throws DeviceManagementDAOException;
|
|
||||||
|
|
||||||
boolean setStatus(String currentOwner, Status status, int tenantId) throws DeviceManagementDAOException;
|
boolean setStatus(String currentOwner, Status status, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
boolean setStatus(int enrolmentId, Status status, int tenantId) throws DeviceManagementDAOException;
|
boolean setStatus(int enrolmentId, Status status, int tenantId) throws DeviceManagementDAOException;
|
||||||
@ -48,6 +42,8 @@ public interface EnrollmentDAO {
|
|||||||
|
|
||||||
EnrolmentInfo getEnrollment(int deviceId, String currentUser, int tenantId) throws DeviceManagementDAOException;
|
EnrolmentInfo getEnrollment(int deviceId, String currentUser, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
EnrolmentInfo getEnrollment(int deviceId, int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
List<EnrolmentInfo> getEnrollmentsOfUser(int deviceId, String user, int tenantId) throws
|
List<EnrolmentInfo> getEnrollmentsOfUser(int deviceId, String user, int tenantId) throws
|
||||||
DeviceManagementDAOException;
|
DeviceManagementDAOException;
|
||||||
|
|
||||||
|
|||||||
@ -16,23 +16,6 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
||||||
*
|
*
|
||||||
@ -170,6 +153,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
+ "e.OWNER, "
|
+ "e.OWNER, "
|
||||||
+ "e.OWNERSHIP, "
|
+ "e.OWNERSHIP, "
|
||||||
+ "e.STATUS, "
|
+ "e.STATUS, "
|
||||||
|
+ "e.IS_TRANSFERRED, "
|
||||||
+ "e.DATE_OF_LAST_UPDATE, "
|
+ "e.DATE_OF_LAST_UPDATE, "
|
||||||
+ "e.DATE_OF_ENROLMENT, "
|
+ "e.DATE_OF_ENROLMENT, "
|
||||||
+ "e.ID AS ENROLMENT_ID "
|
+ "e.ID AS ENROLMENT_ID "
|
||||||
@ -247,7 +231,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
||||||
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
||||||
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
||||||
@ -287,7 +271,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
"d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
"d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
|
||||||
"FROM " +
|
"FROM " +
|
||||||
"DM_ENROLMENT e," +
|
"DM_ENROLMENT e," +
|
||||||
@ -334,7 +318,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
||||||
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
||||||
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
||||||
@ -368,7 +352,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
||||||
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " +
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " +
|
||||||
"WHERE t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
|
"WHERE t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
|
||||||
@ -558,7 +542,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " +
|
||||||
"FROM" +
|
"FROM" +
|
||||||
" DM_ENROLMENT e, " +
|
" DM_ENROLMENT e, " +
|
||||||
@ -603,7 +587,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
||||||
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " +
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " +
|
||||||
"WHERE t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
|
"WHERE t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
|
||||||
@ -638,7 +622,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
||||||
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
||||||
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
"t.NAME = ? AND t.ID = d.DEVICE_TYPE_ID AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
||||||
@ -676,6 +660,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -726,7 +711,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
||||||
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
||||||
"d.ID = ? AND t.ID = d.DEVICE_TYPE_ID AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
"d.ID = ? AND t.ID = d.DEVICE_TYPE_ID AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
||||||
@ -753,11 +738,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Device> devices = null;
|
List<Device> devices;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, " +
|
||||||
"d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
|
||||||
@ -789,7 +774,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " +
|
||||||
"d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
"d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
|
"DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
|
||||||
@ -823,10 +808,10 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.DATE_OF_LAST_UPDATE," +
|
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.IS_TRANSFERRED, e1.DATE_OF_LAST_UPDATE," +
|
||||||
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
||||||
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
||||||
"e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
"e.DEVICE_ID, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
||||||
"e.TENANT_ID = ? AND LOWER(e.OWNER) = LOWER(?)) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
"e.TENANT_ID = ? AND LOWER(e.OWNER) = LOWER(?)) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
||||||
"AND t.ID = d.DEVICE_TYPE_ID ORDER BY e1.DATE_OF_LAST_UPDATE DESC";
|
"AND t.ID = d.DEVICE_TYPE_ID ORDER BY e1.DATE_OF_LAST_UPDATE DESC";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -856,10 +841,10 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.DATE_OF_LAST_UPDATE," +
|
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.IS_TRANSFERRED, e1.DATE_OF_LAST_UPDATE," +
|
||||||
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
||||||
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
||||||
"e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
"e.DEVICE_ID, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
||||||
"e.TENANT_ID = ? AND LOWER(e.OWNER) = LOWER(?) ORDER BY e.DATE_OF_LAST_UPDATE DESC) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
"e.TENANT_ID = ? AND LOWER(e.OWNER) = LOWER(?) ORDER BY e.DATE_OF_LAST_UPDATE DESC) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
||||||
"AND t.ID = d.DEVICE_TYPE_ID AND t.NAME= ?";
|
"AND t.ID = d.DEVICE_TYPE_ID AND t.NAME= ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -1449,16 +1434,17 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
int enrolmentId = -1;
|
int enrolmentId = -1;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, " +
|
String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS, IS_TRANSFERRED, " +
|
||||||
"DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
"DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(sql, new String[]{"id"});
|
stmt = conn.prepareStatement(sql, new String[]{"id"});
|
||||||
stmt.setInt(1, device.getId());
|
stmt.setInt(1, device.getId());
|
||||||
stmt.setString(2, device.getEnrolmentInfo().getOwner());
|
stmt.setString(2, device.getEnrolmentInfo().getOwner());
|
||||||
stmt.setString(3, device.getEnrolmentInfo().getOwnership().toString());
|
stmt.setString(3, device.getEnrolmentInfo().getOwnership().toString());
|
||||||
stmt.setString(4, device.getEnrolmentInfo().getStatus().toString());
|
stmt.setString(4, device.getEnrolmentInfo().getStatus().toString());
|
||||||
stmt.setTimestamp(5, new Timestamp(new Date().getTime()));
|
stmt.setBoolean(5, device.getEnrolmentInfo().isTransferred());
|
||||||
stmt.setTimestamp(6, new Timestamp(new Date().getTime()));
|
stmt.setTimestamp(6, new Timestamp(new Date().getTime()));
|
||||||
stmt.setInt(7, tenantId);
|
stmt.setTimestamp(7, new Timestamp(new Date().getTime()));
|
||||||
|
stmt.setInt(8, tenantId);
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
|
|
||||||
rs = stmt.getGeneratedKeys();
|
rs = stmt.getGeneratedKeys();
|
||||||
@ -1542,6 +1528,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
+ "OWNER, "
|
+ "OWNER, "
|
||||||
+ "OWNERSHIP, "
|
+ "OWNERSHIP, "
|
||||||
+ "STATUS, "
|
+ "STATUS, "
|
||||||
|
+ "IS_TRANSFERRED, "
|
||||||
+ "DATE_OF_ENROLMENT, "
|
+ "DATE_OF_ENROLMENT, "
|
||||||
+ "DATE_OF_LAST_UPDATE, "
|
+ "DATE_OF_LAST_UPDATE, "
|
||||||
+ "TENANT_ID "
|
+ "TENANT_ID "
|
||||||
@ -1589,7 +1576,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
EnrolmentInfo enrolmentInfo = null;
|
EnrolmentInfo enrolmentInfo = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
|
String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, IS_TRANSFERRED, DATE_OF_ENROLMENT, " +
|
||||||
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
|
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
|
||||||
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
||||||
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
|
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
|
||||||
@ -1622,9 +1609,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
||||||
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e" +
|
"e.DATE_OF_ENROLMENT, e.ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e" +
|
||||||
".OWNERSHIP, e.STATUS, e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS " +
|
".OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS " +
|
||||||
"ENROLMENT_ID FROM DM_ENROLMENT e WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
"ENROLMENT_ID FROM DM_ENROLMENT e WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
||||||
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -1687,7 +1674,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, " +
|
||||||
"d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE, d.LAST_UPDATED_TIMESTAMP FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE, d.LAST_UPDATED_TIMESTAMP FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? AND d.LAST_UPDATED_TIMESTAMP < CURRENT_TIMESTAMP) d1 " +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? AND d.LAST_UPDATED_TIMESTAMP < CURRENT_TIMESTAMP) d1 " +
|
||||||
@ -1805,8 +1792,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
StringJoiner joiner = new StringJoiner(",",
|
StringJoiner joiner = new StringJoiner(",",
|
||||||
"SELECT "
|
"SELECT "
|
||||||
+ "d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, "
|
+ "d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, "
|
||||||
+ "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, "
|
+ "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, "
|
||||||
+ "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID "
|
+ "e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID "
|
||||||
+ "FROM "
|
+ "FROM "
|
||||||
+ "DM_ENROLMENT e, "
|
+ "DM_ENROLMENT e, "
|
||||||
+ "(SELECT d.ID, d.DESCRIPTION, d.NAME, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION "
|
+ "(SELECT d.ID, d.DESCRIPTION, d.NAME, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION "
|
||||||
@ -1970,6 +1957,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
|
|||||||
@ -781,6 +781,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
|
|||||||
+ "e.OWNER, "
|
+ "e.OWNER, "
|
||||||
+ "e.OWNERSHIP, "
|
+ "e.OWNERSHIP, "
|
||||||
+ "e.STATUS, "
|
+ "e.STATUS, "
|
||||||
|
+ "e.IS_TRANSFERRED, "
|
||||||
+ "e.DATE_OF_LAST_UPDATE, "
|
+ "e.DATE_OF_LAST_UPDATE, "
|
||||||
+ "e.DATE_OF_ENROLMENT, "
|
+ "e.DATE_OF_ENROLMENT, "
|
||||||
+ "e.ID AS ENROLMENT_ID "
|
+ "e.ID AS ENROLMENT_ID "
|
||||||
@ -834,11 +835,11 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
|
|||||||
"ENROLMENT.OWNERSHIP, " +
|
"ENROLMENT.OWNERSHIP, " +
|
||||||
"ENROLMENT.DATE_OF_ENROLMENT, " +
|
"ENROLMENT.DATE_OF_ENROLMENT, " +
|
||||||
"ENROLMENT.DATE_OF_LAST_UPDATE, " +
|
"ENROLMENT.DATE_OF_LAST_UPDATE, " +
|
||||||
"ENROLMENT.STATUS " +
|
"ENROLMENT.STATUS, " +
|
||||||
|
"ENROLMENT.IS_TRANSFERRED " +
|
||||||
"FROM DM_DEVICE AS DEVICE, DM_DEVICE_TYPE AS DEVICE_TYPE, DM_ENROLMENT " +
|
"FROM DM_DEVICE AS DEVICE, DM_DEVICE_TYPE AS DEVICE_TYPE, DM_ENROLMENT " +
|
||||||
"AS ENROLMENT " +
|
"AS ENROLMENT " +
|
||||||
"WHERE DEVICE_TYPE.NAME = ? AND DEVICE" +
|
"WHERE DEVICE_TYPE.NAME = ? AND DEVICE.ID " +
|
||||||
".ID " +
|
|
||||||
"NOT IN " +
|
"NOT IN " +
|
||||||
"(SELECT DEVICE_ID " +
|
"(SELECT DEVICE_ID " +
|
||||||
"FROM DM_DEVICE_GROUP_MAP " +
|
"FROM DM_DEVICE_GROUP_MAP " +
|
||||||
|
|||||||
@ -75,47 +75,21 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int updateEnrollment(int deviceId, EnrolmentInfo enrolmentInfo,
|
public int updateEnrollment(EnrolmentInfo enrolmentInfo, int tenantId) throws DeviceManagementDAOException {
|
||||||
int tenantId) throws DeviceManagementDAOException {
|
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, DATE_OF_LAST_UPDATE = ? WHERE DEVICE_ID = ?" +
|
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, DATE_OF_LAST_UPDATE = ? " +
|
||||||
" AND OWNER = ? AND TENANT_ID = ? AND ID = ?";
|
"WHERE ID = ? AND TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setString(1, enrolmentInfo.getOwnership().toString());
|
|
||||||
stmt.setString(2, enrolmentInfo.getStatus().toString());
|
|
||||||
stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
|
|
||||||
stmt.setInt(4, deviceId);
|
|
||||||
stmt.setString(5, enrolmentInfo.getOwner());
|
|
||||||
stmt.setInt(6, tenantId);
|
|
||||||
stmt.setInt(7, enrolmentInfo.getId());
|
|
||||||
int status = stmt.executeUpdate();
|
|
||||||
return status;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int updateEnrollment(EnrolmentInfo enrolmentInfo) throws DeviceManagementDAOException {
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, DATE_OF_LAST_UPDATE = ? WHERE ID = ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, enrolmentInfo.getOwnership().toString());
|
stmt.setString(1, enrolmentInfo.getOwnership().toString());
|
||||||
stmt.setString(2, enrolmentInfo.getStatus().toString());
|
stmt.setString(2, enrolmentInfo.getStatus().toString());
|
||||||
stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
|
stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
|
||||||
stmt.setInt(4, enrolmentInfo.getId());
|
stmt.setInt(4, enrolmentInfo.getId());
|
||||||
int status = stmt.executeUpdate();
|
stmt.setInt(5, tenantId);
|
||||||
return status;
|
return stmt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e);
|
throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -188,28 +162,6 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setStatus(int enrolmentID, String currentOwner, EnrolmentInfo.Status status,
|
|
||||||
int tenantId) throws DeviceManagementDAOException {
|
|
||||||
Connection conn;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String sql = "UPDATE DM_ENROLMENT SET STATUS = ? WHERE ID = ? AND OWNER = ? AND TENANT_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setString(1, status.toString());
|
|
||||||
stmt.setInt(2, enrolmentID);
|
|
||||||
stmt.setString(3, currentOwner);
|
|
||||||
stmt.setInt(4, tenantId);
|
|
||||||
stmt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new DeviceManagementDAOException("Error occurred while setting the status of device enrolment", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getCountOfDevicesOfOwner(String owner, int tenantID) throws DeviceManagementDAOException {
|
private int getCountOfDevicesOfOwner(String owner, int tenantID) throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -314,7 +266,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
EnrolmentInfo enrolmentInfo = null;
|
EnrolmentInfo enrolmentInfo = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
|
String sql = "SELECT ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, IS_TRANSFERRED, DATE_OF_ENROLMENT, " +
|
||||||
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?";
|
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, deviceId);
|
stmt.setInt(1, deviceId);
|
||||||
@ -333,6 +285,33 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnrolmentInfo getEnrollment(int deviceId, int tenantId) throws DeviceManagementDAOException {
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
EnrolmentInfo enrolmentInfo = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String sql = "SELECT ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, IS_TRANSFERRED, DATE_OF_ENROLMENT, " +
|
||||||
|
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND TENANT_ID = ? " +
|
||||||
|
"ORDER BY DATE_OF_LAST_UPDATE DESC";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
if (rs.next()) {
|
||||||
|
enrolmentInfo = this.loadEnrolment(rs);
|
||||||
|
}
|
||||||
|
return enrolmentInfo;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
|
||||||
|
"information of device '" + deviceId + "'", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EnrolmentInfo> getEnrollmentsOfUser(int deviceId, String user, int tenantId)
|
public List<EnrolmentInfo> getEnrollmentsOfUser(int deviceId, String user, int tenantId)
|
||||||
throws DeviceManagementDAOException {
|
throws DeviceManagementDAOException {
|
||||||
@ -343,7 +322,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
EnrolmentInfo enrolmentInfo = null;
|
EnrolmentInfo enrolmentInfo = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
|
String sql = "SELECT ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, IS_TRANSFERRED, DATE_OF_ENROLMENT, " +
|
||||||
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?";
|
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, deviceId);
|
stmt.setInt(1, deviceId);
|
||||||
@ -369,20 +348,21 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
try {
|
try {
|
||||||
Connection conn = this.getConnection();
|
Connection conn = this.getConnection();
|
||||||
boolean updateStatus = true;
|
boolean updateStatus = true;
|
||||||
String sql = "UPDATE "
|
String sql = "UPDATE DM_ENROLMENT "
|
||||||
+ "DM_ENROLMENT "
|
+ "SET OWNER = ?, IS_TRANSFERRED = ?, DATE_OF_LAST_UPDATE = ? "
|
||||||
+ "SET OWNER = ? "
|
+ "WHERE ID = ? AND TENANT_ID = ?";
|
||||||
+ "WHERE ID = ? AND "
|
|
||||||
+ "TENANT_ID = ?";
|
|
||||||
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||||
if (conn.getMetaData().supportsBatchUpdates()) {
|
if (conn.getMetaData().supportsBatchUpdates()) {
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
ps.setString(1, owner);
|
ps.setString(1, owner);
|
||||||
ps.setInt(2, device.getId());
|
ps.setBoolean(2, device.getEnrolmentInfo().isTransferred());
|
||||||
ps.setInt(3, tenantId);
|
ps.setTimestamp(3, new Timestamp(new Date().getTime()));
|
||||||
|
ps.setInt(4, device.getEnrolmentInfo().getId());
|
||||||
|
ps.setInt(5, tenantId);
|
||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
}
|
}
|
||||||
for (int i : ps.executeBatch()) {
|
int[] batchResult = ps.executeBatch();
|
||||||
|
for (int i : batchResult) {
|
||||||
if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) {
|
if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) {
|
||||||
updateStatus = false;
|
updateStatus = false;
|
||||||
break;
|
break;
|
||||||
@ -391,8 +371,9 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
} else {
|
} else {
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
ps.setString(1, owner);
|
ps.setString(1, owner);
|
||||||
ps.setInt(2, device.getId());
|
ps.setBoolean(2, device.getEnrolmentInfo().isTransferred());
|
||||||
ps.setInt(3, tenantId);
|
ps.setInt(3, device.getId());
|
||||||
|
ps.setInt(4, tenantId);
|
||||||
if (ps.executeUpdate() == 0) {
|
if (ps.executeUpdate() == 0) {
|
||||||
updateStatus = false;
|
updateStatus = false;
|
||||||
break;
|
break;
|
||||||
@ -415,6 +396,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
|||||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
||||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
||||||
|
enrolmentInfo.setTransferred(rs.getBoolean("IS_TRANSFERRED"));
|
||||||
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
|
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
|
||||||
enrolmentInfo.setDateOfLastUpdate(rs.getTimestamp("DATE_OF_LAST_UPDATE").getTime());
|
enrolmentInfo.setDateOfLastUpdate(rs.getTimestamp("DATE_OF_LAST_UPDATE").getTime());
|
||||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS")));
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS")));
|
||||||
|
|||||||
@ -77,6 +77,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -86,8 +87,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"d.NAME, " +
|
"d.NAME, " +
|
||||||
"d.DEVICE_IDENTIFICATION, " +
|
"d.DEVICE_IDENTIFICATION, " +
|
||||||
"t.NAME AS DEVICE_TYPE " +
|
"t.NAME AS DEVICE_TYPE " +
|
||||||
"FROM DM_DEVICE d, " +
|
"FROM DM_DEVICE d, DM_DEVICE_TYPE t ";
|
||||||
"DM_DEVICE_TYPE t ";
|
|
||||||
//Add the query to filter active devices on timestamp
|
//Add the query to filter active devices on timestamp
|
||||||
if (since != null) {
|
if (since != null) {
|
||||||
sql = sql + ", DM_DEVICE_DETAIL dt";
|
sql = sql + ", DM_DEVICE_DETAIL dt";
|
||||||
@ -204,6 +204,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -320,10 +321,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.DATE_OF_LAST_UPDATE," +
|
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.IS_TRANSFERRED, e1.DATE_OF_LAST_UPDATE," +
|
||||||
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
||||||
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
||||||
"e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
"e.DEVICE_ID, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
||||||
"e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
"e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
||||||
"AND t.ID = d.DEVICE_TYPE_ID LIMIT ?,?";
|
"AND t.ID = d.DEVICE_TYPE_ID LIMIT ?,?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -355,7 +356,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||||
"d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
||||||
@ -390,8 +391,8 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
||||||
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
|
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
|
||||||
"WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
"WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
||||||
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ?,?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ?,?";
|
||||||
@ -432,6 +433,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -441,6 +443,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -504,6 +507,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE," +
|
"e.DATE_OF_LAST_UPDATE," +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -703,7 +707,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||||
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||||
@ -766,6 +770,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
+ "DM_ENROLMENT.DATE_OF_ENROLMENT, "
|
+ "DM_ENROLMENT.DATE_OF_ENROLMENT, "
|
||||||
+ "DM_ENROLMENT.DATE_OF_LAST_UPDATE, "
|
+ "DM_ENROLMENT.DATE_OF_LAST_UPDATE, "
|
||||||
+ "DM_ENROLMENT.STATUS, "
|
+ "DM_ENROLMENT.STATUS, "
|
||||||
|
+ "DM_ENROLMENT.IS_TRANSFERRED, "
|
||||||
+ "device_types.NAME AS DEVICE_TYPE "
|
+ "device_types.NAME AS DEVICE_TYPE "
|
||||||
+ "FROM DM_DEVICE "
|
+ "FROM DM_DEVICE "
|
||||||
+ "INNER JOIN DM_ENROLMENT ON "
|
+ "INNER JOIN DM_ENROLMENT ON "
|
||||||
@ -881,6 +886,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT " +
|
"e.DATE_OF_ENROLMENT " +
|
||||||
"FROM DM_DEVICE_INFO ddi," +
|
"FROM DM_DEVICE_INFO ddi," +
|
||||||
|
|||||||
@ -78,6 +78,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -206,6 +207,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -323,10 +325,10 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.DATE_OF_LAST_UPDATE,"
|
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.IS_TRANSFERRED, e1.DATE_OF_LAST_UPDATE,"
|
||||||
+ " e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME "
|
+ " e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME "
|
||||||
+ "AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, "
|
+ "AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, "
|
||||||
+ "e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE "
|
+ "e.DEVICE_ID, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE "
|
||||||
+ "e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID "
|
+ "e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID "
|
||||||
+ "AND t.ID = d.DEVICE_TYPE_ID ORDER BY ENROLMENT_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
+ "AND t.ID = d.DEVICE_TYPE_ID ORDER BY ENROLMENT_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -358,7 +360,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, "
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, "
|
||||||
+ "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, "
|
+ "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, "
|
||||||
+ "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, "
|
+ "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, "
|
||||||
+ "d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, "
|
+ "d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, "
|
||||||
+ "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 "
|
+ "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 "
|
||||||
@ -394,8 +396,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, "
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, "
|
||||||
+ "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, "
|
+ "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, "
|
||||||
+ "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, "
|
+ "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, "
|
||||||
+ "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e "
|
+ "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e "
|
||||||
+ "WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t "
|
+ "WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t "
|
||||||
+ "WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? ORDER BY ENROLMENT_ID "
|
+ "WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? ORDER BY ENROLMENT_ID "
|
||||||
@ -438,6 +440,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -446,6 +449,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -509,6 +513,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE," +
|
"e.DATE_OF_LAST_UPDATE," +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -673,7 +678,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||||
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||||
@ -735,6 +740,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
+ "DM_ENROLMENT.DATE_OF_ENROLMENT, "
|
+ "DM_ENROLMENT.DATE_OF_ENROLMENT, "
|
||||||
+ "DM_ENROLMENT.DATE_OF_LAST_UPDATE, "
|
+ "DM_ENROLMENT.DATE_OF_LAST_UPDATE, "
|
||||||
+ "DM_ENROLMENT.STATUS, "
|
+ "DM_ENROLMENT.STATUS, "
|
||||||
|
+ "DM_ENROLMENT.IS_TRANSFERRED, "
|
||||||
+ "device_types.NAME AS DEVICE_TYPE "
|
+ "device_types.NAME AS DEVICE_TYPE "
|
||||||
+ "FROM DM_DEVICE "
|
+ "FROM DM_DEVICE "
|
||||||
+ "INNER JOIN DM_ENROLMENT ON "
|
+ "INNER JOIN DM_ENROLMENT ON "
|
||||||
@ -847,6 +853,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT " +
|
"e.DATE_OF_ENROLMENT " +
|
||||||
"FROM DM_DEVICE_INFO ddi, " +
|
"FROM DM_DEVICE_INFO ddi, " +
|
||||||
|
|||||||
@ -77,6 +77,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -194,6 +195,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -310,10 +312,10 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.DATE_OF_LAST_UPDATE," +
|
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.IS_TRANSFERRED, e1.DATE_OF_LAST_UPDATE," +
|
||||||
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
||||||
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
||||||
"e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
"e.DEVICE_ID, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
||||||
"e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
"e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
||||||
"AND t.ID = d.DEVICE_TYPE_ID LIMIT ? OFFSET ?";
|
"AND t.ID = d.DEVICE_TYPE_ID LIMIT ? OFFSET ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -345,7 +347,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||||
"d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
||||||
@ -380,8 +382,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
||||||
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
|
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
|
||||||
"WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
"WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
||||||
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ? OFFSET ?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? LIMIT ? OFFSET ?";
|
||||||
@ -423,6 +425,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -432,6 +435,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -493,6 +497,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE," +
|
"e.DATE_OF_LAST_UPDATE," +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -658,7 +663,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||||
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||||
@ -721,6 +726,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
+ "DM_ENROLMENT.DATE_OF_ENROLMENT, "
|
+ "DM_ENROLMENT.DATE_OF_ENROLMENT, "
|
||||||
+ "DM_ENROLMENT.DATE_OF_LAST_UPDATE, "
|
+ "DM_ENROLMENT.DATE_OF_LAST_UPDATE, "
|
||||||
+ "DM_ENROLMENT.STATUS, "
|
+ "DM_ENROLMENT.STATUS, "
|
||||||
|
+ "DM_ENROLMENT.IS_TRANSFERRED, "
|
||||||
+ "device_types.NAME AS DEVICE_TYPE "
|
+ "device_types.NAME AS DEVICE_TYPE "
|
||||||
+ "FROM DM_DEVICE "
|
+ "FROM DM_DEVICE "
|
||||||
+ "INNER JOIN DM_ENROLMENT ON "
|
+ "INNER JOIN DM_ENROLMENT ON "
|
||||||
@ -833,6 +839,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT " +
|
"e.DATE_OF_ENROLMENT " +
|
||||||
"FROM DM_DEVICE_INFO ddi, " +
|
"FROM DM_DEVICE_INFO ddi, " +
|
||||||
|
|||||||
@ -79,6 +79,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -206,6 +207,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -322,10 +324,10 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
List<Device> devices = new ArrayList<>();
|
List<Device> devices = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.DATE_OF_LAST_UPDATE," +
|
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.IS_TRANSFERRED, e1.DATE_OF_LAST_UPDATE," +
|
||||||
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
||||||
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
||||||
"e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
"e.DEVICE_ID, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
||||||
"e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
"e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
||||||
"AND t.ID = d.DEVICE_TYPE_ID ORDER BY ENROLMENT_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
"AND t.ID = d.DEVICE_TYPE_ID ORDER BY ENROLMENT_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -357,7 +359,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||||
"d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
||||||
@ -393,8 +395,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
||||||
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
|
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
|
||||||
"WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
"WHERE TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
||||||
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? ORDER BY ENROLMENT_ID " +
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? ORDER BY ENROLMENT_ID " +
|
||||||
@ -437,6 +439,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -446,6 +449,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
@ -520,7 +524,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
|
||||||
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
"d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
|
||||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
||||||
@ -583,6 +587,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
+ "DM_ENROLMENT.DATE_OF_ENROLMENT, "
|
+ "DM_ENROLMENT.DATE_OF_ENROLMENT, "
|
||||||
+ "DM_ENROLMENT.DATE_OF_LAST_UPDATE, "
|
+ "DM_ENROLMENT.DATE_OF_LAST_UPDATE, "
|
||||||
+ "DM_ENROLMENT.STATUS, "
|
+ "DM_ENROLMENT.STATUS, "
|
||||||
|
+ "DM_ENROLMENT.IS_TRANSFERRED, "
|
||||||
+ "device_types.NAME AS DEVICE_TYPE "
|
+ "device_types.NAME AS DEVICE_TYPE "
|
||||||
+ "FROM DM_DEVICE "
|
+ "FROM DM_DEVICE "
|
||||||
+ "INNER JOIN DM_ENROLMENT ON "
|
+ "INNER JOIN DM_ENROLMENT ON "
|
||||||
@ -649,6 +654,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE, " +
|
"e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT " +
|
"e.DATE_OF_ENROLMENT " +
|
||||||
"FROM DM_DEVICE_INFO ddi, " +
|
"FROM DM_DEVICE_INFO ddi, " +
|
||||||
@ -761,6 +767,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|||||||
"e.OWNER, " +
|
"e.OWNER, " +
|
||||||
"e.OWNERSHIP, " +
|
"e.OWNERSHIP, " +
|
||||||
"e.STATUS, " +
|
"e.STATUS, " +
|
||||||
|
"e.IS_TRANSFERRED, " +
|
||||||
"e.DATE_OF_LAST_UPDATE," +
|
"e.DATE_OF_LAST_UPDATE," +
|
||||||
"e.DATE_OF_ENROLMENT, " +
|
"e.DATE_OF_ENROLMENT, " +
|
||||||
"e.ID AS ENROLMENT_ID " +
|
"e.ID AS ENROLMENT_ID " +
|
||||||
|
|||||||
@ -177,7 +177,7 @@ public class GenericGroupDAOImpl extends AbstractGroupDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = GroupManagementDAOFactory.getConnection();
|
conn = GroupManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
||||||
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
||||||
"FROM " +
|
"FROM " +
|
||||||
|
|||||||
@ -178,7 +178,7 @@ public class OracleGroupDAOImpl extends AbstractGroupDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = GroupManagementDAOFactory.getConnection();
|
conn = GroupManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
||||||
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
||||||
"FROM " +
|
"FROM " +
|
||||||
|
|||||||
@ -218,7 +218,7 @@ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = GroupManagementDAOFactory.getConnection();
|
conn = GroupManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
||||||
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
||||||
"FROM " +
|
"FROM " +
|
||||||
|
|||||||
@ -178,7 +178,7 @@ public class SQLServerGroupDAOImpl extends AbstractGroupDAOImpl {
|
|||||||
try {
|
try {
|
||||||
conn = GroupManagementDAOFactory.getConnection();
|
conn = GroupManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.IS_TRANSFERRED, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
||||||
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
||||||
"FROM " +
|
"FROM " +
|
||||||
|
|||||||
@ -144,6 +144,7 @@ public final class DeviceManagementDAOUtil {
|
|||||||
enrolmentInfo.setId(rs.getInt("ENROLMENT_ID"));
|
enrolmentInfo.setId(rs.getInt("ENROLMENT_ID"));
|
||||||
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
||||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
||||||
|
enrolmentInfo.setTransferred(rs.getBoolean("IS_TRANSFERRED"));
|
||||||
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
|
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
|
||||||
enrolmentInfo.setDateOfLastUpdate(rs.getTimestamp("DATE_OF_LAST_UPDATE").getTime());
|
enrolmentInfo.setDateOfLastUpdate(rs.getTimestamp("DATE_OF_LAST_UPDATE").getTime());
|
||||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS")));
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.valueOf(rs.getString("STATUS")));
|
||||||
@ -198,7 +199,6 @@ public final class DeviceManagementDAOUtil {
|
|||||||
//This method will retrieve most appropriate device information when there are multiple device enrollments for
|
//This method will retrieve most appropriate device information when there are multiple device enrollments for
|
||||||
//a single device. Here we'll consider only active status.
|
//a single device. Here we'll consider only active status.
|
||||||
public static Device loadActiveDevice(ResultSet rs, boolean deviceInfoIncluded) throws SQLException {
|
public static Device loadActiveDevice(ResultSet rs, boolean deviceInfoIncluded) throws SQLException {
|
||||||
Map<EnrolmentInfo.Status, Device> deviceMap = new HashMap<>();
|
|
||||||
Device device = loadDevice(rs);
|
Device device = loadDevice(rs);
|
||||||
if (deviceInfoIncluded) {
|
if (deviceInfoIncluded) {
|
||||||
device.setDeviceInfo(loadDeviceInfo(rs));
|
device.setDeviceInfo(loadDeviceInfo(rs));
|
||||||
@ -209,7 +209,6 @@ public final class DeviceManagementDAOUtil {
|
|||||||
//This method will retrieve most appropriate device information when there are multiple device enrollments for
|
//This method will retrieve most appropriate device information when there are multiple device enrollments for
|
||||||
//a single device. We'll give the highest priority to active devices.
|
//a single device. We'll give the highest priority to active devices.
|
||||||
public static Device loadMatchingDevice(ResultSet rs, boolean deviceInfoIncluded) throws SQLException {
|
public static Device loadMatchingDevice(ResultSet rs, boolean deviceInfoIncluded) throws SQLException {
|
||||||
Map<EnrolmentInfo.Status, Device> deviceMap = new HashMap<>();
|
|
||||||
Device device = loadDevice(rs);
|
Device device = loadDevice(rs);
|
||||||
if (deviceInfoIncluded) {
|
if (deviceInfoIncluded) {
|
||||||
device.setDeviceInfo(loadDeviceInfo(rs));
|
device.setDeviceInfo(loadDeviceInfo(rs));
|
||||||
|
|||||||
@ -60,6 +60,8 @@ public interface DeviceInformationManager {
|
|||||||
*/
|
*/
|
||||||
DeviceInfo getDeviceInfo(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException;
|
DeviceInfo getDeviceInfo(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException;
|
||||||
|
|
||||||
|
DeviceInfo getDeviceInfo(Device device) throws DeviceDetailsMgtException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will return device information for the supplied devices list.
|
* This method will return device information for the supplied devices list.
|
||||||
* @param deviceIdentifiers
|
* @param deviceIdentifiers
|
||||||
|
|||||||
@ -273,8 +273,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
|
|||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_LOCATION (DEVICE_ID, LATITUDE, LONGITUDE, STREET1, " +
|
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_LOCATION (DEVICE_ID, LATITUDE, LONGITUDE, STREET1, " +
|
||||||
"STREET2, CITY, ZIP, STATE, COUNTRY, GEO_HASH, UPDATE_TIMESTAMP, ENROLMENT_ID, ALTITUDE, SPEED, BEARING, " +
|
"STREET2, CITY, ZIP, STATE, COUNTRY, GEO_HASH, UPDATE_TIMESTAMP, ENROLMENT_ID, ALTITUDE, SPEED, BEARING, " +
|
||||||
"DISTANCE) " +
|
"DISTANCE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
||||||
stmt.setInt(1, deviceLocation.getDeviceId());
|
stmt.setInt(1, deviceLocation.getDeviceId());
|
||||||
stmt.setDouble(2, deviceLocation.getLatitude());
|
stmt.setDouble(2, deviceLocation.getLatitude());
|
||||||
stmt.setDouble(3, deviceLocation.getLongitude());
|
stmt.setDouble(3, deviceLocation.getLongitude());
|
||||||
|
|||||||
@ -64,7 +64,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
||||||
|
|
||||||
private DeviceDetailsDAO deviceDetailsDAO;
|
private final DeviceDetailsDAO deviceDetailsDAO;
|
||||||
private DeviceDAO deviceDAO;
|
private DeviceDAO deviceDAO;
|
||||||
private static final Log log = LogFactory.getLog(DeviceInformationManagerImpl.class);
|
private static final Log log = LogFactory.getLog(DeviceInformationManagerImpl.class);
|
||||||
private static final String LOCATION_EVENT_STREAM_DEFINITION = "org.wso2.iot.LocationStream";
|
private static final String LOCATION_EVENT_STREAM_DEFINITION = "org.wso2.iot.LocationStream";
|
||||||
@ -117,7 +117,10 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
|||||||
addOSVersionValue(device, newDeviceInfo);
|
addOSVersionValue(device, newDeviceInfo);
|
||||||
for (String key : newDeviceInfo.getDeviceDetailsMap().keySet()) {
|
for (String key : newDeviceInfo.getDeviceDetailsMap().keySet()) {
|
||||||
if (previousDeviceProperties.containsKey(key)) {
|
if (previousDeviceProperties.containsKey(key)) {
|
||||||
|
String val = previousDeviceProperties.get(key);
|
||||||
|
if (val != null &&!val.equals(newDeviceInfo.getDeviceDetailsMap().get(key))) {
|
||||||
updatableProps.put(key, newDeviceInfo.getDeviceDetailsMap().get(key));
|
updatableProps.put(key, newDeviceInfo.getDeviceDetailsMap().get(key));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
injectableProps.put(key, newDeviceInfo.getDeviceDetailsMap().get(key));
|
injectableProps.put(key, newDeviceInfo.getDeviceDetailsMap().get(key));
|
||||||
}
|
}
|
||||||
@ -160,20 +163,17 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (TransactionManagementException e) {
|
} catch (TransactionManagementException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new DeviceDetailsMgtException("Transactional error occurred while adding the device information.", e);
|
throw new DeviceDetailsMgtException("Transactional error occurred while adding the device information.", e);
|
||||||
} catch (DeviceDetailsMgtDAOException e) {
|
} catch (DeviceDetailsMgtDAOException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
throw new DeviceDetailsMgtException("Error occurred while adding the device information.", e);
|
throw new DeviceDetailsMgtException("Error occurred while adding the device information.", e);
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new DeviceDetailsMgtException("Error occurred while retrieving the device information.", e);
|
throw new DeviceDetailsMgtException("Error occurred while retrieving the device information.", e);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
throw new DeviceDetailsMgtException("Error occurred while updating the last update timestamp of the " +
|
throw new DeviceDetailsMgtException("Error occurred while updating the last update timestamp of the " +
|
||||||
"device", e);
|
"device", e);
|
||||||
} catch (DataPublisherConfigurationException e) {
|
} catch (DataPublisherConfigurationException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new DeviceDetailsMgtException("Error occurred while publishing the device location information.", e);
|
throw new DeviceDetailsMgtException("Error occurred while publishing the device location information.", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
@ -226,17 +226,30 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
|||||||
if (device == null) {
|
if (device == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return getDeviceInfo(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceInfo getDeviceInfo(Device device) throws DeviceDetailsMgtException {
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId(),
|
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId(),
|
||||||
device.getEnrolmentInfo().getId());
|
device.getEnrolmentInfo().getId());
|
||||||
|
if (deviceInfo == null) {
|
||||||
|
deviceInfo = new DeviceInfo();
|
||||||
|
}
|
||||||
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId(),
|
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId(),
|
||||||
device.getEnrolmentInfo().getId()));
|
device.getEnrolmentInfo().getId()));
|
||||||
|
DeviceLocation location = deviceDetailsDAO.getDeviceLocation(device.getId(),
|
||||||
|
device.getEnrolmentInfo().getId());
|
||||||
|
if (location != null) {
|
||||||
|
//There are some cases where the device-info is not updated properly. Hence returning a null value.
|
||||||
|
deviceInfo.setLocation(location);
|
||||||
|
}
|
||||||
return deviceInfo;
|
return deviceInfo;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device " + deviceId.toString()
|
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device " +
|
||||||
+ "'s info from database.", e);
|
device.getDeviceIdentifier() + "'s info from database.", e);
|
||||||
} catch (DeviceDetailsMgtDAOException e) {
|
} catch (DeviceDetailsMgtDAOException e) {
|
||||||
throw new DeviceDetailsMgtException("Exception occurred while retrieving device details.", e);
|
throw new DeviceDetailsMgtException("Exception occurred while retrieving device details.", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -263,11 +276,21 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
DeviceInfo deviceInfo;
|
||||||
for (Device device : deviceIds) {
|
for (Device device : deviceIds) {
|
||||||
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId(),
|
deviceInfo = deviceDetailsDAO.getDeviceInformation(device.getId(),
|
||||||
device.getEnrolmentInfo().getId());
|
device.getEnrolmentInfo().getId());
|
||||||
|
if (deviceInfo == null) {
|
||||||
|
deviceInfo = new DeviceInfo();
|
||||||
|
}
|
||||||
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId(),
|
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(device.getId(),
|
||||||
device.getEnrolmentInfo().getId()));
|
device.getEnrolmentInfo().getId()));
|
||||||
|
DeviceLocation location = deviceDetailsDAO.getDeviceLocation(device.getId(),
|
||||||
|
device.getEnrolmentInfo().getId());
|
||||||
|
if (location != null) {
|
||||||
|
//There are some cases where the device-info is not updated properly. Hence returning a null value.
|
||||||
|
deviceInfo.setLocation(location);
|
||||||
|
}
|
||||||
deviceInfos.add(deviceInfo);
|
deviceInfos.add(deviceInfo);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.core.dto.operation.mgt;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class OperationResponseMeta {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private int enrolmentId;
|
||||||
|
private int operationMappingId;
|
||||||
|
private boolean isLargeResponse;
|
||||||
|
private Timestamp receivedTimestamp;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnrolmentId() {
|
||||||
|
return enrolmentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnrolmentId(int enrolmentId) {
|
||||||
|
this.enrolmentId = enrolmentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOperationMappingId() {
|
||||||
|
return operationMappingId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOperationMappingId(int operationMappingId) {
|
||||||
|
this.operationMappingId = operationMappingId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLargeResponse() {
|
||||||
|
return isLargeResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLargeResponse(boolean largeResponse) {
|
||||||
|
isLargeResponse = largeResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getReceivedTimestamp() {
|
||||||
|
return receivedTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReceivedTimestamp(Timestamp receivedTimestamp) {
|
||||||
|
this.receivedTimestamp = receivedTimestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
||||||
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
||||||
@ -45,11 +46,13 @@ import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecu
|
|||||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO;
|
import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.OperationResponseMeta;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||||
@ -66,12 +69,14 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated
|
* This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated
|
||||||
@ -84,19 +89,21 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
private static final int CACHE_VALIDITY_PERIOD = 5 * 60 * 1000;
|
private static final int CACHE_VALIDITY_PERIOD = 5 * 60 * 1000;
|
||||||
private static final String NOTIFIER_TYPE_LOCAL = "LOCAL";
|
private static final String NOTIFIER_TYPE_LOCAL = "LOCAL";
|
||||||
private static final String SYSTEM = "system";
|
private static final String SYSTEM = "system";
|
||||||
|
public static final int maxOperationCacheSize = 100;
|
||||||
|
|
||||||
private OperationDAO commandOperationDAO;
|
private final OperationDAO commandOperationDAO;
|
||||||
private OperationDAO configOperationDAO;
|
private final OperationDAO configOperationDAO;
|
||||||
private OperationDAO profileOperationDAO;
|
private final OperationDAO profileOperationDAO;
|
||||||
private OperationDAO policyOperationDAO;
|
private final OperationDAO policyOperationDAO;
|
||||||
private OperationMappingDAO operationMappingDAO;
|
private final OperationMappingDAO operationMappingDAO;
|
||||||
private OperationDAO operationDAO;
|
private final OperationDAO operationDAO;
|
||||||
private DeviceDAO deviceDAO;
|
private final DeviceDAO deviceDAO;
|
||||||
private EnrollmentDAO enrollmentDAO;
|
private final EnrollmentDAO enrollmentDAO;
|
||||||
private String deviceType;
|
private String deviceType;
|
||||||
private DeviceManagementService deviceManagementService;
|
private DeviceManagementService deviceManagementService;
|
||||||
private Map<Integer, NotificationStrategy> notificationStrategies;
|
private final Map<Integer, NotificationStrategy> notificationStrategies;
|
||||||
private Map<Integer, Long> lastUpdatedTimeStamps;
|
private final Map<Integer, Long> lastUpdatedTimeStamps;
|
||||||
|
private final ConcurrentMap<Integer, String> operationsInitBy;
|
||||||
|
|
||||||
public OperationManagerImpl() {
|
public OperationManagerImpl() {
|
||||||
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
|
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
|
||||||
@ -109,6 +116,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
||||||
notificationStrategies = new HashMap<>();
|
notificationStrategies = new HashMap<>();
|
||||||
lastUpdatedTimeStamps = new HashMap<>();
|
lastUpdatedTimeStamps = new HashMap<>();
|
||||||
|
operationsInitBy = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationManagerImpl(String deviceType, DeviceManagementService deviceManagementService) {
|
public OperationManagerImpl(String deviceType, DeviceManagementService deviceManagementService) {
|
||||||
@ -159,26 +167,15 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
try {
|
try {
|
||||||
DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
|
DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
|
||||||
List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
|
List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
|
||||||
|
if (validDeviceIds.size() > 0) {
|
||||||
if (validDeviceIds.isEmpty()) {
|
|
||||||
String msg = "Invalid device Identifiers found.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new InvalidDeviceException(msg);
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled() && deviceIds.get(0).getType() != null) {
|
|
||||||
log.debug("Adding operation for Device type : " + deviceIds.get(0).getType() + ", tenant ID:"
|
|
||||||
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId() + ", domain:"
|
|
||||||
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + ", device count:"
|
|
||||||
+ deviceIds.size() + " operation type:" + operation.getCode());
|
|
||||||
}
|
|
||||||
DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
|
DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
|
||||||
List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList();
|
List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList();
|
||||||
if (authorizedDeviceIds.isEmpty()) {
|
if (authorizedDeviceIds.size() <= 0) {
|
||||||
log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list.");
|
log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list.");
|
||||||
Activity activity = new Activity();
|
Activity activity = new Activity();
|
||||||
//Send the operation statuses only for admin triggered operations
|
//Send the operation statuses only for admin triggered operations
|
||||||
activity.setActivityStatus(
|
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
||||||
this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
deviceAuthorizationResult));
|
||||||
return activity;
|
return activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,51 +193,46 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
operation.setInitiatedBy(initiatedBy);
|
operation.setInitiatedBy(initiatedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = OperationDAOUtil
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
||||||
.convertOperation(operation);
|
OperationDAOUtil.convertOperation(operation);
|
||||||
int enrolmentId;
|
|
||||||
String operationCode = operationDto.getCode();
|
String operationCode = operationDto.getCode();
|
||||||
|
Map<Integer, Device> enrolments = new HashMap<>();
|
||||||
List<Device> authorizedDevices = new ArrayList<>();
|
Device device;
|
||||||
List<Device> ignoredDevices = new ArrayList<>();
|
|
||||||
for (DeviceIdentifier deviceId : authorizedDeviceIds) {
|
for (DeviceIdentifier deviceId : authorizedDeviceIds) {
|
||||||
Device device = getDevice(deviceId);
|
device = getDevice(deviceId);
|
||||||
authorizedDevices.add(device);
|
enrolments.put(device.getEnrolmentInfo().getId(), device);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
int existingOperationID;
|
Map<Integer, Integer> pendingOperationIDs = operationDAO
|
||||||
for (Device device : authorizedDevices) {
|
.getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
|
||||||
enrolmentId = device.getEnrolmentInfo().getId();
|
for (Integer enrolmentId : pendingOperationIDs.keySet()) {
|
||||||
existingOperationID = operationDAO.getExistingOperationID(enrolmentId, operationCode);
|
operation.setId(pendingOperationIDs.get(enrolmentId));
|
||||||
if (existingOperationID > 0) {
|
device = enrolments.get(enrolmentId);
|
||||||
ignoredDevices.add(device);
|
|
||||||
operation.setId(existingOperationID);
|
|
||||||
this.sendNotification(operation, device);
|
this.sendNotification(operation, device);
|
||||||
|
//No need to keep this enrollment as it has a pending operation
|
||||||
|
enrolments.remove(enrolmentId);
|
||||||
}
|
}
|
||||||
}
|
if (enrolments.size() == 0) {
|
||||||
}
|
//No operations to be add. All are repeated.
|
||||||
|
|
||||||
if (!ignoredDevices.isEmpty()) {
|
|
||||||
if (authorizedDevices.size() == ignoredDevices.size()) {
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(
|
log.debug("All the devices contain a pending operation for the Operation Code: "
|
||||||
"All the devices contain a pending operation for the Operation Code: " + operationCode);
|
+ operationCode);
|
||||||
}
|
}
|
||||||
Activity activity = new Activity();
|
Activity activity = new Activity();
|
||||||
//Send the operation statuses only for admin triggered operations
|
//Send the operation statuses only for admin triggered operations
|
||||||
activity.setActivityStatus(
|
String deviceType = validDeviceIds.get(0).getType();
|
||||||
this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
||||||
|
deviceAuthorizationResult));
|
||||||
return activity;
|
return activity;
|
||||||
} else {
|
|
||||||
authorizedDevices.removeAll(ignoredDevices);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
||||||
operation.setId(operationId);
|
operationDto.setId(operationId);
|
||||||
|
|
||||||
boolean isScheduled = false;
|
boolean isScheduled = false;
|
||||||
NotificationStrategy notificationStrategy = getNotificationStrategy();
|
NotificationStrategy notificationStrategy = getNotificationStrategy();
|
||||||
@ -248,21 +240,37 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
// check whether device list is greater than batch size notification strategy has enable to send push
|
// check whether device list is greater than batch size notification strategy has enable to send push
|
||||||
// notification using scheduler task
|
// notification using scheduler task
|
||||||
if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||||
getPushNotificationConfiguration().getSchedulerBatchSize() <= authorizedDeviceIds.size()
|
getPushNotificationConfiguration().getSchedulerBatchSize() <= authorizedDeviceIds.size() &&
|
||||||
&& notificationStrategy != null) {
|
notificationStrategy != null) {
|
||||||
isScheduled = notificationStrategy.getConfig().isScheduled();
|
isScheduled = notificationStrategy.getConfig().isScheduled();
|
||||||
}
|
}
|
||||||
|
int failAttempts = 0;
|
||||||
List<Integer> enrolmentIds = new ArrayList<>();
|
while (true) {
|
||||||
for (Device device : authorizedDevices) {
|
try {
|
||||||
enrolmentId = device.getEnrolmentInfo().getId();
|
operationMappingDAO.addOperationMapping(operationDto,
|
||||||
enrolmentIds.add(enrolmentId);
|
new ArrayList<>(enrolments.values()), isScheduled, tenantId);
|
||||||
}
|
|
||||||
operationMappingDAO.addOperationMapping(operationId, enrolmentIds, isScheduled);
|
|
||||||
OperationManagementDAOFactory.commitTransaction();
|
OperationManagementDAOFactory.commitTransaction();
|
||||||
|
break;
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
|
if (++failAttempts > 3) {
|
||||||
|
String msg = "Error occurred while updating operation mapping. Operation ID: " +
|
||||||
|
operationId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new OperationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
log.warn("Unable to update operation status. Operation ID: " + operationId +
|
||||||
|
", Attempt: " + failAttempts + ", Error: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!isScheduled && notificationStrategy != null) {
|
if (!isScheduled && notificationStrategy != null) {
|
||||||
for (Device device : authorizedDevices) {
|
for (Device d : enrolments.values()) {
|
||||||
this.sendNotification(operation, device);
|
this.sendNotification(operation, d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,10 +281,15 @@ 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(
|
//Get the device-type from 1st valid DeviceIdentifier. We know the 1st element is definitely there.
|
||||||
this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
String deviceType = validDeviceIds.get(0).getType();
|
||||||
|
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
||||||
|
deviceAuthorizationResult));
|
||||||
}
|
}
|
||||||
return activity;
|
return activity;
|
||||||
|
} else {
|
||||||
|
throw new InvalidDeviceException("Invalid device Identifiers found.");
|
||||||
|
}
|
||||||
} catch (OperationManagementDAOException e) {
|
} catch (OperationManagementDAOException e) {
|
||||||
OperationManagementDAOFactory.rollbackTransaction();
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
throw new OperationManagementException("Error occurred while adding operation", e);
|
throw new OperationManagementException("Error occurred while adding operation", e);
|
||||||
@ -287,12 +300,120 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotification(Operation operation, Device device) {
|
@Override
|
||||||
if (log.isDebugEnabled()) {
|
public void addTaskOperation(String deviceType, Operation operation) throws OperationManagementException {
|
||||||
log.debug("Sending notification for device id: " + device.getDeviceIdentifier() + ", type:" + device
|
List<String> validStatuses = Arrays.asList(EnrolmentInfo.Status.ACTIVE.toString(),
|
||||||
.getType() + ", tenant:" + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()
|
EnrolmentInfo.Status.INACTIVE.toString(),
|
||||||
+ ", domain:" + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
|
EnrolmentInfo.Status.UNREACHABLE.toString());
|
||||||
|
int batchSize = 2000;
|
||||||
|
try {
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
PaginationRequest paginationRequest;
|
||||||
|
boolean hasRecords;
|
||||||
|
int start = 0;
|
||||||
|
OperationManagementDAOFactory.beginTransaction();
|
||||||
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
|
do {
|
||||||
|
paginationRequest = new PaginationRequest(start, batchSize);
|
||||||
|
paginationRequest.setStatusList(validStatuses);
|
||||||
|
paginationRequest.setDeviceType(deviceType);
|
||||||
|
List<Device> devices = deviceDAO.getDevices(paginationRequest, tenantId);
|
||||||
|
if (devices.size() == batchSize) {
|
||||||
|
hasRecords = true;
|
||||||
|
start += batchSize;
|
||||||
|
} else if (devices.size() == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
hasRecords = false;
|
||||||
}
|
}
|
||||||
|
operation.setInitiatedBy(SYSTEM);
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
||||||
|
OperationDAOUtil.convertOperation(operation);
|
||||||
|
String operationCode = operationDto.getCode();
|
||||||
|
Map<Integer, Device> enrolments = new HashMap<>();
|
||||||
|
for (Device device : devices) {
|
||||||
|
enrolments.put(device.getEnrolmentInfo().getId(), device);
|
||||||
|
}
|
||||||
|
if (operationDto.getControl() ==
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
|
||||||
|
Map<Integer, Integer> pendingOperationIDs = operationDAO
|
||||||
|
.getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
|
||||||
|
Device device;
|
||||||
|
for (Integer enrolmentId : pendingOperationIDs.keySet()) {
|
||||||
|
operation.setId(pendingOperationIDs.get(enrolmentId));
|
||||||
|
device = enrolments.get(enrolmentId);
|
||||||
|
this.sendNotification(operation, device);
|
||||||
|
//No need to keep this enrollment as it has a pending operation
|
||||||
|
enrolments.remove(enrolmentId);
|
||||||
|
}
|
||||||
|
if (enrolments.size() == 0) {
|
||||||
|
//No operations to be add. All are repeated.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
||||||
|
operationDto.setId(operationId);
|
||||||
|
|
||||||
|
boolean isScheduled = false;
|
||||||
|
NotificationStrategy notificationStrategy = getNotificationStrategy();
|
||||||
|
|
||||||
|
// check whether device list is greater than batch size notification strategy has enable to send push
|
||||||
|
// notification using scheduler task
|
||||||
|
if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||||
|
getPushNotificationConfiguration().getSchedulerBatchSize() <= enrolments.size() &&
|
||||||
|
notificationStrategy != null) {
|
||||||
|
isScheduled = notificationStrategy.getConfig().isScheduled();
|
||||||
|
}
|
||||||
|
int failAttempts = 0;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
operationMappingDAO.addOperationMapping(operationDto,
|
||||||
|
new ArrayList<>(enrolments.values()), isScheduled, tenantId);
|
||||||
|
OperationManagementDAOFactory.commitTransaction();
|
||||||
|
break;
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
|
if (++failAttempts > 3) {
|
||||||
|
String msg = "Error occurred while updating operation mapping. Operation ID: " +
|
||||||
|
operationId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new OperationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
log.warn("Unable to update operation status. Operation ID: " + operationId +
|
||||||
|
", Attempt: " + failAttempts + ", Error: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isScheduled && notificationStrategy != null) {
|
||||||
|
for (Device device : enrolments.values()) {
|
||||||
|
this.sendNotification(operation, device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (hasRecords);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while getting devices to add operations", e);
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
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 {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendNotification(Operation operation, Device device) {
|
||||||
NotificationStrategy notificationStrategy = getNotificationStrategy();
|
NotificationStrategy notificationStrategy = getNotificationStrategy();
|
||||||
/*
|
/*
|
||||||
* If notification strategy has not enable to send push notification using scheduler task we will send
|
* If notification strategy has not enable to send push notification using scheduler task we will send
|
||||||
@ -314,18 +435,36 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
* Reschedule if push notification failed. Doing db transactions in atomic way to prevent
|
* Reschedule if push notification failed. Doing db transactions in atomic way to prevent
|
||||||
* deadlocks.
|
* deadlocks.
|
||||||
*/
|
*/
|
||||||
|
int failAttempts = 0;
|
||||||
|
while (true) {
|
||||||
try {
|
try {
|
||||||
operationMappingDAO.updateOperationMapping(operation.getId(), device.getEnrolmentInfo().getId(), org.wso2.carbon
|
operationMappingDAO.updateOperationMapping(operation.getId(), device.getEnrolmentInfo().getId(),
|
||||||
.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
|
||||||
OperationManagementDAOFactory.commitTransaction();
|
OperationManagementDAOFactory.commitTransaction();
|
||||||
|
break;
|
||||||
} catch (OperationManagementDAOException ex) {
|
} catch (OperationManagementDAOException ex) {
|
||||||
// Not throwing this exception in order to keep scheduling remaining notifications if any.
|
|
||||||
log.error("Error occurred while setting push notification status to SCHEDULED.", ex);
|
|
||||||
OperationManagementDAOFactory.rollbackTransaction();
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
|
if (++failAttempts > 3) {
|
||||||
|
String msg = "Error occurred while setting push notification status to SCHEDULED. Operation ID: " +
|
||||||
|
operation.getId() + ", Enrollment ID: " + device.getEnrolmentInfo().getId() +
|
||||||
|
", Device ID:" + device.getDeviceIdentifier();
|
||||||
|
log.error(msg, e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
log.warn("Unable to set push notification status to SCHEDULED. Operation ID: " +
|
||||||
|
operation.getId() + ", Enrollment ID: " + device.getEnrolmentInfo().getId() +
|
||||||
|
", Device ID:" + device.getDeviceIdentifier() + ", Attempt: " + failAttempts +
|
||||||
|
", Error: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error occurred while sending notifications to " + device.getType() + " device carrying id '"
|
log.error("Error occurred while sending notifications to " + device.getType() +
|
||||||
+ device.getDeviceIdentifier() + "'", e);
|
" device carrying id '" + device.getDeviceIdentifier() + "'", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,17 +474,17 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
List<ActivityStatus> activityStatuses = new ArrayList<>();
|
List<ActivityStatus> activityStatuses = new ArrayList<>();
|
||||||
ActivityStatus activityStatus;
|
ActivityStatus activityStatus;
|
||||||
//Add the invalid DeviceIds
|
//Add the invalid DeviceIds
|
||||||
for (DeviceIdentifier id : deviceIdValidationResult.getErrorDeviceIdList()) {
|
for (DeviceIdentifier deviceIdentifier : deviceIdValidationResult.getErrorDeviceIdList()) {
|
||||||
activityStatus = new ActivityStatus();
|
activityStatus = new ActivityStatus();
|
||||||
activityStatus.setDeviceIdentifier(id);
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
||||||
activityStatus.setStatus(ActivityStatus.Status.INVALID);
|
activityStatus.setStatus(ActivityStatus.Status.INVALID);
|
||||||
activityStatuses.add(activityStatus);
|
activityStatuses.add(activityStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add the unauthorized DeviceIds
|
//Add the unauthorized DeviceIds
|
||||||
for (DeviceIdentifier id : deviceAuthResult.getErrorDeviceIdList()) {
|
for (DeviceIdentifier deviceIdentifier : deviceAuthResult.getErrorDeviceIdList()) {
|
||||||
activityStatus = new ActivityStatus();
|
activityStatus = new ActivityStatus();
|
||||||
activityStatus.setDeviceIdentifier(id);
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
||||||
activityStatus.setStatus(ActivityStatus.Status.UNAUTHORIZED);
|
activityStatus.setStatus(ActivityStatus.Status.UNAUTHORIZED);
|
||||||
activityStatuses.add(activityStatus);
|
activityStatuses.add(activityStatus);
|
||||||
}
|
}
|
||||||
@ -401,7 +540,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||||
List<Operation> operations = null;
|
List<Operation> operations;
|
||||||
|
|
||||||
if (!isActionAuthorized(deviceId)) {
|
if (!isActionAuthorized(deviceId)) {
|
||||||
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
|
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
|
||||||
@ -440,7 +579,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
@Override
|
@Override
|
||||||
public PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request)
|
public PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request)
|
||||||
throws OperationManagementException {
|
throws OperationManagementException {
|
||||||
PaginationResult paginationResult = null;
|
PaginationResult paginationResult;
|
||||||
List<Operation> operations = new ArrayList<>();
|
List<Operation> operations = new ArrayList<>();
|
||||||
String owner = request.getOwner();
|
String owner = request.getOwner();
|
||||||
try {
|
try {
|
||||||
@ -492,14 +631,36 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceId, Operation.Status status)
|
||||||
|
throws OperationManagementException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isActionAuthorized(deviceId)) {
|
||||||
|
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
|
||||||
|
deviceId.getType() + "' device, which carries the identifier '" +
|
||||||
|
deviceId.getId() + "'");
|
||||||
|
}
|
||||||
|
PaginationRequest request = new PaginationRequest(0, 0);
|
||||||
|
request.setOwner(getUser());
|
||||||
|
EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId, request);
|
||||||
|
if (enrolmentInfo == null) {
|
||||||
|
throw new OperationManagementException("Device not found for the given device Identifier:" +
|
||||||
|
deviceId.getId() + " and given type:" +
|
||||||
|
deviceId.getType());
|
||||||
|
}
|
||||||
|
int enrolmentId = enrolmentInfo.getId();
|
||||||
|
return getOperations(deviceId, status, enrolmentId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws
|
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws
|
||||||
OperationManagementException {
|
OperationManagementException {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
|
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
|
||||||
}
|
}
|
||||||
List<Operation> operations = new ArrayList<>();
|
|
||||||
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = new ArrayList<>();
|
|
||||||
|
|
||||||
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
|
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
|
||||||
if (enrolmentInfo == null) {
|
if (enrolmentInfo == null) {
|
||||||
@ -513,36 +674,12 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
case INACTIVE:
|
case INACTIVE:
|
||||||
case UNREACHABLE:
|
case UNREACHABLE:
|
||||||
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
|
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
DeviceCacheManagerImpl.getInstance().removeDeviceFromCache(deviceId, tenantId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return getOperations(deviceId, Operation.Status.PENDING, enrolmentId);
|
||||||
OperationManagementDAOFactory.openConnection();
|
|
||||||
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
|
|
||||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(
|
|
||||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(
|
|
||||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(
|
|
||||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
Operation operation;
|
|
||||||
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
||||||
operations.add(operation);
|
|
||||||
}
|
|
||||||
Collections.sort(operations, new OperationIdComparator());
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
||||||
"pending operations assigned for '" + deviceId.getType() +
|
|
||||||
"' device '" + deviceId.getId() + "'", e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Error occurred while opening a connection to the data source", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
return operations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -553,17 +690,21 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
device.getId() + " and given type:" +
|
device.getId() + " and given type:" +
|
||||||
device.getType());
|
device.getType());
|
||||||
}
|
}
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setType(device.getType());
|
||||||
|
deviceIdentifier.setId(device.getDeviceIdentifier());
|
||||||
int enrolmentId = enrolmentInfo.getId();
|
int enrolmentId = enrolmentInfo.getId();
|
||||||
//Changing the enrollment status & attempt count if the device is marked as inactive or unreachable
|
//Changing the enrollment status & attempt count if the device is marked as inactive or unreachable
|
||||||
switch (enrolmentInfo.getStatus()) {
|
switch (enrolmentInfo.getStatus()) {
|
||||||
case INACTIVE:
|
case INACTIVE:
|
||||||
case UNREACHABLE:
|
case UNREACHABLE:
|
||||||
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
|
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
DeviceCacheManagerImpl.getInstance().addDeviceToCache(deviceIdentifier, device, tenantId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
||||||
deviceIdentifier.setType(device.getType());
|
|
||||||
deviceIdentifier.setId(device.getDeviceIdentifier());
|
|
||||||
return getOperations(deviceIdentifier, Operation.Status.PENDING, enrolmentId);
|
return getOperations(deviceIdentifier, Operation.Status.PENDING, enrolmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,6 +740,8 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
case INACTIVE:
|
case INACTIVE:
|
||||||
case UNREACHABLE:
|
case UNREACHABLE:
|
||||||
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
|
this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE);
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
DeviceCacheManagerImpl.getInstance().removeDeviceFromCache(deviceId, tenantId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,29 +816,136 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
"Device not found for device id:" + deviceId.getId() + " " + "type:" +
|
"Device not found for device id:" + deviceId.getId() + " " + "type:" +
|
||||||
deviceId.getType());
|
deviceId.getType());
|
||||||
}
|
}
|
||||||
updateOperation(enrolmentInfo.getId(), operation);
|
updateOperation(enrolmentInfo.getId(), operation, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateOperation(int enrolmentId, Operation operation) throws OperationManagementException {
|
public void updateOperation(int enrolmentId, Operation operation, DeviceIdentifier deviceId)
|
||||||
|
throws OperationManagementException {
|
||||||
int operationId = operation.getId();
|
int operationId = operation.getId();
|
||||||
try {
|
try {
|
||||||
OperationManagementDAOFactory.beginTransaction();
|
OperationManagementDAOFactory.beginTransaction();
|
||||||
if (operation.getStatus() != null) {
|
if (operation.getStatus() != null) {
|
||||||
|
int failAttempts = 0;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
operationDAO.updateOperationStatus(enrolmentId, operationId,
|
operationDAO.updateOperationStatus(enrolmentId, operationId,
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.
|
||||||
Operation.Status.valueOf(operation.getStatus().
|
Operation.Status.valueOf(operation.getStatus().
|
||||||
toString()));
|
toString()));
|
||||||
}
|
|
||||||
if (operation.getOperationResponse() != null) {
|
|
||||||
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
|
|
||||||
}
|
|
||||||
OperationManagementDAOFactory.commitTransaction();
|
OperationManagementDAOFactory.commitTransaction();
|
||||||
|
break;
|
||||||
} catch (OperationManagementDAOException e) {
|
} catch (OperationManagementDAOException e) {
|
||||||
OperationManagementDAOFactory.rollbackTransaction();
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
throw new OperationManagementException(
|
if (++failAttempts > 3) {
|
||||||
"Error occurred while updating the operation: " + operationId + " status:" +
|
String msg = "Error occurred while updating operation status. Operation ID: " +
|
||||||
operation.getStatus(), e);
|
operationId + ", Enrollment ID: " + enrolmentId + ", Device ID:" + deviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new OperationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
log.warn("Unable to update operation status. Operation ID: " + operationId +
|
||||||
|
", Enrollment ID: " + enrolmentId + ", Device ID:" + deviceId + ", Attempt: " + failAttempts +
|
||||||
|
", Error: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (operation.getOperationResponse() != null) {
|
||||||
|
OperationMonitoringTaskConfig operationMonitoringTaskConfig = DeviceManagementDataHolder
|
||||||
|
.getInstance().getDeviceManagementProvider().getDeviceMonitoringConfig(deviceId.getType());
|
||||||
|
List<MonitoringOperation> monitoringOperations = operationMonitoringTaskConfig.getMonitoringOperation();
|
||||||
|
MonitoringOperation currentMonitoringOperation = null;
|
||||||
|
for (MonitoringOperation monitoringOperation : monitoringOperations) {
|
||||||
|
if (operation.getCode().equals(monitoringOperation.getTaskName())) {
|
||||||
|
currentMonitoringOperation = monitoringOperation;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currentMonitoringOperation != null && !currentMonitoringOperation.hasResponsePersistence()) {
|
||||||
|
String initiatedBy = operationsInitBy.get(operationId);
|
||||||
|
if (initiatedBy == null) {
|
||||||
|
try {
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
||||||
|
operationDAO.getOperation(operationId);
|
||||||
|
operation.setInitiatedBy(operationDto.getInitiatedBy());
|
||||||
|
if (operationsInitBy.size() > maxOperationCacheSize) {
|
||||||
|
Integer obsoleteOperationId = (Integer) operationsInitBy.keySet().toArray()[0];
|
||||||
|
operationsInitBy.remove(obsoleteOperationId);
|
||||||
|
}
|
||||||
|
operationsInitBy.put(operationId, operation.getInitiatedBy());
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
log.warn("Unable to get operationDTO for Operation ID: " + operationId +
|
||||||
|
", Error: " + e.getErrorMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
operation.setInitiatedBy(initiatedBy);
|
||||||
|
}
|
||||||
|
if (SYSTEM.equals(operation.getInitiatedBy())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OperationResponseMeta responseMeta = null;
|
||||||
|
if (operation.getOperationResponse() != null) {
|
||||||
|
int failAttempts = 0;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
responseMeta = operationDAO.addOperationResponse(enrolmentId, operation, deviceId.getId());
|
||||||
|
OperationManagementDAOFactory.commitTransaction();
|
||||||
|
break;
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
|
if (++failAttempts > 3) {
|
||||||
|
String msg = "Error occurred while updating operation response. Operation ID: " +
|
||||||
|
operationId + ", Enrollment ID: " + enrolmentId + ", Device ID:" + deviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new OperationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
log.warn("Unable to update operation response. Operation ID: " + operationId +
|
||||||
|
", Enrollment ID: " + enrolmentId + ", Device ID:" + deviceId + " Attempt: " + failAttempts +
|
||||||
|
", Error: " + e.getErrorMessage());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (responseMeta != null && responseMeta.isLargeResponse() && responseMeta.getId() > 0) {
|
||||||
|
int failAttempts = 0;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
operationDAO.addOperationResponseLarge(responseMeta, operation, deviceId.getId());
|
||||||
|
OperationManagementDAOFactory.commitTransaction();
|
||||||
|
break;
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
|
if (++failAttempts > 3) {
|
||||||
|
String msg = "Error occurred while updating large operation response. " +
|
||||||
|
"Enrollment Mapping ID: " + responseMeta.getOperationMappingId() +
|
||||||
|
", Response ID: " + responseMeta.getId() + ", Operation ID: " + operationId +
|
||||||
|
", Enrollment ID: " + enrolmentId + ", Device ID:" + deviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new OperationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
log.warn("Unable to update large operation response. " +
|
||||||
|
"Enrollment Mapping ID: " + responseMeta.getOperationMappingId() +
|
||||||
|
", Response ID: " + responseMeta.getId() + ", Operation ID: " + operationId +
|
||||||
|
", Enrollment ID: " + enrolmentId + ", Device ID:" + deviceId +
|
||||||
|
", Attempt: " + failAttempts + ", Error: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (TransactionManagementException e) {
|
} catch (TransactionManagementException e) {
|
||||||
throw new OperationManagementException("Error occurred while initiating a transaction", e);
|
throw new OperationManagementException("Error occurred while initiating a transaction", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -706,7 +956,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
@Override
|
@Override
|
||||||
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
|
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
|
||||||
throws OperationManagementException {
|
throws OperationManagementException {
|
||||||
Operation operation = null;
|
Operation operation;
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " +
|
log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " +
|
||||||
deviceId.getId());
|
deviceId.getId());
|
||||||
@ -913,7 +1163,8 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity getOperationByActivityIdAndDevice(String activity, DeviceIdentifier deviceId) throws OperationManagementException {
|
public Activity getOperationByActivityIdAndDevice(String activity, DeviceIdentifier deviceId)
|
||||||
|
throws OperationManagementException {
|
||||||
// This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer.
|
// This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer.
|
||||||
int operationId = Integer.parseInt(
|
int operationId = Integer.parseInt(
|
||||||
activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
|
activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
|
||||||
@ -1142,23 +1393,38 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
return enrolmentInfo;
|
return enrolmentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setEnrolmentStatus(int enrolmentId, EnrolmentInfo.Status status) throws OperationManagementException {
|
private void setEnrolmentStatus(int enrolmentId, EnrolmentInfo.Status status) throws OperationManagementException {
|
||||||
boolean updateStatus;
|
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
updateStatus = enrollmentDAO.setStatus(enrolmentId, status, tenantId);
|
int failAttempts = 0;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
enrollmentDAO.setStatus(enrolmentId, status, tenantId);
|
||||||
DeviceManagementDAOFactory.commitTransaction();
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
|
break;
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
throw new OperationManagementException("Error occurred while updating enrollment status of device of " +
|
if (++failAttempts > 3) {
|
||||||
"enrolment-id '" + enrolmentId + "'", e);
|
String msg = "Error occurred while updating enrollment status of device of " +
|
||||||
|
"enrolment-id '" + enrolmentId + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new OperationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
log.warn("Unable to update enrollment status of device of enrolment-id '" +
|
||||||
|
enrolmentId + ", Attempt: " + failAttempts + ", Error: " + e.getMessage());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (TransactionManagementException e) {
|
} catch (TransactionManagementException e) {
|
||||||
throw new OperationManagementException("Error occurred while initiating a transaction", e);
|
throw new OperationManagementException("Error occurred while initiating a transaction", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
return updateStatus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTaskScheduledOperation(Operation operation) {
|
private boolean isTaskScheduledOperation(Operation operation) {
|
||||||
@ -1173,6 +1439,10 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSameUser(String user, String owner) {
|
||||||
|
return user.equalsIgnoreCase(owner);
|
||||||
|
}
|
||||||
|
|
||||||
private List<? extends Operation> getOperations(DeviceIdentifier deviceId, Operation.Status status, int enrolmentId)
|
private List<? extends Operation> getOperations(DeviceIdentifier deviceId, Operation.Status status, int enrolmentId)
|
||||||
throws OperationManagementException {
|
throws OperationManagementException {
|
||||||
List<Operation> operations = new ArrayList<>();
|
List<Operation> operations = new ArrayList<>();
|
||||||
|
|||||||
@ -20,7 +20,9 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
|
|||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.OperationResponseMeta;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -54,15 +56,24 @@ public interface OperationDAO {
|
|||||||
void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
|
void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
|
||||||
Operation.Status newStatus) throws OperationManagementDAOException;
|
Operation.Status newStatus) throws OperationManagementDAOException;
|
||||||
|
|
||||||
int getExistingOperationID(int enrolmentId, String operationCode) throws OperationManagementDAOException;
|
Map<Integer, Integer> getExistingOperationIDs(Integer[] enrolmentIds, String operationCode)
|
||||||
|
throws OperationManagementDAOException;
|
||||||
|
|
||||||
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
|
OperationResponseMeta addOperationResponse(int enrolmentId, org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation, String deviceId)
|
||||||
throws OperationManagementDAOException;
|
throws OperationManagementDAOException;
|
||||||
|
|
||||||
Activity getActivity(int operationId) throws OperationManagementDAOException;
|
Activity getActivity(int operationId) throws OperationManagementDAOException;
|
||||||
|
|
||||||
List<Activity> getActivityList(List<Integer> operationIds) throws OperationManagementDAOException;
|
List<Activity> getActivityList(List<Integer> operationIds) throws OperationManagementDAOException;
|
||||||
|
|
||||||
|
void addOperationResponseLarge(OperationResponseMeta responseMeta,
|
||||||
|
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation,
|
||||||
|
String deviceId) throws OperationManagementDAOException;
|
||||||
|
|
||||||
|
Map<String, Map<String, List<OperationResponse>>> getLargeOperationResponsesInBulk(List<Integer> operationIds) throws OperationManagementDAOException;
|
||||||
|
|
||||||
|
void populateLargeOperationResponses(List<Activity> activities, List<Integer> largeResponseIDs) throws OperationManagementDAOException;
|
||||||
|
|
||||||
Activity getActivityByDevice(int operationId, int deviceId) throws OperationManagementDAOException;
|
Activity getActivityByDevice(int operationId, int deviceId) throws OperationManagementDAOException;
|
||||||
|
|
||||||
List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementDAOException;
|
List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementDAOException;
|
||||||
|
|||||||
@ -37,14 +37,9 @@ public class OperationManagementDAOUtil {
|
|||||||
log.warn("Error occurred while closing the result set", e);
|
log.warn("Error occurred while closing the result set", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stmt != null) {
|
cleanupResources(stmt);
|
||||||
try {
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Error occurred while closing the statement", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanupResources(Statement stmt) {
|
public static void cleanupResources(Statement stmt) {
|
||||||
if (stmt != null) {
|
if (stmt != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
|
package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||||
@ -27,10 +29,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
public interface OperationMappingDAO {
|
public interface OperationMappingDAO {
|
||||||
|
|
||||||
void addOperationMapping(int operationId, int enrollmentId, boolean isScheduled)
|
void addOperationMapping(Operation operation, Integer deviceId, boolean isScheduled, Device device, Integer tenantId) throws OperationManagementDAOException;
|
||||||
throws OperationManagementDAOException;
|
|
||||||
|
|
||||||
void addOperationMapping(int operationId, List<Integer> enrollmentIds, boolean isScheduled)
|
void addOperationMapping(Operation operation, List<Device> devices, boolean isScheduled, Integer tenantId)
|
||||||
throws OperationManagementDAOException;
|
throws OperationManagementDAOException;
|
||||||
|
|
||||||
void removeOperationMapping(int operationId, Integer deviceId) throws OperationManagementDAOException;
|
void removeOperationMapping(int operationId, Integer deviceId) throws OperationManagementDAOException;
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.OperationResponseMeta;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||||
@ -33,10 +34,8 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF
|
|||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -44,7 +43,6 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -81,7 +79,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
throw new OperationManagementDAOException("Error occurred while adding operation metadata. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -106,7 +105,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
|
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
|
||||||
"metadata", e);
|
"metadata. " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
OperationManagementDAOUtil.cleanupResources(stmt);
|
||||||
}
|
}
|
||||||
@ -151,48 +150,59 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getExistingOperationID(int enrolmentId, String operationCode)
|
public Map<Integer, Integer> getExistingOperationIDs(Integer[] enrolmentIds, String operationCode)
|
||||||
throws OperationManagementDAOException {
|
throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
int result = -1;
|
Map<Integer, Integer> existingOperationIds = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
String query = "SELECT DM.ID FROM DM_ENROLMENT_OP_MAPPING EOM INNER JOIN DM_OPERATION DM "
|
StringBuilder query = new StringBuilder("SELECT OPERATION_ID, ENROLMENT_ID FROM DM_ENROLMENT_OP_MAPPING " +
|
||||||
+ "ON DM.ID = EOM.OPERATION_ID WHERE EOM.ENROLMENT_ID = ? AND DM.OPERATION_CODE = ? AND "
|
"WHERE OPERATION_CODE = ? AND STATUS = ? AND ENROLMENT_ID IN (");
|
||||||
+ "EOM.STATUS = ?";
|
for (int i = 0; i < enrolmentIds.length; i++) {
|
||||||
stmt = connection.prepareStatement(query);
|
query.append(" ?,");
|
||||||
stmt.setInt(1, enrolmentId);
|
}
|
||||||
stmt.setString(2, operationCode);
|
query.deleteCharAt(query.length() - 1);
|
||||||
stmt.setString(3, Operation.Status.PENDING.toString());
|
query.append(")");
|
||||||
// This will return only one result always.
|
stmt = connection.prepareStatement(query.toString());
|
||||||
|
stmt.setString(1, operationCode);
|
||||||
|
stmt.setString(2, Operation.Status.PENDING.toString());
|
||||||
|
|
||||||
|
for (int i = 0; i < enrolmentIds.length; i++) {
|
||||||
|
stmt.setInt(i + 3, enrolmentIds[i]);
|
||||||
|
}
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
if (rs.next()) {
|
int operationId;
|
||||||
result = rs.getInt("ID");
|
int enrollmentId;
|
||||||
|
while (rs.next()) {
|
||||||
|
enrollmentId = rs.getInt("ENROLMENT_ID");
|
||||||
|
operationId = rs.getInt("OPERATION_ID");
|
||||||
|
existingOperationIds.put(enrollmentId, operationId);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException(
|
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
|
||||||
"Error occurred while update device mapping operation status " + "metadata", e);
|
"metadata. " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
return result;
|
return existingOperationIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
|
public OperationResponseMeta addOperationResponse(int enrolmentId,
|
||||||
throws OperationManagementDAOException {
|
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation,
|
||||||
|
String deviceId) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ByteArrayOutputStream bao = null;
|
|
||||||
ObjectOutputStream oos = null;
|
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
|
boolean isLargeResponse = false;
|
||||||
try {
|
try {
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
|
|
||||||
stmt = connection.prepareStatement("SELECT ID FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? " +
|
stmt = connection.prepareStatement("SELECT ID FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? " +
|
||||||
"AND OPERATION_ID = ?");
|
"AND OPERATION_ID = ?");
|
||||||
stmt.setInt(1, enrolmentId);
|
stmt.setInt(1, enrolmentId);
|
||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operation.getId());
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
int enPrimaryId = 0;
|
int enPrimaryId = 0;
|
||||||
@ -200,21 +210,74 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
enPrimaryId = rs.getInt("ID");
|
enPrimaryId = rs.getInt("ID");
|
||||||
}
|
}
|
||||||
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID, " +
|
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID, " +
|
||||||
"EN_OP_MAP_ID, OPERATION_RESPONSE, RECEIVED_TIMESTAMP) VALUES(?, ?, ?, ?, ?)");
|
"EN_OP_MAP_ID, OPERATION_RESPONSE, IS_LARGE_RESPONSE, RECEIVED_TIMESTAMP) VALUES(?, ?, ?, ?, ?, ?)",
|
||||||
bao = new ByteArrayOutputStream();
|
new String[]{"ID"});
|
||||||
oos = new ObjectOutputStream(bao);
|
stmt.setInt(1, operation.getId());
|
||||||
oos.writeObject(operationResponse);
|
|
||||||
|
|
||||||
stmt.setInt(1, operationId);
|
|
||||||
stmt.setInt(2, enrolmentId);
|
stmt.setInt(2, enrolmentId);
|
||||||
stmt.setInt(3, enPrimaryId);
|
stmt.setInt(3, enPrimaryId);
|
||||||
stmt.setBytes(4, bao.toByteArray());
|
|
||||||
stmt.setTimestamp(5, new Timestamp(new Date().getTime()));
|
if (operation.getOperationResponse() != null && operation.getOperationResponse().length() >= 1000) {
|
||||||
|
isLargeResponse = true;
|
||||||
|
stmt.setBytes(4, null);
|
||||||
|
} else {
|
||||||
|
stmt.setString(4, operation.getOperationResponse());
|
||||||
|
}
|
||||||
|
stmt.setBoolean(5, isLargeResponse);
|
||||||
|
|
||||||
|
Timestamp receivedTimestamp = new Timestamp(new Date().getTime());
|
||||||
|
stmt.setTimestamp(6, receivedTimestamp);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
rs = stmt.getGeneratedKeys();
|
||||||
|
int opResID = -1;
|
||||||
|
if (rs.next()) {
|
||||||
|
opResID = rs.getInt(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
OperationResponseMeta responseMeta = new OperationResponseMeta();
|
||||||
|
responseMeta.setId(opResID);
|
||||||
|
responseMeta.setEnrolmentId(enrolmentId);
|
||||||
|
responseMeta.setOperationMappingId(enPrimaryId);
|
||||||
|
responseMeta.setReceivedTimestamp(receivedTimestamp);
|
||||||
|
responseMeta.setLargeResponse(isLargeResponse);
|
||||||
|
return responseMeta;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementDAOException("Error occurred while inserting operation response. " +
|
||||||
|
e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addOperationResponseLarge(OperationResponseMeta responseMeta,
|
||||||
|
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation,
|
||||||
|
String deviceId) throws OperationManagementDAOException {
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ByteArrayOutputStream bao = null;
|
||||||
|
ObjectOutputStream oos = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
|
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE_LARGE " +
|
||||||
|
"(ID, OPERATION_RESPONSE, OPERATION_ID, EN_OP_MAP_ID, RECEIVED_TIMESTAMP, DEVICE_IDENTIFICATION) " +
|
||||||
|
"VALUES(?, ?, ?, ?, ?, ?)");
|
||||||
|
bao = new ByteArrayOutputStream();
|
||||||
|
oos = new ObjectOutputStream(bao);
|
||||||
|
oos.writeObject(operation.getOperationResponse());
|
||||||
|
stmt.setInt(1, responseMeta.getId());
|
||||||
|
stmt.setBytes(2, bao.toByteArray());
|
||||||
|
stmt.setInt(3, operation.getId());
|
||||||
|
stmt.setInt(4, responseMeta.getOperationMappingId());
|
||||||
|
stmt.setTimestamp(5, responseMeta.getReceivedTimestamp());
|
||||||
|
stmt.setString(6, deviceId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while inserting operation response", e);
|
throw new OperationManagementDAOException("Error occurred while inserting operation response. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e);
|
throw new OperationManagementDAOException("Error occurred while serializing operation response object. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (bao != null) {
|
if (bao != null) {
|
||||||
try {
|
try {
|
||||||
@ -234,6 +297,93 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Map<String, List<OperationResponse>>> getLargeOperationResponsesInBulk(List<Integer> operationResponseIds)
|
||||||
|
throws OperationManagementDAOException {
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Map<String, Map<String, List<OperationResponse>>> operationResponseMapping = new HashMap<>();
|
||||||
|
Map<String, List<OperationResponse>> operationDeviceMappings;
|
||||||
|
List<OperationResponse> responseList;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
|
||||||
|
String sql1 = "SELECT * FROM DM_DEVICE_OPERATION_RESPONSE_LARGE WHERE ID IN (";
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (int i = 0; i < operationResponseIds.size(); i++) {
|
||||||
|
builder.append("?,");
|
||||||
|
}
|
||||||
|
sql1 += builder.deleteCharAt(builder.length() - 1).toString() + ")";
|
||||||
|
stmt = conn.prepareStatement(sql1);
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < operationResponseIds.size(); i++) {
|
||||||
|
stmt.setInt(i + 1, operationResponseIds.get(i));
|
||||||
|
}
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
String activityID = OperationDAOUtil.getActivityId(rs.getInt("OPERATION_ID"));
|
||||||
|
String deviceID = rs.getString("DEVICE_IDENTIFICATION");
|
||||||
|
|
||||||
|
if (operationResponseMapping.containsKey(activityID)) {
|
||||||
|
operationDeviceMappings = operationResponseMapping.get(activityID);
|
||||||
|
if (operationDeviceMappings.containsKey(deviceID)) {
|
||||||
|
responseList = operationDeviceMappings.get(deviceID);
|
||||||
|
} else {
|
||||||
|
responseList = new ArrayList<>();
|
||||||
|
operationDeviceMappings.put(deviceID, responseList);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
responseList = new ArrayList<>();
|
||||||
|
operationDeviceMappings = new HashMap<>();
|
||||||
|
operationDeviceMappings.put(deviceID, responseList);
|
||||||
|
operationResponseMapping.put(activityID, operationDeviceMappings);
|
||||||
|
}
|
||||||
|
responseList.add(OperationDAOUtil.getLargeOperationResponse(rs));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementDAOException(
|
||||||
|
"Error occurred while getting the operation details from the database. " + e.getMessage(), e);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new OperationManagementDAOException(
|
||||||
|
"Error occurred while converting the operation response to string.. " + e.getMessage(), e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new OperationManagementDAOException(
|
||||||
|
"IO exception occurred while converting the operations responses. " + e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return operationResponseMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void populateLargeOperationResponses(List<Activity> activities,
|
||||||
|
List<Integer> largeResponseIDs)
|
||||||
|
throws OperationManagementDAOException {
|
||||||
|
if (!largeResponseIDs.isEmpty()) {
|
||||||
|
Map<String, Map<String, List<OperationResponse>>> largeOperationResponses = getLargeOperationResponsesInBulk(largeResponseIDs);
|
||||||
|
if (!largeOperationResponses.isEmpty()) {
|
||||||
|
for (Activity tempActivity : activities) {
|
||||||
|
if (largeOperationResponses.containsKey(tempActivity.getActivityId())) {
|
||||||
|
List<ActivityStatus> activityStatuses = tempActivity.getActivityStatus();
|
||||||
|
Map<String, List<OperationResponse>> deviceOpResponseMap = largeOperationResponses.get(tempActivity.getActivityId());
|
||||||
|
for (Map.Entry<String, List<OperationResponse>> deviceOpRes : deviceOpResponseMap.entrySet()) {
|
||||||
|
for (ActivityStatus status : activityStatuses) {
|
||||||
|
if (deviceOpRes.getKey().equalsIgnoreCase(status.getDeviceIdentifier().getId())) {
|
||||||
|
status.getResponses().addAll(deviceOpRes.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Activity getActivity(int operationId) throws OperationManagementDAOException {
|
public Activity getActivity(int operationId) throws OperationManagementDAOException {
|
||||||
|
|
||||||
@ -243,18 +393,29 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
List<ActivityStatus> activityStatusList = new ArrayList<>();
|
List<ActivityStatus> activityStatusList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT eom.ENROLMENT_ID, eom.OPERATION_ID, eom.ID AS EOM_MAPPING_ID, dor.ID AS OP_RES_ID,\n" +
|
String sql = "SELECT " +
|
||||||
"de.DEVICE_ID, d.DEVICE_IDENTIFICATION, \n" +
|
" eom.ENROLMENT_ID," +
|
||||||
"d.DEVICE_TYPE_ID, dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, \n" +
|
" eom.CREATED_TIMESTAMP," +
|
||||||
"eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, dor.OPERATION_RESPONSE, \n" +
|
" eom.UPDATED_TIMESTAMP," +
|
||||||
"dor.RECEIVED_TIMESTAMP, op.INITIATED_BY FROM DM_ENROLMENT_OP_MAPPING eom \n" +
|
" eom.OPERATION_ID," +
|
||||||
"INNER JOIN DM_OPERATION op ON op.ID=eom.OPERATION_ID\n" +
|
" eom.OPERATION_CODE," +
|
||||||
"INNER JOIN DM_ENROLMENT de ON de.ID=eom.ENROLMENT_ID\n" +
|
" eom.INITIATED_BY," +
|
||||||
"INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID \n" +
|
" eom.TYPE AS OPERATION_TYPE," +
|
||||||
"INNER JOIN DM_DEVICE_TYPE dt ON dt.ID=d.DEVICE_TYPE_ID\n" +
|
" eom.STATUS," +
|
||||||
"LEFT JOIN DM_DEVICE_OPERATION_RESPONSE dor ON dor.ENROLMENT_ID=de.id \n" +
|
" eom.DEVICE_ID," +
|
||||||
"AND dor.OPERATION_ID = eom.OPERATION_ID\n" +
|
" eom.DEVICE_IDENTIFICATION," +
|
||||||
"WHERE eom.OPERATION_ID = ? AND de.TENANT_ID = ?";
|
" eom.DEVICE_TYPE AS DEVICE_TYPE_NAME," +
|
||||||
|
" eom.ID AS EOM_MAPPING_ID," +
|
||||||
|
" opr.ID AS OP_RES_ID," +
|
||||||
|
" opr.RECEIVED_TIMESTAMP," +
|
||||||
|
" opr.OPERATION_RESPONSE," +
|
||||||
|
" opr.IS_LARGE_RESPONSE " +
|
||||||
|
"FROM " +
|
||||||
|
" DM_ENROLMENT_OP_MAPPING eom " +
|
||||||
|
" LEFT JOIN " +
|
||||||
|
" DM_DEVICE_OPERATION_RESPONSE opr ON opr.EN_OP_MAP_ID = eom.ID " +
|
||||||
|
"WHERE " +
|
||||||
|
" eom.OPERATION_ID = ? AND eom.TENANT_ID = ?";
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, operationId);
|
stmt.setInt(1, operationId);
|
||||||
@ -263,7 +424,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
int enrolmentId = 0;
|
int enrolmentId = 0;
|
||||||
ActivityStatus activityStatus = null;
|
ActivityStatus activityStatus = null;
|
||||||
|
int responseId = 0;
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if (enrolmentId == 0) {
|
if (enrolmentId == 0) {
|
||||||
activity = new Activity();
|
activity = new Activity();
|
||||||
@ -295,17 +457,40 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
activity.setActivityStatus(activityStatusList);
|
activity.setActivityStatus(activityStatusList);
|
||||||
} else {
|
} else {
|
||||||
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
||||||
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
if (activityStatus == null) {
|
||||||
|
activityStatus = new ActivityStatus();
|
||||||
|
}
|
||||||
|
if (activityStatus.getResponses() == null) {
|
||||||
|
activityStatus.setResponses(new ArrayList<>());
|
||||||
|
}
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!largeResponseIDs.isEmpty()) {
|
||||||
|
Map<String, Map<String, List<OperationResponse>>> largeOperationResponses = getLargeOperationResponsesInBulk(largeResponseIDs);
|
||||||
|
if (!largeOperationResponses.isEmpty()) {
|
||||||
|
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
|
||||||
|
if (activityStatuses != null) {
|
||||||
|
Map<String, List<OperationResponse>> deviceOpResponseMap = largeOperationResponses.get(activity.getActivityId());
|
||||||
|
for (Map.Entry<String, List<OperationResponse>> deviceOpRes : deviceOpResponseMap.entrySet()) {
|
||||||
|
for (ActivityStatus status : activityStatuses) {
|
||||||
|
if (deviceOpRes.getKey().equalsIgnoreCase(status.getDeviceIdentifier().getId())) {
|
||||||
|
status.getResponses().addAll(deviceOpRes.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
||||||
"the database.", e);
|
"the database. " + e.getMessage(), e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -328,12 +513,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
+ "dor.ID AS OP_RES_ID, de.DEVICE_ID, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID, "
|
+ "dor.ID AS OP_RES_ID, de.DEVICE_ID, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID, "
|
||||||
+ "dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, "
|
+ "dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, "
|
||||||
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
|
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
|
||||||
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP FROM "
|
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE FROM "
|
||||||
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
|
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
|
||||||
+ "ON op.ID=eom.OPERATION_ID INNER JOIN DM_ENROLMENT de "
|
+ "ON op.ID=eom.OPERATION_ID INNER JOIN DM_ENROLMENT de "
|
||||||
+ "ON de.ID=eom.ENROLMENT_ID INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID \n"
|
+ "ON de.ID=eom.ENROLMENT_ID INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID "
|
||||||
+ "INNER JOIN DM_DEVICE_TYPE dt ON dt.ID=d.DEVICE_TYPE_ID\n"
|
+ "INNER JOIN DM_DEVICE_TYPE dt ON dt.ID=d.DEVICE_TYPE_ID "
|
||||||
+ "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE dor ON dor.ENROLMENT_ID=de.id \n"
|
+ "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE dor ON dor.ENROLMENT_ID=de.id "
|
||||||
+ "AND dor.OPERATION_ID = eom.OPERATION_ID WHERE eom.OPERATION_ID "
|
+ "AND dor.OPERATION_ID = eom.OPERATION_ID WHERE eom.OPERATION_ID "
|
||||||
+ "IN (SELECT * FROM TABLE(x INT = ?)) AND de.TENANT_ID = ?";
|
+ "IN (SELECT * FROM TABLE(x INT = ?)) AND de.TENANT_ID = ?";
|
||||||
|
|
||||||
@ -347,6 +532,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
int enrolmentId = 0;
|
int enrolmentId = 0;
|
||||||
int responseId = 0;
|
int responseId = 0;
|
||||||
ActivityStatus activityStatus = new ActivityStatus();
|
ActivityStatus activityStatus = new ActivityStatus();
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
activity = new Activity();
|
activity = new Activity();
|
||||||
|
|
||||||
@ -379,8 +565,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -409,8 +601,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -420,20 +616,21 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID") && rs.getTimestamp(
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID") && rs.getTimestamp(
|
||||||
"RECEIVED_TIMESTAMP") != null) {
|
"RECEIVED_TIMESTAMP") != null) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException(
|
throw new OperationManagementDAOException(
|
||||||
"Error occurred while getting the operation details from " + "the database.", e);
|
"Error occurred while getting the operation details from the database. " + e.getMessage(), e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException(
|
|
||||||
"Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException(
|
|
||||||
"IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -445,6 +642,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Activity activity = null;
|
Activity activity = null;
|
||||||
|
int responseId = 0;
|
||||||
List<ActivityStatus> activityStatusList = new ArrayList<>();
|
List<ActivityStatus> activityStatusList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
@ -452,7 +650,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
"de.DEVICE_ID, d.DEVICE_IDENTIFICATION, \n" +
|
"de.DEVICE_ID, d.DEVICE_IDENTIFICATION, \n" +
|
||||||
"d.DEVICE_TYPE_ID, dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, \n" +
|
"d.DEVICE_TYPE_ID, dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, \n" +
|
||||||
"eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, dor.OPERATION_RESPONSE, \n" +
|
"eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, dor.OPERATION_RESPONSE, \n" +
|
||||||
"dor.RECEIVED_TIMESTAMP, op.INITIATED_BY FROM DM_ENROLMENT_OP_MAPPING AS eom \n" +
|
"dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE, op.INITIATED_BY FROM DM_ENROLMENT_OP_MAPPING AS eom \n" +
|
||||||
"INNER JOIN DM_OPERATION AS op ON op.ID=eom.OPERATION_ID\n" +
|
"INNER JOIN DM_OPERATION AS op ON op.ID=eom.OPERATION_ID\n" +
|
||||||
"INNER JOIN DM_ENROLMENT AS de ON de.ID=eom.ENROLMENT_ID\n" +
|
"INNER JOIN DM_ENROLMENT AS de ON de.ID=eom.ENROLMENT_ID\n" +
|
||||||
"INNER JOIN DM_DEVICE AS d ON d.ID=de.DEVICE_ID \n" +
|
"INNER JOIN DM_DEVICE AS d ON d.ID=de.DEVICE_ID \n" +
|
||||||
@ -469,6 +667,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
int enrolmentId = 0;
|
int enrolmentId = 0;
|
||||||
ActivityStatus activityStatus = null;
|
ActivityStatus activityStatus = null;
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if (enrolmentId == 0) {
|
if (enrolmentId == 0) {
|
||||||
@ -501,17 +700,35 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
activity.setActivityStatus(activityStatusList);
|
activity.setActivityStatus(activityStatusList);
|
||||||
} else {
|
} else {
|
||||||
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
||||||
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!largeResponseIDs.isEmpty()) {
|
||||||
|
Map<String, Map<String, List<OperationResponse>>> largeOperationResponses = getLargeOperationResponsesInBulk(largeResponseIDs);
|
||||||
|
if (!largeOperationResponses.isEmpty()) {
|
||||||
|
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
|
||||||
|
if (activityStatuses != null) {
|
||||||
|
Map<String, List<OperationResponse>> deviceOpResponseMap = largeOperationResponses.get(activity.getActivityId());
|
||||||
|
for (Map.Entry<String, List<OperationResponse>> deviceOpRes : deviceOpResponseMap.entrySet()) {
|
||||||
|
for (ActivityStatus status : activityStatuses) {
|
||||||
|
if (deviceOpRes.getKey().equalsIgnoreCase(status.getDeviceIdentifier().getId())) {
|
||||||
|
status.getResponses().addAll(deviceOpRes.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
||||||
"the database.", e);
|
"the database. " + e.getMessage(), e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -539,8 +756,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
" opr.DEVICE_IDENTIFICATION, " +
|
" opr.DEVICE_IDENTIFICATION, " +
|
||||||
" opr.DEVICE_TYPE, " +
|
" opr.DEVICE_TYPE, " +
|
||||||
" ops.RECEIVED_TIMESTAMP, " +
|
" ops.RECEIVED_TIMESTAMP, " +
|
||||||
" ops.ID OP_RES_ID, " +
|
" ops.ID AS OP_RES_ID, " +
|
||||||
" ops.OPERATION_RESPONSE, " +
|
" ops.OPERATION_RESPONSE, " +
|
||||||
|
" ops.IS_LARGE_RESPONSE, " +
|
||||||
" opr.INITIATED_BY " +
|
" opr.INITIATED_BY " +
|
||||||
" FROM " +
|
" FROM " +
|
||||||
" (SELECT " +
|
" (SELECT " +
|
||||||
@ -551,11 +769,11 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
" opm.OPERATION_ID, " +
|
" opm.OPERATION_ID, " +
|
||||||
" op.OPERATION_CODE, " +
|
" op.OPERATION_CODE, " +
|
||||||
" op.INITIATED_BY, " +
|
" op.INITIATED_BY, " +
|
||||||
" op.TYPE OPERATION_TYPE, " +
|
" op.TYPE AS OPERATION_TYPE, " +
|
||||||
" opm.STATUS, " +
|
" opm.STATUS, " +
|
||||||
" en.DEVICE_ID, " +
|
" en.DEVICE_ID, " +
|
||||||
" de.DEVICE_IDENTIFICATION, " +
|
" de.DEVICE_IDENTIFICATION, " +
|
||||||
" dt.NAME DEVICE_TYPE, " +
|
" dt.NAME AS DEVICE_TYPE, " +
|
||||||
" de.TENANT_ID " +
|
" de.TENANT_ID " +
|
||||||
" FROM" +
|
" FROM" +
|
||||||
" DM_ENROLMENT_OP_MAPPING opm " +
|
" DM_ENROLMENT_OP_MAPPING opm " +
|
||||||
@ -588,6 +806,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
int responseId = 0;
|
int responseId = 0;
|
||||||
Activity activity = null;
|
Activity activity = null;
|
||||||
ActivityStatus activityStatus = null;
|
ActivityStatus activityStatus = null;
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|
||||||
if (operationId != rs.getInt("OPERATION_ID")) {
|
if (operationId != rs.getInt("OPERATION_ID")) {
|
||||||
@ -618,8 +837,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -648,8 +871,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -659,19 +886,22 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
||||||
"the database.", e);
|
"the database. " + e.getMessage(), e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -699,7 +929,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException(
|
throw new OperationManagementDAOException(
|
||||||
"Error occurred while getting the activity count from " + "the database.", e);
|
"Error occurred while getting the activity count from the database. " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -728,8 +958,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
" opr.DEVICE_IDENTIFICATION, " +
|
" opr.DEVICE_IDENTIFICATION, " +
|
||||||
" opr.DEVICE_TYPE, " +
|
" opr.DEVICE_TYPE, " +
|
||||||
" ops.RECEIVED_TIMESTAMP, " +
|
" ops.RECEIVED_TIMESTAMP, " +
|
||||||
" ops.ID OP_RES_ID, " +
|
" ops.ID AS OP_RES_ID, " +
|
||||||
" ops.OPERATION_RESPONSE , " +
|
" ops.OPERATION_RESPONSE , " +
|
||||||
|
" ops.IS_LARGE_RESPONSE , " +
|
||||||
" opr.INITIATED_BY " +
|
" opr.INITIATED_BY " +
|
||||||
" FROM " +
|
" FROM " +
|
||||||
" (SELECT " +
|
" (SELECT " +
|
||||||
@ -740,11 +971,11 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
" opm.OPERATION_ID, " +
|
" opm.OPERATION_ID, " +
|
||||||
" op.OPERATION_CODE, " +
|
" op.OPERATION_CODE, " +
|
||||||
" op.INITIATED_BY, " +
|
" op.INITIATED_BY, " +
|
||||||
" op.TYPE OPERATION_TYPE, " +
|
" op.TYPE AS OPERATION_TYPE, " +
|
||||||
" opm.STATUS, " +
|
" opm.STATUS, " +
|
||||||
" en.DEVICE_ID, " +
|
" en.DEVICE_ID, " +
|
||||||
" de.DEVICE_IDENTIFICATION, " +
|
" de.DEVICE_IDENTIFICATION, " +
|
||||||
" dt.NAME DEVICE_TYPE, " +
|
" dt.NAME AS DEVICE_TYPE, " +
|
||||||
" de.TENANT_ID " +
|
" de.TENANT_ID " +
|
||||||
" FROM" +
|
" FROM" +
|
||||||
" DM_ENROLMENT_OP_MAPPING opm " +
|
" DM_ENROLMENT_OP_MAPPING opm " +
|
||||||
@ -780,6 +1011,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
int responseId = 0;
|
int responseId = 0;
|
||||||
Activity activity = null;
|
Activity activity = null;
|
||||||
ActivityStatus activityStatus = null;
|
ActivityStatus activityStatus = null;
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|
||||||
if (operationId != rs.getInt("OPERATION_ID")) {
|
if (operationId != rs.getInt("OPERATION_ID")) {
|
||||||
@ -810,8 +1042,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -840,8 +1076,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -851,18 +1091,21 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
||||||
"the database.", e);
|
"the database. " + e.getMessage(), e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -871,13 +1114,13 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit,
|
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit,
|
||||||
int offset) throws OperationManagementDAOException {
|
int offset) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Activity> activities = new ArrayList<>();
|
List<Activity> activities = new ArrayList<>();
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
@ -893,7 +1136,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
" opr.DEVICE_IDENTIFICATION, " +
|
" opr.DEVICE_IDENTIFICATION, " +
|
||||||
" opr.DEVICE_TYPE, " +
|
" opr.DEVICE_TYPE, " +
|
||||||
" ops.RECEIVED_TIMESTAMP, " +
|
" ops.RECEIVED_TIMESTAMP, " +
|
||||||
" ops.ID OP_RES_ID, " +
|
" ops.IS_LARGE_RESPONSE, " +
|
||||||
|
" ops.ID AS OP_RES_ID, " +
|
||||||
" ops.OPERATION_RESPONSE " +
|
" ops.OPERATION_RESPONSE " +
|
||||||
" FROM " +
|
" FROM " +
|
||||||
" (SELECT " +
|
" (SELECT " +
|
||||||
@ -903,11 +1147,11 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
" opm.UPDATED_TIMESTAMP, " +
|
" opm.UPDATED_TIMESTAMP, " +
|
||||||
" opm.OPERATION_ID, " +
|
" opm.OPERATION_ID, " +
|
||||||
" op.OPERATION_CODE, " +
|
" op.OPERATION_CODE, " +
|
||||||
" op.TYPE OPERATION_TYPE, " +
|
" op.TYPE AS OPERATION_TYPE, " +
|
||||||
" opm.STATUS, " +
|
" opm.STATUS, " +
|
||||||
" en.DEVICE_ID, " +
|
" en.DEVICE_ID, " +
|
||||||
" de.DEVICE_IDENTIFICATION, " +
|
" de.DEVICE_IDENTIFICATION, " +
|
||||||
" dt.NAME DEVICE_TYPE, " +
|
" dt.NAME AS DEVICE_TYPE, " +
|
||||||
" de.TENANT_ID " +
|
" de.TENANT_ID " +
|
||||||
" FROM" +
|
" FROM" +
|
||||||
" DM_ENROLMENT_OP_MAPPING opm " +
|
" DM_ENROLMENT_OP_MAPPING opm " +
|
||||||
@ -970,8 +1214,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -1000,8 +1248,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -1011,18 +1263,21 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
||||||
"the database.", e);
|
"the database. " + e.getMessage(), e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -1035,9 +1290,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT COUNT(*) AS COUNT FROM DM_ENROLMENT_OP_MAPPING m \n"
|
String sql = "SELECT COUNT(*) AS COUNT FROM DM_ENROLMENT_OP_MAPPING WHERE " +
|
||||||
+ "INNER JOIN DM_ENROLMENT d ON m.ENROLMENT_ID = d.ID \n"
|
"UPDATED_TIMESTAMP > ? AND TENANT_ID = ?";
|
||||||
+ "WHERE m.UPDATED_TIMESTAMP > ? AND d.TENANT_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setLong(1, timestamp);
|
stmt.setLong(1, timestamp);
|
||||||
stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||||
@ -1047,7 +1301,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException(
|
throw new OperationManagementDAOException(
|
||||||
"Error occurred while getting the activity count from " + "the database.", e);
|
"Error occurred while getting the activity count from the database. " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -1060,17 +1314,13 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT \n" +
|
String sql = "SELECT COUNT(*) AS COUNT " +
|
||||||
" COUNT(*) AS COUNT\n" +
|
"FROM DM_ENROLMENT_OP_MAPPING AS m " +
|
||||||
"FROM\n" +
|
" INNER JOIN " +
|
||||||
" DM_ENROLMENT_OP_MAPPING AS m\n" +
|
" DM_OPERATION dp ON dp.ID = m.OPERATION_ID " +
|
||||||
" INNER JOIN\n" +
|
"WHERE m.UPDATED_TIMESTAMP > ?" +
|
||||||
" DM_ENROLMENT AS d ON m.ENROLMENT_ID = d.ID\n" +
|
" AND dp.INITIATED_BY = ?" +
|
||||||
" INNER JOIN \n" +
|
" AND m.TENANT_ID = ?";
|
||||||
" DM_OPERATION dp ON dp.ID = m.OPERATION_ID \n" +
|
|
||||||
"WHERE\n" +
|
|
||||||
" m.UPDATED_TIMESTAMP > ? AND dp.INITIATED_BY = ?\n" +
|
|
||||||
" AND d.TENANT_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setLong(1, timestamp);
|
stmt.setLong(1, timestamp);
|
||||||
stmt.setString(2, user);
|
stmt.setString(2, user);
|
||||||
@ -1081,7 +1331,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while getting the activity count from " +
|
throw new OperationManagementDAOException("Error occurred while getting the activity count from " +
|
||||||
"the database.", e);
|
"the database. " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -1095,7 +1345,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
Operation operation = null;
|
Operation operation = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
|
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY FROM " +
|
||||||
"DM_OPERATION WHERE id = ?";
|
"DM_OPERATION WHERE id = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
@ -1112,6 +1362,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||||
}
|
}
|
||||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||||
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -1270,8 +1521,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
List<Operation> operations = new ArrayList<>();
|
List<Operation> operations = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
||||||
"OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
"o.OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
||||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||||
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " +
|
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " +
|
||||||
"ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC";
|
"ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC";
|
||||||
@ -1312,8 +1563,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
List<Operation> operations = new ArrayList<Operation>();
|
List<Operation> operations = new ArrayList<Operation>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
||||||
"OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
"o.OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
||||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||||
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " +
|
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " +
|
||||||
"ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC LIMIT ?,?";
|
"ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC LIMIT ?,?";
|
||||||
@ -1378,8 +1629,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
stmt = connection.prepareStatement("SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
stmt = connection.prepareStatement("SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
||||||
"OPERATION_CODE, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
"o.OPERATION_CODE, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
||||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||||
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " +
|
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " +
|
||||||
"ORDER BY om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1");
|
"ORDER BY om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1");
|
||||||
@ -1406,19 +1657,19 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
return operation;
|
return operation;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
throw new OperationManagementDAOException("Error occurred while getting operation metadata. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<? extends Operation> getOperationsByDeviceStatusAndType(
|
public List<? extends Operation> getOperationsByDeviceStatusAndType(
|
||||||
int enrolmentId, Operation.Status status, Operation.Type type) throws OperationManagementDAOException {
|
int enrolmentId, Operation.Status status, Operation.Type type) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Operation operation;
|
Operation operation;
|
||||||
List<Operation> operations = new ArrayList<Operation>();
|
List<Operation> operations = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID, " +
|
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID, " +
|
||||||
@ -1499,7 +1750,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
operationMappings.add(operationMapping);
|
operationMappings.add(operationMapping);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("SQL error while getting operation mappings from database. ", e);
|
throw new OperationManagementDAOException("SQL error while getting operation mappings from database. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping;
|
||||||
@ -39,17 +40,18 @@ import java.util.Map;
|
|||||||
public class OperationMappingDAOImpl implements OperationMappingDAO {
|
public class OperationMappingDAOImpl implements OperationMappingDAO {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOperationMapping(int operationId, int enrollmentId, boolean isScheduled) throws
|
public void addOperationMapping(Operation operation, Integer deviceId, boolean isScheduled, Device device, Integer tenantId) throws
|
||||||
OperationManagementDAOException {
|
OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
long time = System.currentTimeMillis() / 1000;
|
long time = System.currentTimeMillis() / 1000;
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "INSERT INTO DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS, " +
|
String sql = "INSERT INTO DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS, " +
|
||||||
"PUSH_NOTIFICATION_STATUS, CREATED_TIMESTAMP, UPDATED_TIMESTAMP) VALUES (?, ?, ?, ?, ?, ?)";
|
"PUSH_NOTIFICATION_STATUS, CREATED_TIMESTAMP, UPDATED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, " +
|
||||||
|
"TYPE, DEVICE_TYPE, DEVICE_ID, DEVICE_IDENTIFICATION, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, enrollmentId);
|
stmt.setInt(1, deviceId);
|
||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operation.getId());
|
||||||
stmt.setString(3, Operation.Status.PENDING.toString());
|
stmt.setString(3, Operation.Status.PENDING.toString());
|
||||||
if (isScheduled) {
|
if (isScheduled) {
|
||||||
stmt.setString(4, Operation.PushNotificationStatus.SCHEDULED.toString());
|
stmt.setString(4, Operation.PushNotificationStatus.SCHEDULED.toString());
|
||||||
@ -58,27 +60,36 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
}
|
}
|
||||||
stmt.setLong(5, time);
|
stmt.setLong(5, time);
|
||||||
stmt.setLong(6, time);
|
stmt.setLong(6, time);
|
||||||
|
stmt.setString(7, operation.getCode());
|
||||||
|
stmt.setString(8, operation.getInitiatedBy());
|
||||||
|
stmt.setString(9, operation.getType().toString());
|
||||||
|
stmt.setString(10, device.getType());
|
||||||
|
stmt.setInt(11, device.getId());
|
||||||
|
stmt.setString(12, device.getDeviceIdentifier());
|
||||||
|
stmt.setInt(13, tenantId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e);
|
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOperationMapping(int operationId, List<Integer> enrollmentIds, boolean isScheduled) throws
|
public void addOperationMapping(Operation operation, List<Device> devices, boolean isScheduled, Integer tenantId) throws
|
||||||
OperationManagementDAOException {
|
OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
long time = System.currentTimeMillis() / 1000;
|
long time = System.currentTimeMillis() / 1000;
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "INSERT INTO DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS, " +
|
String sql = "INSERT INTO DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS, " +
|
||||||
"PUSH_NOTIFICATION_STATUS, CREATED_TIMESTAMP, UPDATED_TIMESTAMP) VALUES (?, ?, ?, ?, ?, ?)";
|
"PUSH_NOTIFICATION_STATUS, CREATED_TIMESTAMP, UPDATED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, " +
|
||||||
|
"TYPE, DEVICE_TYPE, DEVICE_ID, DEVICE_IDENTIFICATION, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
for (int enrollmentId : enrollmentIds) {
|
for (Device device : devices) {
|
||||||
stmt.setInt(1, enrollmentId);
|
stmt.setInt(1, device.getEnrolmentInfo().getId());
|
||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operation.getId());
|
||||||
stmt.setString(3, Operation.Status.PENDING.toString());
|
stmt.setString(3, Operation.Status.PENDING.toString());
|
||||||
if (isScheduled) {
|
if (isScheduled) {
|
||||||
stmt.setString(4, Operation.PushNotificationStatus.SCHEDULED.toString());
|
stmt.setString(4, Operation.PushNotificationStatus.SCHEDULED.toString());
|
||||||
@ -87,11 +98,19 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
}
|
}
|
||||||
stmt.setLong(5, time);
|
stmt.setLong(5, time);
|
||||||
stmt.setLong(6, time);
|
stmt.setLong(6, time);
|
||||||
|
stmt.setString(7, operation.getCode());
|
||||||
|
stmt.setString(8, operation.getInitiatedBy());
|
||||||
|
stmt.setString(9, operation.getType().toString());
|
||||||
|
stmt.setString(10, device.getType());
|
||||||
|
stmt.setInt(11, device.getId());
|
||||||
|
stmt.setString(12, device.getDeviceIdentifier());
|
||||||
|
stmt.setInt(13, tenantId);
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e);
|
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -109,14 +128,17 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operationId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e);
|
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateOperationMapping(int operationId, Integer deviceId, Operation.PushNotificationStatus pushNotificationStatus) throws OperationManagementDAOException {
|
public void updateOperationMapping(int operationId, Integer deviceId,
|
||||||
|
Operation.PushNotificationStatus pushNotificationStatus)
|
||||||
|
throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
@ -128,7 +150,8 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
stmt.setInt(3, operationId);
|
stmt.setInt(3, operationId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while updating device operation mappings", e);
|
throw new OperationManagementDAOException("Error occurred while updating device operation mappings. " +
|
||||||
|
e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -161,7 +184,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while updating device operation mappings as " +
|
throw new OperationManagementDAOException("Error occurred while updating device operation mappings as " +
|
||||||
"batch ", e);
|
"batch . " + e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -172,7 +195,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
long maxDuration, int deviceTypeId) throws OperationManagementDAOException {
|
long maxDuration, int deviceTypeId) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<OperationEnrolmentMapping> enrolmentOperationMappingList = null;
|
List<OperationEnrolmentMapping> enrolmentOperationMappingList;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
//We are specifically looking for operation mappings in 'Pending' & 'Repeated' states. Further we want
|
//We are specifically looking for operation mappings in 'Pending' & 'Repeated' states. Further we want
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
oos = new ObjectOutputStream(bao);
|
oos = new ObjectOutputStream(bao);
|
||||||
oos.writeObject(operation);
|
oos.writeObject(operation);
|
||||||
|
|
||||||
stmt.setObject(6, operation);
|
stmt.setBytes(6, bao.toByteArray());
|
||||||
stmt.setBoolean(7, operation.isEnabled());
|
stmt.setBoolean(7, operation.isEnabled());
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
|||||||
@ -18,19 +18,19 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.operation;
|
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.operation;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.GenericOperationDAOImpl;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.GenericOperationDAOImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -43,6 +43,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MySQLOperationDAOImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Activity> getActivityList(List<Integer> activityIds) throws OperationManagementDAOException {
|
public List<Activity> getActivityList(List<Integer> activityIds) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -53,23 +55,34 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
|
||||||
String sql1 = "SELECT eom.ENROLMENT_ID, eom.OPERATION_ID, eom.ID AS EOM_MAPPING_ID, "
|
String sql1 = "SELECT " +
|
||||||
+ "dor.ID AS OP_RES_ID, de.DEVICE_ID, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID, "
|
" eom.ENROLMENT_ID," +
|
||||||
+ "dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, "
|
" eom.CREATED_TIMESTAMP," +
|
||||||
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
|
" eom.UPDATED_TIMESTAMP," +
|
||||||
+ "dor.OPERATION_RESPONSE, dor.RECEIVED_TIMESTAMP, op.INITIATED_BY FROM "
|
" eom.OPERATION_ID," +
|
||||||
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
|
" eom.OPERATION_CODE," +
|
||||||
+ "ON op.ID=eom.OPERATION_ID INNER JOIN DM_ENROLMENT de "
|
" eom.INITIATED_BY," +
|
||||||
+ "ON de.ID=eom.ENROLMENT_ID INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID \n"
|
" eom.TYPE," +
|
||||||
+ "INNER JOIN DM_DEVICE_TYPE dt ON dt.ID=d.DEVICE_TYPE_ID\n"
|
" eom.STATUS," +
|
||||||
+ "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE dor ON dor.ENROLMENT_ID=de.id \n"
|
" eom.DEVICE_ID," +
|
||||||
+ "AND dor.OPERATION_ID = eom.OPERATION_ID WHERE eom.OPERATION_ID " + "IN (";
|
" eom.DEVICE_IDENTIFICATION," +
|
||||||
|
" eom.DEVICE_TYPE," +
|
||||||
|
" opr.ID AS OP_RES_ID," +
|
||||||
|
" opr.RECEIVED_TIMESTAMP," +
|
||||||
|
" opr.OPERATION_RESPONSE," +
|
||||||
|
" opr.IS_LARGE_RESPONSE " +
|
||||||
|
"FROM " +
|
||||||
|
" DM_ENROLMENT_OP_MAPPING eom " +
|
||||||
|
" LEFT JOIN " +
|
||||||
|
" DM_DEVICE_OPERATION_RESPONSE opr ON opr.EN_OP_MAP_ID = eom.ID " +
|
||||||
|
"WHERE " +
|
||||||
|
" eom.OPERATION_ID IN (";
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (int i = 0; i < activityIds.size(); i++) {
|
for (int i = 0; i < activityIds.size(); i++) {
|
||||||
builder.append("?,");
|
builder.append("?,");
|
||||||
}
|
}
|
||||||
sql1 += builder.deleteCharAt(builder.length() - 1).toString() + ") AND de.TENANT_ID = ?";
|
sql1 += builder.deleteCharAt(builder.length() - 1).toString() + ") AND eom.TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql1);
|
stmt = conn.prepareStatement(sql1);
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < activityIds.size(); i++) {
|
for (i = 0; i < activityIds.size(); i++) {
|
||||||
@ -83,6 +96,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
int enrolmentId = 0;
|
int enrolmentId = 0;
|
||||||
int responseId = 0;
|
int responseId = 0;
|
||||||
ActivityStatus activityStatus = new ActivityStatus();
|
ActivityStatus activityStatus = new ActivityStatus();
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
activity = new Activity();
|
activity = new Activity();
|
||||||
|
|
||||||
@ -94,7 +108,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
operationId = rs.getInt("OPERATION_ID");
|
operationId = rs.getInt("OPERATION_ID");
|
||||||
enrolmentId = rs.getInt("ENROLMENT_ID");
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
||||||
|
|
||||||
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
activity.setType(Activity.Type.valueOf(rs.getString("TYPE")));
|
||||||
activity.setCreatedTimeStamp(
|
activity.setCreatedTimeStamp(
|
||||||
new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
||||||
activity.setCode(rs.getString("OPERATION_CODE"));
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
||||||
@ -102,7 +116,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
||||||
deviceIdentifier.setType(rs.getString("DEVICE_TYPE_NAME"));
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE"));
|
||||||
|
|
||||||
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
||||||
|
|
||||||
@ -115,8 +129,12 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -127,7 +145,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
||||||
activityStatus = new ActivityStatus();
|
activityStatus = new ActivityStatus();
|
||||||
|
|
||||||
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
activity.setType(Activity.Type.valueOf(rs.getString("TYPE")));
|
||||||
activity.setCreatedTimeStamp(
|
activity.setCreatedTimeStamp(
|
||||||
new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
||||||
activity.setCode(rs.getString("OPERATION_CODE"));
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
||||||
@ -135,7 +153,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
||||||
deviceIdentifier.setType(rs.getString("DEVICE_TYPE_NAME"));
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE"));
|
||||||
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
||||||
|
|
||||||
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
|
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
|
||||||
@ -146,8 +164,12 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -157,31 +179,30 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID") && rs.getTimestamp(
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID") && rs.getTimestamp(
|
||||||
"RECEIVED_TIMESTAMP") != null) {
|
"RECEIVED_TIMESTAMP") != null) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException(
|
throw new OperationManagementDAOException(
|
||||||
"Error occurred while getting the operation details from " + "the database.", e);
|
"Error occurred while getting the operation details from " + "the database.", e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException(
|
|
||||||
"Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException(
|
|
||||||
"IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
return activities;
|
return activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit,
|
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit,
|
||||||
int offset) throws OperationManagementDAOException {
|
int offset)
|
||||||
|
throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Activity> activities = new ArrayList<>();
|
List<Activity> activities = new ArrayList<>();
|
||||||
@ -189,51 +210,32 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
" opr.ENROLMENT_ID, " +
|
" eom.ENROLMENT_ID," +
|
||||||
" opr.CREATED_TIMESTAMP, " +
|
" eom.CREATED_TIMESTAMP," +
|
||||||
" opr.UPDATED_TIMESTAMP, " +
|
" eom.UPDATED_TIMESTAMP," +
|
||||||
" opr.OPERATION_ID, " +
|
" eom.OPERATION_ID," +
|
||||||
" opr.OPERATION_CODE, " +
|
" eom.OPERATION_CODE," +
|
||||||
" opr.INITIATED_BY, " +
|
" eom.INITIATED_BY," +
|
||||||
" opr.OPERATION_TYPE, " +
|
" eom.TYPE," +
|
||||||
" opr.STATUS, " +
|
" eom.STATUS," +
|
||||||
" opr.DEVICE_ID, " +
|
" eom.DEVICE_ID," +
|
||||||
" opr.DEVICE_IDENTIFICATION, " +
|
" eom.DEVICE_IDENTIFICATION," +
|
||||||
" opr.DEVICE_TYPE, " +
|
" eom.DEVICE_TYPE," +
|
||||||
" ops.RECEIVED_TIMESTAMP, " +
|
" opr.ID AS OP_RES_ID," +
|
||||||
" ops.ID OP_RES_ID, " +
|
" opr.RECEIVED_TIMESTAMP," +
|
||||||
" ops.OPERATION_RESPONSE " +
|
" opr.OPERATION_RESPONSE," +
|
||||||
|
" opr.IS_LARGE_RESPONSE " +
|
||||||
"FROM " +
|
"FROM " +
|
||||||
" (SELECT " +
|
" DM_ENROLMENT_OP_MAPPING eom FORCE INDEX (IDX_ENROLMENT_OP_MAPPING) " +
|
||||||
" opm.ID MAPPING_ID, " +
|
" LEFT JOIN " +
|
||||||
" opm.ENROLMENT_ID, " +
|
" DM_DEVICE_OPERATION_RESPONSE opr ON opr.EN_OP_MAP_ID = eom.ID " +
|
||||||
" opm.CREATED_TIMESTAMP, " +
|
|
||||||
" opm.UPDATED_TIMESTAMP, " +
|
|
||||||
" opm.OPERATION_ID, " +
|
|
||||||
" op.OPERATION_CODE, " +
|
|
||||||
" op.INITIATED_BY, " +
|
|
||||||
" op.TYPE OPERATION_TYPE, " +
|
|
||||||
" opm.STATUS, " +
|
|
||||||
" en.DEVICE_ID, " +
|
|
||||||
" de.DEVICE_IDENTIFICATION, " +
|
|
||||||
" dt.NAME DEVICE_TYPE, " +
|
|
||||||
" de.TENANT_ID " +
|
|
||||||
" FROM" +
|
|
||||||
" DM_ENROLMENT_OP_MAPPING opm FORCE INDEX (IDX_ENROLMENT_OP_MAPPING) " +
|
|
||||||
" INNER JOIN DM_OPERATION op ON opm.OPERATION_ID = op.ID " +
|
|
||||||
" INNER JOIN DM_ENROLMENT en ON opm.ENROLMENT_ID = en.ID " +
|
|
||||||
" INNER JOIN DM_DEVICE de ON en.DEVICE_ID = de.ID " +
|
|
||||||
" INNER JOIN DM_DEVICE_TYPE dt ON dt.ID = de.DEVICE_TYPE_ID " +
|
|
||||||
"WHERE " +
|
"WHERE " +
|
||||||
" opm.UPDATED_TIMESTAMP > ? " +
|
" eom.UPDATED_TIMESTAMP > ? " +
|
||||||
" AND de.TENANT_ID = ? " +
|
" AND eom.TENANT_ID = ? " +
|
||||||
" ORDER BY opm.UPDATED_TIMESTAMP " +
|
"ORDER BY eom.UPDATED_TIMESTAMP " +
|
||||||
" LIMIT ? OFFSET ?) opr " +
|
"LIMIT ? OFFSET ?";
|
||||||
" LEFT JOIN DM_DEVICE_OPERATION_RESPONSE ops ON opr.MAPPING_ID = ops.EN_OP_MAP_ID " +
|
|
||||||
" WHERE " +
|
|
||||||
" opr.UPDATED_TIMESTAMP > ? " +
|
|
||||||
" AND opr.TENANT_ID = ? ";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
|
|
||||||
@ -241,8 +243,6 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, limit);
|
stmt.setInt(3, limit);
|
||||||
stmt.setInt(4, offset);
|
stmt.setInt(4, offset);
|
||||||
stmt.setLong(5, timestamp);
|
|
||||||
stmt.setInt(6, tenantId);
|
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
@ -251,6 +251,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
int responseId = 0;
|
int responseId = 0;
|
||||||
Activity activity = null;
|
Activity activity = null;
|
||||||
ActivityStatus activityStatus = null;
|
ActivityStatus activityStatus = null;
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|
||||||
if (operationId != rs.getInt("OPERATION_ID")) {
|
if (operationId != rs.getInt("OPERATION_ID")) {
|
||||||
@ -262,7 +263,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
operationId = rs.getInt("OPERATION_ID");
|
operationId = rs.getInt("OPERATION_ID");
|
||||||
enrolmentId = rs.getInt("ENROLMENT_ID");
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
||||||
|
|
||||||
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
activity.setType(Activity.Type.valueOf(rs.getString("TYPE")));
|
||||||
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
||||||
activity.setCode(rs.getString("OPERATION_CODE"));
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
||||||
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
||||||
@ -281,8 +282,12 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -294,7 +299,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
||||||
activityStatus = new ActivityStatus();
|
activityStatus = new ActivityStatus();
|
||||||
|
|
||||||
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
activity.setType(Activity.Type.valueOf(rs.getString("TYPE")));
|
||||||
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
||||||
activity.setCode(rs.getString("OPERATION_CODE"));
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
||||||
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
||||||
@ -312,8 +317,12 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -323,18 +332,21 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
||||||
"the database.", e);
|
"the database.", e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
@ -347,66 +359,55 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Activity> activities = new ArrayList<>();
|
List<Activity> activities = new ArrayList<>();
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
" opr.ENROLMENT_ID, " +
|
" eom.ENROLMENT_ID," +
|
||||||
" opr.CREATED_TIMESTAMP, " +
|
" eom.CREATED_TIMESTAMP," +
|
||||||
" opr.UPDATED_TIMESTAMP, " +
|
" eom.UPDATED_TIMESTAMP," +
|
||||||
" opr.OPERATION_ID, " +
|
" eom.OPERATION_ID," +
|
||||||
" opr.OPERATION_CODE, " +
|
" eom.OPERATION_CODE," +
|
||||||
" opr.INITIATED_BY, " +
|
" eom.INITIATED_BY," +
|
||||||
" opr.OPERATION_TYPE, " +
|
" eom.TYPE," +
|
||||||
" opr.STATUS, " +
|
" eom.STATUS," +
|
||||||
" opr.DEVICE_ID, " +
|
" eom.DEVICE_ID," +
|
||||||
" opr.DEVICE_IDENTIFICATION, " +
|
" eom.DEVICE_IDENTIFICATION," +
|
||||||
" opr.DEVICE_TYPE, " +
|
" eom.DEVICE_TYPE," +
|
||||||
" ops.RECEIVED_TIMESTAMP, " +
|
" opr.ID AS OP_RES_ID," +
|
||||||
" ops.ID OP_RES_ID, " +
|
" opr.RECEIVED_TIMESTAMP," +
|
||||||
" ops.OPERATION_RESPONSE " +
|
" opr.OPERATION_RESPONSE," +
|
||||||
|
" opr.IS_LARGE_RESPONSE " +
|
||||||
"FROM " +
|
"FROM " +
|
||||||
" (SELECT " +
|
" DM_ENROLMENT_OP_MAPPING eom FORCE INDEX (IDX_ENROLMENT_OP_MAPPING) " +
|
||||||
" opm.ID MAPPING_ID, " +
|
" LEFT JOIN " +
|
||||||
" opm.ENROLMENT_ID, " +
|
" DM_DEVICE_OPERATION_RESPONSE opr ON opr.EN_OP_MAP_ID = eom.ID " +
|
||||||
" opm.CREATED_TIMESTAMP, " +
|
|
||||||
" opm.UPDATED_TIMESTAMP, " +
|
|
||||||
" opm.OPERATION_ID, " +
|
|
||||||
" op.OPERATION_CODE, " +
|
|
||||||
" op.INITIATED_BY, " +
|
|
||||||
" op.TYPE OPERATION_TYPE, " +
|
|
||||||
" opm.STATUS, " +
|
|
||||||
" en.DEVICE_ID, " +
|
|
||||||
" de.DEVICE_IDENTIFICATION, " +
|
|
||||||
" dt.NAME DEVICE_TYPE, " +
|
|
||||||
" de.TENANT_ID " +
|
|
||||||
" FROM" +
|
|
||||||
" DM_ENROLMENT_OP_MAPPING opm FORCE INDEX (IDX_ENROLMENT_OP_MAPPING) " +
|
|
||||||
" INNER JOIN DM_OPERATION op ON opm.OPERATION_ID = op.ID " +
|
|
||||||
" INNER JOIN DM_ENROLMENT en ON opm.ENROLMENT_ID = en.ID " +
|
|
||||||
" INNER JOIN DM_DEVICE de ON en.DEVICE_ID = de.ID " +
|
|
||||||
" INNER JOIN DM_DEVICE_TYPE dt ON dt.ID = de.DEVICE_TYPE_ID " +
|
|
||||||
"WHERE " +
|
"WHERE " +
|
||||||
" opm.UPDATED_TIMESTAMP > ? AND op.INITIATED_BY = ?" +
|
" eom.UPDATED_TIMESTAMP > ? " +
|
||||||
" AND de.TENANT_ID = ? " +
|
" AND eom.TENANT_ID = ? " +
|
||||||
" ORDER BY opm.UPDATED_TIMESTAMP " +
|
" AND eom.INITIATED_BY = ? " +
|
||||||
" LIMIT ? OFFSET ?) opr " +
|
"ORDER BY eom.UPDATED_TIMESTAMP " +
|
||||||
" LEFT JOIN DM_DEVICE_OPERATION_RESPONSE ops ON opr.MAPPING_ID = ops.EN_OP_MAP_ID " +
|
"LIMIT ? OFFSET ?";
|
||||||
" WHERE " +
|
|
||||||
" opr.UPDATED_TIMESTAMP > ? AND opr.INITIATED_BY = ? " +
|
|
||||||
" AND opr.TENANT_ID = ? ";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
|
|
||||||
stmt.setLong(1, timestamp);
|
stmt.setLong(1, timestamp);
|
||||||
stmt.setString(2, user);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setString(3, user);
|
||||||
stmt.setInt(4, limit);
|
stmt.setInt(4, limit);
|
||||||
stmt.setInt(5, offset);
|
stmt.setInt(5, offset);
|
||||||
stmt.setLong(6, timestamp);
|
|
||||||
stmt.setString(7, user);
|
// stmt.setLong(1, timestamp);
|
||||||
stmt.setInt(8, tenantId);
|
// stmt.setString(2, user);
|
||||||
|
// stmt.setInt(3, tenantId);
|
||||||
|
// stmt.setInt(4, limit);
|
||||||
|
// stmt.setInt(5, offset);
|
||||||
|
// stmt.setLong(6, timestamp);
|
||||||
|
// stmt.setString(7, user);
|
||||||
|
// stmt.setInt(8, tenantId);
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
@ -426,7 +427,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
operationId = rs.getInt("OPERATION_ID");
|
operationId = rs.getInt("OPERATION_ID");
|
||||||
enrolmentId = rs.getInt("ENROLMENT_ID");
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
||||||
|
|
||||||
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
activity.setType(Activity.Type.valueOf(rs.getString("TYPE")));
|
||||||
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
||||||
activity.setCode(rs.getString("OPERATION_CODE"));
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
||||||
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
||||||
@ -445,8 +446,12 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -458,7 +463,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
||||||
activityStatus = new ActivityStatus();
|
activityStatus = new ActivityStatus();
|
||||||
|
|
||||||
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
activity.setType(Activity.Type.valueOf(rs.getString("TYPE")));
|
||||||
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
||||||
activity.setCode(rs.getString("OPERATION_CODE"));
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
||||||
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
||||||
@ -476,8 +481,12 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -487,31 +496,25 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
||||||
"the database.", e);
|
"the database.", e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
return activities;
|
return activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer[] getIntArrayOfActivityIds(List<Integer> activityIds) {
|
|
||||||
Integer[] arr = new Integer[activityIds.size()];
|
|
||||||
int x = 0;
|
|
||||||
for (Integer activityId : activityIds) {
|
|
||||||
arr[x] = activityId;
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -188,6 +188,7 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Activity> activities = new ArrayList<>();
|
List<Activity> activities = new ArrayList<>();
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
/*String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n"
|
/*String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n"
|
||||||
@ -224,6 +225,7 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
" opr.DEVICE_TYPE, " +
|
" opr.DEVICE_TYPE, " +
|
||||||
" ops.RECEIVED_TIMESTAMP, " +
|
" ops.RECEIVED_TIMESTAMP, " +
|
||||||
" ops.ID OP_RES_ID, " +
|
" ops.ID OP_RES_ID, " +
|
||||||
|
" ops.IS_LARGE_RESPONSE, " +
|
||||||
" ops.OPERATION_RESPONSE " +
|
" ops.OPERATION_RESPONSE " +
|
||||||
" FROM " +
|
" FROM " +
|
||||||
" (SELECT " +
|
" (SELECT " +
|
||||||
@ -301,8 +303,12 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -332,8 +338,12 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -343,20 +353,21 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException(
|
throw new OperationManagementDAOException(
|
||||||
"Error occurred while getting the operation details from " + "the database.", e);
|
"Error occurred while getting the operation details from " + "the database.", e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException(
|
|
||||||
"Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException(
|
|
||||||
"IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.operation;
|
|||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.OperationResponseMeta;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||||
@ -30,7 +31,9 @@ import java.sql.Connection;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,4 +129,63 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
}
|
}
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OperationResponseMeta addOperationResponse(int enrolmentId, org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation,
|
||||||
|
String deviceId) throws OperationManagementDAOException {
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
boolean isLargeResponse = false;
|
||||||
|
try {
|
||||||
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
|
|
||||||
|
stmt = connection.prepareStatement("SELECT ID FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? " +
|
||||||
|
"AND OPERATION_ID = ?");
|
||||||
|
stmt.setInt(1, enrolmentId);
|
||||||
|
stmt.setInt(2, operation.getId());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
int enPrimaryId = 0;
|
||||||
|
if (rs.next()) {
|
||||||
|
enPrimaryId = rs.getInt("ID");
|
||||||
|
}
|
||||||
|
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID, " +
|
||||||
|
"EN_OP_MAP_ID, OPERATION_RESPONSE, IS_LARGE_RESPONSE, RECEIVED_TIMESTAMP) VALUES(?, ?, ?, ?, ?, ?)",
|
||||||
|
new String[]{"id"});
|
||||||
|
stmt.setInt(1, operation.getId());
|
||||||
|
stmt.setInt(2, enrolmentId);
|
||||||
|
stmt.setInt(3, enPrimaryId);
|
||||||
|
|
||||||
|
if (operation.getOperationResponse() != null && operation.getOperationResponse().length() >= 1000) {
|
||||||
|
isLargeResponse = true;
|
||||||
|
stmt.setBytes(4, null);
|
||||||
|
} else {
|
||||||
|
stmt.setString(4, operation.getOperationResponse());
|
||||||
|
}
|
||||||
|
stmt.setBoolean(5, isLargeResponse);
|
||||||
|
|
||||||
|
Timestamp receivedTimestamp = new Timestamp(new Date().getTime());
|
||||||
|
stmt.setTimestamp(6, receivedTimestamp);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
rs = stmt.getGeneratedKeys();
|
||||||
|
int opResID = -1;
|
||||||
|
if (rs.next()) {
|
||||||
|
opResID = rs.getInt(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
OperationResponseMeta responseMeta = new OperationResponseMeta();
|
||||||
|
responseMeta.setId(opResID);
|
||||||
|
responseMeta.setEnrolmentId(enrolmentId);
|
||||||
|
responseMeta.setOperationMappingId(enPrimaryId);
|
||||||
|
responseMeta.setReceivedTimestamp(receivedTimestamp);
|
||||||
|
responseMeta.setLargeResponse(isLargeResponse);
|
||||||
|
return responseMeta;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementDAOException("Error occurred while inserting operation response. " +
|
||||||
|
e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,6 +166,7 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Activity> activities = new ArrayList<>();
|
List<Activity> activities = new ArrayList<>();
|
||||||
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
/*String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n"
|
/*String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n"
|
||||||
@ -201,6 +202,7 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
" opr.DEVICE_TYPE, " +
|
" opr.DEVICE_TYPE, " +
|
||||||
" ops.RECEIVED_TIMESTAMP, " +
|
" ops.RECEIVED_TIMESTAMP, " +
|
||||||
" ops.ID OP_RES_ID, " +
|
" ops.ID OP_RES_ID, " +
|
||||||
|
" ops.IS_LARGE_RESPONSE, " +
|
||||||
" ops.OPERATION_RESPONSE " +
|
" ops.OPERATION_RESPONSE " +
|
||||||
" FROM " +
|
" FROM " +
|
||||||
" (SELECT " +
|
" (SELECT " +
|
||||||
@ -277,8 +279,12 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
statusList.add(activityStatus);
|
statusList.add(activityStatus);
|
||||||
@ -308,8 +314,12 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
||||||
}
|
}
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
activityStatus.setResponses(operationResponses);
|
activityStatus.setResponses(operationResponses);
|
||||||
activity.getActivityStatus().add(activityStatus);
|
activity.getActivityStatus().add(activityStatus);
|
||||||
@ -319,20 +329,21 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
||||||
responseId = rs.getInt("OP_RES_ID");
|
responseId = rs.getInt("OP_RES_ID");
|
||||||
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
||||||
|
largeResponseIDs.add(responseId);
|
||||||
|
} else {
|
||||||
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!largeResponseIDs.isEmpty()) {
|
||||||
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException(
|
throw new OperationManagementDAOException(
|
||||||
"Error occurred while getting the operation details from " + "the database.", e);
|
"Error occurred while getting the operation details from " + "the database.", e);
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new OperationManagementDAOException(
|
|
||||||
"Error occurred while converting the operation response to string.", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException(
|
|
||||||
"IO exception occurred while converting the operations responses.", e);
|
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -123,7 +123,7 @@ public class OperationDAOUtil {
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OperationResponse getOperationResponse(ResultSet rs) throws
|
public static OperationResponse getLargeOperationResponse(ResultSet rs) throws
|
||||||
ClassNotFoundException, IOException, SQLException {
|
ClassNotFoundException, IOException, SQLException {
|
||||||
OperationResponse response = new OperationResponse();
|
OperationResponse response = new OperationResponse();
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
@ -158,6 +158,18 @@ public class OperationDAOUtil {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static OperationResponse getOperationResponse(ResultSet rs) throws SQLException {
|
||||||
|
OperationResponse response = new OperationResponse();
|
||||||
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
||||||
|
response.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||||
|
}
|
||||||
|
if (rs.getString("OPERATION_RESPONSE") != null) {
|
||||||
|
response.setResponse(rs.getString("OPERATION_RESPONSE"));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
public static Operation.Type getType(String type) {
|
public static Operation.Type getType(String type) {
|
||||||
return Operation.Type.valueOf(type);
|
return Operation.Type.valueOf(type);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,6 +89,7 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion;
|
||||||
import org.wso2.carbon.device.mgt.core.geo.GeoCluster;
|
import org.wso2.carbon.device.mgt.core.geo.GeoCluster;
|
||||||
import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate;
|
import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -659,10 +660,7 @@ public interface DeviceManagementProviderService {
|
|||||||
|
|
||||||
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
|
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
|
||||||
|
|
||||||
boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException;
|
boolean setStatus(Device device, EnrolmentInfo.Status status) throws DeviceManagementException;
|
||||||
|
|
||||||
boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
|
|
||||||
EnrolmentInfo.Status status) throws DeviceManagementException;
|
|
||||||
|
|
||||||
boolean setStatus(String currentOwner, EnrolmentInfo.Status status) throws DeviceManagementException;
|
boolean setStatus(String currentOwner, EnrolmentInfo.Status status) throws DeviceManagementException;
|
||||||
|
|
||||||
@ -672,11 +670,16 @@ public interface DeviceManagementProviderService {
|
|||||||
Activity addOperation(String type, Operation operation,
|
Activity addOperation(String type, Operation operation,
|
||||||
List<DeviceIdentifier> devices) throws OperationManagementException, InvalidDeviceException;
|
List<DeviceIdentifier> devices) throws OperationManagementException, InvalidDeviceException;
|
||||||
|
|
||||||
|
void addTaskOperation(String deviceType, Operation operation) throws OperationManagementException;
|
||||||
|
|
||||||
List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException;
|
List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException;
|
||||||
|
|
||||||
PaginationResult getOperations(DeviceIdentifier deviceId,
|
PaginationResult getOperations(DeviceIdentifier deviceId,
|
||||||
PaginationRequest request) throws OperationManagementException;
|
PaginationRequest request) throws OperationManagementException;
|
||||||
|
|
||||||
|
List<? extends Operation> getOperations(DeviceIdentifier deviceId, Operation.Status status)
|
||||||
|
throws OperationManagementException;
|
||||||
|
|
||||||
List<? extends Operation> getPendingOperations(
|
List<? extends Operation> getPendingOperations(
|
||||||
DeviceIdentifier deviceId) throws OperationManagementException;
|
DeviceIdentifier deviceId) throws OperationManagementException;
|
||||||
|
|
||||||
@ -805,7 +808,7 @@ public interface DeviceManagementProviderService {
|
|||||||
|
|
||||||
boolean bulkUpdateDeviceStatus(String deviceType, List<String> deviceList, String status) throws DeviceManagementException;
|
boolean bulkUpdateDeviceStatus(String deviceType, List<String> deviceList, String status) throws DeviceManagementException;
|
||||||
|
|
||||||
boolean updateEnrollment(String owner, List<String> deviceIdentifiers)
|
boolean updateEnrollment(String owner, boolean isTransfer, List<String> deviceIdentifiers)
|
||||||
throws DeviceManagementException, UserNotFoundException, InvalidDeviceException;
|
throws DeviceManagementException, UserNotFoundException, InvalidDeviceException;
|
||||||
|
|
||||||
boolean addDeviceTypeVersion(DeviceTypeVersion deviceTypeVersion) throws DeviceManagementException;
|
boolean addDeviceTypeVersion(DeviceTypeVersion deviceTypeVersion) throws DeviceManagementException;
|
||||||
|
|||||||
@ -14,42 +14,7 @@
|
|||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.service;
|
package org.wso2.carbon.device.mgt.core.service;
|
||||||
|
|
||||||
import org.apache.commons.collections.map.SingletonMap;
|
import org.apache.commons.collections.map.SingletonMap;
|
||||||
@ -67,24 +32,38 @@ import org.wso2.carbon.CarbonConstants;
|
|||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceEnrollmentInfoNotification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceNotification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DevicePropertyNotification;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceTransferRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
||||||
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
||||||
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceTransferRequest;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DevicePropertyNotification;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceEnrollmentInfoNotification;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceNotification;
|
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.AmbiguousConfigurationException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.DeviceConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.DevicePropertyInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.EnrollmentConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.EnrollmentConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceData;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistorySnapshot;
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocationHistorySnapshot;
|
||||||
|
import org.wso2.carbon.device.mgt.common.enrollment.notification.EnrollmentNotificationConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.enrollment.notification.EnrollmentNotifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.enrollment.notification.EnrollmentNotifierException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.BadRequestException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceTypeNotFoundException;
|
||||||
@ -92,20 +71,6 @@ import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
|||||||
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.UnauthorizedDeviceAccessException;
|
import org.wso2.carbon.device.mgt.common.exceptions.UnauthorizedDeviceAccessException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException;
|
import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.BadRequestException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.AmbiguousConfigurationException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.DeviceConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.DevicePropertyInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceData;
|
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
|
||||||
import org.wso2.carbon.device.mgt.common.enrollment.notification.EnrollmentNotificationConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.common.enrollment.notification.EnrollmentNotifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.enrollment.notification.EnrollmentNotifierException;
|
|
||||||
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.group.mgt.DeviceGroupConstants;
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
|
||||||
@ -138,8 +103,6 @@ import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO;
|
|||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException;
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
|
||||||
@ -169,12 +132,12 @@ import java.io.StringWriter;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -182,31 +145,28 @@ import java.util.stream.Collectors;
|
|||||||
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
|
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
|
||||||
PluginInitializationListener {
|
PluginInitializationListener {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
|
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
|
||||||
|
|
||||||
private static final String OPERATION_RESPONSE_EVENT_STREAM_DEFINITION = "org.wso2.iot.OperationResponseStream";
|
private static final String OPERATION_RESPONSE_EVENT_STREAM_DEFINITION = "org.wso2.iot.OperationResponseStream";
|
||||||
private DeviceDAO deviceDAO;
|
private final DeviceManagementPluginRepository pluginRepository;
|
||||||
private DeviceDetailsDAO deviceInfoDAO;
|
private final DeviceInformationManager deviceInformationManager;
|
||||||
private DeviceTypeDAO deviceTypeDAO;
|
private final DeviceDAO deviceDAO;
|
||||||
private EnrollmentDAO enrollmentDAO;
|
private final DeviceTypeDAO deviceTypeDAO;
|
||||||
private ApplicationDAO applicationDAO;
|
private final EnrollmentDAO enrollmentDAO;
|
||||||
private DeviceManagementPluginRepository pluginRepository;
|
private final ApplicationDAO applicationDAO;
|
||||||
private DeviceInformationManager deviceInformationManager;
|
|
||||||
|
|
||||||
public DeviceManagementProviderServiceImpl() {
|
public DeviceManagementProviderServiceImpl() {
|
||||||
this.pluginRepository = new DeviceManagementPluginRepository();
|
this.pluginRepository = new DeviceManagementPluginRepository();
|
||||||
this.deviceInformationManager = new DeviceInformationManagerImpl();
|
this.deviceInformationManager = new DeviceInformationManagerImpl();
|
||||||
initDataAccessObjects();
|
|
||||||
/* Registering a listener to retrieve events when some device management service plugin is installed after
|
|
||||||
* the component is done getting initialized */
|
|
||||||
DeviceManagementServiceComponent.registerPluginInitializationListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initDataAccessObjects() {
|
|
||||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||||
this.deviceInfoDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
|
|
||||||
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
|
this.applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
|
||||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
this.enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
||||||
|
|
||||||
|
/* Registering a listener to retrieve events when some device management service plugin is installed after
|
||||||
|
* the component is done getting initialized */
|
||||||
|
DeviceManagementServiceComponent.registerPluginInitializationListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -251,6 +211,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new DeviceManagementException(msg);
|
throw new DeviceManagementException(msg);
|
||||||
}
|
}
|
||||||
|
if (device.getEnrolmentInfo() == null) {
|
||||||
|
String msg = "Received device without valid enrollment info for device enrollment";
|
||||||
|
log.error(msg);
|
||||||
|
throw new DeviceManagementException(msg);
|
||||||
|
}
|
||||||
|
if (device.getEnrolmentInfo().getStatus() == null) {
|
||||||
|
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Enrolling the device " + device.getId() + "of type '" + device.getType() + "'");
|
||||||
|
}
|
||||||
|
|
||||||
DeviceManager deviceManager = this.getDeviceManager(device.getType());
|
DeviceManager deviceManager = this.getDeviceManager(device.getType());
|
||||||
if (deviceManager == null) {
|
if (deviceManager == null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -278,36 +250,44 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
boolean status = false;
|
boolean status = false;
|
||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
|
||||||
|
|
||||||
deviceManager.enrollDevice(device);
|
|
||||||
if (deviceManager.isClaimable(deviceIdentifier)) {
|
|
||||||
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.INACTIVE);
|
|
||||||
} else {
|
|
||||||
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE);
|
|
||||||
}
|
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
|
|
||||||
Device existingDevice = this.getDevice(deviceIdentifier, false);
|
Device existingDevice = this.getDevice(deviceIdentifier, false);
|
||||||
|
|
||||||
if (existingDevice != null) {
|
if (existingDevice != null) {
|
||||||
|
deviceManager.modifyEnrollment(device);
|
||||||
EnrolmentInfo existingEnrolmentInfo = existingDevice.getEnrolmentInfo();
|
EnrolmentInfo existingEnrolmentInfo = existingDevice.getEnrolmentInfo();
|
||||||
EnrolmentInfo newEnrolmentInfo = device.getEnrolmentInfo();
|
EnrolmentInfo newEnrolmentInfo = device.getEnrolmentInfo();
|
||||||
if (existingEnrolmentInfo != null && newEnrolmentInfo != null) {
|
if (existingEnrolmentInfo != null && newEnrolmentInfo != null) {
|
||||||
|
if (existingDevice.getEnrolmentInfo().isTransferred()
|
||||||
|
&& existingDevice.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) {
|
||||||
|
newEnrolmentInfo = existingEnrolmentInfo;
|
||||||
|
status = true;
|
||||||
|
} else {
|
||||||
//Get all the enrollments of current user for the same device
|
//Get all the enrollments of current user for the same device
|
||||||
List<EnrolmentInfo> enrolmentInfos = this.getEnrollmentsOfUser(existingDevice.getId(),
|
List<EnrolmentInfo> enrolmentInfos = this.getEnrollmentsOfUser(existingDevice.getId(),
|
||||||
newEnrolmentInfo.getOwner());
|
newEnrolmentInfo.getOwner());
|
||||||
for (EnrolmentInfo enrolmentInfo : enrolmentInfos) {
|
for (EnrolmentInfo enrolmentInfo : enrolmentInfos) {
|
||||||
//If the enrollments are same then we'll update the existing enrollment.
|
//If the enrollments are same (owner & ownership) then we'll update the existing enrollment.
|
||||||
if (enrolmentInfo.equals(newEnrolmentInfo)) {
|
if (enrolmentInfo.equals(newEnrolmentInfo)) {
|
||||||
device.setId(existingDevice.getId());
|
newEnrolmentInfo.setDateOfEnrolment(enrolmentInfo.getDateOfEnrolment());
|
||||||
device.getEnrolmentInfo().setDateOfEnrolment(enrolmentInfo.getDateOfEnrolment());
|
newEnrolmentInfo.setId(enrolmentInfo.getId());
|
||||||
device.getEnrolmentInfo().setDateOfLastUpdate(enrolmentInfo.getDateOfLastUpdate());
|
//We are explicitly setting device status only if matching device enrollment is in
|
||||||
device.getEnrolmentInfo().setId(enrolmentInfo.getId());
|
// removed status.
|
||||||
this.modifyEnrollment(device);
|
if (enrolmentInfo.getStatus() == EnrolmentInfo.Status.REMOVED) {
|
||||||
|
newEnrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
} else {
|
||||||
|
newEnrolmentInfo.setStatus(enrolmentInfo.getStatus());
|
||||||
|
}
|
||||||
status = true;
|
status = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!status) {
|
}
|
||||||
|
if (status) {
|
||||||
|
device.setId(existingDevice.getId());
|
||||||
|
device.setEnrolmentInfo(newEnrolmentInfo);
|
||||||
|
this.modifyEnrollment(device);
|
||||||
|
} else {
|
||||||
int updateStatus = 0;
|
int updateStatus = 0;
|
||||||
EnrolmentInfo enrollment;
|
EnrolmentInfo enrollment;
|
||||||
try {
|
try {
|
||||||
@ -315,7 +295,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.beginTransaction();
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
if (!EnrolmentInfo.Status.REMOVED.equals(existingEnrolmentInfo.getStatus())) {
|
if (!EnrolmentInfo.Status.REMOVED.equals(existingEnrolmentInfo.getStatus())) {
|
||||||
existingEnrolmentInfo.setStatus(EnrolmentInfo.Status.REMOVED);
|
existingEnrolmentInfo.setStatus(EnrolmentInfo.Status.REMOVED);
|
||||||
updateStatus = enrollmentDAO.updateEnrollment(existingEnrolmentInfo);
|
updateStatus = enrollmentDAO.updateEnrollment(existingEnrolmentInfo, tenantId);
|
||||||
}
|
}
|
||||||
if ((updateStatus > 0) || EnrolmentInfo.Status.REMOVED.
|
if ((updateStatus > 0) || EnrolmentInfo.Status.REMOVED.
|
||||||
equals(existingEnrolmentInfo.getStatus())) {
|
equals(existingEnrolmentInfo.getStatus())) {
|
||||||
@ -339,16 +319,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
status = true;
|
status = true;
|
||||||
} else {
|
} else {
|
||||||
log.warn("Unable to update device enrollment for device : " + device.toString());
|
log.warn("Unable to update device enrollment for device : " + device.getDeviceIdentifier() +
|
||||||
|
" belonging to user : " + device.getEnrolmentInfo().getOwner());
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
String msg = "Error occurred while adding enrolment related metadata for device: " +
|
String msg = "Error occurred while adding enrolment related metadata for device: " + device.getId();
|
||||||
device.toString();
|
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String msg = "Error occurred while enrolling device: " + device.toString();
|
String msg = "Error occurred while enrolling device: " + device.getId();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -357,12 +337,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
deviceManager.enrollDevice(device);
|
||||||
EnrolmentInfo enrollment;
|
EnrolmentInfo enrollment;
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
DeviceType type = deviceTypeDAO.getDeviceType(device.getType(), tenantId);
|
DeviceType type = deviceTypeDAO.getDeviceType(device.getType(), tenantId);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId);
|
int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId);
|
||||||
|
device.setId(deviceId);
|
||||||
enrollment = enrollmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
|
enrollment = enrollmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
|
||||||
if (enrollment == null) {
|
if (enrollment == null) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
@ -379,7 +361,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
String msg = "Error occurred while adding metadata of device: " + device.toString();
|
String msg = "Error occurred while adding metadata of '" + device.getType() +
|
||||||
|
"' device carrying the identifier '" + device.getDeviceIdentifier() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} catch (TransactionManagementException e) {
|
} catch (TransactionManagementException e) {
|
||||||
@ -402,6 +385,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
addDeviceToGroups(deviceIdentifier, device.getEnrolmentInfo().getOwnership());
|
addDeviceToGroups(deviceIdentifier, device.getEnrolmentInfo().getOwnership());
|
||||||
if (enrollmentConfiguration != null) {
|
if (enrollmentConfiguration != null) {
|
||||||
@ -457,7 +441,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
device.setName(currentDevice.getName());
|
device.setName(currentDevice.getName());
|
||||||
}
|
}
|
||||||
deviceDAO.updateDevice(device, tenantId);
|
deviceDAO.updateDevice(device, tenantId);
|
||||||
enrollmentDAO.updateEnrollment(device.getEnrolmentInfo());
|
enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
|
||||||
DeviceManagementDAOFactory.commitTransaction();
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
this.removeDeviceFromCache(deviceIdentifier);
|
this.removeDeviceFromCache(deviceIdentifier);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
@ -553,7 +537,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
||||||
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
|
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
enrollmentDAO.updateEnrollment(device.getId(), device.getEnrolmentInfo(), tenantId);
|
enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
|
||||||
deviceDAO.updateDevice(device, tenantId);
|
deviceDAO.updateDevice(device, tenantId);
|
||||||
DeviceManagementDAOFactory.commitTransaction();
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
this.removeDeviceFromCache(deviceId);
|
this.removeDeviceFromCache(deviceId);
|
||||||
@ -631,8 +615,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
if (deviceIdentifierMap.containsKey(device.getType())) {
|
if (deviceIdentifierMap.containsKey(device.getType())) {
|
||||||
deviceIdentifierMap.get(device.getType()).add(device.getDeviceIdentifier());
|
deviceIdentifierMap.get(device.getType()).add(device.getDeviceIdentifier());
|
||||||
} else {
|
} else {
|
||||||
deviceIdentifierMap.put(device.getType(),
|
deviceIdentifierMap.put(device.getType(), Collections.singletonList(device.getDeviceIdentifier()));
|
||||||
new ArrayList<>(Arrays.asList(device.getDeviceIdentifier())));
|
|
||||||
DeviceManager deviceManager = this.getDeviceManager(device.getType());
|
DeviceManager deviceManager = this.getDeviceManager(device.getType());
|
||||||
if (deviceManager == null) {
|
if (deviceManager == null) {
|
||||||
log.error("Device Manager associated with the device type '" + device.getType() +
|
log.error("Device Manager associated with the device type '" + device.getType() +
|
||||||
@ -762,7 +745,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
return this.getAllDeviceInfo(allDevices);
|
return this.populateAllDeviceInfo(allDevices);
|
||||||
}
|
}
|
||||||
return allDevices;
|
return allDevices;
|
||||||
}
|
}
|
||||||
@ -798,7 +781,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!allDevices.isEmpty() && requireDeviceInfo) {
|
if (!allDevices.isEmpty() && requireDeviceInfo) {
|
||||||
return this.getAllDeviceInfo(allDevices);
|
return this.populateAllDeviceInfo(allDevices);
|
||||||
}
|
}
|
||||||
return allDevices;
|
return allDevices;
|
||||||
}
|
}
|
||||||
@ -840,7 +823,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
return this.getAllDeviceInfo(allDevices);
|
return this.populateAllDeviceInfo(allDevices);
|
||||||
}
|
}
|
||||||
return allDevices;
|
return allDevices;
|
||||||
}
|
}
|
||||||
@ -866,7 +849,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
int count;
|
int count;
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
String deviceType = request.getDeviceType();
|
String deviceType = request.getDeviceType();
|
||||||
request = DeviceManagerUtil.validateDeviceListPageSize(request);
|
DeviceManagerUtil.validateDeviceListPageSize(request);
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
allDevices = deviceDAO.getDevices(request, tenantId);
|
allDevices = deviceDAO.getDevices(request, tenantId);
|
||||||
@ -889,7 +872,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
paginationResult.setData(this.getAllDeviceInfo(allDevices));
|
paginationResult.setData(this.populateAllDeviceInfo(allDevices));
|
||||||
} else {
|
} else {
|
||||||
paginationResult.setData(allDevices);
|
paginationResult.setData(allDevices);
|
||||||
}
|
}
|
||||||
@ -919,13 +902,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
List<Device> allDevices;
|
List<Device> allDevices;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
request = DeviceManagerUtil.validateDeviceListPageSize(request);
|
DeviceManagerUtil.validateDeviceListPageSize(request);
|
||||||
if (!StringUtils.isEmpty(request.getOwnerRole())) {
|
if (!StringUtils.isEmpty(request.getOwnerRole())) {
|
||||||
devicesForRoles = this.getAllDevicesOfRole(request.getOwnerRole(), false);
|
devicesForRoles = this.getAllDevicesOfRole(request.getOwnerRole(), false);
|
||||||
if (devicesForRoles != null) {
|
if (devicesForRoles != null) {
|
||||||
count = devicesForRoles.size();
|
count = devicesForRoles.size();
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
paginationResult.setData(getAllDeviceInfo(devicesForRoles));
|
paginationResult.setData(populateAllDeviceInfo(devicesForRoles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -954,7 +937,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo && !allDevices.isEmpty()) {
|
if (requireDeviceInfo && !allDevices.isEmpty()) {
|
||||||
paginationResult.setData(getAllDeviceInfo(allDevices));
|
paginationResult.setData(populateAllDeviceInfo(allDevices));
|
||||||
} else {
|
} else {
|
||||||
paginationResult.setData(allDevices);
|
paginationResult.setData(allDevices);
|
||||||
}
|
}
|
||||||
@ -989,7 +972,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
this.addDeviceToCache(deviceId, device);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
String msg = "Error occurred while obtaining the device for '" + deviceId.getId() + "'";
|
String msg = "Error occurred while obtaining the device for '" + deviceId.getId() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
@ -1007,8 +989,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
device = this.getAllDeviceInfo(device);
|
this.populateAllDeviceInfo(device);
|
||||||
}
|
}
|
||||||
|
this.addDeviceToCache(deviceId, device);
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1054,7 +1037,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
device = this.getAllDeviceInfo(device);
|
this.populateAllDeviceInfo(device);
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -1067,12 +1050,19 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new DeviceManagementException(msg);
|
throw new DeviceManagementException(msg);
|
||||||
}
|
}
|
||||||
|
if (owner == null) {
|
||||||
|
String msg = "Received null device owner for method getDevice";
|
||||||
|
log.error(msg);
|
||||||
|
throw new DeviceManagementException(msg);
|
||||||
|
}
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Get device by device id :" + deviceId.getId() + " of type '" + deviceId.getType() +
|
log.debug("Get device by device id :" + deviceId.getId() + " of type '" + deviceId.getType() +
|
||||||
" and owner '" + owner + "' and requiredDeviceInfo: " + requireDeviceInfo);
|
" and owner '" + owner + "' and requiredDeviceInfo: " + requireDeviceInfo);
|
||||||
}
|
}
|
||||||
|
Device device = this.getDeviceFromCache(deviceId);
|
||||||
|
if (device == null || device.getEnrolmentInfo() == null
|
||||||
|
|| !owner.equals(device.getEnrolmentInfo().getOwner())) {
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
Device device;
|
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
device = deviceDAO.getDevice(deviceId, owner, tenantId);
|
device = deviceDAO.getDevice(deviceId, owner, tenantId);
|
||||||
@ -1100,8 +1090,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
device = this.getAllDeviceInfo(device);
|
this.populateAllDeviceInfo(device);
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -1205,8 +1196,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
throw new DeviceManagementException(msg);
|
throw new DeviceManagementException(msg);
|
||||||
}
|
}
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Get tenanted device with id: " + deviceIdentifier.getId() + " of type " +
|
log.debug("Get tenanted device with id: " + deviceIdentifier.getId() + " of type '" +
|
||||||
deviceIdentifier.getType());
|
deviceIdentifier.getType() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
SingletonMap deviceMap;
|
SingletonMap deviceMap;
|
||||||
@ -1219,13 +1210,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
" and id " + deviceIdentifier.getId());
|
" and id " + deviceIdentifier.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
String msg = "Error occurred while obtaining the device for id " + deviceIdentifier.getId();
|
String msg = "Error occurred while obtaining the device for id '" + deviceIdentifier.getId() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while opening a connection for the data source";
|
String msg = "Error occurred while opening a connection to the data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String msg = "Error occurred in getTenantedDevice device: " + deviceIdentifier.getId();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -1233,7 +1227,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requireDeviceInfo && deviceMap != null) {
|
if (requireDeviceInfo && deviceMap != null) {
|
||||||
getAllDeviceInfo((Device) deviceMap.getValue());
|
populateAllDeviceInfo((Device) deviceMap.getValue());
|
||||||
}
|
}
|
||||||
return deviceMap;
|
return deviceMap;
|
||||||
}
|
}
|
||||||
@ -1316,7 +1310,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
device = this.getAllDeviceInfo(device);
|
this.populateAllDeviceInfo(device);
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -1333,7 +1327,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.debug("Get device by device identifier :" + deviceData.getDeviceIdentifier().getId() + " of type '"
|
log.debug("Get device by device identifier :" + deviceData.getDeviceIdentifier().getId() + " of type '"
|
||||||
+ deviceData.getDeviceIdentifier().getType() + "' and requiredDeviceInfo: " + requireDeviceInfo);
|
+ deviceData.getDeviceIdentifier().getType() + "' and requiredDeviceInfo: " + requireDeviceInfo);
|
||||||
}
|
}
|
||||||
Device device = null;
|
Device device;
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
@ -1364,7 +1358,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
return this.getAllDeviceInfo(device);
|
this.populateAllDeviceInfo(device);
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -1445,7 +1439,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
device = this.getAllDeviceInfo(device);
|
this.populateAllDeviceInfo(device);
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -1490,7 +1484,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
device = this.getAllDeviceInfo(device);
|
this.populateAllDeviceInfo(device);
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -1538,7 +1532,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
device = this.getAllDeviceInfo(device);
|
this.populateAllDeviceInfo(device);
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@ -1663,40 +1657,28 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean setStatus(Device device, EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||||
DeviceManager deviceManager = this.getDeviceManager(deviceId.getType());
|
|
||||||
if (deviceManager == null) {
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " +
|
log.debug("Set status of device: " + device.getDeviceIdentifier());
|
||||||
"Therefore, not attempting method 'isClaimable'");
|
|
||||||
}
|
}
|
||||||
return false;
|
try {
|
||||||
}
|
boolean success;
|
||||||
return deviceManager.isClaimable(deviceId);
|
int tenantId = this.getTenantId();
|
||||||
}
|
EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo();
|
||||||
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
@Override
|
if (enrolmentInfo == null) {
|
||||||
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
|
enrolmentInfo = enrollmentDAO.getEnrollment(device.getId(), tenantId);
|
||||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
if (enrolmentInfo == null) {
|
||||||
if (deviceId == null) {
|
String msg = "Error occurred in getting enrollment for device :" + device.getDeviceIdentifier();
|
||||||
String msg = "Received null deviceIdentifier for setStatus";
|
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new DeviceManagementException(msg);
|
throw new DeviceManagementException(msg);
|
||||||
}
|
}
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Set status of device: " + deviceId.getId());
|
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
boolean success = false;
|
|
||||||
int tenantId = this.getTenantId();
|
|
||||||
Device device = this.getDevice(deviceId, false);
|
|
||||||
EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo();
|
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
|
||||||
if (enrolmentInfo != null) {
|
|
||||||
success = enrollmentDAO.setStatus(enrolmentInfo.getId(), status, tenantId);
|
success = enrollmentDAO.setStatus(enrolmentInfo.getId(), status, tenantId);
|
||||||
}
|
|
||||||
DeviceManagementDAOFactory.commitTransaction();
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
this.removeDeviceFromCache(deviceId);
|
enrolmentInfo.setStatus(status);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
this.addDeviceToCache(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()), device);
|
||||||
return success;
|
return success;
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
@ -1708,7 +1690,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String msg = "Error occurred in setStatus for device :" + deviceId.getId();
|
String msg = "Error occurred in setStatus for device :" + device.getDeviceIdentifier();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -1717,8 +1699,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setStatus(String currentOwner,
|
public boolean setStatus(String currentOwner, EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Update enrollment with status");
|
log.debug("Update enrollment with status");
|
||||||
}
|
}
|
||||||
@ -1837,6 +1818,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
return pluginRepository.getOperationManager(type, this.getTenantId()).addOperation(operation, devices);
|
return pluginRepository.getOperationManager(type, this.getTenantId()).addOperation(operation, devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTaskOperation(String type, Operation operation) throws OperationManagementException {
|
||||||
|
pluginRepository.getOperationManager(type, this.getTenantId()).addTaskOperation(type, operation);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||||
return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId()).getOperations(deviceId);
|
return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId()).getOperations(deviceId);
|
||||||
@ -1845,8 +1831,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
@Override
|
@Override
|
||||||
public PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request)
|
public PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request)
|
||||||
throws OperationManagementException {
|
throws OperationManagementException {
|
||||||
|
DeviceManagerUtil.validateOperationListPageSize(request);
|
||||||
return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId())
|
return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId())
|
||||||
.getOperations(deviceId, DeviceManagerUtil.validateOperationListPageSize(request));
|
.getOperations(deviceId, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceId, Operation.Status status)
|
||||||
|
throws OperationManagementException {
|
||||||
|
return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId())
|
||||||
|
.getOperations(deviceId, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1927,7 +1921,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
}
|
}
|
||||||
pluginRepository.getOperationManager(device.getType(), this.getTenantId())
|
pluginRepository.getOperationManager(device.getType(), this.getTenantId())
|
||||||
.updateOperation(enrolmentInfo.getId(), operation);
|
.updateOperation(deviceIdentifier, operation);
|
||||||
if (DeviceManagerUtil.isPublishOperationResponseEnabled()) {
|
if (DeviceManagerUtil.isPublishOperationResponseEnabled()) {
|
||||||
List<String> permittedOperations = DeviceManagerUtil.getEnabledOperationsForResponsePublish();
|
List<String> permittedOperations = DeviceManagerUtil.getEnabledOperationsForResponsePublish();
|
||||||
if (permittedOperations.contains(operation.getCode())
|
if (permittedOperations.contains(operation.getCode())
|
||||||
@ -1955,7 +1949,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new OperationManagementException(msg, e);
|
throw new OperationManagementException(msg, e);
|
||||||
} catch (BadRequestException e) {
|
} catch (BadRequestException e) {
|
||||||
String msg = "Error occured due to invalid request";
|
String msg = "Error occurred due to invalid request";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new OperationManagementException(msg, e);
|
throw new OperationManagementException(msg, e);
|
||||||
}
|
}
|
||||||
@ -2147,7 +2141,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
return this.getAllDeviceInfo(userDevices);
|
return this.populateAllDeviceInfo(userDevices);
|
||||||
}
|
}
|
||||||
return userDevices;
|
return userDevices;
|
||||||
}
|
}
|
||||||
@ -2191,7 +2185,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
return this.getAllDeviceInfo(userDevices);
|
return this.populateAllDeviceInfo(userDevices);
|
||||||
}
|
}
|
||||||
return userDevices;
|
return userDevices;
|
||||||
}
|
}
|
||||||
@ -2218,7 +2212,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
String username = request.getOwner();
|
String username = request.getOwner();
|
||||||
List<Device> userDevices;
|
List<Device> userDevices;
|
||||||
request = DeviceManagerUtil.validateDeviceListPageSize(request);
|
DeviceManagerUtil.validateDeviceListPageSize(request);
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
userDevices = deviceDAO.getDevicesOfUser(request, tenantId);
|
userDevices = deviceDAO.getDevicesOfUser(request, tenantId);
|
||||||
@ -2240,7 +2234,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
result.setData(this.getAllDeviceInfo(userDevices));
|
result.setData(this.populateAllDeviceInfo(userDevices));
|
||||||
} else {
|
} else {
|
||||||
result.setData(userDevices);
|
result.setData(userDevices);
|
||||||
}
|
}
|
||||||
@ -2272,7 +2266,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
int deviceCount;
|
int deviceCount;
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
String ownerShip = request.getOwnership();
|
String ownerShip = request.getOwnership();
|
||||||
request = DeviceManagerUtil.validateDeviceListPageSize(request);
|
DeviceManagerUtil.validateDeviceListPageSize(request);
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
allDevices = deviceDAO.getDevicesByOwnership(request, tenantId);
|
allDevices = deviceDAO.getDevicesByOwnership(request, tenantId);
|
||||||
@ -2293,7 +2287,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
result.setData(this.getAllDeviceInfo(allDevices));
|
result.setData(this.populateAllDeviceInfo(allDevices));
|
||||||
} else {
|
} else {
|
||||||
result.setData(allDevices);
|
result.setData(allDevices);
|
||||||
}
|
}
|
||||||
@ -2351,7 +2345,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
this.getAllDeviceInfo(userDevices);
|
this.populateAllDeviceInfo(userDevices);
|
||||||
}
|
}
|
||||||
devices.addAll(userDevices);
|
devices.addAll(userDevices);
|
||||||
}
|
}
|
||||||
@ -2499,7 +2493,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
return this.getAllDeviceInfo(allDevices);
|
return this.populateAllDeviceInfo(allDevices);
|
||||||
}
|
}
|
||||||
return allDevices;
|
return allDevices;
|
||||||
}
|
}
|
||||||
@ -2524,7 +2518,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
List<Device> allDevices;
|
List<Device> allDevices;
|
||||||
String deviceName = request.getDeviceName();
|
String deviceName = request.getDeviceName();
|
||||||
request = DeviceManagerUtil.validateDeviceListPageSize(request);
|
DeviceManagerUtil.validateDeviceListPageSize(request);
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
allDevices = deviceDAO.getDevicesByName(request, tenantId);
|
allDevices = deviceDAO.getDevicesByName(request, tenantId);
|
||||||
@ -2547,7 +2541,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
result.setData(this.getAllDeviceInfo(allDevices));
|
result.setData(this.populateAllDeviceInfo(allDevices));
|
||||||
} else {
|
} else {
|
||||||
result.setData(allDevices);
|
result.setData(allDevices);
|
||||||
}
|
}
|
||||||
@ -2618,7 +2612,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
return this.getAllDeviceInfo(allDevices);
|
return this.populateAllDeviceInfo(allDevices);
|
||||||
}
|
}
|
||||||
return allDevices;
|
return allDevices;
|
||||||
}
|
}
|
||||||
@ -2673,8 +2667,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
result.setRecordsTotal(deviceCount);
|
result.setRecordsTotal(deviceCount);
|
||||||
result.setRecordsFiltered(deviceCount);
|
result.setRecordsFiltered(deviceCount);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
String msg = "Error occurred while fetching the list of devices that matches to status: " +
|
String msg = "Error occurred while fetching the list of devices that matches to status: '" + status + "'";
|
||||||
status;
|
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -2689,7 +2682,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
if (requireDeviceInfo) {
|
if (requireDeviceInfo) {
|
||||||
result.setData(this.getAllDeviceInfo(allDevices));
|
result.setData(this.populateAllDeviceInfo(allDevices));
|
||||||
} else {
|
} else {
|
||||||
result.setData(allDevices);
|
result.setData(allDevices);
|
||||||
}
|
}
|
||||||
@ -2737,14 +2730,22 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
Device device = getDevice(deviceIdentifier, false);
|
Device device = getDevice(deviceIdentifier, false);
|
||||||
int deviceId = device.getId();
|
int deviceId = device.getId();
|
||||||
EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo();
|
EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo();
|
||||||
enrolmentInfo.setStatus(newStatus);
|
if (enrolmentInfo.getStatus().equals(newStatus)) {
|
||||||
|
return false; //New status is similar to current
|
||||||
|
}
|
||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
switch (newStatus) {
|
switch (newStatus) {
|
||||||
case ACTIVE:
|
case ACTIVE:
|
||||||
isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId);
|
isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId);
|
||||||
break;
|
break;
|
||||||
case INACTIVE:
|
case INACTIVE:
|
||||||
|
enrolmentInfo = device.getEnrolmentInfo();
|
||||||
|
if (enrolmentInfo.getStatus() != newStatus) {
|
||||||
|
enrolmentInfo.setStatus(newStatus);
|
||||||
isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId);
|
isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId);
|
||||||
|
} else {
|
||||||
|
isDeviceUpdated = false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case REMOVED:
|
case REMOVED:
|
||||||
isDeviceUpdated = disenrollDevice(deviceIdentifier);
|
isDeviceUpdated = disenrollDevice(deviceIdentifier);
|
||||||
@ -2786,12 +2787,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.debug("Update enrollment of device: " + deviceId);
|
log.debug("Update enrollment of device: " + deviceId);
|
||||||
}
|
}
|
||||||
boolean isUpdatedEnrollment = false;
|
boolean isUpdatedEnrollment = false;
|
||||||
boolean isAutoCommit = true;
|
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
isAutoCommit = DeviceManagementDAOFactory.getConnection().getAutoCommit();
|
int updatedRows = enrollmentDAO.updateEnrollment(enrolmentInfo, tenantId);
|
||||||
DeviceManagementDAOFactory.getConnection().setAutoCommit(true);
|
|
||||||
int updatedRows = enrollmentDAO.updateEnrollment(deviceId, enrolmentInfo, tenantId);
|
|
||||||
if (updatedRows > 0) {
|
if (updatedRows > 0) {
|
||||||
isUpdatedEnrollment = true;
|
isUpdatedEnrollment = true;
|
||||||
}
|
}
|
||||||
@ -2800,6 +2798,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
String msg = "Error occurred while updating the enrollment information device for" +
|
String msg = "Error occurred while updating the enrollment information device for" +
|
||||||
"id '" + deviceId + "' .";
|
"id '" + deviceId + "' .";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
@ -2809,11 +2808,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.getConnection().setAutoCommit(isAutoCommit);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Exception occurred while setting auto commit.");
|
|
||||||
}
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
return isUpdatedEnrollment;
|
return isUpdatedEnrollment;
|
||||||
@ -3116,35 +3110,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Get device info of device: " + device.getId() + " of type '" + device.getType() + "'");
|
log.debug("Get device info of device: " + device.getId() + " of type '" + device.getType() + "'");
|
||||||
}
|
}
|
||||||
DeviceInfo info = null;
|
DeviceInfo info;
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
info = deviceInformationManager.getDeviceInfo(device);
|
||||||
info = deviceInfoDAO.getDeviceInformation(device.getId(), device.getEnrolmentInfo().getId());
|
} catch (DeviceDetailsMgtException e) {
|
||||||
DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId(),
|
|
||||||
device.getEnrolmentInfo().getId());
|
|
||||||
if (location != null) {
|
|
||||||
//There are some cases where the device-info is not updated properly. Hence returning a null value.
|
|
||||||
if (info != null) {
|
|
||||||
info.setLocation(location);
|
|
||||||
} else {
|
|
||||||
info = new DeviceInfo();
|
|
||||||
info.setLocation(location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (DeviceDetailsMgtDAOException e) {
|
|
||||||
String msg = "Error occurred while retrieving advance info of '" + device.getType() +
|
String msg = "Error occurred while retrieving advance info of '" + device.getType() +
|
||||||
"' that carries the id '" + device.getDeviceIdentifier() + "'";
|
"' that carries the id '" + device.getDeviceIdentifier() + "'";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while opening a connection to the data source";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementException(msg, e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String msg = "Error occurred in getDeviceInfo for device: " + device.getId();
|
|
||||||
log.error(msg, e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@ -3186,7 +3159,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
* Returns all the available information (device-info, location, applications and plugin-db data)
|
* Returns all the available information (device-info, location, applications and plugin-db data)
|
||||||
* of the given device list.
|
* of the given device list.
|
||||||
*/
|
*/
|
||||||
private List<Device> getAllDeviceInfo(List<Device> allDevices) throws DeviceManagementException {
|
private List<Device> populateAllDeviceInfo(List<Device> allDevices) throws DeviceManagementException {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Get all device info of devices, num of devices: " + allDevices.size());
|
log.debug("Get all device info of devices, num of devices: " + allDevices.size());
|
||||||
}
|
}
|
||||||
@ -3218,7 +3191,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
* Returns all the available information (device-info, location, applications and plugin-db data)
|
* Returns all the available information (device-info, location, applications and plugin-db data)
|
||||||
* of a given device.
|
* of a given device.
|
||||||
*/
|
*/
|
||||||
private Device getAllDeviceInfo(Device device) throws DeviceManagementException {
|
private void populateAllDeviceInfo(Device device) throws DeviceManagementException {
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
String msg = "Received empty device for getAllDeviceInfo";
|
String msg = "Received empty device for getAllDeviceInfo";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
@ -3236,7 +3209,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " +
|
log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " +
|
||||||
"Therefore, not attempting method 'isEnrolled'");
|
"Therefore, not attempting method 'isEnrolled'");
|
||||||
}
|
}
|
||||||
return device;
|
return;
|
||||||
}
|
}
|
||||||
Device dmsDevice =
|
Device dmsDevice =
|
||||||
deviceManager.getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
deviceManager.getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||||
@ -3244,7 +3217,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
device.setFeatures(dmsDevice.getFeatures());
|
device.setFeatures(dmsDevice.getFeatures());
|
||||||
device.setProperties(dmsDevice.getProperties());
|
device.setProperties(dmsDevice.getProperties());
|
||||||
}
|
}
|
||||||
return device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Device getDeviceFromCache(DeviceIdentifier deviceIdentifier) {
|
private Device getDeviceFromCache(DeviceIdentifier deviceIdentifier) {
|
||||||
@ -3358,28 +3330,41 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateEnrollment(String owner, List<String> deviceIdentifiers)
|
@Override
|
||||||
|
public boolean updateEnrollment(String owner, boolean isTransfer, List<String> deviceIdentifiers)
|
||||||
throws DeviceManagementException, UserNotFoundException, InvalidDeviceException {
|
throws DeviceManagementException, UserNotFoundException, InvalidDeviceException {
|
||||||
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
List<Device> existingDevices;
|
List<Device> existingDevices;
|
||||||
|
List<Device> existingNonRemovedDevices = new ArrayList<>();
|
||||||
owner = validateOwner(owner, tenantId);
|
owner = validateOwner(owner, tenantId);
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
existingDevices = deviceDAO.getDevicesByIdentifiers(deviceIdentifiers, tenantId);
|
existingDevices = deviceDAO.getDevicesByIdentifiers(deviceIdentifiers, tenantId);
|
||||||
if (existingDevices.size() != deviceIdentifiers.size()) {
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Requested devices: " + deviceIdentifiers.toString());
|
||||||
|
}
|
||||||
for (Device device : existingDevices) {
|
for (Device device : existingDevices) {
|
||||||
|
if (device.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) {
|
||||||
|
device.getEnrolmentInfo().setTransferred(isTransfer);
|
||||||
|
existingNonRemovedDevices.add(device);
|
||||||
deviceIdentifiers.remove(device.getDeviceIdentifier());
|
deviceIdentifiers.remove(device.getDeviceIdentifier());
|
||||||
}
|
}
|
||||||
String msg =
|
}
|
||||||
"Couldn't find device ids for requested all device identifiers. Therefore payload should "
|
if (log.isDebugEnabled()) {
|
||||||
+ "contains device identifiers which are not in the system. Invalid device "
|
log.debug("Valid devices: " + existingNonRemovedDevices.toString());
|
||||||
+ "identifiers are " + deviceIdentifiers.toString();
|
}
|
||||||
|
if (deviceIdentifiers.size() > 0) {
|
||||||
|
String msg = "Couldn't find valid devices for invalid device identifiers: " +
|
||||||
|
deviceIdentifiers.toString();
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new InvalidDeviceException(msg);
|
throw new InvalidDeviceException(msg);
|
||||||
}
|
}
|
||||||
if (enrollmentDAO.updateOwnerOfEnrollment(existingDevices, owner, tenantId)) {
|
if (enrollmentDAO.updateOwnerOfEnrollment(existingNonRemovedDevices, owner, tenantId)) {
|
||||||
DeviceManagementDAOFactory.commitTransaction();
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
|
for (Device device : existingNonRemovedDevices) {
|
||||||
|
this.removeDeviceFromCache(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
@ -3395,6 +3380,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String validateOwner(String owner, int tenantId) throws UserNotFoundException, DeviceManagementException {
|
private String validateOwner(String owner, int tenantId) throws UserNotFoundException, DeviceManagementException {
|
||||||
@ -3402,9 +3388,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
if (StringUtils.isEmpty(owner)) {
|
if (StringUtils.isEmpty(owner)) {
|
||||||
owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
} else {
|
} else {
|
||||||
boolean isUserExisit = DeviceManagementDataHolder.getInstance().getRealmService()
|
boolean isUserExist = DeviceManagementDataHolder.getInstance().getRealmService()
|
||||||
.getTenantUserRealm(tenantId).getUserStoreManager().isExistingUser(owner);
|
.getTenantUserRealm(tenantId).getUserStoreManager().isExistingUser(owner);
|
||||||
if (!isUserExisit) {
|
if (!isUserExist) {
|
||||||
String msg = "Owner does not exist in the user storage. Owner: " + owner;
|
String msg = "Owner does not exist in the user storage. Owner: " + owner;
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new UserNotFoundException(msg);
|
throw new UserNotFoundException(msg);
|
||||||
@ -3416,10 +3402,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracting device location properties
|
* Extracting device location properties
|
||||||
|
*
|
||||||
* @param device Device object
|
* @param device Device object
|
||||||
*/
|
*/
|
||||||
private void extractDeviceLocationToUpdate(Device device) {
|
private void extractDeviceLocationToUpdate(Device device) {
|
||||||
@ -3832,8 +3820,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
|
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
|
||||||
// different try blocks are used to isolate transactions
|
// different try blocks are used to isolate transactions
|
||||||
try {
|
try {
|
||||||
enrollmentDAO.updateEnrollment(device.getId(), device.getEnrolmentInfo(),
|
enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
|
||||||
tenantId);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
String msg = "Error occurred while dis-enrolling device: " +
|
String msg = "Error occurred while dis-enrolling device: " +
|
||||||
@ -4064,7 +4051,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
paginationResult.setData(getAllDeviceInfo(subscribedDeviceDetails));
|
paginationResult.setData(populateAllDeviceInfo(subscribedDeviceDetails));
|
||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4140,6 +4127,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap the device configuration data into DeviceConfiguration bean
|
* Wrap the device configuration data into DeviceConfiguration bean
|
||||||
|
*
|
||||||
* @param device Device queried using the properties
|
* @param device Device queried using the properties
|
||||||
* @param tenantDomain tenant domain
|
* @param tenantDomain tenant domain
|
||||||
* @param configurationEntries platformConfiguration list
|
* @param configurationEntries platformConfiguration list
|
||||||
|
|||||||
@ -21,10 +21,12 @@ package org.wso2.carbon.device.mgt.core.status.task.impl;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.cache.impl.DeviceCacheManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping;
|
||||||
@ -65,19 +67,20 @@ public class DeviceStatusMonitoringTask implements Task {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
List<OperationEnrolmentMapping> operationEnrolmentMappings = null;
|
List<OperationEnrolmentMapping> operationEnrolmentMappings;
|
||||||
List<EnrolmentInfo> enrolmentInfoTobeUpdated = new ArrayList<>();
|
List<EnrolmentInfo> enrolmentInfoTobeUpdated = new ArrayList<>();
|
||||||
List<DeviceIdentifier> identifiers = new ArrayList<>();
|
|
||||||
Map<Integer, Long> lastActivities = null;
|
Map<Integer, Long> lastActivities = null;
|
||||||
EnrolmentInfo enrolmentInfo;
|
EnrolmentInfo enrolmentInfo;
|
||||||
DeviceIdentifier deviceIdentifier;
|
DeviceIdentifier deviceIdentifier;
|
||||||
|
Device device;
|
||||||
try {
|
try {
|
||||||
operationEnrolmentMappings = this.getOperationEnrolmentMappings();
|
operationEnrolmentMappings = this.getOperationEnrolmentMappings();
|
||||||
if (operationEnrolmentMappings != null && operationEnrolmentMappings.size() > 0) {
|
if (operationEnrolmentMappings.size() > 0) {
|
||||||
lastActivities = this.getLastDeviceActivities();
|
lastActivities = this.getLastDeviceActivities();
|
||||||
}
|
}
|
||||||
} catch (DeviceStatusTaskException e) {
|
} catch (DeviceStatusTaskException e) {
|
||||||
log.error("Error occurred while fetching OperationEnrolment mappings of deviceType '" + deviceType + "'", e);
|
log.error("Error occurred while fetching OperationEnrolment mappings of deviceType '" + deviceType + "'", e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (OperationEnrolmentMapping mapping : operationEnrolmentMappings) {
|
for (OperationEnrolmentMapping mapping : operationEnrolmentMappings) {
|
||||||
long lastActivity = -1;
|
long lastActivity = -1;
|
||||||
@ -86,23 +89,27 @@ public class DeviceStatusMonitoringTask implements Task {
|
|||||||
}
|
}
|
||||||
EnrolmentInfo.Status newStatus = this.determineDeviceStatus(mapping, lastActivity);
|
EnrolmentInfo.Status newStatus = this.determineDeviceStatus(mapping, lastActivity);
|
||||||
if (newStatus != mapping.getDeviceStatus()) {
|
if (newStatus != mapping.getDeviceStatus()) {
|
||||||
enrolmentInfo = new EnrolmentInfo();
|
|
||||||
enrolmentInfo.setId(mapping.getEnrolmentId());
|
|
||||||
enrolmentInfo.setStatus(newStatus);
|
|
||||||
enrolmentInfoTobeUpdated.add(enrolmentInfo);
|
|
||||||
|
|
||||||
deviceIdentifier = new DeviceIdentifier();
|
deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(mapping.getDeviceId());
|
deviceIdentifier.setId(mapping.getDeviceId());
|
||||||
deviceIdentifier.setId(mapping.getDeviceType());
|
deviceIdentifier.setId(mapping.getDeviceType());
|
||||||
identifiers.add(deviceIdentifier);
|
device = DeviceCacheManagerImpl.getInstance().getDeviceFromCache(deviceIdentifier, mapping.getTenantId());
|
||||||
|
if (device == null) {
|
||||||
|
enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setId(mapping.getEnrolmentId());
|
||||||
|
enrolmentInfo.setStatus(newStatus);
|
||||||
|
} else {
|
||||||
|
enrolmentInfo = device.getEnrolmentInfo();
|
||||||
|
enrolmentInfo.setStatus(newStatus);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
DeviceCacheManagerImpl.getInstance().addDeviceToCache(deviceIdentifier, device, mapping.getTenantId());
|
||||||
|
}
|
||||||
|
enrolmentInfoTobeUpdated.add(enrolmentInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enrolmentInfoTobeUpdated.size() > 0) {
|
if (enrolmentInfoTobeUpdated.size() > 0) {
|
||||||
try {
|
try {
|
||||||
this.updateDeviceStatus(enrolmentInfoTobeUpdated);
|
this.updateDeviceStatus(enrolmentInfoTobeUpdated);
|
||||||
//Remove updated entries from cache
|
|
||||||
//DeviceCacheManagerImpl.getInstance().removeDevicesFromCache(identifiers);
|
|
||||||
} catch (DeviceStatusTaskException e) {
|
} catch (DeviceStatusTaskException e) {
|
||||||
log.error("Error occurred while updating non-responsive device-status of devices of type '" + deviceType + "'", e);
|
log.error("Error occurred while updating non-responsive device-status of devices of type '" + deviceType + "'", e);
|
||||||
}
|
}
|
||||||
@ -157,7 +164,7 @@ public class DeviceStatusMonitoringTask implements Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<OperationEnrolmentMapping> getOperationEnrolmentMappings() throws DeviceStatusTaskException {
|
private List<OperationEnrolmentMapping> getOperationEnrolmentMappings() throws DeviceStatusTaskException {
|
||||||
List<OperationEnrolmentMapping> operationEnrolmentMappings = null;
|
List<OperationEnrolmentMapping> operationEnrolmentMappings;
|
||||||
try {
|
try {
|
||||||
OperationManagementDAOFactory.openConnection();
|
OperationManagementDAOFactory.openConnection();
|
||||||
operationEnrolmentMappings = OperationManagementDAOFactory.
|
operationEnrolmentMappings = OperationManagementDAOFactory.
|
||||||
@ -176,7 +183,7 @@ public class DeviceStatusMonitoringTask implements Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<Integer, Long> getLastDeviceActivities() throws DeviceStatusTaskException {
|
private Map<Integer, Long> getLastDeviceActivities() throws DeviceStatusTaskException {
|
||||||
Map<Integer, Long> lastActivities = null;
|
Map<Integer, Long> lastActivities;
|
||||||
try {
|
try {
|
||||||
OperationManagementDAOFactory.openConnection();
|
OperationManagementDAOFactory.openConnection();
|
||||||
lastActivities = OperationManagementDAOFactory.
|
lastActivities = OperationManagementDAOFactory.
|
||||||
|
|||||||
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.task;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the bean for the operations added by the task.
|
|
||||||
*/
|
|
||||||
public class TaskOperation {
|
|
||||||
|
|
||||||
private String taskName;
|
|
||||||
private int recurrentTimes;
|
|
||||||
private List<String> taskPlatforms;
|
|
||||||
|
|
||||||
public List<String> getTaskPlatforms() {
|
|
||||||
return taskPlatforms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskPlatforms(List<String> taskPlatforms) {
|
|
||||||
this.taskPlatforms = taskPlatforms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTaskName() {
|
|
||||||
return taskName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskName(String taskName) {
|
|
||||||
this.taskName = taskName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRecurrentTimes() {
|
|
||||||
return recurrentTimes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRecurrentTimes(int recurrentTimes) {
|
|
||||||
this.recurrentTimes = recurrentTimes;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -33,7 +33,6 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.task;
|
package org.wso2.carbon.device.mgt.core.task;
|
||||||
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
@ -86,4 +85,3 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,9 +30,9 @@ import java.util.Date;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
public class ArchivalTask implements Task {
|
public class ArchivalTask implements Task {
|
||||||
private static Log log = LogFactory.getLog(ArchivalTask.class);
|
|
||||||
|
private static final Log log = LogFactory.getLog(ArchivalTask.class);
|
||||||
|
|
||||||
private ArchivalService archivalService;
|
private ArchivalService archivalService;
|
||||||
|
|
||||||
@ -72,16 +72,6 @@ public class ArchivalTask implements Task {
|
|||||||
millis -= TimeUnit.MINUTES.toMillis(minutes);
|
millis -= TimeUnit.MINUTES.toMillis(minutes);
|
||||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
|
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(64);
|
return (days + " Days " + hours + " Hours " + minutes + " Minutes " + seconds + " Seconds");
|
||||||
sb.append(days);
|
|
||||||
sb.append(" Days ");
|
|
||||||
sb.append(hours);
|
|
||||||
sb.append(" Hours ");
|
|
||||||
sb.append(minutes);
|
|
||||||
sb.append(" Minutes ");
|
|
||||||
sb.append(seconds);
|
|
||||||
sb.append(" Seconds");
|
|
||||||
|
|
||||||
return (sb.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,5 +124,4 @@ public class ArchivalTaskManagerImpl implements ArchivalTaskManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,19 +32,16 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.task.impl;
|
package org.wso2.carbon.device.mgt.core.task.impl;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.base.ServerConfiguration;
|
import org.wso2.carbon.base.ServerConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||||
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
@ -54,16 +51,19 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|||||||
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
||||||
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
|
||||||
import org.wso2.carbon.device.mgt.core.task.Utils;
|
import org.wso2.carbon.device.mgt.core.task.Utils;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
|
private static final Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
|
||||||
private String deviceType;
|
private final String deviceType;
|
||||||
static volatile Map<Integer, Map<String, Map<String, Long>>> map = new HashMap<>();
|
static volatile Map<Integer, Map<String, Map<String, Long>>> map = new HashMap<>();
|
||||||
private static volatile Map<Integer, List<String>> startupConfigMap = new HashMap<>();
|
private static final Map<Integer, List<String>> startupConfigMap = new HashMap<>();
|
||||||
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
|
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
|
||||||
private StartupOperationConfig startupOperationConfig;
|
private StartupOperationConfig startupOperationConfig;
|
||||||
|
|
||||||
@ -118,7 +118,6 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|||||||
public void addOperations() throws DeviceMgtTaskException {
|
public void addOperations() throws DeviceMgtTaskException {
|
||||||
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
|
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance().
|
||||||
getDeviceManagementProvider();
|
getDeviceManagementProvider();
|
||||||
try {
|
|
||||||
//list operations for device type
|
//list operations for device type
|
||||||
List<String> operations = this.getValidOperationNames();
|
List<String> operations = this.getValidOperationNames();
|
||||||
if (operations.isEmpty()) {
|
if (operations.isEmpty()) {
|
||||||
@ -127,49 +126,17 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<DeviceIdentifier> validDeviceIdentifiers;
|
|
||||||
List<String> startupOperations;
|
|
||||||
//list devices of device type
|
|
||||||
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType, false);
|
|
||||||
|
|
||||||
if (!devices.isEmpty()) {
|
|
||||||
if (log.isDebugEnabled() && deviceType != null) {
|
|
||||||
log.info("Devices exist to add operations and the total number of devices are " + devices.size());
|
|
||||||
}
|
|
||||||
validDeviceIdentifiers = DeviceManagerUtil.getValidDeviceIdentifiers(devices);
|
|
||||||
if (!validDeviceIdentifiers.isEmpty()) {
|
|
||||||
if (log.isDebugEnabled() && deviceType != null) {
|
|
||||||
log.debug("Number of valid device identifier size to add operations: " + validDeviceIdentifiers
|
|
||||||
.size());
|
|
||||||
}
|
|
||||||
for (String str : operations) {
|
for (String str : operations) {
|
||||||
CommandOperation operation = new CommandOperation();
|
CommandOperation operation = new CommandOperation();
|
||||||
operation.setEnabled(true);
|
operation.setEnabled(true);
|
||||||
operation.setType(Operation.Type.COMMAND);
|
operation.setType(Operation.Type.COMMAND);
|
||||||
operation.setCode(str);
|
operation.setCode(str);
|
||||||
deviceManagementProviderService.addOperation(deviceType, operation, validDeviceIdentifiers);
|
try {
|
||||||
}
|
deviceManagementProviderService.addTaskOperation(deviceType, operation);
|
||||||
startupOperations = getStartupOperations();
|
|
||||||
if (startupOperations != null && !startupOperations.isEmpty()) {
|
|
||||||
addStartupOperations(startupOperations, validDeviceIdentifiers,
|
|
||||||
deviceManagementProviderService);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("No valid devices are available.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("No devices are available to perform the operations.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (InvalidDeviceException e) {
|
|
||||||
throw new DeviceMgtTaskException("Invalid DeviceIdentifiers found.", e);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
throw new DeviceMgtTaskException("Error occurred while retrieving the device list.", e);
|
|
||||||
} catch (OperationManagementException e) {
|
} catch (OperationManagementException e) {
|
||||||
throw new DeviceMgtTaskException("Error occurred while adding the operations to devices", e);
|
throw new DeviceMgtTaskException("Error occurred while adding task operations to devices", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +154,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|||||||
mp.put(top.getTaskName(), milliseconds);
|
mp.put(top.getTaskName(), milliseconds);
|
||||||
} else {
|
} else {
|
||||||
Long lastExecutedTime = mp.get(top.getTaskName());
|
Long lastExecutedTime = mp.get(top.getTaskName());
|
||||||
Long evalTime = lastExecutedTime + (frequency * top.getRecurrentTimes());
|
long evalTime = lastExecutedTime + (frequency * top.getRecurrentTimes());
|
||||||
if (evalTime <= milliseconds) {
|
if (evalTime <= milliseconds) {
|
||||||
opNames.add(top.getTaskName());
|
opNames.add(top.getTaskName());
|
||||||
mp.put(top.getTaskName(), milliseconds);
|
mp.put(top.getTaskName(), milliseconds);
|
||||||
@ -230,9 +197,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|||||||
private List<MonitoringOperation> getOperationListforTask() throws DeviceMgtTaskException {
|
private List<MonitoringOperation> getOperationListforTask() throws DeviceMgtTaskException {
|
||||||
|
|
||||||
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
|
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
|
||||||
.getInstance().
|
.getInstance().getDeviceManagementProvider();
|
||||||
getDeviceManagementProvider();
|
|
||||||
|
|
||||||
return deviceManagementProviderService.getMonitoringOperationList(
|
return deviceManagementProviderService.getMonitoringOperationList(
|
||||||
deviceType);//Get task list from each device type
|
deviceType);//Get task list from each device type
|
||||||
}
|
}
|
||||||
@ -265,9 +230,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|||||||
} catch (DeviceMgtTaskException e) {
|
} catch (DeviceMgtTaskException e) {
|
||||||
// ignoring the error, no need to throw, If error occurs, return value will be false.
|
// ignoring the error, no need to throw, If error occurs, return value will be false.
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,29 +14,12 @@
|
|||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.util;
|
package org.wso2.carbon.device.mgt.core.util;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
@ -56,15 +39,15 @@ import org.wso2.carbon.device.mgt.common.ApplicationRegistration;
|
|||||||
import org.wso2.carbon.device.mgt.common.ApplicationRegistrationException;
|
import org.wso2.carbon.device.mgt.common.ApplicationRegistrationException;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.EnrollmentConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.EnrollmentConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||||
@ -112,7 +95,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
@ -124,7 +106,6 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
|
||||||
public final class DeviceManagerUtil {
|
public final class DeviceManagerUtil {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
||||||
@ -166,7 +147,7 @@ import java.util.stream.IntStream;
|
|||||||
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
||||||
jndiConfig.getJndiProperties();
|
jndiConfig.getJndiProperties();
|
||||||
if (jndiPropertyList != null) {
|
if (jndiPropertyList != null) {
|
||||||
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
Hashtable<Object, Object> jndiProperties = new Hashtable<>();
|
||||||
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
||||||
jndiProperties.put(prop.getName(), prop.getValue());
|
jndiProperties.put(prop.getName(), prop.getValue());
|
||||||
}
|
}
|
||||||
@ -186,8 +167,8 @@ import java.util.stream.IntStream;
|
|||||||
* @param isSharedWithAllTenants is this device type shared with all tenants.
|
* @param isSharedWithAllTenants is this device type shared with all tenants.
|
||||||
* @return status of the operation
|
* @return status of the operation
|
||||||
*/
|
*/
|
||||||
public static boolean registerDeviceType(String typeName, int tenantId, boolean isSharedWithAllTenants
|
public static boolean registerDeviceType(String typeName, int tenantId, boolean isSharedWithAllTenants,
|
||||||
, DeviceTypeMetaDefinition deviceTypeDefinition)
|
DeviceTypeMetaDefinition deviceTypeDefinition)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
boolean status;
|
boolean status;
|
||||||
try {
|
try {
|
||||||
@ -229,7 +210,7 @@ import java.util.stream.IntStream;
|
|||||||
* @return DeviceType which contains info about the device-type.
|
* @return DeviceType which contains info about the device-type.
|
||||||
*/
|
*/
|
||||||
public static DeviceType getDeviceType(String typeName, int tenantId) throws DeviceManagementException {
|
public static DeviceType getDeviceType(String typeName, int tenantId) throws DeviceManagementException {
|
||||||
DeviceType deviceType = null;
|
DeviceType deviceType;
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.openConnection();
|
DeviceManagementDAOFactory.openConnection();
|
||||||
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
@ -316,7 +297,6 @@ import java.util.stream.IntStream;
|
|||||||
return deviceIdentifiers;
|
return deviceIdentifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getServerBaseHttpsUrl() {
|
public static String getServerBaseHttpsUrl() {
|
||||||
String hostName = "localhost";
|
String hostName = "localhost";
|
||||||
try {
|
try {
|
||||||
@ -356,10 +336,6 @@ import java.util.stream.IntStream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the tenant Id of the specific tenant Domain
|
* returns the tenant Id of the specific tenant Domain
|
||||||
*
|
|
||||||
* @param tenantDomain
|
|
||||||
* @return
|
|
||||||
* @throws DeviceManagementException
|
|
||||||
*/
|
*/
|
||||||
public static int getTenantId(String tenantDomain) throws DeviceManagementException {
|
public static int getTenantId(String tenantDomain) throws DeviceManagementException {
|
||||||
try {
|
try {
|
||||||
@ -396,8 +372,8 @@ import java.util.stream.IntStream;
|
|||||||
return limit;
|
return limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PaginationRequest validateOperationListPageSize(PaginationRequest paginationRequest) throws
|
public static PaginationRequest validateOperationListPageSize(PaginationRequest paginationRequest)
|
||||||
OperationManagementException {
|
throws OperationManagementException {
|
||||||
if (paginationRequest.getRowCount() == 0) {
|
if (paginationRequest.getRowCount() == 0) {
|
||||||
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
||||||
getDeviceManagementConfig();
|
getDeviceManagementConfig();
|
||||||
@ -412,8 +388,8 @@ import java.util.stream.IntStream;
|
|||||||
return paginationRequest;
|
return paginationRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PaginationRequest validateNotificationListPageSize(PaginationRequest paginationRequest) throws
|
public static PaginationRequest validateNotificationListPageSize(PaginationRequest paginationRequest)
|
||||||
NotificationManagementException {
|
throws NotificationManagementException {
|
||||||
if (paginationRequest.getRowCount() == 0) {
|
if (paginationRequest.getRowCount() == 0) {
|
||||||
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
||||||
getDeviceManagementConfig();
|
getDeviceManagementConfig();
|
||||||
@ -421,15 +397,15 @@ import java.util.stream.IntStream;
|
|||||||
paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration().
|
paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration().
|
||||||
getNotificationListPageSize());
|
getNotificationListPageSize());
|
||||||
} else {
|
} else {
|
||||||
throw new NotificationManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
throw new NotificationManagementException("Device-Mgt configuration has not initialized. " +
|
||||||
"cdm-config.xml file.");
|
"Please check the cdm-config.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return paginationRequest;
|
return paginationRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PaginationRequest validateDeviceListPageSize(PaginationRequest paginationRequest) throws
|
public static PaginationRequest validateDeviceListPageSize(PaginationRequest paginationRequest)
|
||||||
DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
if (paginationRequest.getRowCount() == 0) {
|
if (paginationRequest.getRowCount() == 0) {
|
||||||
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
||||||
getDeviceManagementConfig();
|
getDeviceManagementConfig();
|
||||||
@ -437,15 +413,15 @@ import java.util.stream.IntStream;
|
|||||||
paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration().
|
paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration().
|
||||||
getDeviceListPageSize());
|
getDeviceListPageSize());
|
||||||
} else {
|
} else {
|
||||||
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
throw new DeviceManagementException("Device-Mgt configuration has not initialized. " +
|
||||||
"cdm-config.xml file.");
|
"Please check the cdm-config.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return paginationRequest;
|
return paginationRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GroupPaginationRequest validateGroupListPageSize(GroupPaginationRequest paginationRequest) throws
|
public static GroupPaginationRequest validateGroupListPageSize(GroupPaginationRequest paginationRequest)
|
||||||
GroupManagementException {
|
throws GroupManagementException {
|
||||||
if (paginationRequest.getRowCount() == 0) {
|
if (paginationRequest.getRowCount() == 0) {
|
||||||
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance()
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance()
|
||||||
.getDeviceManagementConfig();
|
.getDeviceManagementConfig();
|
||||||
@ -453,8 +429,8 @@ import java.util.stream.IntStream;
|
|||||||
paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration()
|
paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration()
|
||||||
.getDeviceListPageSize());
|
.getDeviceListPageSize());
|
||||||
} else {
|
} else {
|
||||||
throw new GroupManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
throw new GroupManagementException("Device-Mgt configuration has not initialized. " +
|
||||||
"cdm-config.xml file.");
|
"Please check the cdm-config.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return paginationRequest;
|
return paginationRequest;
|
||||||
@ -467,8 +443,8 @@ import java.util.stream.IntStream;
|
|||||||
if (deviceManagementConfig != null) {
|
if (deviceManagementConfig != null) {
|
||||||
return deviceManagementConfig.getPaginationConfiguration().getDeviceListPageSize();
|
return deviceManagementConfig.getPaginationConfiguration().getDeviceListPageSize();
|
||||||
} else {
|
} else {
|
||||||
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
throw new DeviceManagementException("Device-Mgt configuration has not initialized. " +
|
||||||
"cdm-config.xml file.");
|
"Please check the cdm-config.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return limit;
|
return limit;
|
||||||
@ -480,8 +456,8 @@ import java.util.stream.IntStream;
|
|||||||
if (deviceManagementConfig != null) {
|
if (deviceManagementConfig != null) {
|
||||||
return deviceManagementConfig.getOperationAnalyticsConfiguration().isPublishLocationResponseEnabled();
|
return deviceManagementConfig.getOperationAnalyticsConfiguration().isPublishLocationResponseEnabled();
|
||||||
} else {
|
} else {
|
||||||
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
throw new DeviceManagementException("Device-Mgt configuration has not initialized. " +
|
||||||
"cdm-config.xml file.");
|
"Please check the cdm-config.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,8 +467,8 @@ import java.util.stream.IntStream;
|
|||||||
if (deviceManagementConfig != null) {
|
if (deviceManagementConfig != null) {
|
||||||
return deviceManagementConfig.getOperationAnalyticsConfiguration().isPublishDeviceInfoResponseEnabled();
|
return deviceManagementConfig.getOperationAnalyticsConfiguration().isPublishDeviceInfoResponseEnabled();
|
||||||
} else {
|
} else {
|
||||||
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
throw new DeviceManagementException("Device-Mgt configuration has not initialized. " +
|
||||||
"cdm-config.xml file.");
|
"Please check the cdm-config.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,8 +479,8 @@ import java.util.stream.IntStream;
|
|||||||
return deviceManagementConfig.getOperationAnalyticsConfiguration()
|
return deviceManagementConfig.getOperationAnalyticsConfiguration()
|
||||||
.getOperationResponseConfigurations().isEnabled();
|
.getOperationResponseConfigurations().isEnabled();
|
||||||
} else {
|
} else {
|
||||||
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
throw new DeviceManagementException("Device-Mgt configuration has not initialized. " +
|
||||||
"cdm-config.xml file.");
|
"Please check the cdm-config.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,8 +491,8 @@ import java.util.stream.IntStream;
|
|||||||
return deviceManagementConfig.getOperationAnalyticsConfiguration()
|
return deviceManagementConfig.getOperationAnalyticsConfiguration()
|
||||||
.getOperationResponseConfigurations().getOperations();
|
.getOperationResponseConfigurations().getOperations();
|
||||||
} else {
|
} else {
|
||||||
throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " +
|
throw new DeviceManagementException("Device-Mgt configuration has not initialized. " +
|
||||||
"cdm-config.xml file.");
|
"Please check the cdm-config.xml file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,6 +516,7 @@ import java.util.stream.IntStream;
|
|||||||
errorDeviceIdList.add(deviceIdentifier);
|
errorDeviceIdList.add(deviceIdentifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
|
DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
|
||||||
deviceIDHolder.setValidDeviceIDList(validDeviceIDList);
|
deviceIDHolder.setValidDeviceIDList(validDeviceIDList);
|
||||||
deviceIDHolder.setErrorDeviceIdList(errorDeviceIdList);
|
deviceIDHolder.setErrorDeviceIdList(errorDeviceIdList);
|
||||||
@ -553,8 +530,10 @@ import java.util.stream.IntStream;
|
|||||||
if (device == null || device.getDeviceIdentifier() == null ||
|
if (device == null || device.getDeviceIdentifier() == null ||
|
||||||
device.getDeviceIdentifier().isEmpty() || device.getEnrolmentInfo() == null) {
|
device.getDeviceIdentifier().isEmpty() || device.getEnrolmentInfo() == null) {
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else if (EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus())) {
|
||||||
return !EnrolmentInfo.Status.REMOVED.equals(device.getEnrolmentInfo().getStatus());
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDeviceExists(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
public static boolean isDeviceExists(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
@ -595,7 +574,7 @@ import java.util.stream.IntStream;
|
|||||||
deviceCacheExpiry)).setExpiry(CacheConfiguration.ExpiryType.ACCESSED, new CacheConfiguration.
|
deviceCacheExpiry)).setExpiry(CacheConfiguration.ExpiryType.ACCESSED, new CacheConfiguration.
|
||||||
Duration(TimeUnit.SECONDS, deviceCacheExpiry)).setStoreByValue(true).build();
|
Duration(TimeUnit.SECONDS, deviceCacheExpiry)).setStoreByValue(true).build();
|
||||||
if(deviceCacheCapacity > 0 ) {
|
if(deviceCacheCapacity > 0 ) {
|
||||||
((CacheImpl)(manager.<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE))).
|
((CacheImpl) manager.<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE)).
|
||||||
setCapacity(deviceCacheCapacity);
|
setCapacity(deviceCacheCapacity);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -627,10 +606,10 @@ import java.util.stream.IntStream;
|
|||||||
initializeDeviceCache();
|
initializeDeviceCache();
|
||||||
}
|
}
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
deviceCache = manager.<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE);
|
deviceCache = manager.getCache(DeviceManagementConstants.DEVICE_CACHE);
|
||||||
} else {
|
} else {
|
||||||
deviceCache = Caching.getCacheManager(DeviceManagementConstants.DM_CACHE_MANAGER).
|
deviceCache = Caching.getCacheManager(DeviceManagementConstants.DM_CACHE_MANAGER)
|
||||||
<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE);
|
.getCache(DeviceManagementConstants.DEVICE_CACHE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deviceCache;
|
return deviceCache;
|
||||||
|
|||||||
@ -118,11 +118,6 @@ public class TestDeviceManager implements DeviceManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status)
|
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public class TestDataHolder {
|
|||||||
public static Device generateDummyDeviceData(String deviceType) {
|
public static Device generateDummyDeviceData(String deviceType) {
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
device.setEnrolmentInfo(generateEnrollmentInfo(new Date().getTime(), new Date().getTime(), OWNER, EnrolmentInfo
|
device.setEnrolmentInfo(generateEnrollmentInfo(new Date().getTime(), new Date().getTime(), OWNER, EnrolmentInfo
|
||||||
.OwnerShip.BYOD, EnrolmentInfo.Status.CREATED));
|
.OwnerShip.BYOD, EnrolmentInfo.Status.ACTIVE));
|
||||||
device.setDescription("Test Description");
|
device.setDescription("Test Description");
|
||||||
device.setDeviceIdentifier(initialDeviceIdentifier);
|
device.setDeviceIdentifier(initialDeviceIdentifier);
|
||||||
device.setType(deviceType);
|
device.setType(deviceType);
|
||||||
@ -118,7 +118,7 @@ public class TestDataHolder {
|
|||||||
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
||||||
enrolmentInfo.setOwner(OWNER);
|
enrolmentInfo.setOwner(OWNER);
|
||||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED);
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
device.setEnrolmentInfo(enrolmentInfo);
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
device.setDescription("Test Description");
|
device.setDescription("Test Description");
|
||||||
device.setDeviceIdentifier(deviceId.getId());
|
device.setDeviceIdentifier(deviceId.getId());
|
||||||
@ -131,7 +131,7 @@ public class TestDataHolder {
|
|||||||
public static Device generateDummyDeviceData(DeviceIdentifier deviceIdentifier) {
|
public static Device generateDummyDeviceData(DeviceIdentifier deviceIdentifier) {
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
device.setEnrolmentInfo(generateEnrollmentInfo(new Date().getTime(), new Date().getTime(), OWNER, EnrolmentInfo
|
device.setEnrolmentInfo(generateEnrollmentInfo(new Date().getTime(), new Date().getTime(), OWNER, EnrolmentInfo
|
||||||
.OwnerShip.BYOD, EnrolmentInfo.Status.CREATED));
|
.OwnerShip.BYOD, EnrolmentInfo.Status.ACTIVE));
|
||||||
device.setDescription("Test Description");
|
device.setDescription("Test Description");
|
||||||
device.setDeviceIdentifier(deviceIdentifier.getId());
|
device.setDeviceIdentifier(deviceIdentifier.getId());
|
||||||
device.setType(deviceIdentifier.getType());
|
device.setType(deviceIdentifier.getType());
|
||||||
|
|||||||
@ -42,7 +42,7 @@ public class EnrolmentPersistenceTests extends BaseDeviceManagementTest {
|
|||||||
/* Initializing source enrolment configuration bean to be tested */
|
/* Initializing source enrolment configuration bean to be tested */
|
||||||
EnrolmentInfo source =
|
EnrolmentInfo source =
|
||||||
new EnrolmentInfo(owner, EnrolmentInfo.OwnerShip.BYOD,
|
new EnrolmentInfo(owner, EnrolmentInfo.OwnerShip.BYOD,
|
||||||
EnrolmentInfo.Status.CREATED);
|
EnrolmentInfo.Status.ACTIVE);
|
||||||
|
|
||||||
/* Adding dummy enrolment configuration to the device management metadata store */
|
/* Adding dummy enrolment configuration to the device management metadata store */
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -238,7 +238,7 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|||||||
@Test(dependsOnMethods = "addProfileOperation")
|
@Test(dependsOnMethods = "addProfileOperation")
|
||||||
public void getOperations() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
public void getOperations() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
|
||||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||||
List operations = this.operationMgtService.getOperations(deviceIdentifier);
|
List<? extends Operation> operations = this.operationMgtService.getOperations(deviceIdentifier);
|
||||||
Assert.assertEquals(operations.size(), 4, "The operations should be 4, but found only " + operations.size());
|
Assert.assertEquals(operations.size(), 4, "The operations should be 4, but found only " + operations.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -611,14 +611,16 @@ public class OperationManagementTests extends BaseDeviceManagementTest {
|
|||||||
|
|
||||||
private void changeStatus(EnrolmentInfo.Status status) throws DeviceManagementException,
|
private void changeStatus(EnrolmentInfo.Status status) throws DeviceManagementException,
|
||||||
OperationManagementException {
|
OperationManagementException {
|
||||||
Device device = this.deviceMgmtProvider.getDevice(this.deviceIds.get(1));
|
Device device = this.deviceMgmtProvider.getDevice(this.deviceIds.get(1), false);
|
||||||
Assert.assertTrue(device != null);
|
Assert.assertTrue(device != null);
|
||||||
Assert.assertEquals(device.getType(), DEVICE_TYPE);
|
Assert.assertEquals(device.getType(), DEVICE_TYPE);
|
||||||
Assert.assertTrue(device.getEnrolmentInfo() != null);
|
Assert.assertTrue(device.getEnrolmentInfo() != null);
|
||||||
device.getEnrolmentInfo().setStatus(status);
|
|
||||||
boolean modified = this.deviceMgmtProvider.changeDeviceStatus(this.deviceIds.get(1), status);
|
boolean modified = this.deviceMgmtProvider.changeDeviceStatus(this.deviceIds.get(1), status);
|
||||||
|
if (device.getEnrolmentInfo().getStatus() != status) {
|
||||||
Assert.assertTrue(modified);
|
Assert.assertTrue(modified);
|
||||||
device = this.deviceMgmtProvider.getDevice(this.deviceIds.get(1));
|
device.getEnrolmentInfo().setStatus(status);
|
||||||
|
}
|
||||||
|
device = this.deviceMgmtProvider.getDevice(this.deviceIds.get(1), false);
|
||||||
Assert.assertEquals(device.getEnrolmentInfo().getStatus(), status);
|
Assert.assertEquals(device.getEnrolmentInfo().getStatus(), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -108,10 +108,8 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|||||||
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
|
private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceTest.class);
|
||||||
public static final String DEVICE_ID = "9999";
|
public static final String DEVICE_ID = "9999";
|
||||||
private static final String ALTERNATE_DEVICE_ID = "1128";
|
private static final String ALTERNATE_DEVICE_ID = "1128";
|
||||||
private DeviceManagementProviderService providerService;
|
|
||||||
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
|
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
|
||||||
private static final String DEVICE_OWNER = "admin";
|
private final DeviceDetailsDAO deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
|
||||||
private DeviceDetailsDAO deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
|
|
||||||
|
|
||||||
DeviceManagementProviderService deviceMgtService;
|
DeviceManagementProviderService deviceMgtService;
|
||||||
|
|
||||||
@ -253,7 +251,7 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|||||||
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
|
||||||
enrolmentInfo.setOwner("user1");
|
enrolmentInfo.setOwner("user1");
|
||||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.CREATED);
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
|
||||||
Device alternateDevice = TestDataHolder.generateDummyDeviceData(DEVICE_ID, DEVICE_TYPE,
|
Device alternateDevice = TestDataHolder.generateDummyDeviceData(DEVICE_ID, DEVICE_TYPE,
|
||||||
enrolmentInfo);
|
enrolmentInfo);
|
||||||
@ -884,8 +882,8 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|||||||
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
|
@Test(dependsOnMethods = {"testReEnrollmentofSameDeviceUnderSameUser"})
|
||||||
public void testUpdateDevicesStatusWithDeviceID() throws DeviceManagementException {
|
public void testUpdateDevicesStatusWithDeviceID() throws DeviceManagementException {
|
||||||
if (!isMock()) {
|
if (!isMock()) {
|
||||||
boolean status = deviceMgtService.setStatus(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE), "user1",
|
Device device = TestDataHolder.generateDummyDeviceData("abc");
|
||||||
EnrolmentInfo.Status.ACTIVE);
|
boolean status = deviceMgtService.setStatus(device, EnrolmentInfo.Status.ACTIVE);
|
||||||
Assert.assertTrue(status);
|
Assert.assertTrue(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,6 +89,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
|||||||
OWNER VARCHAR(50) NOT NULL,
|
OWNER VARCHAR(50) NOT NULL,
|
||||||
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
|
IS_TRANSFERRED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
@ -106,6 +107,13 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
|
|||||||
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
||||||
CREATED_TIMESTAMP INT NOT NULL,
|
CREATED_TIMESTAMP INT NOT NULL,
|
||||||
UPDATED_TIMESTAMP INT NOT NULL,
|
UPDATED_TIMESTAMP INT NOT NULL,
|
||||||
|
OPERATION_CODE VARCHAR(50) NOT NULL,
|
||||||
|
INITIATED_BY VARCHAR(100) NULL,
|
||||||
|
TYPE VARCHAR(20) NOT NULL,
|
||||||
|
DEVICE_ID INTEGER DEFAULT NULL,
|
||||||
|
DEVICE_TYPE VARCHAR(300) NOT NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
@ -118,7 +126,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
|||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
EN_OP_MAP_ID INTEGER NOT NULL,
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
OPERATION_RESPONSE VARCHAR(1024) DEFAULT NULL ,
|
||||||
|
IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
@ -129,6 +138,21 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
|||||||
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
CONSTRAINT fk_dm_device_operation_response_large_mapping FOREIGN KEY (ID)
|
||||||
|
REFERENCES DM_DEVICE_OPERATION_RESPONSE (ID)
|
||||||
|
ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT fk_dm_en_op_map_response_large FOREIGN KEY (EN_OP_MAP_ID)
|
||||||
|
REFERENCES DM_ENROLMENT_OP_MAPPING (ID)
|
||||||
|
ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
-- POLICY RELATED TABLES --
|
-- POLICY RELATED TABLES --
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_PROFILE (
|
CREATE TABLE IF NOT EXISTS DM_PROFILE (
|
||||||
@ -358,16 +382,14 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
|||||||
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
|
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
|
||||||
NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL,
|
NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
STATUS VARCHAR(10) NULL,
|
STATUS VARCHAR(10) NULL,
|
||||||
DESCRIPTION VARCHAR(1000) NULL,
|
DESCRIPTION VARCHAR(1000) NULL,
|
||||||
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
PRIMARY KEY (NOTIFICATION_ID),
|
PRIMARY KEY (NOTIFICATION_ID),
|
||||||
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
);
|
||||||
-- NOTIFICATION TABLE END --
|
-- NOTIFICATION TABLE END --
|
||||||
|
|
||||||
|
|||||||
@ -40,21 +40,21 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
|
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DataSource;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DataSource;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TableConfig;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Table;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Table;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TableConfig;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceDAODefinition;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceDAODefinition;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOManager;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOManager;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException;
|
||||||
@ -80,7 +80,7 @@ import javax.xml.stream.XMLStreamReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,19 +90,18 @@ import java.util.List;
|
|||||||
public class DeviceTypeManager implements DeviceManager {
|
public class DeviceTypeManager implements DeviceManager {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceTypeManager.class);
|
private static final Log log = LogFactory.getLog(DeviceTypeManager.class);
|
||||||
private String deviceType;
|
private final String deviceType;
|
||||||
private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
|
private final LicenseManager licenseManager;
|
||||||
private LicenseManager licenseManager;
|
private final PlatformConfiguration defaultPlatformConfiguration;
|
||||||
private PlatformConfiguration defaultPlatformConfiguration;
|
private final boolean requiredDeviceTypeAuthorization;
|
||||||
private boolean propertiesExist;
|
|
||||||
private boolean requiredDeviceTypeAuthorization;
|
|
||||||
private boolean claimable;
|
|
||||||
|
|
||||||
private static final String PATH_MOBILE_PLUGIN_CONF_DIR =
|
private static final String PATH_MOBILE_PLUGIN_CONF_DIR =
|
||||||
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + File.separator
|
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + File.separator
|
||||||
+ "mobile";
|
+ "mobile";
|
||||||
|
|
||||||
private FeatureManager featureManager;
|
private FeatureManager featureManager;
|
||||||
|
private boolean propertiesExist;
|
||||||
|
private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
|
||||||
|
|
||||||
public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
|
public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
|
||||||
DeviceTypeConfiguration deviceTypeConfiguration) {
|
DeviceTypeConfiguration deviceTypeConfiguration) {
|
||||||
@ -135,10 +134,6 @@ public class DeviceTypeManager implements DeviceManager {
|
|||||||
String msg = "Error occurred while adding default license for " + deviceType + " devices.";
|
String msg = "Error occurred while adding default license for " + deviceType + " devices.";
|
||||||
throw new DeviceTypeDeployerPayloadException(msg, e);
|
throw new DeviceTypeDeployerPayloadException(msg, e);
|
||||||
}
|
}
|
||||||
claimable = false;
|
|
||||||
if (deviceTypeConfiguration.getClaimable() != null ) {
|
|
||||||
claimable = deviceTypeConfiguration.getClaimable().isEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loading default platform configuration
|
// Loading default platform configuration
|
||||||
try {
|
try {
|
||||||
@ -295,8 +290,7 @@ public class DeviceTypeManager implements DeviceManager {
|
|||||||
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
|
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
|
||||||
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
|
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
|
||||||
XMLStreamReader reader = factory.createXMLStreamReader(
|
XMLStreamReader reader = factory.createXMLStreamReader(
|
||||||
new StringReader(new String((byte[]) resource.getContent(), Charset
|
new StringReader(new String((byte[]) resource.getContent(), StandardCharsets.UTF_8)));
|
||||||
.forName(DeviceTypePluginConstants.CHARSET_UTF8))));
|
|
||||||
|
|
||||||
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
||||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||||
@ -476,11 +470,6 @@ public class DeviceTypeManager implements DeviceManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
|
||||||
return claimable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
||||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||||
|
|||||||
@ -80,17 +80,17 @@ public class DeviceTypeManagerService implements DeviceManagementService {
|
|||||||
private static final String NOTIFIER_PROPERTY = "notifierType";
|
private static final String NOTIFIER_PROPERTY = "notifierType";
|
||||||
private static final String NOTIFIER_TYPE_LOCAL = "LOCAL";
|
private static final String NOTIFIER_TYPE_LOCAL = "LOCAL";
|
||||||
|
|
||||||
private DeviceManager deviceManager;
|
private final DeviceManager deviceManager;
|
||||||
private PushNotificationConfig pushNotificationConfig;
|
private PushNotificationConfig pushNotificationConfig;
|
||||||
private ProvisioningConfig provisioningConfig;
|
private ProvisioningConfig provisioningConfig;
|
||||||
private String type;
|
private String type;
|
||||||
private OperationMonitoringTaskConfig operationMonitoringConfigs;
|
private final OperationMonitoringTaskConfig operationMonitoringConfigs;
|
||||||
private List<MonitoringOperation> monitoringOperations;
|
private List<MonitoringOperation> monitoringOperations = new ArrayList<>();
|
||||||
private PolicyMonitoringManager policyMonitoringManager;
|
private PolicyMonitoringManager policyMonitoringManager;
|
||||||
private InitialOperationConfig initialOperationConfig;
|
private final InitialOperationConfig initialOperationConfig;
|
||||||
private StartupOperationConfig startupOperationConfig;
|
private StartupOperationConfig startupOperationConfig;
|
||||||
private PullNotificationSubscriber pullNotificationSubscriber;
|
private PullNotificationSubscriber pullNotificationSubscriber;
|
||||||
private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig;
|
private final DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig;
|
||||||
private DeviceTypePlatformDetails deviceTypePlatformDetails;
|
private DeviceTypePlatformDetails deviceTypePlatformDetails;
|
||||||
private GeneralConfig generalConfig;
|
private GeneralConfig generalConfig;
|
||||||
private boolean isRegistryBasedConfigs = false;
|
private boolean isRegistryBasedConfigs = false;
|
||||||
@ -141,6 +141,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
|
|||||||
MonitoringOperation monitoringOperation = new MonitoringOperation();
|
MonitoringOperation monitoringOperation = new MonitoringOperation();
|
||||||
monitoringOperation.setTaskName(op.getOperationName());
|
monitoringOperation.setTaskName(op.getOperationName());
|
||||||
monitoringOperation.setRecurrentTimes(op.getRecurrency());
|
monitoringOperation.setRecurrentTimes(op.getRecurrency());
|
||||||
|
monitoringOperation.setResponsePersistence(op.getResponsePersistence());
|
||||||
monitoringOperations.add(monitoringOperation);
|
monitoringOperations.add(monitoringOperation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfi
|
|||||||
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
|
||||||
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Claimable;
|
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Features;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Features;
|
||||||
@ -60,9 +59,6 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple
|
|||||||
DeviceTypeConfiguration deviceTypeConfiguration = new DeviceTypeConfiguration();
|
DeviceTypeConfiguration deviceTypeConfiguration = new DeviceTypeConfiguration();
|
||||||
|
|
||||||
if (deviceTypeMetaDefinition != null) {
|
if (deviceTypeMetaDefinition != null) {
|
||||||
Claimable claimable = new Claimable();
|
|
||||||
claimable.setEnabled(deviceTypeMetaDefinition.isClaimable());
|
|
||||||
deviceTypeConfiguration.setClaimable(claimable);
|
|
||||||
|
|
||||||
if (deviceTypeMetaDefinition.getProperties() != null &&
|
if (deviceTypeMetaDefinition.getProperties() != null &&
|
||||||
deviceTypeMetaDefinition.getProperties().size() > 0) {
|
deviceTypeMetaDefinition.getProperties().size() > 0) {
|
||||||
|
|||||||
@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
|
||||||
import javax.xml.bind.annotation.XmlType;
|
|
||||||
import javax.xml.bind.annotation.XmlValue;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Java class for DeviceDetails complex type.
|
|
||||||
*
|
|
||||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* <complexType name="DeviceDetails">
|
|
||||||
* <simpleContent>
|
|
||||||
* <extension base="<http://www.w3.org/2001/XMLSchema>string">
|
|
||||||
* <attribute name="table-id" type="{http://www.w3.org/2001/XMLSchema}string" />
|
|
||||||
* </extension>
|
|
||||||
* </simpleContent>
|
|
||||||
* </complexType>
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
|
||||||
@XmlType(name = "Claimable", propOrder = {
|
|
||||||
"value"
|
|
||||||
})
|
|
||||||
public class Claimable {
|
|
||||||
|
|
||||||
@XmlValue
|
|
||||||
protected String value;
|
|
||||||
@XmlAttribute(name = "enabled")
|
|
||||||
protected boolean enabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the value property.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* possible object is
|
|
||||||
* {@link String }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the value property.
|
|
||||||
*
|
|
||||||
* @param value
|
|
||||||
* allowed object is
|
|
||||||
* {@link String }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setValue(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the enabled property.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* possible object is
|
|
||||||
* {@link String }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the enabled property.
|
|
||||||
*
|
|
||||||
* @param enabled
|
|
||||||
* allowed object is
|
|
||||||
* {@link String }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -78,8 +78,6 @@ public class DeviceTypeConfiguration {
|
|||||||
|
|
||||||
@XmlElement(name = "DeviceDetails", required = true)
|
@XmlElement(name = "DeviceDetails", required = true)
|
||||||
protected DeviceDetails deviceDetails;
|
protected DeviceDetails deviceDetails;
|
||||||
@XmlElement(name = "Claimable", required = true)
|
|
||||||
protected Claimable claimable;
|
|
||||||
@XmlElement(name = "Features", required = true)
|
@XmlElement(name = "Features", required = true)
|
||||||
protected Features features;
|
protected Features features;
|
||||||
@XmlElement(name = "PolicyUIConfigurations", required = true)
|
@XmlElement(name = "PolicyUIConfigurations", required = true)
|
||||||
@ -198,27 +196,6 @@ public class DeviceTypeConfiguration {
|
|||||||
this.deviceDetails = value;
|
this.deviceDetails = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the Claimable property.
|
|
||||||
*
|
|
||||||
* @return possible object is
|
|
||||||
* {@link DeviceDetails }
|
|
||||||
*/
|
|
||||||
public Claimable getClaimable() {
|
|
||||||
return claimable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the deviceDetails property.
|
|
||||||
*
|
|
||||||
* @param value allowed object is
|
|
||||||
* {@link DeviceDetails }
|
|
||||||
*/
|
|
||||||
public void setClaimable(Claimable value) {
|
|
||||||
this.claimable = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of the policyMonitoring property.
|
* Gets the value of the policyMonitoring property.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -67,6 +67,7 @@ public class TaskConfiguration {
|
|||||||
|
|
||||||
private String operationName;
|
private String operationName;
|
||||||
private int recurrency;
|
private int recurrency;
|
||||||
|
private boolean responsePersistence = true;
|
||||||
|
|
||||||
@XmlElement(name = "Name", required = true)
|
@XmlElement(name = "Name", required = true)
|
||||||
public String getOperationName() {
|
public String getOperationName() {
|
||||||
@ -86,6 +87,14 @@ public class TaskConfiguration {
|
|||||||
this.recurrency = recurrency;
|
this.recurrency = recurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "ResponsePersistence")
|
||||||
|
public boolean getResponsePersistence() {
|
||||||
|
return responsePersistence;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponsePersistence(boolean responsePersistence) {
|
||||||
|
this.responsePersistence = responsePersistence;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,5 @@ package org.wso2.carbon.device.mgt.extensions.device.type.template.util;
|
|||||||
*/
|
*/
|
||||||
public class DeviceTypePluginConstants {
|
public class DeviceTypePluginConstants {
|
||||||
public static final String MEDIA_TYPE_XML = "application/xml";
|
public static final String MEDIA_TYPE_XML = "application/xml";
|
||||||
public static final String CHARSET_UTF8 = "UTF8";
|
|
||||||
public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
|
public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -220,7 +220,6 @@ public class HttpDeviceTypeManagerServiceAndDeviceTypeGeneratorServceTest {
|
|||||||
deviceTypeMetaDefinition = new DeviceTypeMetaDefinition();
|
deviceTypeMetaDefinition = new DeviceTypeMetaDefinition();
|
||||||
deviceTypeMetaDefinition.setPushNotificationConfig(pushNotificationConfig);
|
deviceTypeMetaDefinition.setPushNotificationConfig(pushNotificationConfig);
|
||||||
deviceTypeMetaDefinition.setDescription("This is android_sense");
|
deviceTypeMetaDefinition.setDescription("This is android_sense");
|
||||||
deviceTypeMetaDefinition.setClaimable(true);
|
|
||||||
deviceTypeMetaDefinition.setLicense(androidSenseLicense);
|
deviceTypeMetaDefinition.setLicense(androidSenseLicense);
|
||||||
deviceTypeMetaDefinition.setFeatures(features);
|
deviceTypeMetaDefinition.setFeatures(features);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,21 +23,20 @@ import org.wso2.carbon.device.mgt.oauth.extensions.internal.OAuthExtensionsDataH
|
|||||||
import org.wso2.carbon.identity.oauth.cache.CacheEntry;
|
import org.wso2.carbon.identity.oauth.cache.CacheEntry;
|
||||||
import org.wso2.carbon.identity.oauth.cache.OAuthCache;
|
import org.wso2.carbon.identity.oauth.cache.OAuthCache;
|
||||||
import org.wso2.carbon.identity.oauth.cache.OAuthCacheKey;
|
import org.wso2.carbon.identity.oauth.cache.OAuthCacheKey;
|
||||||
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
|
|
||||||
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
|
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
|
||||||
import org.wso2.carbon.identity.oauth2.dao.TokenMgtDAO;
|
import org.wso2.carbon.identity.oauth2.dao.TokenManagementDAO;
|
||||||
|
import org.wso2.carbon.identity.oauth2.dao.TokenManagementDAOImpl;
|
||||||
import org.wso2.carbon.identity.oauth2.model.AccessTokenDO;
|
import org.wso2.carbon.identity.oauth2.model.AccessTokenDO;
|
||||||
import org.wso2.carbon.identity.oauth2.model.ResourceScopeCacheEntry;
|
import org.wso2.carbon.identity.oauth2.model.ResourceScopeCacheEntry;
|
||||||
import org.wso2.carbon.identity.oauth2.validators.OAuth2ScopeValidator;
|
import org.wso2.carbon.identity.oauth2.validators.OAuth2ScopeValidator;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class ScopeValidationHandler extends OAuth2ScopeValidator {
|
public class ScopeValidationHandler extends OAuth2ScopeValidator {
|
||||||
|
|
||||||
private final static Log log = LogFactory.getLog(ScopeValidationHandler.class);
|
private final static Log log = LogFactory.getLog(ScopeValidationHandler.class);
|
||||||
private Map<String, OAuth2ScopeValidator> scopeValidators;
|
private final Map<String, OAuth2ScopeValidator> scopeValidators;
|
||||||
|
|
||||||
private final String DEFAULT_PREFIX = "default";
|
|
||||||
|
|
||||||
public ScopeValidationHandler() {
|
public ScopeValidationHandler() {
|
||||||
scopeValidators = OAuthExtensionsDataHolder.getInstance().getScopeValidators();
|
scopeValidators = OAuthExtensionsDataHolder.getInstance().getScopeValidators();
|
||||||
@ -63,7 +62,7 @@ public class ScopeValidationHandler extends OAuth2ScopeValidator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String scope[] = resourceScope.split(":");
|
String[] scope = resourceScope.split(":");
|
||||||
String scopePrefix = scope[0];
|
String scopePrefix = scope[0];
|
||||||
|
|
||||||
OAuth2ScopeValidator scopeValidator = scopeValidators.get(scopePrefix);
|
OAuth2ScopeValidator scopeValidator = scopeValidators.get(scopePrefix);
|
||||||
@ -74,6 +73,7 @@ public class ScopeValidationHandler extends OAuth2ScopeValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// loading default scope validator if matching validator is not found
|
// loading default scope validator if matching validator is not found
|
||||||
|
String DEFAULT_PREFIX = "default";
|
||||||
scopeValidator = scopeValidators.get(DEFAULT_PREFIX);
|
scopeValidator = scopeValidators.get(DEFAULT_PREFIX);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Loading default scope validator");
|
log.debug("Loading default scope validator");
|
||||||
@ -95,8 +95,7 @@ public class ScopeValidationHandler extends OAuth2ScopeValidator {
|
|||||||
|
|
||||||
String resourceScope = null;
|
String resourceScope = null;
|
||||||
boolean cacheHit = false;
|
boolean cacheHit = false;
|
||||||
// Check the cache, if caching is enabled.
|
|
||||||
if (OAuthServerConfiguration.getInstance().isCacheEnabled()) {
|
|
||||||
OAuthCache oauthCache = OAuthCache.getInstance();
|
OAuthCache oauthCache = OAuthCache.getInstance();
|
||||||
OAuthCacheKey cacheKey = new OAuthCacheKey(resource);
|
OAuthCacheKey cacheKey = new OAuthCacheKey(resource);
|
||||||
CacheEntry result = oauthCache.getValueFromCache(cacheKey);
|
CacheEntry result = oauthCache.getValueFromCache(cacheKey);
|
||||||
@ -106,25 +105,20 @@ public class ScopeValidationHandler extends OAuth2ScopeValidator {
|
|||||||
resourceScope = ((ResourceScopeCacheEntry) result).getScope();
|
resourceScope = ((ResourceScopeCacheEntry) result).getScope();
|
||||||
cacheHit = true;
|
cacheHit = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
TokenMgtDAO tokenMgtDAO = new TokenMgtDAO();
|
|
||||||
if (!cacheHit) {
|
if (!cacheHit) {
|
||||||
|
TokenManagementDAO tokenMgtDAO = new TokenManagementDAOImpl();
|
||||||
try {
|
try {
|
||||||
resourceScope = tokenMgtDAO.findScopeOfResource(resource);
|
resourceScope = tokenMgtDAO.findTenantAndScopeOfResource(resource).getLeft();
|
||||||
} catch (IdentityOAuth2Exception e) {
|
} catch (IdentityOAuth2Exception e) {
|
||||||
log.error("Error occurred while retrieving scope for resource '" + resource + "'");
|
log.error("Error occurred while retrieving scope for resource '" + resource + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OAuthServerConfiguration.getInstance().isCacheEnabled()) {
|
|
||||||
OAuthCache oauthCache = OAuthCache.getInstance();
|
|
||||||
OAuthCacheKey cacheKey = new OAuthCacheKey(resource);
|
|
||||||
ResourceScopeCacheEntry cacheEntry = new ResourceScopeCacheEntry(resourceScope);
|
ResourceScopeCacheEntry cacheEntry = new ResourceScopeCacheEntry(resourceScope);
|
||||||
//Store resourceScope in cache even if it is null (to avoid database calls when accessing resources for
|
//Store resourceScope in cache even if it is null (to avoid database calls when accessing resources for
|
||||||
//which scopes haven't been defined).
|
//which scopes haven't been defined).
|
||||||
oauthCache.addToCache(cacheKey, cacheEntry);
|
oauthCache.addToCache(cacheKey, cacheEntry);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return resourceScope;
|
return resourceScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -74,8 +74,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||||
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
|
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
|
||||||
Device device = service.getDevice(deviceIdentifier, false);
|
Device device = service.getDevice(deviceIdentifier, false);
|
||||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
service.setStatus(device, EnrolmentInfo.Status.UNREACHABLE);
|
||||||
EnrolmentInfo.Status.UNREACHABLE);
|
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while setting the device as unreachable";
|
String msg = "Error occurred while setting the device as unreachable";
|
||||||
@ -91,8 +90,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||||
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
|
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
|
||||||
Device device = service.getDevice(deviceIdentifier, false);
|
Device device = service.getDevice(deviceIdentifier, false);
|
||||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
service.setStatus(device, EnrolmentInfo.Status.INACTIVE);
|
||||||
EnrolmentInfo.Status.INACTIVE);
|
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while setting the device as inactive";
|
String msg = "Error occurred while setting the device as inactive";
|
||||||
@ -109,8 +107,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
deviceIdentifier.setId(device.getDeviceIdentifier());
|
deviceIdentifier.setId(device.getDeviceIdentifier());
|
||||||
deviceIdentifier.setType(device.getType());
|
deviceIdentifier.setType(device.getType());
|
||||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
service.setStatus(device, EnrolmentInfo.Status.UNREACHABLE);
|
||||||
EnrolmentInfo.Status.UNREACHABLE);
|
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while setting the device as unreachable";
|
String msg = "Error occurred while setting the device as unreachable";
|
||||||
@ -126,8 +123,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
|
|
||||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||||
Device device = service.getDevice(deviceIdentifier, false);
|
Device device = service.getDevice(deviceIdentifier, false);
|
||||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
service.setStatus(device, EnrolmentInfo.Status.ACTIVE);
|
||||||
EnrolmentInfo.Status.ACTIVE);
|
|
||||||
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while setting the device as reachable for " +
|
String msg = "Error occurred while setting the device as reachable for " +
|
||||||
@ -231,8 +227,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
try {
|
try {
|
||||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||||
Device device = service.getDevice(deviceIdentifier, false);
|
Device device = service.getDevice(deviceIdentifier, false);
|
||||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
service.setStatus(device, EnrolmentInfo.Status.ACTIVE);
|
||||||
EnrolmentInfo.Status.ACTIVE);
|
|
||||||
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while marking device as compliance " + deviceIdentifier.getId() + " - " +
|
String msg = "Error occurred while marking device as compliance " + deviceIdentifier.getId() + " - " +
|
||||||
@ -246,11 +241,9 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
public void deactivateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
public void deactivateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||||
Device device = service.getDevice(deviceIdentifier, false);
|
Device device = service.getDevice(deviceIdentifier, false);
|
||||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
service.setStatus(device, EnrolmentInfo.Status.INACTIVE);
|
||||||
EnrolmentInfo.Status.INACTIVE);
|
|
||||||
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while deactivating the device " + deviceIdentifier.getId() + " - " +
|
String msg = "Error occurred while deactivating the device " + deviceIdentifier.getId() + " - " +
|
||||||
@ -266,8 +259,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
try {
|
try {
|
||||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||||
Device device = service.getDevice(deviceIdentifier, false);
|
Device device = service.getDevice(deviceIdentifier, false);
|
||||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
service.setStatus(device, EnrolmentInfo.Status.ACTIVE);
|
||||||
EnrolmentInfo.Status.ACTIVE);
|
|
||||||
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while activating the device " + deviceIdentifier.getId() + " - " +
|
String msg = "Error occurred while activating the device " + deviceIdentifier.getId() + " - " +
|
||||||
|
|||||||
@ -150,15 +150,10 @@ public class MonitoringTask implements Task {
|
|||||||
deviceType);
|
deviceType);
|
||||||
}
|
}
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
|
|
||||||
EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus();
|
EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus();
|
||||||
if (status.equals(EnrolmentInfo.Status.BLOCKED) ||
|
if (status.equals(EnrolmentInfo.Status.ACTIVE) ||
|
||||||
status.equals(EnrolmentInfo.Status.REMOVED) ||
|
status.equals(EnrolmentInfo.Status.INACTIVE) ||
|
||||||
status.equals(EnrolmentInfo.Status.UNCLAIMED) ||
|
status.equals(EnrolmentInfo.Status.UNREACHABLE)) {
|
||||||
status.equals(EnrolmentInfo.Status.DISENROLLMENT_REQUESTED) ||
|
|
||||||
status.equals(EnrolmentInfo.Status.SUSPENDED)) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
notifiableDevices.add(device);
|
notifiableDevices.add(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,11 +124,6 @@ public class TypeXDeviceManager implements DeviceManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isClaimable(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status)
|
public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
|
|||||||
@ -56,6 +56,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
|||||||
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS GROUP_PROPERTIES;
|
||||||
CREATE TABLE IF NOT EXISTS GROUP_PROPERTIES (
|
CREATE TABLE IF NOT EXISTS GROUP_PROPERTIES (
|
||||||
GROUP_ID INTEGER NOT NULL,
|
GROUP_ID INTEGER NOT NULL,
|
||||||
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
||||||
@ -97,6 +98,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
|||||||
OWNER VARCHAR(50) NOT NULL,
|
OWNER VARCHAR(50) NOT NULL,
|
||||||
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
|
IS_TRANSFERRED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
@ -111,9 +113,16 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
|
|||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
|
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
||||||
CREATED_TIMESTAMP INT NOT NULL,
|
CREATED_TIMESTAMP INT NOT NULL,
|
||||||
UPDATED_TIMESTAMP INT NOT NULL,
|
UPDATED_TIMESTAMP INT NOT NULL,
|
||||||
PUSH_NOTIFICATION_STATUS VARCHAR(50),
|
OPERATION_CODE VARCHAR(50) NOT NULL,
|
||||||
|
INITIATED_BY VARCHAR(100) NULL,
|
||||||
|
TYPE VARCHAR(20) NOT NULL,
|
||||||
|
DEVICE_ID INTEGER DEFAULT NULL,
|
||||||
|
DEVICE_TYPE VARCHAR(300) NOT NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
@ -126,13 +135,29 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
|||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
OPERATION_RESPONSE BLOB DEFAULT NULL,
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
|
OPERATION_RESPONSE VARCHAR(1024) DEFAULT NULL ,
|
||||||
|
IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT fk_dm_en_op_map_response FOREIGN KEY (EN_OP_MAP_ID) REFERENCES
|
||||||
|
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE_LARGE;
|
||||||
|
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
CONSTRAINT fk_dm_device_operation_response_large_mapping FOREIGN KEY (ID)
|
||||||
|
REFERENCES DM_DEVICE_OPERATION_RESPONSE (ID)
|
||||||
|
ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
-- POLICY RELATED TABLES --
|
-- POLICY RELATED TABLES --
|
||||||
@ -174,6 +199,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS DM_POLICY_CORRECTIVE_ACTION;
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
|
||||||
ID INT(11) NOT NULL AUTO_INCREMENT,
|
ID INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
ACTION_TYPE VARCHAR(45) NOT NULL,
|
ACTION_TYPE VARCHAR(45) NOT NULL,
|
||||||
@ -287,7 +313,6 @@ DROP TABLE IF EXISTS DM_DEVICE_POLICY_APPLIED;
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS DM_CRITERIA;
|
DROP TABLE IF EXISTS DM_CRITERIA;
|
||||||
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
|
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
@ -296,7 +321,6 @@ CREATE TABLE IF NOT EXISTS DM_CRITERIA (
|
|||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS DM_POLICY_CRITERIA;
|
DROP TABLE IF EXISTS DM_POLICY_CRITERIA;
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
@ -315,6 +339,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS DM_POLICY_CRITERIA_PROPERTIES;
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
POLICY_CRITERION_ID INT NOT NULL,
|
POLICY_CRITERION_ID INT NOT NULL,
|
||||||
@ -368,21 +393,6 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS DM_ENROLMENT;
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
|
||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
|
||||||
OWNER VARCHAR(50) NOT NULL,
|
|
||||||
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
|
||||||
STATUS VARCHAR(50) NULL,
|
|
||||||
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
|
||||||
TENANT_ID INT NOT NULL,
|
|
||||||
PRIMARY KEY (ID),
|
|
||||||
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
|
||||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS DM_APPLICATION;
|
DROP TABLE IF EXISTS DM_APPLICATION;
|
||||||
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
@ -432,6 +442,7 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
|
|||||||
);
|
);
|
||||||
-- NOTIFICATION TABLE END --
|
-- NOTIFICATION TABLE END --
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS DM_DEVICE_INFO;
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
|
||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INT NULL,
|
DEVICE_ID INT NULL,
|
||||||
@ -451,6 +462,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS DM_DEVICE_LOCATION;
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
|
||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INT NULL,
|
DEVICE_ID INT NULL,
|
||||||
@ -478,7 +490,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS DM_DEVICE_DETAIL;
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
DEVICE_ID INT NOT NULL,
|
DEVICE_ID INT NOT NULL,
|
||||||
@ -512,8 +524,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- POLICY AND DEVICE GROUP MAPPING --
|
-- POLICY AND DEVICE GROUP MAPPING --
|
||||||
DROP TABLE IF EXISTS DM_DEVICE_GROUP_POLICY;
|
DROP TABLE IF EXISTS DM_DEVICE_GROUP_POLICY;
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
|
||||||
|
|||||||
@ -28,7 +28,6 @@
|
|||||||
<class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/>
|
<class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/>
|
||||||
<class name="org.wso2.carbon.policy.mgt.core.MonitoringTestCase" />
|
<class name="org.wso2.carbon.policy.mgt.core.MonitoringTestCase" />
|
||||||
<class name="org.wso2.carbon.policy.mgt.core.PolicyEvaluationTestCase" />
|
<class name="org.wso2.carbon.policy.mgt.core.PolicyEvaluationTestCase" />
|
||||||
|
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
|
|
||||||
|
|||||||
@ -100,6 +100,11 @@
|
|||||||
</DataSourceConfiguration>
|
</DataSourceConfiguration>
|
||||||
<ArchivalTask>
|
<ArchivalTask>
|
||||||
<Enabled>false</Enabled>
|
<Enabled>false</Enabled>
|
||||||
|
<ArchivePendingOperations>false</ArchivePendingOperations>
|
||||||
|
<DBConfig>
|
||||||
|
<SourceDB>DM_DB</SourceDB>
|
||||||
|
<DestinationDB>ARCHIVAL_DB</DestinationDB>
|
||||||
|
</DBConfig>
|
||||||
<TaskClass>org.wso2.carbon.device.mgt.core.task.impl.ArchivalTask</TaskClass>
|
<TaskClass>org.wso2.carbon.device.mgt.core.task.impl.ArchivalTask</TaskClass>
|
||||||
<!-- Cron expression to run the task at specified time -->
|
<!-- Cron expression to run the task at specified time -->
|
||||||
<CronExpression>0 0 0 1/1 * ? *</CronExpression>
|
<CronExpression>0 0 0 1/1 * ? *</CronExpression>
|
||||||
|
|||||||
@ -8,10 +8,10 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION_ARCH (
|
|||||||
INITIATED_BY VARCHAR(100) NULL,
|
INITIATED_BY VARCHAR(100) NULL,
|
||||||
OPERATION_DETAILS BLOB DEFAULT NULL,
|
OPERATION_DETAILS BLOB DEFAULT NULL,
|
||||||
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
|
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
ARCHIVED_AT TIMESTAMP DEFAULT NOW(),
|
ARCHIVED_AT TIMESTAMP DEFAULT NOW()
|
||||||
PRIMARY KEY (ID)
|
|
||||||
)ENGINE = InnoDB;
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
|
CREATE INDEX IDX_OPR_ARC ON DM_OPERATION_ARCH(ARCHIVED_AT);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING_ARCH (
|
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING_ARCH (
|
||||||
ID INTEGER NOT NULL,
|
ID INTEGER NOT NULL,
|
||||||
@ -20,20 +20,31 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING_ARCH (
|
|||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
CREATED_TIMESTAMP INTEGER NOT NULL,
|
CREATED_TIMESTAMP INTEGER NOT NULL,
|
||||||
UPDATED_TIMESTAMP INTEGER NOT NULL,
|
UPDATED_TIMESTAMP INTEGER NOT NULL,
|
||||||
ARCHIVED_AT TIMESTAMP DEFAULT NOW(),
|
ARCHIVED_AT TIMESTAMP DEFAULT NOW()
|
||||||
PRIMARY KEY (ID)
|
|
||||||
)ENGINE = InnoDB;
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
|
CREATE INDEX IDX_EN_OP_MAP_ARCH ON DM_ENROLMENT_OP_MAPPING_ARCH(ARCHIVED_AT);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE_ARCH (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE_ARCH (
|
||||||
ID INT(11) NOT NULL,
|
ID INT(11) NOT NULL,
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
OPERATION_RESPONSE VARCHAR(4096) DEFAULT NULL,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
ARCHIVED_AT TIMESTAMP DEFAULT NOW(),
|
ARCHIVED_AT TIMESTAMP DEFAULT NOW(),
|
||||||
PRIMARY KEY (ID)
|
IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE
|
||||||
)ENGINE = InnoDB;
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
|
CREATE INDEX IDX_OPR_RES_ARCH ON DM_DEVICE_OPERATION_RESPONSE_ARCH(ARCHIVED_AT);
|
||||||
|
|
||||||
|
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE_ARCH (
|
||||||
|
ID INT(11) NOT NULL,
|
||||||
|
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
||||||
|
ARCHIVED_AT TIMESTAMP DEFAULT NOW()
|
||||||
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
|
CREATE INDEX IDX_OPR_RES_LRG_ARCH ON DM_DEVICE_OPERATION_RESPONSE_LARGE_ARCH(ARCHIVED_AT);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION_ARCH (
|
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION_ARCH (
|
||||||
NOTIFICATION_ID INTEGER NOT NULL,
|
NOTIFICATION_ID INTEGER NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
@ -41,6 +52,7 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION_ARCH (
|
|||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
STATUS VARCHAR(10) NULL,
|
STATUS VARCHAR(10) NULL,
|
||||||
DESCRIPTION VARCHAR(1000) NULL,
|
DESCRIPTION VARCHAR(1000) NULL,
|
||||||
ARCHIVED_AT TIMESTAMP DEFAULT NOW(),
|
ARCHIVED_AT TIMESTAMP DEFAULT NOW()
|
||||||
PRIMARY KEY (NOTIFICATION_ID)
|
|
||||||
)ENGINE = InnoDB;
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
|
CREATE INDEX IDX_NOT_ARCH ON DM_NOTIFICATION_ARCH(ARCHIVED_AT);
|
||||||
|
|||||||
@ -0,0 +1,57 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS DM_OPERATION_ARCH (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
TYPE VARCHAR(20) NOT NULL,
|
||||||
|
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
|
||||||
|
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
|
||||||
|
OPERATION_CODE VARCHAR(50) NOT NULL,
|
||||||
|
INITIATED_BY VARCHAR(100) NULL,
|
||||||
|
OPERATION_DETAILS BYTEA DEFAULT NULL,
|
||||||
|
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
ARCHIVED_AT TIMESTAMP(0) DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IDX_OPR_ARC ON DM_OPERATION_ARCH(ARCHIVED_AT);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING_ARCH (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
STATUS VARCHAR(50) NULL,
|
||||||
|
CREATED_TIMESTAMP INTEGER NOT NULL,
|
||||||
|
UPDATED_TIMESTAMP INTEGER NOT NULL,
|
||||||
|
ARCHIVED_AT TIMESTAMP(0) DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IDX_EN_OP_MAP_ARCH ON DM_ENROLMENT_OP_MAPPING_ARCH(ARCHIVED_AT);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE_ARCH (
|
||||||
|
ID INT NOT NULL,
|
||||||
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
OPERATION_RESPONSE VARCHAR(4096) DEFAULT NULL,
|
||||||
|
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
|
||||||
|
ARCHIVED_AT TIMESTAMP(0) DEFAULT NOW(),
|
||||||
|
IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IDX_OPR_RES_ARCH ON DM_DEVICE_OPERATION_RESPONSE_ARCH(ARCHIVED_AT);
|
||||||
|
|
||||||
|
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE_ARCH (
|
||||||
|
ID INT NOT NULL,
|
||||||
|
OPERATION_RESPONSE BYTEA DEFAULT NULL,
|
||||||
|
ARCHIVED_AT TIMESTAMP(0) DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IDX_OPR_RES_LRG_ARCH ON DM_DEVICE_OPERATION_RESPONSE_LARGE_ARCH(ARCHIVED_AT);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION_ARCH (
|
||||||
|
NOTIFICATION_ID INTEGER NOT NULL,
|
||||||
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
TENANT_ID INTEGER NOT NULL,
|
||||||
|
STATUS VARCHAR(10) NULL,
|
||||||
|
DESCRIPTION VARCHAR(1000) NULL,
|
||||||
|
ARCHIVED_AT TIMESTAMP(0) DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IDX_NOT_ARCH ON DM_NOTIFICATION_ARCH(ARCHIVED_AT);
|
||||||
@ -98,6 +98,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
|||||||
OWNER VARCHAR(255) NOT NULL,
|
OWNER VARCHAR(255) NOT NULL,
|
||||||
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
|
IS_TRANSFERRED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
@ -115,6 +116,13 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
|
|||||||
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
||||||
CREATED_TIMESTAMP INT NOT NULL,
|
CREATED_TIMESTAMP INT NOT NULL,
|
||||||
UPDATED_TIMESTAMP INT NOT NULL,
|
UPDATED_TIMESTAMP INT NOT NULL,
|
||||||
|
OPERATION_CODE VARCHAR(50) NOT NULL,
|
||||||
|
INITIATED_BY VARCHAR(100) NULL,
|
||||||
|
TYPE VARCHAR(20) NOT NULL,
|
||||||
|
DEVICE_ID INTEGER DEFAULT NULL,
|
||||||
|
DEVICE_TYPE VARCHAR(300) NOT NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
@ -127,7 +135,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
|||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
EN_OP_MAP_ID INTEGER NOT NULL,
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
OPERATION_RESPONSE VARCHAR(1024) DEFAULT NULL ,
|
||||||
|
IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
@ -138,6 +147,21 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
|||||||
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
CONSTRAINT fk_dm_device_operation_response_large_mapping FOREIGN KEY (ID)
|
||||||
|
REFERENCES DM_DEVICE_OPERATION_RESPONSE (ID)
|
||||||
|
ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT fk_dm_en_op_map_response_large FOREIGN KEY (EN_OP_MAP_ID)
|
||||||
|
REFERENCES DM_ENROLMENT_OP_MAPPING (ID)
|
||||||
|
ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
-- POLICY RELATED TABLES --
|
-- POLICY RELATED TABLES --
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_PROFILE (
|
CREATE TABLE IF NOT EXISTS DM_PROFILE (
|
||||||
|
|||||||
@ -114,47 +114,11 @@ CREATE TABLE DM_OPERATION (
|
|||||||
RECEIVED_TIMESTAMP DATETIME2 NULL,
|
RECEIVED_TIMESTAMP DATETIME2 NULL,
|
||||||
OPERATION_CODE VARCHAR(50) NOT NULL,
|
OPERATION_CODE VARCHAR(50) NOT NULL,
|
||||||
INITIATED_BY VARCHAR(100) NULL,
|
INITIATED_BY VARCHAR(100) NULL,
|
||||||
|
OPERATION_DETAILS VARBINARY(MAX) DEFAULT NULL,
|
||||||
|
ENABLED BIT NOT NULL DEFAULT 0,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_CONFIG_OPERATION]') AND TYPE IN (N'U'))
|
|
||||||
CREATE TABLE DM_CONFIG_OPERATION (
|
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
|
||||||
OPERATION_CONFIG VARBINARY(MAX) DEFAULT NULL,
|
|
||||||
ENABLED BIT NOT NULL DEFAULT 0,
|
|
||||||
PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_COMMAND_OPERATION]') AND TYPE IN (N'U'))
|
|
||||||
CREATE TABLE DM_COMMAND_OPERATION (
|
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
|
||||||
ENABLED BIT NOT NULL DEFAULT 0,
|
|
||||||
PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT FK_DM_OPERATION_COMMAND FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_OPERATION]') AND TYPE IN (N'U'))
|
|
||||||
CREATE TABLE DM_POLICY_OPERATION (
|
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
|
||||||
ENABLED INTEGER NOT NULL DEFAULT 0,
|
|
||||||
OPERATION_DETAILS VARBINARY(MAX) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT FK_DM_OPERATION_POLICY FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_PROFILE_OPERATION]') AND TYPE IN (N'U'))
|
|
||||||
CREATE TABLE DM_PROFILE_OPERATION (
|
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
|
||||||
ENABLED INTEGER NOT NULL DEFAULT 0,
|
|
||||||
OPERATION_DETAILS VARBINARY(MAX) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT FK_DM_OPERATION_PROFILE FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_ENROLMENT]') AND TYPE IN (N'U'))
|
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_ENROLMENT]') AND TYPE IN (N'U'))
|
||||||
CREATE TABLE DM_ENROLMENT (
|
CREATE TABLE DM_ENROLMENT (
|
||||||
@ -163,6 +127,7 @@ CREATE TABLE DM_ENROLMENT (
|
|||||||
OWNER VARCHAR(255) NOT NULL,
|
OWNER VARCHAR(255) NOT NULL,
|
||||||
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
|
IS_TRANSFERRED TINYINT NOT NULL DEFAULT 0,
|
||||||
DATE_OF_ENROLMENT DATETIME2 DEFAULT NULL,
|
DATE_OF_ENROLMENT DATETIME2 DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE DATETIME2 DEFAULT NULL,
|
DATE_OF_LAST_UPDATE DATETIME2 DEFAULT NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
@ -205,7 +170,8 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
|
|||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
EN_OP_MAP_ID INTEGER NOT NULL,
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
OPERATION_RESPONSE VARBINARY(MAX) DEFAULT NULL,
|
OPERATION_RESPONSE VARCHAR(1024) DEFAULT NULL,
|
||||||
|
IS_LARGE_RESPONSE BIT NOT NULL DEFAULT 0,
|
||||||
RECEIVED_TIMESTAMP DATETIME2 DEFAULT NULL
|
RECEIVED_TIMESTAMP DATETIME2 DEFAULT NULL
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT FK_DM_DEVICE_OPERATION_RESP_ENROLMENT FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT FK_DM_DEVICE_OPERATION_RESP_ENROLMENT FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
@ -222,6 +188,26 @@ CREATE INDEX IDX_ENID_OPID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLME
|
|||||||
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DM_EN_OP_MAP_RES' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_OPERATION_RESPONSE'))
|
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DM_EN_OP_MAP_RES' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_OPERATION_RESPONSE'))
|
||||||
CREATE INDEX IDX_DM_EN_OP_MAP_RES ON DM_DEVICE_OPERATION_RESPONSE(EN_OP_MAP_ID);
|
CREATE INDEX IDX_DM_EN_OP_MAP_RES ON DM_DEVICE_OPERATION_RESPONSE(EN_OP_MAP_ID);
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_OPERATION_RESPONSE_LARGE]') AND TYPE IN (N'U'))
|
||||||
|
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE (
|
||||||
|
ID INTEGER IDENTITY(1,1) NOT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
|
OPERATION_RESPONSE VARBINARY(MAX) DEFAULT NULL,
|
||||||
|
RECEIVED_TIMESTAMP DATETIME2 DEFAULT NULL
|
||||||
|
PRIMARY KEY (ID),
|
||||||
|
CONSTRAINT FK_DM_DEVICE_OPERATION_RESP_LARGE_OPERATION FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||||
|
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT FK_DM_EN_OP_MAP_RESPONSE_LARGE FOREIGN KEY (EN_OP_MAP_ID) REFERENCES
|
||||||
|
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENID_OPID_LARGE' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_OPERATION_RESPONSE_LARGE'))
|
||||||
|
CREATE INDEX IDX_ENID_OPID_LARGE ON DM_DEVICE_OPERATION_RESPONSE_LARGE(OPERATION_ID);
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_DM_EN_OP_MAP_RES_LARGE' AND OBJECT_ID = OBJECT_ID('DM_DEVICE_OPERATION_RESPONSE_LARGE'))
|
||||||
|
CREATE INDEX IDX_DM_EN_OP_MAP_RES_LARGE ON DM_DEVICE_OPERATION_RESPONSE_LARGE(EN_OP_MAP_ID);
|
||||||
|
|
||||||
-- POLICY RELATED TABLES --
|
-- POLICY RELATED TABLES --
|
||||||
|
|
||||||
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_PROFILE]') AND TYPE IN (N'U'))
|
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_PROFILE]') AND TYPE IN (N'U'))
|
||||||
|
|||||||
@ -113,6 +113,7 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
|||||||
OWNER VARCHAR(255) NOT NULL,
|
OWNER VARCHAR(255) NOT NULL,
|
||||||
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
|
IS_TRANSFERRED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
|
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
@ -133,6 +134,13 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
|
|||||||
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
||||||
CREATED_TIMESTAMP INTEGER NOT NULL,
|
CREATED_TIMESTAMP INTEGER NOT NULL,
|
||||||
UPDATED_TIMESTAMP INTEGER NOT NULL,
|
UPDATED_TIMESTAMP INTEGER NOT NULL,
|
||||||
|
OPERATION_CODE VARCHAR(50) NOT NULL,
|
||||||
|
INITIATED_BY VARCHAR(100) NULL,
|
||||||
|
TYPE VARCHAR(20) NOT NULL,
|
||||||
|
DEVICE_ID INTEGER DEFAULT NULL,
|
||||||
|
DEVICE_TYPE VARCHAR(300) NOT NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
TENANT_ID INTEGER DEFAULT 0;
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
KEY `fk_dm_device_operation_mapping_operation` (`OPERATION_ID`),
|
KEY `fk_dm_device_operation_mapping_operation` (`OPERATION_ID`),
|
||||||
KEY `IDX_DM_ENROLMENT_OP_MAPPING` (`ENROLMENT_ID`,`OPERATION_ID`),
|
KEY `IDX_DM_ENROLMENT_OP_MAPPING` (`ENROLMENT_ID`,`OPERATION_ID`),
|
||||||
@ -148,13 +156,14 @@ CREATE INDEX IDX_EN_OP_MAPPING_EN_ID ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID);
|
|||||||
CREATE INDEX IDX_EN_OP_MAPPING_OP_ID ON DM_ENROLMENT_OP_MAPPING(OPERATION_ID);
|
CREATE INDEX IDX_EN_OP_MAPPING_OP_ID ON DM_ENROLMENT_OP_MAPPING(OPERATION_ID);
|
||||||
CREATE INDEX IDX_EN_OP_MAPPING_EN_ID_STATUS ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, STATUS);
|
CREATE INDEX IDX_EN_OP_MAPPING_EN_ID_STATUS ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, STATUS);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
(
|
||||||
ID INT(11) NOT NULL AUTO_INCREMENT,
|
ID INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
EN_OP_MAP_ID INTEGER NOT NULL,
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
OPERATION_RESPONSE VARCHAR(1024) DEFAULT NULL,
|
||||||
|
IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
@ -165,8 +174,26 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
|||||||
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
) ENGINE = InnoDB;
|
) ENGINE = InnoDB;
|
||||||
|
|
||||||
CREATE INDEX IDX_ENID_OPID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID);
|
CREATE INDEX IDX_DM_RES_RT ON DM_DEVICE_OPERATION_RESPONSE(RECEIVED_TIMESTAMP);
|
||||||
CREATE INDEX IDX_DM_EN_OP_MAP_RES ON DM_DEVICE_OPERATION_RESPONSE(EN_OP_MAP_ID);
|
CREATE INDEX IDX_ENID_OP_ID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID);
|
||||||
|
CREATE INDEX IDX_DM_EN_OP_MAP_ID ON DM_DEVICE_OPERATION_RESPONSE(EN_OP_MAP_ID);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE_LARGE
|
||||||
|
(
|
||||||
|
ID INT(11) NOT NULL,
|
||||||
|
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
CONSTRAINT fk_dm_device_operation_response_large FOREIGN KEY (ID) REFERENCES
|
||||||
|
DM_DEVICE_OPERATION_RESPONSE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT fk_dm_en_op_map_response_large FOREIGN KEY (EN_OP_MAP_ID) REFERENCES
|
||||||
|
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
) ENGINE = InnoDB;
|
||||||
|
|
||||||
|
CREATE INDEX IDX_DM_RES_LRG_RT ON DM_DEVICE_OPERATION_RESPONSE_LARGE(RECEIVED_TIMESTAMP);
|
||||||
|
CREATE INDEX IDX_DM_EN_OP_MAP_ID ON DM_DEVICE_OPERATION_RESPONSE_LARGE(EN_OP_MAP_ID);
|
||||||
|
|
||||||
-- POLICY RELATED TABLES ---
|
-- POLICY RELATED TABLES ---
|
||||||
|
|
||||||
@ -451,6 +478,8 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
|
|||||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
)ENGINE = InnoDB;
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
|
CREATE INDEX IDX_NOTF_UT ON DM_NOTIFICATION(LAST_UPDATED_TIMESTAMP);
|
||||||
|
|
||||||
-- END NOTIFICATION TABLES --
|
-- END NOTIFICATION TABLES --
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
|
||||||
|
|||||||
@ -176,6 +176,8 @@ CREATE TABLE DM_OPERATION (
|
|||||||
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
|
||||||
OPERATION_CODE VARCHAR2(1000) NOT NULL,
|
OPERATION_CODE VARCHAR2(1000) NOT NULL,
|
||||||
INITIATED_BY VARCHAR2(100) NULL,
|
INITIATED_BY VARCHAR2(100) NULL,
|
||||||
|
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
|
||||||
|
OPERATION_DETAILS BLOB DEFAULT NULL,
|
||||||
CONSTRAINT PK_DM_OPERATION PRIMARY KEY (ID)
|
CONSTRAINT PK_DM_OPERATION PRIMARY KEY (ID)
|
||||||
)
|
)
|
||||||
/
|
/
|
||||||
@ -193,47 +195,14 @@ WHEN (NEW.ID IS NULL)
|
|||||||
END;
|
END;
|
||||||
/
|
/
|
||||||
|
|
||||||
CREATE TABLE DM_CONFIG_OPERATION (
|
|
||||||
OPERATION_ID NUMBER(10) NOT NULL,
|
|
||||||
OPERATION_CONFIG BLOB DEFAULT NULL,
|
|
||||||
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
|
|
||||||
CONSTRAINT PK_DM_CONFIG_OPERATION PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID)
|
|
||||||
)
|
|
||||||
/
|
|
||||||
CREATE TABLE DM_COMMAND_OPERATION (
|
|
||||||
OPERATION_ID NUMBER(10) NOT NULL,
|
|
||||||
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
|
|
||||||
CONSTRAINT PK_DM_COMMAND_OPERATION PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT FK_DM_OPERATION_COMMAND FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID)
|
|
||||||
)
|
|
||||||
/
|
|
||||||
CREATE TABLE DM_POLICY_OPERATION (
|
|
||||||
OPERATION_ID NUMBER(10) NOT NULL,
|
|
||||||
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
|
|
||||||
OPERATION_DETAILS BLOB DEFAULT NULL,
|
|
||||||
CONSTRAINT PK_DM_POLICY_OPERATION PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT FK_DM_OPERATION_POLICY FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID)
|
|
||||||
)
|
|
||||||
/
|
|
||||||
CREATE TABLE DM_PROFILE_OPERATION (
|
|
||||||
OPERATION_ID NUMBER(10) NOT NULL,
|
|
||||||
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
|
|
||||||
OPERATION_DETAILS BLOB DEFAULT NULL,
|
|
||||||
CONSTRAINT PK_DM_PROFILE_OPERATION PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT FK_DM_OPERATION_PROFILE FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID)
|
|
||||||
)
|
|
||||||
/
|
|
||||||
CREATE TABLE DM_ENROLMENT (
|
CREATE TABLE DM_ENROLMENT (
|
||||||
ID NUMBER(10) NOT NULL,
|
ID NUMBER(10) NOT NULL,
|
||||||
DEVICE_ID NUMBER(10) NOT NULL,
|
DEVICE_ID NUMBER(10) NOT NULL,
|
||||||
OWNER VARCHAR2(255) NOT NULL,
|
OWNER VARCHAR2(255) NOT NULL,
|
||||||
OWNERSHIP VARCHAR2(45) DEFAULT NULL,
|
OWNERSHIP VARCHAR2(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR2(50) NULL,
|
STATUS VARCHAR2(50) NULL,
|
||||||
|
IS_TRANSFERRED NUMBER(1) DEFAULT 0 NOT NULL,
|
||||||
DATE_OF_ENROLMENT TIMESTAMP(0) DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP(0) DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL,
|
DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL,
|
||||||
TENANT_ID NUMBER(10) NOT NULL,
|
TENANT_ID NUMBER(10) NOT NULL,
|
||||||
|
|||||||
@ -1,168 +1,175 @@
|
|||||||
|
CREATE SEQUENCE DM_DEVICE_TYPE_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
||||||
ID BIGSERIAL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_TYPE_seq') NOT NULL,
|
||||||
NAME VARCHAR(300) DEFAULT NULL,
|
NAME VARCHAR(300) DEFAULT NULL,
|
||||||
DEVICE_TYPE_META VARCHAR(20000) DEFAULT NULL,
|
DEVICE_TYPE_META VARCHAR(20000) DEFAULT NULL,
|
||||||
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
LAST_UPDATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
|
||||||
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
||||||
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
UNIQUE(NAME, PROVIDER_TENANT_ID)
|
PRIMARY KEY (ID)
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE (
|
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
|
||||||
SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,
|
|
||||||
CERTIFICATE BYTEA DEFAULT NULL,
|
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
|
||||||
USERNAME VARCHAR(500) DEFAULT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_GROUP (
|
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
|
||||||
GROUP_NAME VARCHAR(100) DEFAULT NULL,
|
|
||||||
STATUS VARCHAR(50) DEFAULT NULL,
|
|
||||||
DESCRIPTION TEXT DEFAULT NULL,
|
|
||||||
OWNER VARCHAR(255) DEFAULT NULL,
|
|
||||||
TENANT_ID INTEGER DEFAULT 0
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_ROLE_GROUP_MAP (
|
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
|
||||||
GROUP_ID INTEGER DEFAULT NULL,
|
|
||||||
ROLE VARCHAR(45) DEFAULT NULL,
|
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
|
||||||
CONSTRAINT fk_DM_ROLE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID)
|
|
||||||
REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IDX_DEVICE_TYPE ON DM_DEVICE_TYPE (NAME, PROVIDER_TENANT_ID);
|
CREATE INDEX IDX_DEVICE_TYPE ON DM_DEVICE_TYPE (NAME, PROVIDER_TENANT_ID);
|
||||||
|
CREATE INDEX IDX_DEVICE_NAME ON DM_DEVICE_TYPE (NAME);
|
||||||
|
CREATE INDEX IDX_DEVICE_TYPE_DEVICE_NAME ON DM_DEVICE_TYPE(ID, NAME);
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_GROUP_seq;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_GROUP (
|
||||||
|
ID INTEGER DEFAULT NEXTVAL ('DM_GROUP_seq') NOT NULL,
|
||||||
|
GROUP_NAME VARCHAR(100) DEFAULT NULL,
|
||||||
|
DESCRIPTION TEXT DEFAULT NULL,
|
||||||
|
OWNER VARCHAR(45) DEFAULT NULL,
|
||||||
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_ROLE_GROUP_MAP_seq;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_ROLE_GROUP_MAP (
|
||||||
|
ID INTEGER DEFAULT NEXTVAL ('DM_ROLE_GROUP_MAP_seq') NOT NULL,
|
||||||
|
GROUP_ID INTEGER DEFAULT NULL,
|
||||||
|
ROLE VARCHAR(45) DEFAULT NULL,
|
||||||
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
|
CONSTRAINT DM_ROLE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID)
|
||||||
|
REFERENCES DM_GROUP (ID)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_DEVICE_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_seq') NOT NULL,
|
||||||
DESCRIPTION TEXT DEFAULT NULL,
|
DESCRIPTION TEXT DEFAULT NULL,
|
||||||
NAME VARCHAR(100) DEFAULT NULL,
|
NAME VARCHAR(100) DEFAULT NULL,
|
||||||
DEVICE_TYPE_ID INTEGER DEFAULT NULL,
|
DEVICE_TYPE_ID INTEGER DEFAULT NULL,
|
||||||
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
LAST_UPDATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID)
|
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID)
|
||||||
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IDX_DM_DEVICE ON DM_DEVICE(TENANT_ID, DEVICE_TYPE_ID);
|
||||||
|
CREATE INDEX IDX_DM_DEVICE_TYPE_ID_DEVICE_IDENTIFICATION ON DM_DEVICE(TENANT_ID, DEVICE_TYPE_ID,DEVICE_IDENTIFICATION);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
||||||
DEVICE_TYPE_NAME VARCHAR(300) NOT NULL,
|
DEVICE_TYPE_NAME VARCHAR(300) NOT NULL,
|
||||||
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
||||||
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
||||||
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
TENANT_ID VARCHAR(100),
|
||||||
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, TENANT_ID)
|
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, TENANT_ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS GROUP_PROPERTIES (
|
CREATE SEQUENCE DM_DEVICE_GROUP_MAP_seq;
|
||||||
GROUP_ID INTEGER NOT NULL,
|
|
||||||
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
|
||||||
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
|
||||||
PRIMARY KEY (GROUP_ID, PROPERTY_NAME, TENANT_ID)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX IDX_DM_DEVICE ON DM_DEVICE(TENANT_ID, DEVICE_TYPE_ID);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_GROUP_MAP_seq') NOT NULL,
|
||||||
DEVICE_ID INTEGER DEFAULT NULL,
|
DEVICE_ID INTEGER DEFAULT NULL,
|
||||||
GROUP_ID INTEGER DEFAULT NULL,
|
GROUP_ID INTEGER DEFAULT NULL,
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_DEVICE2 FOREIGN KEY (DEVICE_ID)
|
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_DEVICE2 FOREIGN KEY (DEVICE_ID)
|
||||||
REFERENCES DM_DEVICE (ID) ON DELETE CASCADE ON UPDATE CASCADE,
|
REFERENCES DM_DEVICE (ID)
|
||||||
|
ON DELETE CASCADE
|
||||||
|
ON UPDATE CASCADE ,
|
||||||
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID)
|
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID)
|
||||||
REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE
|
REFERENCES DM_GROUP (ID)
|
||||||
);
|
ON DELETE CASCADE
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_OPERATION_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_OPERATION (
|
CREATE TABLE IF NOT EXISTS DM_OPERATION (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_OPERATION_seq') NOT NULL,
|
||||||
TYPE VARCHAR(50) NOT NULL,
|
TYPE VARCHAR(20) NOT NULL,
|
||||||
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
|
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
|
||||||
OPERATION_CODE VARCHAR(1000) NOT NULL,
|
OPERATION_CODE VARCHAR(50) NOT NULL,
|
||||||
INITIATED_BY VARCHAR(50) NULL
|
INITIATED_BY VARCHAR(100) NULL,
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
|
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
|
||||||
OPERATION_CONFIG BYTEA DEFAULT NULL,
|
|
||||||
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
|
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
|
||||||
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
|
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
|
||||||
ENABLED INTEGER NOT NULL DEFAULT 0,
|
|
||||||
OPERATION_DETAILS BYTEA DEFAULT NULL,
|
OPERATION_DETAILS BYTEA DEFAULT NULL,
|
||||||
PRIMARY KEY (OPERATION_ID),
|
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
CONSTRAINT fk_dm_operation_policy FOREIGN KEY (OPERATION_ID) REFERENCES
|
PRIMARY KEY (ID)
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
|
CREATE SEQUENCE DM_ENROLMENT_seq;
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
|
||||||
ENABLED INTEGER NOT NULL DEFAULT 0,
|
|
||||||
OPERATION_DETAILS BYTEA DEFAULT NULL,
|
|
||||||
PRIMARY KEY (OPERATION_ID),
|
|
||||||
CONSTRAINT fk_dm_operation_profile FOREIGN KEY (OPERATION_ID) REFERENCES
|
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_ENROLMENT_seq') NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
OWNER VARCHAR(255) NOT NULL,
|
OWNER VARCHAR(50) NOT NULL,
|
||||||
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
|
IS_TRANSFERRED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP(0) NULL DEFAULT NULL,
|
||||||
|
DATE_OF_LAST_UPDATE TIMESTAMP(0) NULL DEFAULT NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
PRIMARY KEY (ID),
|
||||||
|
CONSTRAINT FK_DM_DEVICE_ENROLMENT FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IDX_ENROLMENT_FK_DEVICE_ID ON DM_ENROLMENT(DEVICE_ID);
|
CREATE INDEX IDX_ENROLMENT_FK_DEVICE_ID ON DM_ENROLMENT(DEVICE_ID);
|
||||||
CREATE INDEX IDX_ENROLMENT_DEVICE_ID_TENANT_ID ON DM_ENROLMENT(DEVICE_ID, TENANT_ID);
|
CREATE INDEX IDX_ENROLMENT_DEVICE_ID_TENANT_ID ON DM_ENROLMENT(DEVICE_ID, TENANT_ID);
|
||||||
|
CREATE INDEX IDX_ENROLMENT_DEVICE_ID_TENANT_ID_STATUS ON DM_ENROLMENT(DEVICE_ID, TENANT_ID, STATUS);
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_ENROLMENT_OP_MAPPING_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
|
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_ENROLMENT_OP_MAPPING_seq') NOT NULL,
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL,
|
||||||
CREATED_TIMESTAMP INTEGER NOT NULL,
|
CREATED_TIMESTAMP INTEGER NOT NULL,
|
||||||
UPDATED_TIMESTAMP INTEGER NOT NULL,
|
UPDATED_TIMESTAMP INTEGER NOT NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
|
,
|
||||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE INDEX fk_dm_device_operation_mapping_operation ON DM_ENROLMENT_OP_MAPPING (OPERATION_ID);
|
||||||
|
CREATE INDEX IDX_DM_ENROLMENT_OP_MAPPING ON DM_ENROLMENT_OP_MAPPING (ENROLMENT_ID,OPERATION_ID);
|
||||||
|
CREATE INDEX ID_DM_ENROLMENT_OP_MAPPING_UPDATED_TIMESTAMP ON DM_ENROLMENT_OP_MAPPING (UPDATED_TIMESTAMP);
|
||||||
|
|
||||||
|
ALTER TABLE DM_ENROLMENT_OP_MAPPING
|
||||||
|
ADD OPERATION_CODE VARCHAR(50) NOT NULL,
|
||||||
|
ADD INITIATED_BY VARCHAR(100) NULL,
|
||||||
|
ADD TYPE VARCHAR(20) NOT NULL,
|
||||||
|
ADD DEVICE_ID INTEGER DEFAULT NULL,
|
||||||
|
ADD DEVICE_TYPE VARCHAR(300) NOT NULL,
|
||||||
|
ADD DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
ADD TENANT_ID INTEGER DEFAULT 0;
|
||||||
|
|
||||||
CREATE INDEX IDX_ENROLMENT_OP_MAPPING ON DM_ENROLMENT_OP_MAPPING (UPDATED_TIMESTAMP);
|
CREATE INDEX IDX_ENROLMENT_OP_MAPPING ON DM_ENROLMENT_OP_MAPPING (UPDATED_TIMESTAMP);
|
||||||
CREATE INDEX IDX_EN_OP_MAPPING_EN_ID ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID);
|
CREATE INDEX IDX_EN_OP_MAPPING_EN_ID ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID);
|
||||||
CREATE INDEX IDX_EN_OP_MAPPING_OP_ID ON DM_ENROLMENT_OP_MAPPING(OPERATION_ID);
|
CREATE INDEX IDX_EN_OP_MAPPING_OP_ID ON DM_ENROLMENT_OP_MAPPING(OPERATION_ID);
|
||||||
|
CREATE INDEX IDX_EN_OP_MAPPING_EN_ID_STATUS ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, STATUS);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
CREATE SEQUENCE DM_DEVICE_OPERATION_RESPONSE_seq;
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE
|
||||||
|
(
|
||||||
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_OPERATION_RESPONSE_seq'),
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
EN_OP_MAP_ID INTEGER NOT NULL,
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
OPERATION_RESPONSE BYTEA DEFAULT NULL,
|
OPERATION_RESPONSE VARCHAR(1024) DEFAULT NULL,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||||
@ -171,21 +178,46 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
|
|||||||
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IDX_ENID_OPID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID);
|
CREATE INDEX IDX_DM_RES_RT ON DM_DEVICE_OPERATION_RESPONSE(RECEIVED_TIMESTAMP);
|
||||||
CREATE INDEX IDX_DM_EN_OP_MAP_RES ON DM_DEVICE_OPERATION_RESPONSE(EN_OP_MAP_ID);
|
CREATE INDEX IDX_ENID_OP_ID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID);
|
||||||
|
CREATE INDEX IDX_DM_EN_OP_MAP_ID ON DM_DEVICE_OPERATION_RESPONSE(EN_OP_MAP_ID);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE_LARGE
|
||||||
|
(
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
OPERATION_RESPONSE BYTEA DEFAULT NULL,
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
EN_OP_MAP_ID INTEGER NOT NULL,
|
||||||
|
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
|
CONSTRAINT fk_dm_device_operation_response_large FOREIGN KEY (ID) REFERENCES
|
||||||
|
DM_DEVICE_OPERATION_RESPONSE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT fk_dm_en_op_map_response_large FOREIGN KEY (EN_OP_MAP_ID) REFERENCES
|
||||||
|
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IDX_DM_RES_LRG_RT ON DM_DEVICE_OPERATION_RESPONSE_LARGE(RECEIVED_TIMESTAMP);
|
||||||
|
CREATE INDEX IDX_OP_RES_LARGE_EN_OP_MAP_ID ON DM_DEVICE_OPERATION_RESPONSE_LARGE(EN_OP_MAP_ID);
|
||||||
|
|
||||||
-- POLICY RELATED TABLES ---
|
-- POLICY RELATED TABLES ---
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_PROFILE_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_PROFILE (
|
CREATE TABLE IF NOT EXISTS DM_PROFILE (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_PROFILE_seq') ,
|
||||||
PROFILE_NAME VARCHAR(45) NOT NULL ,
|
PROFILE_NAME VARCHAR(45) NOT NULL ,
|
||||||
TENANT_ID INTEGER NOT NULL ,
|
TENANT_ID INTEGER NOT NULL ,
|
||||||
DEVICE_TYPE VARCHAR(300) NOT NULL ,
|
DEVICE_TYPE VARCHAR(300) NOT NULL ,
|
||||||
CREATED_TIME TIMESTAMP NOT NULL ,
|
CREATED_TIME TIMESTAMP(0) NOT NULL ,
|
||||||
UPDATED_TIME TIMESTAMP NOT NULL
|
UPDATED_TIME TIMESTAMP(0) NOT NULL ,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_POLICY_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_POLICY (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_POLICY_seq') ,
|
||||||
NAME VARCHAR(45) DEFAULT NULL ,
|
NAME VARCHAR(45) DEFAULT NULL ,
|
||||||
DESCRIPTION VARCHAR(1000) NULL,
|
DESCRIPTION VARCHAR(1000) NULL,
|
||||||
TENANT_ID INTEGER NOT NULL ,
|
TENANT_ID INTEGER NOT NULL ,
|
||||||
@ -195,7 +227,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
|
|||||||
PRIORITY INTEGER NOT NULL,
|
PRIORITY INTEGER NOT NULL,
|
||||||
ACTIVE INTEGER NOT NULL,
|
ACTIVE INTEGER NOT NULL,
|
||||||
UPDATED INTEGER NULL,
|
UPDATED INTEGER NULL,
|
||||||
POLICY_TYPE VARCHAR(45) NULL,
|
PRIMARY KEY (ID) ,
|
||||||
CONSTRAINT FK_DM_PROFILE_DM_POLICY
|
CONSTRAINT FK_DM_PROFILE_DM_POLICY
|
||||||
FOREIGN KEY (PROFILE_ID )
|
FOREIGN KEY (PROFILE_ID )
|
||||||
REFERENCES DM_PROFILE (ID )
|
REFERENCES DM_PROFILE (ID )
|
||||||
@ -203,24 +235,16 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
|
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
CREATE SEQUENCE DM_DEVICE_POLICY_seq;
|
||||||
ACTION_TYPE VARCHAR(45) NOT NULL,
|
|
||||||
CORRECTIVE_POLICY_ID INTEGER DEFAULT NULL,
|
|
||||||
POLICY_ID INTEGER NOT NULL,
|
|
||||||
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
|
|
||||||
FOREIGN KEY (POLICY_ID)
|
|
||||||
REFERENCES DM_POLICY (ID)
|
|
||||||
ON DELETE NO ACTION
|
|
||||||
ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_POLICY_seq') ,
|
||||||
DEVICE_ID INTEGER NOT NULL ,
|
DEVICE_ID INTEGER NOT NULL ,
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
DEVICE BYTEA NOT NULL,
|
DEVICE BYTEA NOT NULL,
|
||||||
POLICY_ID INTEGER NOT NULL ,
|
POLICY_ID INTEGER NOT NULL ,
|
||||||
|
PRIMARY KEY (ID) ,
|
||||||
CONSTRAINT FK_POLICY_DEVICE_POLICY
|
CONSTRAINT FK_POLICY_DEVICE_POLICY
|
||||||
FOREIGN KEY (POLICY_ID )
|
FOREIGN KEY (POLICY_ID )
|
||||||
REFERENCES DM_POLICY (ID )
|
REFERENCES DM_POLICY (ID )
|
||||||
@ -233,6 +257,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
|
||||||
ID INTEGER NOT NULL ,
|
ID INTEGER NOT NULL ,
|
||||||
DEVICE_TYPE VARCHAR(300) NOT NULL ,
|
DEVICE_TYPE VARCHAR(300) NOT NULL ,
|
||||||
@ -245,13 +270,17 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_PROFILE_FEATURES_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
|
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_PROFILE_FEATURES_seq'),
|
||||||
PROFILE_ID INTEGER NOT NULL,
|
PROFILE_ID INTEGER NOT NULL,
|
||||||
FEATURE_CODE VARCHAR(100) NOT NULL,
|
FEATURE_CODE VARCHAR(100) NOT NULL,
|
||||||
DEVICE_TYPE VARCHAR(300) NOT NULL ,
|
DEVICE_TYPE VARCHAR(300) NOT NULL ,
|
||||||
TENANT_ID INTEGER NOT NULL ,
|
TENANT_ID INTEGER NOT NULL ,
|
||||||
CONTENT BYTEA NULL DEFAULT NULL,
|
CONTENT BYTEA NULL DEFAULT NULL,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
|
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
|
||||||
FOREIGN KEY (PROFILE_ID)
|
FOREIGN KEY (PROFILE_ID)
|
||||||
REFERENCES DM_PROFILE (ID)
|
REFERENCES DM_PROFILE (ID)
|
||||||
@ -259,10 +288,14 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_ROLE_POLICY_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_ROLE_POLICY_seq') ,
|
||||||
ROLE_NAME VARCHAR(45) NOT NULL ,
|
ROLE_NAME VARCHAR(45) NOT NULL ,
|
||||||
POLICY_ID INTEGER NOT NULL ,
|
POLICY_ID INTEGER NOT NULL ,
|
||||||
|
PRIMARY KEY (ID) ,
|
||||||
CONSTRAINT FK_ROLE_POLICY_POLICY
|
CONSTRAINT FK_ROLE_POLICY_POLICY
|
||||||
FOREIGN KEY (POLICY_ID )
|
FOREIGN KEY (POLICY_ID )
|
||||||
REFERENCES DM_POLICY (ID )
|
REFERENCES DM_POLICY (ID )
|
||||||
@ -270,10 +303,14 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_USER_POLICY_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_USER_POLICY_seq') ,
|
||||||
POLICY_ID INT NOT NULL ,
|
POLICY_ID INTEGER NOT NULL ,
|
||||||
USERNAME VARCHAR(45) NOT NULL ,
|
USERNAME VARCHAR(45) NOT NULL ,
|
||||||
|
PRIMARY KEY (ID) ,
|
||||||
CONSTRAINT DM_POLICY_USER_POLICY
|
CONSTRAINT DM_POLICY_USER_POLICY
|
||||||
FOREIGN KEY (POLICY_ID )
|
FOREIGN KEY (POLICY_ID )
|
||||||
REFERENCES DM_POLICY (ID )
|
REFERENCES DM_POLICY (ID )
|
||||||
@ -281,34 +318,46 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_DEVICE_POLICY_APPLIED_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_POLICY_APPLIED_seq') ,
|
||||||
DEVICE_ID INTEGER NOT NULL ,
|
DEVICE_ID INTEGER NOT NULL ,
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
POLICY_ID INTEGER NOT NULL ,
|
POLICY_ID INTEGER NOT NULL ,
|
||||||
POLICY_CONTENT BYTEA NULL ,
|
POLICY_CONTENT BYTEA NULL ,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
APPLIED BOOLEAN NULL ,
|
APPLIED SMALLINT NULL ,
|
||||||
CREATED_TIME TIMESTAMP NULL ,
|
CREATED_TIME TIMESTAMP(0) NULL ,
|
||||||
UPDATED_TIME TIMESTAMP NULL ,
|
UPDATED_TIME TIMESTAMP(0) NULL ,
|
||||||
APPLIED_TIME TIMESTAMP NULL ,
|
APPLIED_TIME TIMESTAMP(0) NULL ,
|
||||||
CONSTRAINT FK_DM_POLICY_DEVICE_APPLIED
|
PRIMARY KEY (ID) ,
|
||||||
|
CONSTRAINT FK_DM_POLICY_DEVCIE_APPLIED
|
||||||
FOREIGN KEY (DEVICE_ID )
|
FOREIGN KEY (DEVICE_ID )
|
||||||
REFERENCES DM_DEVICE (ID )
|
REFERENCES DM_DEVICE (ID )
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_CRITERIA_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
|
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_CRITERIA_seq'),
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
NAME VARCHAR(50) NULL
|
NAME VARCHAR(50) NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_POLICY_CRITERIA_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_POLICY_CRITERIA_seq'),
|
||||||
CRITERIA_ID INT NOT NULL,
|
CRITERIA_ID INTEGER NOT NULL,
|
||||||
POLICY_ID INT NOT NULL,
|
POLICY_ID INTEGER NOT NULL,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT FK_CRITERIA_POLICY_CRITERIA
|
CONSTRAINT FK_CRITERIA_POLICY_CRITERIA
|
||||||
FOREIGN KEY (CRITERIA_ID)
|
FOREIGN KEY (CRITERIA_ID)
|
||||||
REFERENCES DM_CRITERIA (ID)
|
REFERENCES DM_CRITERIA (ID)
|
||||||
@ -321,46 +370,61 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_POLICY_CRITERIA_PROPERTIES_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_POLICY_CRITERIA_PROPERTIES_seq'),
|
||||||
POLICY_CRITERION_ID INT NOT NULL,
|
POLICY_CRITERION_ID INTEGER NOT NULL,
|
||||||
PROP_KEY VARCHAR(45) NULL,
|
PROP_KEY VARCHAR(45) NULL,
|
||||||
PROP_VALUE VARCHAR(100) NULL,
|
PROP_VALUE VARCHAR(100) NULL,
|
||||||
CONTENT BYTEA NULL ,
|
CONTENT BYTEA NULL ,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES
|
CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES
|
||||||
FOREIGN KEY (POLICY_CRITERION_ID)
|
FOREIGN KEY (POLICY_CRITERION_ID)
|
||||||
REFERENCES DM_POLICY_CRITERIA (ID)
|
REFERENCES DM_POLICY_CRITERIA (ID)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
COMMENT ON COLUMN DM_POLICY_CRITERIA_PROPERTIES.CONTENT IS 'This is used to ';
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_POLICY_COMPLIANCE_STATUS_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_POLICY_COMPLIANCE_STATUS_seq'),
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
POLICY_ID INTEGER NOT NULL,
|
POLICY_ID INTEGER NOT NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
STATUS INTEGER NULL,
|
STATUS INTEGER NULL,
|
||||||
LAST_SUCCESS_TIME TIMESTAMP NULL,
|
LAST_SUCCESS_TIME TIMESTAMP(0) NULL,
|
||||||
LAST_REQUESTED_TIME TIMESTAMP NULL,
|
LAST_REQUESTED_TIME TIMESTAMP(0) NULL,
|
||||||
LAST_FAILED_TIME TIMESTAMP NULL,
|
LAST_FAILED_TIME TIMESTAMP(0) NULL,
|
||||||
ATTEMPTS INTEGER NULL
|
ATTEMPTS INTEGER NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_POLICY_CHANGE_MGT_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_POLICY_CHANGE_MGT_seq'),
|
||||||
POLICY_ID INTEGER NOT NULL,
|
POLICY_ID INTEGER NOT NULL,
|
||||||
DEVICE_TYPE VARCHAR(300) NOT NULL ,
|
DEVICE_TYPE VARCHAR(300) NOT NULL ,
|
||||||
TENANT_ID INTEGER NOT NULL
|
TENANT_ID INTEGER NOT NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_POLICY_COMPLIANCE_FEATURES_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_POLICY_COMPLIANCE_FEATURES_seq'),
|
||||||
COMPLIANCE_STATUS_ID INTEGER NOT NULL,
|
COMPLIANCE_STATUS_ID INTEGER NOT NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
FEATURE_CODE VARCHAR(100) NOT NULL,
|
FEATURE_CODE VARCHAR(100) NOT NULL,
|
||||||
STATUS INTEGER NULL,
|
STATUS INTEGER NULL,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
|
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
|
||||||
FOREIGN KEY (COMPLIANCE_STATUS_ID)
|
FOREIGN KEY (COMPLIANCE_STATUS_ID)
|
||||||
REFERENCES DM_POLICY_COMPLIANCE_STATUS (ID)
|
REFERENCES DM_POLICY_COMPLIANCE_STATUS (ID)
|
||||||
@ -368,8 +432,10 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_APPLICATION_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_APPLICATION_seq') NOT NULL,
|
||||||
NAME VARCHAR(150) NOT NULL,
|
NAME VARCHAR(150) NOT NULL,
|
||||||
APP_IDENTIFIER VARCHAR(150) NOT NULL,
|
APP_IDENTIFIER VARCHAR(150) NOT NULL,
|
||||||
PLATFORM VARCHAR(50) DEFAULT NULL,
|
PLATFORM VARCHAR(50) DEFAULT NULL,
|
||||||
@ -384,21 +450,25 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
|||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
ENROLMENT_ID INTEGER NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
CONSTRAINT fk_dm_enrollement FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
-- POLICY RELATED TABLES FINISHED --
|
-- END OF POLICY RELATED TABLES --
|
||||||
|
|
||||||
-- POLICY AND DEVICE GROUP MAPPING --
|
-- POLICY AND DEVICE GROUP MAPPING --
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_GROUP_POLICY_seq'),
|
||||||
DEVICE_GROUP_ID INTEGER NOT NULL,
|
DEVICE_GROUP_ID INTEGER NOT NULL,
|
||||||
POLICY_ID INTEGER NOT NULL,
|
POLICY_ID INTEGER NOT NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
|
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
|
||||||
FOREIGN KEY (DEVICE_GROUP_ID)
|
FOREIGN KEY (DEVICE_GROUP_ID)
|
||||||
REFERENCES DM_GROUP (ID)
|
REFERENCES DM_GROUP (ID)
|
||||||
@ -413,30 +483,37 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
|
|||||||
|
|
||||||
-- END OF POLICY AND DEVICE GROUP MAPPING --
|
-- END OF POLICY AND DEVICE GROUP MAPPING --
|
||||||
|
|
||||||
-- NOTIFICATION TABLE --
|
-- NOTIFICATION TABLES --
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_NOTIFICATION_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
|
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
|
||||||
NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY,
|
NOTIFICATION_ID INTEGER DEFAULT NEXTVAL ('DM_NOTIFICATION_seq') NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NULL,
|
OPERATION_ID INTEGER NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
STATUS VARCHAR(10) NULL,
|
STATUS VARCHAR(10) NULL,
|
||||||
DESCRIPTION VARCHAR(1000) NULL,
|
DESCRIPTION VARCHAR(1000) NULL,
|
||||||
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
LAST_UPDATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
|
||||||
|
PRIMARY KEY (NOTIFICATION_ID),
|
||||||
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
-- NOTIFICATION TABLE END --
|
CREATE INDEX IDX_NOTF_UT ON DM_NOTIFICATION(LAST_UPDATED_TIMESTAMP);
|
||||||
|
|
||||||
-- Device Info and Search Table --
|
-- END NOTIFICATION TABLES --
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_DEVICE_INFO_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_INFO_seq') NOT NULL,
|
||||||
DEVICE_ID INT NOT NULL,
|
DEVICE_ID INTEGER NULL,
|
||||||
ENROLMENT_ID INT NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
KEY_FIELD VARCHAR(45) NULL,
|
KEY_FIELD VARCHAR(45) NULL,
|
||||||
VALUE_FIELD VARCHAR(1000) NULL,
|
VALUE_FIELD VARCHAR(100) NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
|
,
|
||||||
CONSTRAINT DM_DEVICE_INFO_DEVICE
|
CONSTRAINT DM_DEVICE_INFO_DEVICE
|
||||||
FOREIGN KEY (DEVICE_ID)
|
FOREIGN KEY (DEVICE_ID)
|
||||||
REFERENCES DM_DEVICE (ID)
|
REFERENCES DM_DEVICE (ID)
|
||||||
@ -447,12 +524,17 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
|
|||||||
REFERENCES DM_ENROLMENT (ID)
|
REFERENCES DM_ENROLMENT (ID)
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC);
|
||||||
|
CREATE INDEX DM_DEVICE_INFO_DEVICE_ENROLLMENT_idx ON DM_DEVICE_INFO (ENROLMENT_ID ASC);
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_DEVICE_LOCATION_seq;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_LOCATION_seq') NOT NULL,
|
||||||
DEVICE_ID INT NOT NULL,
|
DEVICE_ID INT NULL,
|
||||||
ENROLMENT_ID INT NOT NULL,
|
ENROLMENT_ID INT NOT NULL,
|
||||||
LATITUDE DOUBLE PRECISION NULL,
|
LATITUDE DOUBLE PRECISION NULL,
|
||||||
LONGITUDE DOUBLE PRECISION NULL,
|
LONGITUDE DOUBLE PRECISION NULL,
|
||||||
@ -464,10 +546,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
|
|||||||
COUNTRY VARCHAR(45) NULL,
|
COUNTRY VARCHAR(45) NULL,
|
||||||
GEO_HASH VARCHAR(45) NULL,
|
GEO_HASH VARCHAR(45) NULL,
|
||||||
UPDATE_TIMESTAMP BIGINT NOT NULL,
|
UPDATE_TIMESTAMP BIGINT NOT NULL,
|
||||||
ALTITUDE DOUBLE PRECISION NULL,
|
PRIMARY KEY (ID)
|
||||||
SPEED FLOAT NULL,
|
,
|
||||||
BEARING FLOAT NULL,
|
|
||||||
DISTANCE DOUBLE PRECISION NULL,
|
|
||||||
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
|
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
|
||||||
FOREIGN KEY (DEVICE_ID)
|
FOREIGN KEY (DEVICE_ID)
|
||||||
REFERENCES DM_DEVICE (ID)
|
REFERENCES DM_DEVICE (ID)
|
||||||
@ -478,37 +558,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
|
|||||||
REFERENCES DM_ENROLMENT (ID)
|
REFERENCES DM_ENROLMENT (ID)
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
)
|
||||||
|
;
|
||||||
|
|
||||||
|
CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC);
|
||||||
CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION (GEO_HASH ASC);
|
CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION (GEO_HASH ASC);
|
||||||
|
CREATE INDEX DM_DEVICE_LOCATION_DM_ENROLLMENT_idx ON DM_DEVICE_LOCATION (ENROLMENT_ID ASC);
|
||||||
|
|
||||||
|
CREATE SEQUENCE DM_DEVICE_DETAIL_seq;
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_HISTORY_LAST_SEVEN_DAYS (
|
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
|
||||||
DEVICE_ID_NAME VARCHAR(255) NOT NULL,
|
|
||||||
TENANT_ID INTEGER NOT NULL,
|
|
||||||
DEVICE_TYPE_NAME VARCHAR(45) NOT NULL,
|
|
||||||
LATITUDE DOUBLE PRECISION NULL,
|
|
||||||
LONGITUDE DOUBLE PRECISION NULL,
|
|
||||||
SPEED FLOAT NULL,
|
|
||||||
HEADING FLOAT NULL,
|
|
||||||
TIMESTAMP BIGINT NOT NULL,
|
|
||||||
GEO_HASH VARCHAR(45) NULL,
|
|
||||||
DEVICE_OWNER VARCHAR(45) NULL,
|
|
||||||
DEVICE_ALTITUDE DOUBLE PRECISION NULL,
|
|
||||||
DISTANCE DOUBLE PRECISION NULL,
|
|
||||||
CONSTRAINT DM_DEVICE_HISTORY_LAST_SEVEN_DAYS
|
|
||||||
FOREIGN KEY (DEVICE_ID)
|
|
||||||
REFERENCES DM_DEVICE (ID)
|
|
||||||
ON DELETE NO ACTION
|
|
||||||
ON UPDATE NO ACTION
|
|
||||||
);
|
|
||||||
CREATE INDEX DM_DEVICE_HISTORY_LAST_SEVEN_DAYS_GEO_hashx ON DM_DEVICE_HISTORY_LAST_SEVEN_DAYS(GEO_HASH ASC);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'),
|
||||||
DEVICE_ID INT NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
ENROLMENT_ID INT NOT NULL,
|
ENROLMENT_ID INTEGER NOT NULL,
|
||||||
DEVICE_MODEL VARCHAR(45) NULL,
|
DEVICE_MODEL VARCHAR(45) NULL,
|
||||||
VENDOR VARCHAR(45) NULL,
|
VENDOR VARCHAR(45) NULL,
|
||||||
OS_VERSION VARCHAR(45) NULL,
|
OS_VERSION VARCHAR(45) NULL,
|
||||||
@ -523,8 +585,10 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
|||||||
CPU_USAGE DECIMAL(5) NULL,
|
CPU_USAGE DECIMAL(5) NULL,
|
||||||
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
|
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
|
||||||
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
|
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
|
||||||
PLUGGED_IN BOOLEAN NOT NULL DEFAULT FALSE,
|
PLUGGED_IN Boolean NULL,
|
||||||
UPDATE_TIMESTAMP BIGINT NOT NULL,
|
UPDATE_TIMESTAMP BIGINT NOT NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
|
,
|
||||||
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
|
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
|
||||||
FOREIGN KEY (DEVICE_ID)
|
FOREIGN KEY (DEVICE_ID)
|
||||||
REFERENCES DM_DEVICE (ID)
|
REFERENCES DM_DEVICE (ID)
|
||||||
@ -535,36 +599,16 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
|||||||
REFERENCES DM_ENROLMENT (ID)
|
REFERENCES DM_ENROLMENT (ID)
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
)
|
||||||
|
;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_PLATFORM (
|
CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC);
|
||||||
ID BIGSERIAL NOT NULL PRIMARY KEY,
|
CREATE INDEX FK_DM_ENROLMENT_DEVICE_DETAILS_idx ON DM_DEVICE_DETAIL (ENROLMENT_ID ASC);
|
||||||
DEVICE_TYPE_ID INT DEFAULT 0,
|
|
||||||
VERSION_NAME VARCHAR(100) NULL,
|
|
||||||
VERSION_STATUS VARCHAR(100) DEFAULT 'ACTIVE',
|
|
||||||
CONSTRAINT FK_DM_DEVICE_TYPE_PLATFORM_MAPPING
|
|
||||||
FOREIGN KEY (DEVICE_TYPE_ID)
|
|
||||||
REFERENCES DM_DEVICE_TYPE (ID)
|
|
||||||
ON DELETE NO ACTION
|
|
||||||
ON UPDATE NO ACTION,
|
|
||||||
CONSTRAINT device_type_version_uk
|
|
||||||
UNIQUE (DEVICE_TYPE_ID, VERSION_NAME)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- DASHBOARD RELATED VIEWS --
|
-- DASHBOARD RELATED VIEWS --
|
||||||
|
|
||||||
CREATE VIEW POLICY_COMPLIANCE_INFO AS
|
CREATE VIEW DEVICE_INFO_VIEW AS
|
||||||
SELECT
|
SELECT
|
||||||
DEVICE_INFO.DEVICE_ID,
|
|
||||||
DEVICE_INFO.DEVICE_IDENTIFICATION,
|
|
||||||
DEVICE_INFO.PLATFORM,
|
|
||||||
DEVICE_INFO.OWNERSHIP,
|
|
||||||
DEVICE_INFO.CONNECTIVITY_STATUS,
|
|
||||||
COALESCE(DEVICE_WITH_POLICY_INFO.POLICY_ID, -1) AS POLICY_ID,
|
|
||||||
COALESCE(DEVICE_WITH_POLICY_INFO.IS_COMPLIANT, -1) AS IS_COMPLIANT,
|
|
||||||
DEVICE_INFO.TENANT_ID
|
|
||||||
FROM
|
|
||||||
(SELECT
|
|
||||||
DM_DEVICE.ID AS DEVICE_ID,
|
DM_DEVICE.ID AS DEVICE_ID,
|
||||||
DM_DEVICE.DEVICE_IDENTIFICATION,
|
DM_DEVICE.DEVICE_IDENTIFICATION,
|
||||||
DM_DEVICE_TYPE.NAME AS PLATFORM,
|
DM_DEVICE_TYPE.NAME AS PLATFORM,
|
||||||
@ -572,15 +616,31 @@ DM_ENROLMENT.OWNERSHIP,
|
|||||||
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
|
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
|
||||||
DM_DEVICE.TENANT_ID
|
DM_DEVICE.TENANT_ID
|
||||||
FROM DM_DEVICE, DM_DEVICE_TYPE, DM_ENROLMENT
|
FROM DM_DEVICE, DM_DEVICE_TYPE, DM_ENROLMENT
|
||||||
WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) DEVICE_INFO
|
WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID;
|
||||||
LEFT JOIN
|
|
||||||
(SELECT
|
CREATE VIEW DEVICE_WITH_POLICY_INFO_VIEW AS
|
||||||
|
SELECT
|
||||||
DEVICE_ID,
|
DEVICE_ID,
|
||||||
POLICY_ID,
|
POLICY_ID,
|
||||||
STATUS AS IS_COMPLIANT
|
STATUS AS IS_COMPLIANT
|
||||||
FROM DM_POLICY_COMPLIANCE_STATUS) DEVICE_WITH_POLICY_INFO
|
FROM DM_POLICY_COMPLIANCE_STATUS;
|
||||||
ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID
|
|
||||||
ORDER BY DEVICE_INFO.DEVICE_ID;
|
CREATE VIEW POLICY_COMPLIANCE_INFO AS
|
||||||
|
SELECT
|
||||||
|
DEVICE_INFO_VIEW.DEVICE_ID,
|
||||||
|
DEVICE_INFO_VIEW.DEVICE_IDENTIFICATION,
|
||||||
|
DEVICE_INFO_VIEW.PLATFORM,
|
||||||
|
DEVICE_INFO_VIEW.OWNERSHIP,
|
||||||
|
DEVICE_INFO_VIEW.CONNECTIVITY_STATUS,
|
||||||
|
COALESCE(DEVICE_WITH_POLICY_INFO_VIEW.POLICY_ID, -1) AS POLICY_ID,
|
||||||
|
COALESCE(DEVICE_WITH_POLICY_INFO_VIEW.IS_COMPLIANT, -1) AS IS_COMPLIANT,
|
||||||
|
DEVICE_INFO_VIEW.TENANT_ID
|
||||||
|
FROM
|
||||||
|
DEVICE_INFO_VIEW
|
||||||
|
LEFT JOIN
|
||||||
|
DEVICE_WITH_POLICY_INFO_VIEW
|
||||||
|
ON DEVICE_INFO_VIEW.DEVICE_ID = DEVICE_WITH_POLICY_INFO_VIEW.DEVICE_ID
|
||||||
|
ORDER BY DEVICE_INFO_VIEW.DEVICE_ID;
|
||||||
|
|
||||||
CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS
|
CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS
|
||||||
SELECT
|
SELECT
|
||||||
@ -608,3 +668,10 @@ DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
|
|||||||
ORDER BY TENANT_ID, DEVICE_ID;
|
ORDER BY TENANT_ID, DEVICE_ID;
|
||||||
|
|
||||||
-- END OF DASHBOARD RELATED VIEWS --
|
-- END OF DASHBOARD RELATED VIEWS --
|
||||||
|
|
||||||
|
-- TEMP TABLE REQUIRED FOR DATA ARCHIVAL JOB
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_ARCHIVED_OPERATIONS (
|
||||||
|
ID INTEGER NOT NULL,
|
||||||
|
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
|
);
|
||||||
Loading…
Reference in New Issue
Block a user