diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index e5022670b3..3496bacb8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -31,7 +31,11 @@ public class Operation implements Serializable { } public enum Status { - IN_PROGRESS, PENDING, COMPLETED, ERROR + IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED + } + + public enum Control { + REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE } private String code; @@ -39,6 +43,7 @@ public class Operation implements Serializable { private Type type; private int id; private Status status; + private Control control; private String receivedTimeStamp; private String createdTimeStamp; private boolean isEnabled; @@ -88,6 +93,11 @@ public class Operation implements Serializable { if (status != operation.status) { return false; } + + if(control != operation.control){ + return false; + } + if (type != operation.type) { return false; } @@ -152,6 +162,14 @@ public class Operation implements Serializable { this.status = status; } + public Control getControl() { + return control; + } + + public void setControl(Control control) { + this.control = control; + } + public String getReceivedTimeStamp() { return receivedTimeStamp; } @@ -207,6 +225,7 @@ public class Operation implements Serializable { ", type=" + type + ", id=" + id + ", status=" + status + + ", control=" + control + ", receivedTimeStamp='" + receivedTimeStamp + '\'' + ", createdTimeStamp='" + createdTimeStamp + '\'' + ", isEnabled=" + isEnabled + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java index 28c43cd6bd..bc132a9b20 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java @@ -34,4 +34,8 @@ public class CommandOperation extends Operation { return Type.COMMAND; } + public Control getControl(){ + return Control.NO_REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java index bd4fc50ae6..c2be65a372 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java @@ -77,4 +77,9 @@ public class ConfigOperation extends Operation { return Type.CONFIG; } + + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java index 37e0736eb5..360deb868a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java @@ -18,8 +18,6 @@ */ package org.wso2.carbon.device.mgt.core.dto.operation.mgt; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.util.Properties; @@ -30,7 +28,11 @@ public class Operation implements Serializable { } public enum Status { - IN_PROGRESS, PENDING, COMPLETED, ERROR + IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED + } + + public enum Control { + REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE } private String code; @@ -38,6 +40,7 @@ public class Operation implements Serializable { private Type type; private int id; private Status status; + private Control control; private String receivedTimeStamp; private String createdTimeStamp; private boolean isEnabled; @@ -84,6 +87,14 @@ public class Operation implements Serializable { this.status = status; } + public Control getControl() { + return control; + } + + public void setControl(Control control) { + this.control = control; + } + public String getReceivedTimeStamp() { return receivedTimeStamp; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java index f1d97a0dd0..dc6ae4dd78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java @@ -31,4 +31,8 @@ public class PolicyOperation extends Operation{ private List profileOperations; + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java index 61bb18d698..107cf091d7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java @@ -26,4 +26,9 @@ public class ProfileOperation extends ConfigOperation implements Serializable { return Type.PROFILE; } + + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java index 852142c1b8..3a9ecefca3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java @@ -35,5 +35,8 @@ public class CommandOperation extends Operation { public Type getType() { return Type.COMMAND; } + public Control getControl(){ + return Control.NO_REPEAT; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java index 83cfd0e612..69d8aafc4a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java @@ -78,4 +78,8 @@ public class ConfigOperation extends Operation { return Type.CONFIG; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 6ea7adbf59..9e156618b6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -109,6 +109,12 @@ public class OperationManagerImpl implements OperationManager { OperationDAOUtil.convertOperation(operation); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); for (EnrolmentInfo enrolmentInfo : enrolments) { + if(operationDto.getControl() == + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT){ + operationDAO.updateEnrollmentOperationsStatus(enrolmentInfo.getId(), operationDto.getCode(), + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING, + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED); + } operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId()); } OperationManagementDAOFactory.commitTransaction(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java index 0740728be0..6b36492a83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java @@ -33,4 +33,8 @@ public class PolicyOperation extends Operation { this.profileOperations = profileOperations; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java index 6c9abbed4c..f984fdfb0c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java @@ -26,4 +26,8 @@ public class ProfileOperation extends ConfigOperation implements Serializable { return Type.PROFILE; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index c24887d1bf..9234953829 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -52,6 +52,9 @@ public interface OperationDAO { void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status) throws OperationManagementDAOException; + void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus, + Operation.Status newStatus) throws OperationManagementDAOException; + void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index b866285ff0..592be91c71 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -105,6 +105,41 @@ public class GenericOperationDAOImpl implements OperationDAO { } } + @Override + public void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus, + Operation.Status newStatus) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection connection = OperationManagementDAOFactory.getConnection(); + String query = "SELECT EOM.ID FROM DM_ENROLMENT_OP_MAPPING AS EOM INNER JOIN DM_OPERATION DM " + + "ON DM.ID = EOM.OPERATION_ID WHERE EOM.ENROLMENT_ID = ? AND DM.OPERATION_CODE = ? " + + "AND EOM.STATUS = ?;"; + stmt = connection.prepareStatement(query); + stmt.setInt(1, enrolmentId); + stmt.setString(2, operationCode); + stmt.setString(3, existingStatus.toString()); + // This will return only one result always. + rs = stmt.executeQuery(); + int id = 0; + while (rs.next()){ + id = rs.getInt("ID"); + } + if (id != 0){ + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS = ? WHERE ID = ?"); + stmt.setString(1, newStatus.toString()); + stmt.setInt(2, id); + stmt.executeUpdate(); + } + + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while update device mapping operation status " + + "metadata", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt); + } + } + @Override public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java index 20485921bb..6625ceab89 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -97,6 +97,7 @@ public class OperationDAOUtil { operation.setProperties(dtoOperation.getProperties()); operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId()); + return operation; } }