Adding the changes for removing repeated operations from pending operations, if same operation is added twice, are making them repeated, Device will not recieve them

4.x.x
geethkokila 9 years ago
parent c0dd2c423e
commit f2128762f0

@ -31,7 +31,11 @@ public class Operation implements Serializable {
} }
public enum Status { 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; private String code;
@ -39,6 +43,7 @@ public class Operation implements Serializable {
private Type type; private Type type;
private int id; private int id;
private Status status; private Status status;
private Control control;
private String receivedTimeStamp; private String receivedTimeStamp;
private String createdTimeStamp; private String createdTimeStamp;
private boolean isEnabled; private boolean isEnabled;
@ -88,6 +93,11 @@ public class Operation implements Serializable {
if (status != operation.status) { if (status != operation.status) {
return false; return false;
} }
if(control != operation.control){
return false;
}
if (type != operation.type) { if (type != operation.type) {
return false; return false;
} }
@ -152,6 +162,14 @@ public class Operation implements Serializable {
this.status = status; this.status = status;
} }
public Control getControl() {
return control;
}
public void setControl(Control control) {
this.control = control;
}
public String getReceivedTimeStamp() { public String getReceivedTimeStamp() {
return receivedTimeStamp; return receivedTimeStamp;
} }
@ -207,6 +225,7 @@ public class Operation implements Serializable {
", type=" + type + ", type=" + type +
", id=" + id + ", id=" + id +
", status=" + status + ", status=" + status +
", control=" + control +
", receivedTimeStamp='" + receivedTimeStamp + '\'' + ", receivedTimeStamp='" + receivedTimeStamp + '\'' +
", createdTimeStamp='" + createdTimeStamp + '\'' + ", createdTimeStamp='" + createdTimeStamp + '\'' +
", isEnabled=" + isEnabled + ", isEnabled=" + isEnabled +

@ -34,4 +34,8 @@ public class CommandOperation extends Operation {
return Type.COMMAND; return Type.COMMAND;
} }
public Control getControl(){
return Control.NO_REPEAT;
}
} }

@ -77,4 +77,9 @@ public class ConfigOperation extends Operation {
return Type.CONFIG; return Type.CONFIG;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -18,8 +18,6 @@
*/ */
package org.wso2.carbon.device.mgt.core.dto.operation.mgt; 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.io.Serializable;
import java.util.Properties; import java.util.Properties;
@ -30,7 +28,11 @@ public class Operation implements Serializable {
} }
public enum Status { 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; private String code;
@ -38,6 +40,7 @@ public class Operation implements Serializable {
private Type type; private Type type;
private int id; private int id;
private Status status; private Status status;
private Control control;
private String receivedTimeStamp; private String receivedTimeStamp;
private String createdTimeStamp; private String createdTimeStamp;
private boolean isEnabled; private boolean isEnabled;
@ -84,6 +87,14 @@ public class Operation implements Serializable {
this.status = status; this.status = status;
} }
public Control getControl() {
return control;
}
public void setControl(Control control) {
this.control = control;
}
public String getReceivedTimeStamp() { public String getReceivedTimeStamp() {
return receivedTimeStamp; return receivedTimeStamp;
} }

@ -31,4 +31,8 @@ public class PolicyOperation extends Operation{
private List<ProfileOperation> profileOperations; private List<ProfileOperation> profileOperations;
public Control getControl(){
return Control.REPEAT;
}
} }

@ -26,4 +26,9 @@ public class ProfileOperation extends ConfigOperation implements Serializable {
return Type.PROFILE; return Type.PROFILE;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -35,5 +35,8 @@ public class CommandOperation extends Operation {
public Type getType() { public Type getType() {
return Type.COMMAND; return Type.COMMAND;
} }
public Control getControl(){
return Control.NO_REPEAT;
}
} }

@ -78,4 +78,8 @@ public class ConfigOperation extends Operation {
return Type.CONFIG; return Type.CONFIG;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -109,6 +109,12 @@ public class OperationManagerImpl implements OperationManager {
OperationDAOUtil.convertOperation(operation); OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
for (EnrolmentInfo enrolmentInfo : enrolments) { 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()); operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId());
} }
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();

@ -33,4 +33,8 @@ public class PolicyOperation extends Operation {
this.profileOperations = profileOperations; this.profileOperations = profileOperations;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -26,4 +26,8 @@ public class ProfileOperation extends ConfigOperation implements Serializable {
return Type.PROFILE; return Type.PROFILE;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -52,6 +52,9 @@ public interface OperationDAO {
void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status) void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status)
throws OperationManagementDAOException; throws OperationManagementDAOException;
void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
Operation.Status newStatus) throws OperationManagementDAOException;
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException; throws OperationManagementDAOException;

@ -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 @Override
public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException { throws OperationManagementDAOException {

@ -97,6 +97,7 @@ public class OperationDAOUtil {
operation.setProperties(dtoOperation.getProperties()); operation.setProperties(dtoOperation.getProperties());
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId()); operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId());
return operation; return operation;
} }
} }

Loading…
Cancel
Save