Fixing the operation activity id issues

merge-requests/7/head
geethkokila 9 years ago
parent c945d63038
commit 362cf40d85

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.operation.mgt;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import java.util.Properties; import java.util.Properties;
@XmlRootElement @XmlRootElement
@ -50,6 +51,7 @@ public class Operation implements Serializable {
private Object payLoad; private Object payLoad;
private String operationResponse; private String operationResponse;
private String activityId; private String activityId;
private List<OperationResponse> responses;
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
@ -218,6 +220,14 @@ public class Operation implements Serializable {
this.activityId = activityId; this.activityId = activityId;
} }
public List<OperationResponse> getResponses() {
return responses;
}
public void setResponses(List<OperationResponse> responses) {
this.responses = responses;
}
@Override @Override
public String toString() { public String toString() {
return "Operation{" + return "Operation{" +

@ -0,0 +1,43 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common.operation.mgt;
public class OperationResponse {
private String response;
private String recievedTimeStamp;
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public String getRecievedTimeStamp() {
return recievedTimeStamp;
}
public void setRecievedTimeStamp(String recievedTimeStamp) {
this.recievedTimeStamp = recievedTimeStamp;
}
}

@ -46,6 +46,7 @@ public class Operation implements Serializable {
private boolean isEnabled; private boolean isEnabled;
private Object payLoad; private Object payLoad;
private Object operationResponse; private Object operationResponse;
private String activityId;
public String getCode() { public String getCode() {
return code; return code;
@ -135,4 +136,12 @@ public class Operation implements Serializable {
this.operationResponse = operationResponse; this.operationResponse = operationResponse;
} }
public String getActivityId() {
return activityId;
}
public void setActivityId(String activityId) {
this.activityId = activityId;
}
} }

@ -659,12 +659,57 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public Operation getOperationByActivityId(String activity) throws OperationManagementException { public Operation getOperationByActivityId(String activity) throws OperationManagementException {
// This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer. // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer.
int operationId = Integer.parseInt( Operation operation;
int enrollmentOpMappingId = Integer.parseInt(
activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
if(operationId == 0){ if(enrollmentOpMappingId == 0){
throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
} }
return this.getOperation(operationId); try {
OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation =
operationDAO.getOperationFromEnrollment(enrollmentOpMappingId);
if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for given activity Id:" + activity);
}
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status status = dtoOperation.getStatus();
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);
int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId);
if (enrolmentId !=0) {
operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId()));
}
operation.setStatus(Operation.Status.valueOf(status.toString()));
operation.setActivityId(activity);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" +
activity, e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
// return this.getOperation(operationId);
return operation;
} }
private OperationDAO lookupOperationDAO(Operation operation) { private OperationDAO lookupOperationDAO(Operation operation) {
@ -722,4 +767,8 @@ public class OperationManagerImpl implements OperationManager {
return status; return status;
} }
private void setActivityId(Operation operation, int enrolmentId) {
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + enrolmentId);
}
} }

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.core.operation.mgt.dao; package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import java.util.List; import java.util.List;
@ -33,6 +34,8 @@ public interface OperationDAO {
Operation getOperation(int operationId) throws OperationManagementDAOException; Operation getOperation(int operationId) throws OperationManagementDAOException;
Operation getOperationFromEnrollment(int enrollmentOpMappingId) throws OperationManagementDAOException;
Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException; Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException;
List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, Operation.Status status) List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, Operation.Status status)
@ -58,4 +61,8 @@ public interface OperationDAO {
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException; throws OperationManagementDAOException;
List<OperationResponse> getOperationResponses(int enrolmentId, int operationId) throws OperationManagementDAOException;
int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException;
} }

