|
|
@ -32,6 +32,7 @@ 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 org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.sql.*;
|
|
|
|
import java.sql.*;
|
|
|
@ -345,7 +346,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
List<OperationResponse> operationResponses = new ArrayList<>();
|
|
|
|
List<OperationResponse> operationResponses = new ArrayList<>();
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
activityStatus.setUpdatedTimestamp(new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
activityStatus.setUpdatedTimestamp(new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
operationResponses.add(this.getOperationResponse(rs));
|
|
|
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
|
|
|
|
|
|
|
@ -355,7 +356,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
activity.setActivityStatus(activityStatusList);
|
|
|
|
activity.setActivityStatus(activityStatusList);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
activityStatus.getResponses().add(this.getOperationResponse(rs));
|
|
|
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -397,7 +398,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
// "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE AS dor ON dor.ENROLMENT_ID=de.id \n" +
|
|
|
|
// "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE AS dor ON dor.ENROLMENT_ID=de.id \n" +
|
|
|
|
// "AND dor.OPERATION_ID=eom.OPERATION_ID\n" +
|
|
|
|
// "AND dor.OPERATION_ID=eom.OPERATION_ID\n" +
|
|
|
|
// "WHERE eom.UPDATED_TIMESTAMP > ? AND de.TENANT_ID = ? ORDER BY eom.OPERATION_ID";
|
|
|
|
// "WHERE eom.UPDATED_TIMESTAMP > ? AND de.TENANT_ID = ? ORDER BY eom.OPERATION_ID";
|
|
|
|
|
|
|
|
|
|
|
|
// if(limit > 0) {
|
|
|
|
// if(limit > 0) {
|
|
|
|
// sql = sql + " LIMIT ?";
|
|
|
|
// sql = sql + " LIMIT ?";
|
|
|
|
// }
|
|
|
|
// }
|
|
|
@ -455,7 +455,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE_NAME"));
|
|
|
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE"));
|
|
|
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
|
|
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
|
|
|
|
|
|
|
|
|
|
|
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
|
|
|
@ -467,13 +467,13 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
operationResponses.add(this.getOperationResponse(rs));
|
|
|
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
statusList.add(activityStatus);
|
|
|
|
statusList.add(activityStatus);
|
|
|
|
activity.setActivityStatus(statusList);
|
|
|
|
activity.setActivityStatus(statusList);
|
|
|
|
activity.setActivityId(this.getActivityId(rs.getInt("OPERATION_ID")));
|
|
|
|
activity.setActivityId(OperationDAOUtil.getActivityId(rs.getInt("OPERATION_ID")));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -497,7 +497,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
operationResponses.add(this.getOperationResponse(rs));
|
|
|
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
@ -506,9 +506,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
|
|
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")){
|
|
|
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
activityStatus.getResponses().add(this.getOperationResponse(rs));
|
|
|
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -539,7 +539,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
stmt.setLong(1, timestamp);
|
|
|
|
stmt.setLong(1, timestamp);
|
|
|
|
stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
if(rs.next()){
|
|
|
|
if (rs.next()) {
|
|
|
|
return rs.getInt("COUNT");
|
|
|
|
return rs.getInt("COUNT");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -551,41 +551,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private OperationResponse getOperationResponse(ResultSet rs) throws
|
|
|
|
|
|
|
|
ClassNotFoundException, IOException, SQLException {
|
|
|
|
|
|
|
|
OperationResponse response = new OperationResponse();
|
|
|
|
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
|
|
|
|
response.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ByteArrayInputStream bais = null;
|
|
|
|
|
|
|
|
ObjectInputStream ois = null;
|
|
|
|
|
|
|
|
byte[] contentBytes;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (rs.getBytes("OPERATION_RESPONSE") != null) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException {
|
|
|
|
public int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
@ -728,7 +693,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("ID"));
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation .", e);
|
|
|
|
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation .", e);
|
|
|
@ -774,7 +739,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
this.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("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 " +
|
|
|
@ -821,7 +786,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("ID"));
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
operations.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -873,7 +838,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"));
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
|
|
|
|
operations.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -972,7 +937,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("ID"));
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
operations.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -1026,7 +991,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
Operation operation = null;
|
|
|
|
Operation operation = null;
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
operation = new Operation();
|
|
|
|
operation = new Operation();
|
|
|
|
operation.setType(this.getType(rs.getString("TYPE")));
|
|
|
|
operation.setType(OperationDAOUtil.getType(rs.getString("TYPE")));
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
@ -1042,7 +1007,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("ID"));
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operation;
|
|
|
|
return operation;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -1090,7 +1055,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
this.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
operations.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -1102,18 +1067,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
return operations;
|
|
|
|
return operations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Operation.Type getType(String type) {
|
|
|
|
|
|
|
|
return Operation.Type.valueOf(type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setActivityId(Operation operation, int operationId) {
|
|
|
|
|
|
|
|
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getActivityId(int operationId) {
|
|
|
|
|
|
|
|
return DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|