mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Refractor Operations to handle Policy Operations and remove joins
This commit is contained in:
parent
8ee09793f2
commit
917c0cf965
@ -44,6 +44,65 @@ public class Operation implements Serializable {
|
|||||||
private boolean isEnabled;
|
private boolean isEnabled;
|
||||||
private Object payLoad;
|
private Object payLoad;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Operation operation = (Operation) o;
|
||||||
|
|
||||||
|
if (id != operation.id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isEnabled != operation.isEnabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!code.equals(operation.code)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (createdTimeStamp != null ?
|
||||||
|
!createdTimeStamp.equals(operation.createdTimeStamp) :
|
||||||
|
operation.createdTimeStamp != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (payLoad != null ? !payLoad.equals(operation.payLoad) : operation.payLoad != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (properties != null ? !properties.equals(operation.properties) : operation.properties != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!receivedTimeStamp.equals(operation.receivedTimeStamp)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (status != operation.status) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (type != operation.type) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = code.hashCode();
|
||||||
|
result = 31 * result + (properties != null ? properties.hashCode() : 0);
|
||||||
|
result = 31 * result + type.hashCode();
|
||||||
|
result = 31 * result + id;
|
||||||
|
result = 31 * result + status.hashCode();
|
||||||
|
result = 31 * result + receivedTimeStamp.hashCode();
|
||||||
|
result = 31 * result + (createdTimeStamp != null ? createdTimeStamp.hashCode() : 0);
|
||||||
|
result = 31 * result + (isEnabled ? 1 : 0);
|
||||||
|
result = 31 * result + (payLoad != null ? payLoad.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return code;
|
return code;
|
||||||
|
|||||||
@ -71,5 +71,4 @@ public interface OperationManager {
|
|||||||
|
|
||||||
public Operation getOperation(int operationId) throws OperationManagementException;
|
public Operation getOperation(int operationId) throws OperationManagementException;
|
||||||
|
|
||||||
public List<? extends Operation> getOperationsForStatus(Operation.Status status) throws OperationManagementException;
|
|
||||||
}
|
}
|
||||||
@ -484,12 +484,6 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
|
|||||||
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId);
|
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<? extends Operation> getOperationsForStatus(Operation.Status status)
|
|
||||||
throws OperationManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationsForStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getAllDevicesOfUser(String userName)
|
public List<Device> getAllDevicesOfUser(String userName)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import java.util.Properties;
|
|||||||
public class Operation implements Serializable {
|
public class Operation implements Serializable {
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
CONFIG, MESSAGE, INFO, COMMAND, PROFILE
|
CONFIG, MESSAGE, INFO, COMMAND, PROFILE , POLICY
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
|
|||||||
@ -26,17 +26,17 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|||||||
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.common.operation.mgt.OperationManager;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.*;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation;
|
|
||||||
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;
|
||||||
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.OperationMappingDAO;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
||||||
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 org.wso2.carbon.device.mgt.core.operation.mgt.util.OperationCreateTimeComparator;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,6 +51,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
private OperationDAO commandOperationDAO;
|
private OperationDAO commandOperationDAO;
|
||||||
private OperationDAO configOperationDAO;
|
private OperationDAO configOperationDAO;
|
||||||
private OperationDAO profileOperationDAO;
|
private OperationDAO profileOperationDAO;
|
||||||
|
private OperationDAO policyOperationDAO;
|
||||||
private OperationMappingDAO operationMappingDAO;
|
private OperationMappingDAO operationMappingDAO;
|
||||||
private OperationDAO operationDAO;
|
private OperationDAO operationDAO;
|
||||||
private DeviceManagementService deviceManagementService;
|
private DeviceManagementService deviceManagementService;
|
||||||
@ -79,7 +80,6 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
OperationManagementDAOFactory.beginTransaction();
|
OperationManagementDAOFactory.beginTransaction();
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
||||||
OperationDAOUtil.convertOperation(operation);
|
OperationDAOUtil.convertOperation(operation);
|
||||||
operationDto.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING);
|
|
||||||
|
|
||||||
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
||||||
org.wso2.carbon.device.mgt.common.Device device;
|
org.wso2.carbon.device.mgt.common.Device device;
|
||||||
@ -163,8 +163,10 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
org.wso2.carbon.device.mgt.common.Device device;
|
org.wso2.carbon.device.mgt.common.Device device;
|
||||||
List<Operation> operations;
|
List<Operation> operations = new ArrayList<Operation>();
|
||||||
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList;
|
|
||||||
|
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
||||||
|
new ArrayList<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -174,15 +176,25 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
throw new OperationManagementException("Device not found for given device " +
|
throw new OperationManagementException("Device not found for given device " +
|
||||||
"Identifier:" + deviceIdentifier.getId() + " and given type:" + deviceIdentifier.getType());
|
"Identifier:" + deviceIdentifier.getId() + " and given type:" + deviceIdentifier.getType());
|
||||||
}
|
}
|
||||||
operations = new ArrayList<Operation>();
|
|
||||||
dtoOperationList = operationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING);
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
|
||||||
|
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
|
||||||
|
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
|
||||||
|
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
|
||||||
Operation operation;
|
Operation operation;
|
||||||
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
operations.add(operation);
|
operations.add(operation);
|
||||||
}
|
}
|
||||||
|
Collections.sort(operations, new OperationCreateTimeComparator());
|
||||||
return operations;
|
return operations;
|
||||||
} catch (DeviceManagementException deviceMgtException) {
|
} catch (DeviceManagementException deviceMgtException) {
|
||||||
String errorMsg = "Error occurred while retrieving the device " +
|
String errorMsg = "Error occurred while retrieving the device " +
|
||||||
@ -201,7 +213,8 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
public Operation getNextPendingOperation(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType() + "]");
|
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType()
|
||||||
|
+ "]");
|
||||||
}
|
}
|
||||||
Operation operation = null;
|
Operation operation = null;
|
||||||
Device device;
|
Device device;
|
||||||
@ -214,6 +227,25 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
}
|
}
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
||||||
.getNextOperation(device.getId());
|
.getNextOperation(device.getId());
|
||||||
|
|
||||||
|
if (dtoOperation.getType()
|
||||||
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
||||||
|
commandOperation = (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO
|
||||||
|
.getOperation(dtoOperation.getId());
|
||||||
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
||||||
|
} else if (dtoOperation.getType()
|
||||||
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
||||||
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
||||||
|
.PROFILE)) {
|
||||||
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
||||||
|
.POLICY)) {
|
||||||
|
|
||||||
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
}
|
||||||
|
|
||||||
if (dtoOperation != null) {
|
if (dtoOperation != null) {
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
}
|
}
|
||||||
@ -224,7 +256,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
+ deviceIdentifier.getId();
|
+ deviceIdentifier.getId();
|
||||||
log.error(errorMsg, deviceMgtException);
|
log.error(errorMsg, deviceMgtException);
|
||||||
throw new OperationManagementException(errorMsg, deviceMgtException);
|
throw new OperationManagementException(errorMsg, deviceMgtException);
|
||||||
} catch (OperationManagementDAOException e) {
|
} catch (OperationManagementDAOException e) {
|
||||||
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
|
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,6 +341,24 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
||||||
.getOperationByDeviceAndId(device.getId(), operationId);
|
.getOperationByDeviceAndId(device.getId(), operationId);
|
||||||
|
|
||||||
|
if (dtoOperation.getType()
|
||||||
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
||||||
|
commandOperation = (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO
|
||||||
|
.getOperation(dtoOperation.getId());
|
||||||
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
||||||
|
} else if (dtoOperation.getType()
|
||||||
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
||||||
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
||||||
|
.PROFILE)) {
|
||||||
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
||||||
|
.POLICY)) {
|
||||||
|
|
||||||
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
}
|
||||||
|
|
||||||
if (dtoOperation == null) {
|
if (dtoOperation == null) {
|
||||||
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
|
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
|
||||||
" device" + " Id:" + device.getId());
|
" device" + " Id:" + device.getId());
|
||||||
@ -334,19 +384,30 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<Operation> operations = new ArrayList<Operation>();
|
List<Operation> operations = new ArrayList<Operation>();
|
||||||
|
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
||||||
|
new ArrayList<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation>();
|
||||||
|
|
||||||
org.wso2.carbon.device.mgt.common.Device device = deviceManagementService.getCoreDevice(identifier);
|
org.wso2.carbon.device.mgt.common.Device device = deviceManagementService.getCoreDevice(identifier);
|
||||||
|
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
throw new DeviceManagementException("Device not found for device id:" + identifier.getId() + " " +
|
throw new DeviceManagementException("Device not found for device id:" + identifier.getId() + " " +
|
||||||
"type:" + identifier.getType());
|
"type:" + identifier.getType());
|
||||||
}
|
}
|
||||||
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
|
||||||
operationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
|
|
||||||
.valueOf(status.toString()));
|
|
||||||
|
|
||||||
Operation operation = null;
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status dtoOpStatus = org.wso2.carbon.device
|
||||||
PolicyOperation policyOperation;
|
.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString());
|
||||||
|
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(device.getId(), dtoOpStatus));
|
||||||
|
|
||||||
|
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
|
||||||
|
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
|
||||||
|
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||||
|
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) {
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
@ -375,6 +436,25 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
if (dtoOperation == null) {
|
if (dtoOperation == null) {
|
||||||
throw new OperationManagementException("Operation not found for given Id:" + operationId);
|
throw new OperationManagementException("Operation not found for given Id:" + operationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dtoOperation.getType()
|
||||||
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
||||||
|
commandOperation = (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO
|
||||||
|
.getOperation(dtoOperation.getId());
|
||||||
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
||||||
|
} else if (dtoOperation.getType()
|
||||||
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
||||||
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
||||||
|
.PROFILE)) {
|
||||||
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
||||||
|
.POLICY)) {
|
||||||
|
|
||||||
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
}
|
||||||
|
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
} catch (OperationManagementDAOException e) {
|
} catch (OperationManagementDAOException e) {
|
||||||
String errorMsg = "Error occurred while retrieving the operation with operation Id '" + operationId;
|
String errorMsg = "Error occurred while retrieving the operation with operation Id '" + operationId;
|
||||||
@ -384,28 +464,6 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<? extends Operation> getOperationsForStatus(Operation.Status status)
|
|
||||||
throws OperationManagementException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<Operation> operations = new ArrayList<Operation>();
|
|
||||||
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
|
||||||
operationDAO.getOperationsForStatus(
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
|
|
||||||
.valueOf(status.toString()));
|
|
||||||
Operation operation;
|
|
||||||
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
||||||
operations.add(operation);
|
|
||||||
}
|
|
||||||
return operations;
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
||||||
"operations for status:'" + status.toString(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private OperationDAO lookupOperationDAO(Operation operation) {
|
private OperationDAO lookupOperationDAO(Operation operation) {
|
||||||
|
|
||||||
if (operation instanceof CommandOperation) {
|
if (operation instanceof CommandOperation) {
|
||||||
|
|||||||
@ -40,8 +40,6 @@ public interface OperationDAO {
|
|||||||
|
|
||||||
List<? extends Operation> getOperationsForDevice(int deviceId) throws OperationManagementDAOException;
|
List<? extends Operation> getOperationsForDevice(int deviceId) throws OperationManagementDAOException;
|
||||||
|
|
||||||
List<? extends Operation> getOperationsForStatus(Operation.Status status) throws OperationManagementDAOException;
|
|
||||||
|
|
||||||
Operation getNextOperation(int deviceId) throws OperationManagementDAOException;
|
Operation getNextOperation(int deviceId) throws OperationManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||||
@ -34,6 +36,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CommandOperationDAOImpl extends OperationDAOImpl {
|
public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(CommandOperationDAOImpl.class);
|
||||||
@Override
|
@Override
|
||||||
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
||||||
|
|
||||||
@ -94,4 +97,79 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandOperation getOperation(int id) throws OperationManagementDAOException {
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
CommandOperation commandOperation = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT OPERATION_ID, ENABLED FROM DM_COMMAND_OPERATION WHERE OPERATION_ID=?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, id);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
commandOperation = new CommandOperation();
|
||||||
|
commandOperation.setEnabled(rs.getInt("ENABLED") == 0 ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL Error occurred while retrieving the command operation object " + "available for " +
|
||||||
|
"the id '"
|
||||||
|
+ id;
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return commandOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId,
|
||||||
|
Operation.Status status) throws OperationManagementDAOException {
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Operation operation;
|
||||||
|
|
||||||
|
List<Operation> operationList = new ArrayList<Operation>();
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "Select co.OPERATION_ID,ENABLED from DM_COMMAND_OPERATION co "+
|
||||||
|
"INNER JOIN "+
|
||||||
|
"(Select * From DM_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID=? "+
|
||||||
|
"AND STATUS=? ) dm ON dm.OPERATION_ID = co.OPERATION_ID";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setString(2, status.toString());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
int operationId;
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
|
||||||
|
operationId = rs.getInt("ID");
|
||||||
|
operation = super.getOperation(operationId);
|
||||||
|
operation.setEnabled(rs.getInt("ENABLED") == 0?false:true);
|
||||||
|
operationList.add(operation);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||||
|
"' with status '" + status.toString();
|
||||||
|
log.error(errorMsg);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return operationList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,18 +19,28 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.service.component.annotations.ConfigurationPolicy;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation;
|
||||||
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.ConfigOperation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation;
|
||||||
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 java.io.*;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(ConfigOperationDAOImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
||||||
|
|
||||||
@ -38,8 +48,9 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID) VALUES(?)");
|
stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID, OPERATION_CONFIG) VALUES(?,?)");
|
||||||
stmt.setInt(1, operationId);
|
stmt.setInt(1, operationId);
|
||||||
|
stmt.setObject(2, operation);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementDAOException("Error occurred while adding command operation", e);
|
throw new OperationManagementDAOException("Error occurred while adding command operation", e);
|
||||||
@ -65,4 +76,162 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
|||||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
OperationManagementDAOUtil.cleanupResources(stmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ByteArrayOutputStream bao = null;
|
||||||
|
ObjectOutputStream oos = null;
|
||||||
|
super.updateOperation(operation);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
|
stmt = connection.prepareStatement("UPDATE DM_CONFIG_OPERATION O SET O.OPERATION_CONFIG=? " +
|
||||||
|
"WHERE O.OPERATION_ID=?");
|
||||||
|
|
||||||
|
bao = new ByteArrayOutputStream();
|
||||||
|
oos = new ObjectOutputStream(bao);
|
||||||
|
oos.writeObject(operation);
|
||||||
|
|
||||||
|
stmt.setBytes(1, bao.toByteArray());
|
||||||
|
stmt.setInt(2, operation.getId());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementDAOException("Error occurred while update policy operation metadata", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e);
|
||||||
|
} finally {
|
||||||
|
if (bao != null) {
|
||||||
|
try {
|
||||||
|
bao.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("Error occurred while closing ByteArrayOutputStream", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (oos != null) {
|
||||||
|
try {
|
||||||
|
oos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("Error occurred while closing ObjectOutputStream", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation getOperation(int operationId) throws OperationManagementDAOException {
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
ConfigOperation configOperation = null;
|
||||||
|
|
||||||
|
ByteArrayInputStream bais;
|
||||||
|
ObjectInputStream ois;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_CONFIG FROM DM_CONFIG_OPERATION WHERE OPERATION_ID=?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, operationId);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
|
||||||
|
bais = new ByteArrayInputStream(operationDetails);
|
||||||
|
ois = new ObjectInputStream(bais);
|
||||||
|
configOperation = (ConfigOperation) ois.readObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
String errorMsg = "IO Error occurred while de serialize the policy operation object";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
String errorMsg = "Class not found error occurred while de serialize the policy operation object";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL Error occurred while retrieving the policy operation object " + "available for " +
|
||||||
|
"the id '"
|
||||||
|
+ operationId;
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return configOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId,
|
||||||
|
Operation.Status status) throws OperationManagementDAOException {
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
ConfigOperation configOperation;
|
||||||
|
|
||||||
|
List<Operation> operationList = new ArrayList<Operation>();
|
||||||
|
|
||||||
|
ByteArrayInputStream bais = null;
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "Select OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_POLICY_OPERATION po " +
|
||||||
|
"INNER JOIN " +
|
||||||
|
"(Select * From DM_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID=? " +
|
||||||
|
"AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setString(2, status.toString());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
|
||||||
|
bais = new ByteArrayInputStream(operationDetails);
|
||||||
|
ois = new ObjectInputStream(bais);
|
||||||
|
configOperation = (ConfigOperation) ois.readObject();
|
||||||
|
operationList.add(configOperation);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
String errorMsg = "IO Error occurred while de serialize the configuration operation object";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
String errorMsg = "Class not found error occurred while de serialize the configuration operation object";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||||
|
"' with status '" + status.toString();
|
||||||
|
log.error(errorMsg);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
if (bais != null) {
|
||||||
|
try {
|
||||||
|
bais.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("Error occurred while closing ByteArrayOutputStream", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ois != null) {
|
||||||
|
try {
|
||||||
|
ois.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("Error occurred while closing ObjectOutputStream", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return operationList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,18 +20,11 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.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.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.dto.operation.mgt.PolicyOperation;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
|
|
||||||
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;
|
||||||
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 java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -48,13 +41,12 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
try {
|
try {
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
stmt = connection.prepareStatement(
|
stmt = connection.prepareStatement(
|
||||||
"INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, OPERATION_CODE) " +
|
"INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE) " +
|
||||||
"VALUES (?, ?, ?, ?,?)");
|
"VALUES (?, ?, ?, ?)");
|
||||||
stmt.setString(1, operation.getType().toString());
|
stmt.setString(1, operation.getType().toString());
|
||||||
stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
|
stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
|
||||||
stmt.setTimestamp(3, null);
|
stmt.setTimestamp(3, null);
|
||||||
stmt.setString(4, Operation.Status.PENDING.toString());
|
stmt.setString(4, operation.getCode());
|
||||||
stmt.setString(5, operation.getCode());
|
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
rs = stmt.getGeneratedKeys();
|
rs = stmt.getGeneratedKeys();
|
||||||
@ -76,12 +68,11 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=?,O.STATUS=? " +
|
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=? " +
|
||||||
"WHERE O.ID=?");
|
"WHERE O.ID=?");
|
||||||
|
|
||||||
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
||||||
stmt.setString(2, operation.getStatus().toString());
|
stmt.setInt(2, operation.getId());
|
||||||
stmt.setInt(3, operation.getId());
|
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -114,52 +105,28 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Operation operation = null;
|
Operation operation = null;
|
||||||
|
|
||||||
ByteArrayInputStream bais;
|
|
||||||
ObjectInputStream ois;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE," +
|
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
|
||||||
" po.OPERATION_DETAILS, co.ENABLED from" +
|
"DM_OPERATION WHERE id=?";
|
||||||
" (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, OPERATION_CODE FROM " +
|
|
||||||
" DM_OPERATION WHERE id=?) o" +
|
|
||||||
" LEFT OUTER JOIN DM_PROFILE_OPERATION po on o.ID=po.OPERATION_ID" +
|
|
||||||
" LEFT OUTER JOIN DM_COMMAND_OPERATION co on co.OPERATION_ID=o.ID";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
operation = new Operation();
|
||||||
byte[] operationDetails;
|
operation.setId(rs.getInt("ID"));
|
||||||
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||||
bais = new ByteArrayInputStream(operationDetails);
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||||
ois = new ObjectInputStream(bais);
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||||
operation = (ProfileOperation) ois.readObject();
|
operation.setReceivedTimeStamp("");
|
||||||
} else {
|
} else {
|
||||||
operation = new Operation();
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||||
operation.setId(rs.getInt("ID"));
|
|
||||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
||||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
||||||
operation.setReceivedTimeStamp("");
|
|
||||||
} else {
|
|
||||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
||||||
}
|
|
||||||
operation.setEnabled(rs.getBoolean("ENABLED"));
|
|
||||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
||||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
||||||
}
|
}
|
||||||
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
String errorMsg = "IO Error occurred while de serialize the profile operation object";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, e);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
String errorMsg = "Class not found error occurred while de serialize the profile operation object";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, e);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "SQL Error occurred while retrieving the operation object " + "available for the id '"
|
String errorMsg = "SQL Error occurred while retrieving the operation object " + "available for the id '"
|
||||||
+ id;
|
+ id;
|
||||||
@ -179,19 +146,13 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Operation operation = null;
|
Operation operation = null;
|
||||||
|
|
||||||
ByteArrayInputStream bais;
|
|
||||||
ObjectInputStream ois;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE," +
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " +
|
||||||
" po.OPERATION_DETAILS,co.ENABLED from " +
|
" From (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," +
|
||||||
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
|
|
||||||
"OPERATION_CODE FROM DM_OPERATION WHERE id=?) o INNER JOIN (Select * from " +
|
"OPERATION_CODE FROM DM_OPERATION WHERE id=?) o INNER JOIN (Select * from " +
|
||||||
"DM_DEVICE_OPERATION_MAPPING dm where dm.OPERATION_ID=? AND dm.DEVICE_ID=?) om " +
|
"DM_DEVICE_OPERATION_MAPPING dm where dm.OPERATION_ID=? AND dm.DEVICE_ID=?) om " +
|
||||||
"ON o.ID = om.OPERATION_ID " +
|
"ON o.ID = om.OPERATION_ID ";
|
||||||
"LEFT OUTER JOIN DM_PROFILE_OPERATION po on o.ID = po.OPERATION_ID " +
|
|
||||||
"LEFT OUTER JOIN DM_COMMAND_OPERATION co on co.OPERATION_ID=o.ID";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, operationId);
|
stmt.setInt(1, operationId);
|
||||||
@ -200,37 +161,17 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
operation = new Operation();
|
||||||
byte[] operationDetails;
|
operation.setId(rs.getInt("ID"));
|
||||||
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||||
bais = new ByteArrayInputStream(operationDetails);
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||||
ois = new ObjectInputStream(bais);
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||||
operation = (ProfileOperation) ois.readObject();
|
operation.setReceivedTimeStamp("");
|
||||||
} else {
|
} else {
|
||||||
operation = new Operation();
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||||
operation.setId(rs.getInt("ID"));
|
|
||||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
||||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
if (rs.getTimestamp("CREATED_TIMESTAMP") == null) {
|
|
||||||
operation.setReceivedTimeStamp("");
|
|
||||||
} else {
|
|
||||||
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
}
|
|
||||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
||||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
||||||
}
|
}
|
||||||
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
|
||||||
String errorMsg = "IO error occurred while de serializing the profile operation available for the " +
|
|
||||||
"device:" + deviceId + "' with id '" + operationId;
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
String errorMsg =
|
|
||||||
"class not found error occurred while de serializing the profile operation available for " +
|
|
||||||
"the device:" + deviceId + "' with id '" + operationId;
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||||
"' with id '" + operationId;
|
"' with id '" + operationId;
|
||||||
@ -251,62 +192,34 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Operation operation;
|
Operation operation;
|
||||||
|
|
||||||
ByteArrayInputStream bais;
|
|
||||||
ObjectInputStream ois;
|
|
||||||
List<Operation> operationList = new ArrayList<Operation>();
|
List<Operation> operationList = new ArrayList<Operation>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " +
|
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
||||||
"po.OPERATION_DETAILS,co.ENABLED from " +
|
"FROM DM_OPERATION o " +
|
||||||
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
|
|
||||||
"OPERATION_CODE FROM DM_OPERATION WHERE STATUS=?) o " +
|
|
||||||
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
||||||
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID LEFT OUTER JOIN DM_PROFILE_OPERATION po ON " +
|
"where dm.DEVICE_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||||
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, status.toString());
|
stmt.setInt(1, deviceId);
|
||||||
stmt.setInt(2, deviceId);
|
stmt.setString(2, status.toString());
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
operation = new Operation();
|
||||||
byte[] operationDetails;
|
operation.setId(rs.getInt("ID"));
|
||||||
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||||
bais = new ByteArrayInputStream(operationDetails);
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||||
ois = new ObjectInputStream(bais);
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||||
operation = (ProfileOperation) ois.readObject();
|
operation.setReceivedTimeStamp("");
|
||||||
} else {
|
} else {
|
||||||
operation = new Operation();
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||||
operation.setId(rs.getInt("ID"));
|
|
||||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
||||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
if (rs.getTimestamp("CREATED_TIMESTAMP") == null) {
|
|
||||||
operation.setReceivedTimeStamp("");
|
|
||||||
} else {
|
|
||||||
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
}
|
|
||||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
||||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
||||||
if (rs.getObject("ENABLED") != null) {
|
|
||||||
operation.setEnabled(rs.getBoolean("ENABLED"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||||
operationList.add(operation);
|
operationList.add(operation);
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
|
||||||
String errorMsg = "IO error occurred while de serializing the profile operation available for the " +
|
|
||||||
"device:" + deviceId + "' and status '" + status.toString();
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
String errorMsg =
|
|
||||||
"class not found error occurred while de serializing the profile operation available for " +
|
|
||||||
"the device:" + deviceId + "' with status '" + status.toString();
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||||
"' with status '" + status.toString();
|
"' with status '" + status.toString();
|
||||||
@ -327,19 +240,14 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Operation operation;
|
Operation operation;
|
||||||
|
|
||||||
ByteArrayInputStream bais;
|
|
||||||
ObjectInputStream ois;
|
|
||||||
List<Operation> operationList = new ArrayList<Operation>();
|
List<Operation> operationList = new ArrayList<Operation>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " +
|
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
||||||
"po.OPERATION_DETAILS,co.ENABLED from " +
|
"OPERATION_CODE,dm.STATUS FROM DM_OPERATION o " +
|
||||||
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
|
|
||||||
"OPERATION_CODE FROM DM_OPERATION) o " +
|
|
||||||
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
||||||
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID LEFT OUTER JOIN DM_PROFILE_OPERATION po ON " +
|
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||||
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, deviceId);
|
stmt.setInt(1, deviceId);
|
||||||
@ -347,38 +255,19 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
operation = new Operation();
|
||||||
byte[] operationDetails;
|
operation.setId(rs.getInt("ID"));
|
||||||
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||||
bais = new ByteArrayInputStream(operationDetails);
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||||
ois = new ObjectInputStream(bais);
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||||
operation = (ProfileOperation) ois.readObject();
|
operation.setReceivedTimeStamp("");
|
||||||
} else {
|
} else {
|
||||||
operation = new Operation();
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||||
operation.setId(rs.getInt("ID"));
|
|
||||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
||||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
if (rs.getTimestamp("CREATED_TIMESTAMP") == null) {
|
|
||||||
operation.setReceivedTimeStamp("");
|
|
||||||
} else {
|
|
||||||
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
}
|
|
||||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
||||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
||||||
}
|
}
|
||||||
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||||
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||||
operationList.add(operation);
|
operationList.add(operation);
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
|
||||||
String errorMsg = "IO error occurred while de serializing the profile operation available for the " +
|
|
||||||
"device:" + deviceId;
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
String errorMsg =
|
|
||||||
"class not found error occurred while de serializing the profile operation available for " +
|
|
||||||
"the device:" + deviceId;
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||||
"' with status '";
|
"' with status '";
|
||||||
@ -391,141 +280,41 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
return operationList;
|
return operationList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<? extends Operation> getOperationsForStatus(Operation.Status status)
|
|
||||||
throws OperationManagementDAOException {
|
|
||||||
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
Operation operation;
|
|
||||||
|
|
||||||
ByteArrayInputStream byteArrayInputStream;
|
|
||||||
ObjectInputStream ois;
|
|
||||||
List<Operation> operationList = new ArrayList<Operation>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
||||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE,"+
|
|
||||||
"po.OPERATION_DETAILS,co.ENABLED from "+
|
|
||||||
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS,"+
|
|
||||||
"OPERATION_CODE FROM DM_OPERATION WHERE STATUS=?) o "+
|
|
||||||
"LEFT OUTER JOIN DM_PROFILE_OPERATION po ON "+
|
|
||||||
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
|
||||||
stmt.setString(1, status.toString());
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
|
||||||
byte[] operationDetails;
|
|
||||||
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
||||||
byteArrayInputStream = new ByteArrayInputStream(operationDetails);
|
|
||||||
ois = new ObjectInputStream(byteArrayInputStream);
|
|
||||||
operation = (ProfileOperation) ois.readObject();
|
|
||||||
} else {
|
|
||||||
operation = new Operation();
|
|
||||||
operation.setId(rs.getInt("ID"));
|
|
||||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
||||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
if (rs.getTimestamp("CREATED_TIMESTAMP") == null) {
|
|
||||||
operation.setReceivedTimeStamp("");
|
|
||||||
} else {
|
|
||||||
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
}
|
|
||||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
||||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
||||||
}
|
|
||||||
operationList.add(operation);
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
String errorMsg = "IO error occurred while de serializing the profile operation available for the " +
|
|
||||||
"status:" + status.toString();
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
String errorMsg =
|
|
||||||
"class not found error occurred while de serializing the profile operation available for " +
|
|
||||||
"the status:" + status.toString();
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String errorMsg = "SQL error occurred while retrieving the operation available for the status:'" +
|
|
||||||
status.toString();
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
return operationList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation getNextOperation(int deviceId) throws OperationManagementDAOException {
|
public Operation getNextOperation(int deviceId) throws OperationManagementDAOException {
|
||||||
|
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
|
|
||||||
ByteArrayInputStream bais;
|
|
||||||
ObjectInputStream ois;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||||
stmt = connection.prepareStatement(
|
stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP " +
|
||||||
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " +
|
"OPERATION_CODE FROM DM_OPERATION o " +
|
||||||
"po.OPERATION_DETAILS,co.ENABLED from " +
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
||||||
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS, " +
|
"where dm.DEVICE_ID=? AND dm.STATUS=?) om ON o.ID = om.OPERATION_ID " +
|
||||||
"OPERATION_CODE FROM DM_OPERATION WHERE STATUS=?) o " +
|
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
|
||||||
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
|
||||||
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID LEFT OUTER JOIN DM_PROFILE_OPERATION " +
|
|
||||||
"po ON " +
|
|
||||||
"o.ID =po.OPERATION_ID LEFT OUTER JOIN DM_COMMAND_OPERATION co ON co.OPERATION_ID=o.ID " +
|
|
||||||
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
|
|
||||||
|
|
||||||
stmt.setString(1, Operation.Status.PENDING.toString());
|
stmt.setInt(1, deviceId);
|
||||||
stmt.setInt(2, deviceId);
|
stmt.setString(2, Operation.Status.PENDING.toString());
|
||||||
|
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
Operation operation = null;
|
Operation operation = null;
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
if (rs.getBytes("OPERATION_DETAILS") != null) {
|
operation = new Operation();
|
||||||
byte[] operationDetails;
|
operation.setType(this.getType(rs.getString("TYPE")));
|
||||||
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
operation.setStatus(this.getStatus(rs.getString("STATUS")));
|
||||||
bais = new ByteArrayInputStream(operationDetails);
|
operation.setId(rs.getInt("ID"));
|
||||||
ois = new ObjectInputStream(bais);
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||||
operation = (ProfileOperation) ois.readObject();
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||||
|
operation.setReceivedTimeStamp("");
|
||||||
} else {
|
} else {
|
||||||
operation = new Operation();
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||||
operation.setType(this.getType(rs.getString("TYPE")));
|
|
||||||
operation.setStatus(this.getStatus(rs.getString("STATUS")));
|
|
||||||
operation.setId(rs.getInt("ID"));
|
|
||||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
||||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
||||||
operation.setReceivedTimeStamp("");
|
|
||||||
} else {
|
|
||||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
||||||
}
|
|
||||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
||||||
if (rs.getObject("ENABLED") != null) {
|
|
||||||
operation.setEnabled(rs.getBoolean("ENABLED"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||||
}
|
}
|
||||||
return operation;
|
return operation;
|
||||||
} catch (IOException ex) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "IO error occurred while de serializing the next profile operation available for the " +
|
|
||||||
"device:" + deviceId;
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
} catch (ClassNotFoundException ex) {
|
|
||||||
String errorMsg = "class not found error occurred while de serializing the profile operation available " +
|
|
||||||
"for the device:" + deviceId;
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new OperationManagementDAOException(errorMsg, ex);
|
|
||||||
|
|
||||||
}catch (SQLException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
||||||
} finally {
|
} finally {
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
@ -533,6 +322,56 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<? extends Operation> getOperationsByDeviceStatusAndType(int deviceId,
|
||||||
|
Operation.Status status,Operation.Type type) throws OperationManagementDAOException {
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Operation operation;
|
||||||
|
|
||||||
|
List<Operation> operationList = new ArrayList<Operation>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM "+
|
||||||
|
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
||||||
|
"FROM DM_OPERATION o WHERE o.TYPE=?) o " +
|
||||||
|
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
||||||
|
"where dm.DEVICE_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setString(1, type.toString());
|
||||||
|
stmt.setInt(2, deviceId);
|
||||||
|
stmt.setString(3, status.toString());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
operation = new Operation();
|
||||||
|
operation.setId(rs.getInt("ID"));
|
||||||
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||||
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||||
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||||
|
operation.setReceivedTimeStamp("");
|
||||||
|
} else {
|
||||||
|
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||||
|
}
|
||||||
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||||
|
operationList.add(operation);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||||
|
"' with status '" + status.toString();
|
||||||
|
log.error(errorMsg);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return operationList;
|
||||||
|
}
|
||||||
|
|
||||||
private Operation.Status getStatus(String status) {
|
private Operation.Status getStatus(String status) {
|
||||||
return Operation.Status.valueOf(status);
|
return Operation.Status.valueOf(status);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.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;
|
||||||
@ -34,10 +35,11 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "INSERT INTO DM_DEVICE_OPERATION_MAPPING(DEVICE_ID, OPERATION_ID) VALUES(?, ?)";
|
String sql = "INSERT INTO DM_DEVICE_OPERATION_MAPPING(DEVICE_ID, OPERATION_ID,STATUS) VALUES(?, ?,?)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, deviceId);
|
stmt.setInt(1, deviceId);
|
||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operationId);
|
||||||
|
stmt.setString(3, Operation.Status.PENDING.toString());
|
||||||
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);
|
||||||
|
|||||||
@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.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.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.dto.operation.mgt.ProfileOperation;
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||||
@ -29,6 +28,8 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOU
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||||
|
|
||||||
@ -59,67 +60,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|||||||
return operationId;
|
return operationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
|
||||||
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
ByteArrayInputStream bais = null;
|
|
||||||
ObjectInputStream ois = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
||||||
stmt = connection.prepareStatement(
|
|
||||||
"SELECT po.OPERATION_DETAILS AS OPERATION_DETAILS " +
|
|
||||||
"FROM DM_OPERATION o " +
|
|
||||||
"INNER JOIN DM_PROFILE_OPERATION po ON o.ID = po.OPERATION_ID AND o.STATUS =? AND o.ID IN ("
|
|
||||||
+
|
|
||||||
"SELECT dom.OPERATION_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN " +
|
|
||||||
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND " +
|
|
||||||
"d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN DM_DEVICE_OPERATION_MAPPING dom " +
|
|
||||||
"ON d1.ID = dom.DEVICE_ID) ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
|
|
||||||
|
|
||||||
stmt.setString(1, Operation.Status.PENDING.toString());
|
|
||||||
stmt.setString(2, deviceId.getType());
|
|
||||||
stmt.setString(3, deviceId.getId());
|
|
||||||
rs = stmt.executeQuery();
|
|
||||||
|
|
||||||
byte[] operationDetails = new byte[0];
|
|
||||||
if (rs.next()) {
|
|
||||||
operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
||||||
}
|
|
||||||
bais = new ByteArrayInputStream(operationDetails);
|
|
||||||
ois = new ObjectInputStream(bais);
|
|
||||||
return (ProfileOperation) ois.readObject();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("SQL error occurred while retrieving profile operation", e);
|
|
||||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
log.error("Class not found error occurred while retrieving profile operation", e);
|
|
||||||
throw new OperationManagementDAOException("Error occurred while casting retrieved payload as a " +
|
|
||||||
"ProfileOperation object", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("IO error occurred while de serialize profile operation", e);
|
|
||||||
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
|
|
||||||
} finally {
|
|
||||||
if (bais != null) {
|
|
||||||
try {
|
|
||||||
bais.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("Error occurred while closing ByteArrayOutputStream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ois != null) {
|
|
||||||
try {
|
|
||||||
ois.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("Error occurred while closing ObjectOutputStream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
||||||
|
|
||||||
@ -180,4 +120,117 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|||||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
OperationManagementDAOUtil.cleanupResources(stmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
ProfileOperation profileOperation = null;
|
||||||
|
|
||||||
|
ByteArrayInputStream bais;
|
||||||
|
ObjectInputStream ois;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT OPERATION_ID, ENABLED, OPERATION_DETAILS FROM DM_PROFILE_OPERATION WHERE OPERATION_ID=?";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, id);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
|
||||||
|
bais = new ByteArrayInputStream(operationDetails);
|
||||||
|
ois = new ObjectInputStream(bais);
|
||||||
|
profileOperation = (ProfileOperation) ois.readObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
String errorMsg = "IO Error occurred while de serialize the profile operation object";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
String errorMsg = "Class not found error occurred while de serialize the profile operation object";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL Error occurred while retrieving the command operation object " + "available for " +
|
||||||
|
"the id '"
|
||||||
|
+ id;
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return profileOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId,
|
||||||
|
Operation.Status status) throws OperationManagementDAOException {
|
||||||
|
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
ProfileOperation profileOperation;
|
||||||
|
|
||||||
|
List<Operation> operationList = new ArrayList<Operation>();
|
||||||
|
|
||||||
|
ByteArrayInputStream bais = null;
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
|
String sql = "Select OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_PROFILE_OPERATION po " +
|
||||||
|
"INNER JOIN " +
|
||||||
|
"(Select * From DM_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID=? " +
|
||||||
|
"AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setString(2, status.toString());
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
|
||||||
|
bais = new ByteArrayInputStream(operationDetails);
|
||||||
|
ois = new ObjectInputStream(bais);
|
||||||
|
profileOperation = (ProfileOperation) ois.readObject();
|
||||||
|
operationList.add(profileOperation);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
String errorMsg = "IO Error occurred while de serialize the profile operation object";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
String errorMsg = "Class not found error occurred while de serialize the profile operation object";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||||
|
"' with status '" + status.toString();
|
||||||
|
log.error(errorMsg);
|
||||||
|
throw new OperationManagementDAOException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
if (bais != null) {
|
||||||
|
try {
|
||||||
|
bais.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("Error occurred while closing ByteArrayOutputStream", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ois != null) {
|
||||||
|
try {
|
||||||
|
ois.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("Error occurred while closing ObjectOutputStream", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return operationList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,6 +56,7 @@ public class OperationDAOUtil {
|
|||||||
dtoOperation.setId(operation.getId());
|
dtoOperation.setId(operation.getId());
|
||||||
dtoOperation.setPayLoad(operation.getPayLoad());
|
dtoOperation.setPayLoad(operation.getPayLoad());
|
||||||
dtoOperation.setReceivedTimeStamp(operation.getReceivedTimeStamp());
|
dtoOperation.setReceivedTimeStamp(operation.getReceivedTimeStamp());
|
||||||
|
dtoOperation.setProperties(operation.getProperties());
|
||||||
|
|
||||||
return dtoOperation;
|
return dtoOperation;
|
||||||
}
|
}
|
||||||
@ -82,6 +83,7 @@ public class OperationDAOUtil {
|
|||||||
operation.setPayLoad(dtoOperation.getPayLoad());
|
operation.setPayLoad(dtoOperation.getPayLoad());
|
||||||
operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp());
|
operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp());
|
||||||
operation.setEnabled(dtoOperation.isEnabled());
|
operation.setEnabled(dtoOperation.isEnabled());
|
||||||
|
operation.setProperties(dtoOperation.getProperties());
|
||||||
|
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -173,11 +173,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperation(operationId);
|
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperation(operationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<? extends Operation> getOperationsForStatus(Operation.Status status)
|
|
||||||
throws OperationManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperationsForStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties)
|
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties)
|
||||||
|
|||||||
@ -59,6 +59,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
|||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
STATUS VARCHAR(50) NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_mapping_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,
|
||||||
|
|||||||
@ -26,13 +26,13 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
|
|||||||
TYPE VARCHAR(50) NOT NULL,
|
TYPE VARCHAR(50) NOT NULL,
|
||||||
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
|
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
|
||||||
OPERATION_CODE VARCHAR(1000) NOT NULL,
|
OPERATION_CODE VARCHAR(1000) NOT NULL,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
|
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
OPERATION_CONFIG BLOB DEFAULT NULL,
|
||||||
PRIMARY KEY (OPERATION_ID),
|
PRIMARY KEY (OPERATION_ID),
|
||||||
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES
|
CONSTRAINT fk_dm_operation_config 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
|
||||||
@ -46,6 +46,15 @@ CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
|
|||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
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 BLOB 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
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
|
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
ENABLED INTEGER NOT NULL DEFAULT 0,
|
ENABLED INTEGER NOT NULL DEFAULT 0,
|
||||||
@ -59,6 +68,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
|||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
STATUS VARCHAR(50) NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_mapping_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,
|
||||||
|
|||||||
@ -26,7 +26,6 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
|
|||||||
TYPE VARCHAR(50) NOT NULL,
|
TYPE VARCHAR(50) NOT NULL,
|
||||||
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
|
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
RECEIVED_TIMESTAMP TIMESTAMP NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -45,10 +44,29 @@ CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
|
|||||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
ENABLED INTEGER NOT NULL DEFAULT 0,
|
||||||
|
OPERATION_DETAILS BLOB 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_POLICY_OPERATION (
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
ENABLED INTEGER NOT NULL DEFAULT 0,
|
||||||
|
OPERATION_DETAILS BLOB 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
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
STATUS VARCHAR(50) NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_operation_mapping_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,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user