@ -20,15 +20,15 @@ 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.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
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.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.ByteArrayOutputStream; import java.io.*;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -149,7 +149,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,ENROLMENT_ID," + stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,ENROLMENT_ID," +
"OPERATION_RESPONSE) VALUES(?, ?, ?)"); "OPERATION_RESPONSE, RECEIVED_TIMESTAMP) VALUES(?, ?, ?, ?)");
bao = new ByteArrayOutputStream(); bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao); oos = new ObjectOutputStream(bao);
oos.writeObject(operationResponse); oos.writeObject(operationResponse);
@ -157,6 +157,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setInt(2, enrolmentId); stmt.setInt(2, enrolmentId);
stmt.setBytes(3, bao.toByteArray()); stmt.setBytes(3, bao.toByteArray());
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while inserting operation response", e); throw new OperationManagementDAOException("Error occurred while inserting operation response", e);
@ -181,6 +182,92 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
} }
@Override
public List<OperationResponse> getOperationResponses(int enrolmentId, int operationId) throws
OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
List<OperationResponse> responces = new ArrayList<>();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT * FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId);
stmt.setInt(2, operationId);
rs = stmt.executeQuery();
while (rs.next()) {
OperationResponse response = new OperationResponse();
response.setRecievedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
byte[] contentBytes;
try {
contentBytes = (byte[]) rs.getBytes("OPERATION_RESPONSE");
bais = new ByteArrayInputStream(contentBytes);
ois = new ObjectInputStream(bais);
response.setResponse(ois.readObject().toString());
} 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);
}
}
}
responces.add(response);
}
} catch (SQLException e) {
throw new OperationManagementDAOException("SQL Error occurred while retrieving the operation responses for " +
"operation id " + operationId + " and enrolment id " + enrolmentId, e);
} catch (ClassNotFoundException e) {
throw new OperationManagementDAOException("Error occurred while converting the operation responses to string" +
" for operation id " + operationId + " and enrolment id " + enrolmentId, e);
} catch (IOException e) {
throw new OperationManagementDAOException("Error occurred while converting the operation responses to string" +
" for operation id " + operationId + " and enrolment id " + enrolmentId, e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
return responces;
}
@Override
public int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT * FROM DM_ENROLMENT_OP_MAPPING WHERE ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrollmentOpMappingId);
rs = stmt.executeQuery();
if (rs.next()) {
return rs.getInt("ENROLMENT_ID");
}
} catch (SQLException e) {
throw new OperationManagementDAOException("SQL Error occurred while retrieving the enrolment id " +
" for the mapping id '" + enrollmentOpMappingId, e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
return -1;
}
@Override @Override
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -231,6 +318,43 @@ public class GenericOperationDAOImpl implements OperationDAO {
return operation; return operation;
} }
@Override
public Operation getOperationFromEnrollment(int enrollmentOpMappingId) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
Operation operation = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, \n" +
" om.STATUS FROM DM_OPERATION o \n" +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm WHERE dm.ID = ? ) om \n" +
"ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC ";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrollmentOpMappingId);
rs = stmt.executeQuery();
if (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"));
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
this.setActivityId(operation, enrollmentOpMappingId);
}
} catch (SQLException e) {
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation .", e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
return operation;
}
@Override @Override
public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException { public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -238,7 +362,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
Operation operation = null; Operation operation = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT 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, om.ID AS OM_MAPPING_ID " +
" FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," + " FROM (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_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " + "DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
@ -260,6 +384,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
this.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
@ -279,7 +404,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID" +
"FROM DM_OPERATION o " + "FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC";
@ -300,6 +425,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
operation.setStatus(status); operation.setStatus(status);
this.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
operations.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -321,7 +447,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID " +
"FROM DM_OPERATION o " + "FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
@ -345,6 +471,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
operation.setStatus(status); operation.setStatus(status);
this.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
operations.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -365,7 +492,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -384,6 +511,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
this.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
operations.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -405,7 +533,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"; "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -426,6 +554,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
this.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
operations.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -468,7 +597,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE FROM DM_OPERATION o " + "OPERATION_CODE, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " +
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
@ -489,6 +618,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
operation.setStatus(Operation.Status.PENDING); operation.setStatus(Operation.Status.PENDING);
this.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
} }
return operation; return operation;
} catch (SQLException e) { } catch (SQLException e) {
@ -507,7 +637,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID FROM " +
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
"FROM DM_OPERATION o WHERE o.TYPE = ?) o " + "FROM DM_OPERATION o WHERE o.TYPE = ?) o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
@ -530,6 +660,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
} }
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
this.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
operations.add(operation); operations.add(operation);
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -545,4 +676,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
return Operation.Type.valueOf(type); return Operation.Type.valueOf(type);
} }
private void setActivityId(Operation operation, int enrolmentId) {
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + enrolmentId);
}
} }

@ -95,7 +95,7 @@ public class OperationDAOUtil {
operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp()); operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp());
operation.setEnabled(dtoOperation.isEnabled()); operation.setEnabled(dtoOperation.isEnabled());
operation.setProperties(dtoOperation.getProperties()); operation.setProperties(dtoOperation.getProperties());
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId()); operation.setActivityId(dtoOperation.getActivityId());
return operation; return operation;

@ -123,6 +123,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
OPERATION_RESPONSE BLOB DEFAULT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,

@ -123,6 +123,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
OPERATION_RESPONSE VARBINARY(max) DEFAULT NULL, OPERATION_RESPONSE VARBINARY(max) DEFAULT NULL,
RECEIVED_TIMESTAMP DATETIME2(0) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,

@ -108,6 +108,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
OPERATION_RESPONSE BLOB DEFAULT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,

@ -229,6 +229,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
ENROLMENT_ID NUMBER(10) NOT NULL, ENROLMENT_ID NUMBER(10) NOT NULL,
OPERATION_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL,
OPERATION_RESPONSE BLOB DEFAULT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL,
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
CONSTRAINT PK_DM_DEVICE_OP_RESPONSE PRIMARY KEY (ID), CONSTRAINT PK_DM_DEVICE_OP_RESPONSE PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_OP_RES_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES CONSTRAINT FK_DM_DEVICE_OP_RES_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID), DM_ENROLMENT (ID),

@ -94,6 +94,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
ENROLMENT_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
OPERATION_RESPONSE BYTEA DEFAULT NULL, OPERATION_RESPONSE BYTEA DEFAULT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES

Loading…
Cancel
Save