|
|
|
@ -59,7 +59,6 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
@ -76,16 +75,15 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
try {
|
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " +
|
|
|
|
|
"INITIATED_BY, OPERATION_DETAILS, OPERATION_PROPERTIES, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
|
"INITIATED_BY, OPERATION_DETAILS, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
|
stmt = connection.prepareStatement(sql, new String[]{"id"});
|
|
|
|
|
stmt.setString(1, operation.getType().toString());
|
|
|
|
|
stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime());
|
|
|
|
|
stmt.setLong(3, 0);
|
|
|
|
|
stmt.setString(4, operation.getCode());
|
|
|
|
|
stmt.setString(5, operation.getInitiatedBy());
|
|
|
|
|
stmt.setObject(6, operation.getPayLoad());
|
|
|
|
|
stmt.setObject(7, operation.getProperties());
|
|
|
|
|
stmt.setInt(8, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
|
stmt.setObject(6, operation);
|
|
|
|
|
stmt.setInt(7, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
rs = stmt.getGeneratedKeys();
|
|
|
|
@ -166,7 +164,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<Integer, Integer> getExistingNotExecutedOperationIDs(Integer[] enrolmentIds, String operationCode)
|
|
|
|
|
public Map<Integer, Integer> getExistingOperationIDs(Integer[] enrolmentIds, String operationCode)
|
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
@ -578,7 +576,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
+ "dor.ID AS OP_RES_ID, de.DEVICE_ID, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID, "
|
|
|
|
|
+ "dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, "
|
|
|
|
|
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
|
|
|
|
|
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE FROM "
|
|
|
|
|
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE FROM "
|
|
|
|
|
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
|
|
|
|
|
+ "ON op.ID=eom.OPERATION_ID INNER JOIN DM_ENROLMENT de "
|
|
|
|
|
+ "ON de.ID=eom.ENROLMENT_ID INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID "
|
|
|
|
@ -1191,14 +1189,24 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
Operation operation = null;
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, " +
|
|
|
|
|
"OPERATION_DETAILS, OPERATION_PROPERTIES FROM DM_OPERATION WHERE id = ?";
|
|
|
|
|
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY FROM " +
|
|
|
|
|
"DM_OPERATION WHERE id = ?";
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
if (rs.getLong("RECEIVED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(new Timestamp(rs.getLong("RECEIVED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@ -1211,19 +1219,16 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Operation getOperationByDeviceAndId(int enrolmentId, int operationId)
|
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
|
public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Operation operation = null;
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, " +
|
|
|
|
|
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
|
|
|
|
|
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP, om.STATUS FROM " +
|
|
|
|
|
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," +
|
|
|
|
|
"OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, OPERATION_PROPERTIES FROM DM_OPERATION " +
|
|
|
|
|
"WHERE id = ?) o INNER JOIN (SELECT * FROM " +
|
|
|
|
|
"o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, " +
|
|
|
|
|
"om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," +
|
|
|
|
|
"OPERATION_CODE, INITIATED_BY FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " +
|
|
|
|
|
"DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
|
|
|
|
|
"ON o.ID = om.OPERATION_ID ";
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
@ -1233,14 +1238,20 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(
|
|
|
|
|
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
|
|
|
@ -1261,8 +1272,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
|
|
|
|
|
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.ID AS OM_MAPPING_ID, " +
|
|
|
|
|
"om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
|
|
|
|
"o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
|
|
|
|
"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";
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
@ -1271,14 +1281,20 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation.setStatus(status);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(
|
|
|
|
|
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
operation.setStatus(status);
|
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@ -1301,8 +1317,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
|
|
|
|
|
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.ID AS OM_MAPPING_ID, " +
|
|
|
|
|
"om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
|
|
|
|
"o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
|
|
|
|
"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 LIMIT ?,?";
|
|
|
|
@ -1314,15 +1329,20 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation.setStatus(status);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(
|
|
|
|
|
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
operation.setStatus(status);
|
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("OM_MAPPING_ID"));
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@ -1344,8 +1364,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
|
|
|
|
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.STATUS, " +
|
|
|
|
|
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP " +
|
|
|
|
|
"o.OPERATION_CODE, o.INITIATED_BY, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP " +
|
|
|
|
|
"FROM DM_OPERATION o 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, o.ID DESC";
|
|
|
|
@ -1354,13 +1373,18 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(
|
|
|
|
|
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
@ -1404,7 +1428,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
"o.OPERATION_CODE, " +
|
|
|
|
|
"o.INITIATED_BY, " +
|
|
|
|
|
"o.OPERATION_DETAILS, " +
|
|
|
|
|
"o.OPERATION_PROPERTIES, " +
|
|
|
|
|
"om.STATUS, " +
|
|
|
|
|
"om.ID AS OM_MAPPING_ID, " +
|
|
|
|
|
"om.UPDATED_TIMESTAMP " +
|
|
|
|
@ -1491,14 +1514,36 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
stmt.setInt(paramIndex, request.getRowCount());
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(
|
|
|
|
|
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
if (MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL.equals(operation.getCode())) {
|
|
|
|
|
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
|
|
|
try (ByteArrayInputStream bais = new ByteArrayInputStream(operationDetails);
|
|
|
|
|
ObjectInputStream ois = new ObjectInputStream(bais)) {
|
|
|
|
|
profileOperation = (ProfileOperation) ois.readObject();
|
|
|
|
|
operation.setPayLoad(profileOperation.getPayLoad());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
String msg = "IO Error occurred while retrieving app data of operation ";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new OperationManagementDAOException(msg, e);
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
|
String msg = "Class not found error occurred while retrieving app data of operation ";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new OperationManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1517,6 +1562,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
|
String createdTo = null;
|
|
|
|
|
String createdFrom = null;
|
|
|
|
|
ProfileOperation profileOperation = null;
|
|
|
|
|
DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
|
|
|
|
boolean isCreatedDayProvided = false;
|
|
|
|
|
boolean isUpdatedDayProvided = false; //updated day = received day
|
|
|
|
@ -1540,7 +1586,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
"o.OPERATION_CODE, " +
|
|
|
|
|
"o.INITIATED_BY, " +
|
|
|
|
|
"o.OPERATION_DETAILS, " +
|
|
|
|
|
"o.OPERATION_PROPERTIES, " +
|
|
|
|
|
"om.STATUS, " +
|
|
|
|
|
"om.ID AS OM_MAPPING_ID, " +
|
|
|
|
|
"om.UPDATED_TIMESTAMP " +
|
|
|
|
@ -1627,14 +1672,36 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
stmt.setInt(paramIndex, request.getRowCount());
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(
|
|
|
|
|
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
if (MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL.equals(operation.getCode())) {
|
|
|
|
|
byte[] operationDetails = rs.getBytes("OPERATION_DETAILS");
|
|
|
|
|
try (ByteArrayInputStream bais = new ByteArrayInputStream(operationDetails);
|
|
|
|
|
ObjectInputStream ois = new ObjectInputStream(bais)) {
|
|
|
|
|
profileOperation = (ProfileOperation) ois.readObject();
|
|
|
|
|
operation.setPayLoad(profileOperation.getPayLoad());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
String msg = "IO Error occurred while retrieving app data of operation ";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new OperationManagementDAOException(msg, e);
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
|
String msg = "Class not found error occurred while retrieving app data of operation ";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new OperationManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1865,8 +1932,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
try {
|
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
stmt = connection.prepareStatement("SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
|
|
|
|
|
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
|
|
|
|
|
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
|
|
|
|
"o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
|
|
|
|
|
"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 om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1");
|
|
|
|
@ -1876,14 +1942,21 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
Operation operation = null;
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setType(OperationDAOUtil.getType(rs.getString("TYPE")));
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(
|
|
|
|
|
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
operation.setStatus(Operation.Status.PENDING);
|
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
|
}
|
|
|
|
|
return operation;
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@ -1902,9 +1975,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, " +
|
|
|
|
|
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
|
|
|
|
|
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " +
|
|
|
|
|
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, o.INITIATED_BY," +
|
|
|
|
|
" om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " +
|
|
|
|
|
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY " +
|
|
|
|
|
"FROM DM_OPERATION o WHERE o.TYPE = ?) o 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 ASC";
|
|
|
|
@ -1916,14 +1988,19 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
operation = OperationDAOUtil.getOperation(rs);
|
|
|
|
|
operation.setStatus(status);
|
|
|
|
|
operation = new Operation();
|
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
|
} else {
|
|
|
|
|
operation.setReceivedTimeStamp(
|
|
|
|
|
new Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
|
|
|
|
|
}
|
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
operation.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
OperationDAOUtil.setActivityId(operation, rs.getInt("ID"));
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@ -1936,8 +2013,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus,
|
|
|
|
|
Operation.PushNotificationStatus pushNotificationStatus,
|
|
|
|
|
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus,
|
|
|
|
|
int limit) throws OperationManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
@ -1983,8 +2059,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<Integer, List<OperationMapping>> getAllocatedOperationMappingsByStatus(Operation.Status opStatus,
|
|
|
|
|
Operation.PushNotificationStatus pushNotificationStatus,
|
|
|
|
|
int limit, int activeServerCount, int serverIndex)
|
|
|
|
|
Operation.PushNotificationStatus pushNotificationStatus, int limit, int activeServerCount, int serverIndex)
|
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
@ -2197,7 +2272,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getDeviceType() != null ||
|
|
|
|
|
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
|
|
|
|
|
activityPaginationRequest.getSince() != 0 ||
|
|
|
|
|
activityPaginationRequest.getStatuses() != null) {
|
|
|
|
|
activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
|
|
|
|
|
sql.append("(SELECT DISTINCT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING eom WHERE TENANT_ID = ? ");
|
|
|
|
|
|
|
|
|
@ -2230,12 +2305,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
sql.append("AND TYPE = ? ");
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
sql.append("AND STATUS IN (");
|
|
|
|
|
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
|
|
|
|
|
sql.append("?, ");
|
|
|
|
|
}
|
|
|
|
|
sql.append("?) ");
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
sql.append("AND STATUS = ? ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql.append("ORDER BY OPERATION_ID ASC limit ? , ? ) eom_ordered " +
|
|
|
|
@ -2289,12 +2360,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
sql.append("AND eom.TYPE = ? ");
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
sql.append("AND eom.STATUS IN (");
|
|
|
|
|
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
|
|
|
|
|
sql.append("?, ");
|
|
|
|
|
}
|
|
|
|
|
sql.append("?) ");
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
sql.append("AND eom.STATUS = ? ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql.append("ORDER BY eom.OPERATION_ID, eom.UPDATED_TIMESTAMP");
|
|
|
|
@ -2305,7 +2372,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getDeviceType() != null ||
|
|
|
|
|
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
|
|
|
|
|
activityPaginationRequest.getSince() != 0 ||
|
|
|
|
|
activityPaginationRequest.getStatuses() != null) {
|
|
|
|
|
activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
|
|
|
|
|
if (activityPaginationRequest.getDeviceType() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getDeviceType());
|
|
|
|
@ -2334,10 +2401,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getType().name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
|
|
|
|
|
stmt.setString(index++, status.name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getStatus().name());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stmt.setInt(index++, activityPaginationRequest.getOffset());
|
|
|
|
@ -2398,10 +2463,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getType().name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
|
|
|
|
|
stmt.setString(index++, status.name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
stmt.setString(index, activityPaginationRequest.getStatus().name());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
@ -2433,7 +2496,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getDeviceType() != null ||
|
|
|
|
|
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
|
|
|
|
|
activityPaginationRequest.getSince() != 0 ||
|
|
|
|
|
activityPaginationRequest.getStatuses() != null) {
|
|
|
|
|
activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
|
|
|
|
|
sql.append("SELECT count(DISTINCT OPERATION_ID) AS ACTIVITY_COUNT " +
|
|
|
|
|
"FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? ");
|
|
|
|
@ -2463,12 +2526,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
sql.append("AND TYPE = ? ");
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
sql.append("AND STATUS IN (");
|
|
|
|
|
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
|
|
|
|
|
sql.append("?, ");
|
|
|
|
|
}
|
|
|
|
|
sql.append("?) ");
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
sql.append("AND STATUS = ? ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
@ -2496,7 +2555,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getDeviceType() != null ||
|
|
|
|
|
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
|
|
|
|
|
activityPaginationRequest.getSince() != 0 ||
|
|
|
|
|
activityPaginationRequest.getStatuses() != null) {
|
|
|
|
|
activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
if (activityPaginationRequest.getDeviceType() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getDeviceType());
|
|
|
|
|
}
|
|
|
|
@ -2520,10 +2579,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getType().name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
|
|
|
|
|
stmt.setString(index++, status.name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getStatus().name());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (activityPaginationRequest.getOperationCode() != null) {
|
|
|
|
@ -2605,12 +2662,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
sql.append("AND TYPE = ? ");
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
sql.append("AND STATUS IN (");
|
|
|
|
|
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
|
|
|
|
|
sql.append("?, ");
|
|
|
|
|
}
|
|
|
|
|
sql.append("?) ");
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
sql.append("AND STATUS = ? ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql.append("ORDER BY ID ASC limit ? , ? ) eom " +
|
|
|
|
@ -2647,10 +2700,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getType().name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
|
|
|
|
|
stmt.setString(index++, status.name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getStatus().name());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stmt.setInt(index++, activityPaginationRequest.getOffset());
|
|
|
|
@ -2693,6 +2744,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
StringBuilder sql = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sql.append("SELECT count(DISTINCT ID) AS ACTIVITY_COUNT " +
|
|
|
|
|
"FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? ");
|
|
|
|
|
|
|
|
|
@ -2721,12 +2773,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
sql.append("AND TYPE = ? ");
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
sql.append("AND STATUS IN (");
|
|
|
|
|
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
|
|
|
|
|
sql.append("?, ");
|
|
|
|
|
}
|
|
|
|
|
sql.append("?) ");
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
sql.append("AND STATUS = ? ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) {
|
|
|
|
@ -2760,10 +2808,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
|
if (activityPaginationRequest.getType() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getType().name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
|
|
|
|
|
for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
|
|
|
|
|
stmt.setString(index++, status.name());
|
|
|
|
|
}
|
|
|
|
|
if (activityPaginationRequest.getStatus() != null) {
|
|
|
|
|
stmt.setString(index++, activityPaginationRequest.getStatus().name());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isTimeDurationFilteringProvided) {
|
|
|
|
|