|
|
@ -39,7 +39,6 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
private static final Log log = LogFactory.getLog(OperationDAOImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(OperationDAOImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
|
|
|
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -68,17 +67,14 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
|
|
|
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=? " +
|
|
|
|
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP = ? " +
|
|
|
|
"WHERE O.ID=?");
|
|
|
|
"WHERE O.ID = ?");
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setInt(2, operation.getId());
|
|
|
|
stmt.setInt(2, operation.getId());
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while update operation metadata", e);
|
|
|
|
throw new OperationManagementDAOException("Error occurred while update operation metadata", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -88,13 +84,11 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
public void updateOperationStatus(int enrolmentId, int operationId, Operation.Status status)
|
|
|
|
public void updateOperationStatus(int enrolmentId, int operationId, Operation.Status status)
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS=? " +
|
|
|
|
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS = ? " +
|
|
|
|
"WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?");
|
|
|
|
"WHERE O.ENROLMENT_ID = ? and O.OPERATION_ID = ?");
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setString(1, status.toString());
|
|
|
|
stmt.setString(1, status.toString());
|
|
|
|
stmt.setInt(2, enrolmentId);
|
|
|
|
stmt.setInt(2, enrolmentId);
|
|
|
|
stmt.setInt(3, operationId);
|
|
|
|
stmt.setInt(3, operationId);
|
|
|
@ -102,28 +96,22 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
|
|
|
|
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
|
|
|
|
"metadata",
|
|
|
|
"metadata", e);
|
|
|
|
e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ByteArrayOutputStream bao = null;
|
|
|
|
ByteArrayOutputStream bao = null;
|
|
|
|
ObjectOutputStream oos = null;
|
|
|
|
ObjectOutputStream oos = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
|
|
|
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, DEVICE_ID, " +
|
|
|
|
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,DEVICE_ID," +
|
|
|
|
|
|
|
|
"OPERATION_RESPONSE) VALUES(?, ?, ?)");
|
|
|
|
"OPERATION_RESPONSE) VALUES(?, ?, ?)");
|
|
|
|
|
|
|
|
|
|
|
|
bao = new ByteArrayOutputStream();
|
|
|
|
bao = new ByteArrayOutputStream();
|
|
|
|
oos = new ObjectOutputStream(bao);
|
|
|
|
oos = new ObjectOutputStream(bao);
|
|
|
|
oos.writeObject(operationResponse);
|
|
|
|
oos.writeObject(operationResponse);
|
|
|
@ -132,12 +120,11 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
stmt.setInt(2, enrolmentId);
|
|
|
|
stmt.setInt(2, enrolmentId);
|
|
|
|
stmt.setBytes(3, bao.toByteArray());
|
|
|
|
stmt.setBytes(3, bao.toByteArray());
|
|
|
|
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);
|
|
|
|
}catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e);
|
|
|
|
throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e);
|
|
|
|
}finally {
|
|
|
|
} finally {
|
|
|
|
if (bao != null) {
|
|
|
|
if (bao != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
bao.close();
|
|
|
|
bao.close();
|
|
|
@ -158,11 +145,10 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteOperation(int id) throws OperationManagementDAOException {
|
|
|
|
public void deleteOperation(int id) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
stmt = connection.prepareStatement("DELETE DM_OPERATION WHERE ID=?");
|
|
|
|
stmt = connection.prepareStatement("DELETE DM_OPERATION WHERE ID = ?");
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -174,16 +160,13 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Operation getOperation(int id) throws OperationManagementDAOException {
|
|
|
|
public Operation getOperation(int id) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation = null;
|
|
|
|
Operation operation = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
|
|
|
|
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
|
|
|
|
"DM_OPERATION WHERE id=?";
|
|
|
|
"DM_OPERATION WHERE id = ?";
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
@ -202,10 +185,8 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL Error occurred while retrieving the operation object " + "available for the id '"
|
|
|
|
throw new OperationManagementDAOException("SQL Error occurred while retrieving the operation object " +
|
|
|
|
+ id;
|
|
|
|
"available for the id '" + id, e);
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
@ -215,19 +196,16 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@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;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
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 " +
|
|
|
|
" 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_OPERATION_MAPPING dm where dm.OPERATION_ID=? AND dm.ENROLMENT_ID=?) om " +
|
|
|
|
"DM_ENROLMENT_OPERATION_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
|
|
|
|
"ON o.ID = om.OPERATION_ID ";
|
|
|
|
"ON o.ID = om.OPERATION_ID ";
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
|
stmt.setInt(2, operationId);
|
|
|
|
stmt.setInt(2, operationId);
|
|
|
@ -247,10 +225,8 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
|
|
|
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
|
|
|
"' with id '" + operationId;
|
|
|
|
"available for the device'" + enrolmentId + "' with id '" + operationId, e);
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
@ -259,26 +235,21 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
|
|
|
public List<? extends Operation> getOperationsByDeviceAndStatus(
|
|
|
|
Operation.Status status) throws OperationManagementDAOException {
|
|
|
|
int enrolmentId, Operation.Status status) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
List<Operation> operationList = 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 " +
|
|
|
|
"FROM DM_OPERATION o " +
|
|
|
|
"FROM DM_OPERATION o " +
|
|
|
|
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
|
|
|
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " +
|
|
|
|
"where dm.ENROLMENT_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, enrolmentId);
|
|
|
|
stmt.setInt(1, enrolmentId);
|
|
|
|
stmt.setString(2, status.toString());
|
|
|
|
stmt.setString(2, status.toString());
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
@ -293,40 +264,32 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
operation.setStatus(status);
|
|
|
|
operation.setStatus(status);
|
|
|
|
operationList.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
|
|
|
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
|
|
|
"' with status '" + status.toString();
|
|
|
|
"available for the device'" + enrolmentId + "' with status '" + status.toString(), e);
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operationList;
|
|
|
|
return operations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<? extends Operation> getOperationsForDevice(int enrolmentId)
|
|
|
|
public List<? extends Operation> getOperationsForDevice(int enrolmentId) throws OperationManagementDAOException {
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
List<Operation> operationList = new ArrayList<Operation>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,dm.STATUS FROM DM_OPERATION o " +
|
|
|
|
"OPERATION_CODE, dm.STATUS FROM DM_OPERATION o " +
|
|
|
|
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
|
|
|
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " +
|
|
|
|
"where dm.ENROLMENT_ID=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, enrolmentId);
|
|
|
|
stmt.setInt(1, enrolmentId);
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
@ -341,40 +304,34 @@ public class OperationDAOImpl 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")));
|
|
|
|
operationList.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
|
|
|
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
|
|
|
"' with status '";
|
|
|
|
"available for the device'" + enrolmentId + "' with status '", e);
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operationList;
|
|
|
|
return operations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException {
|
|
|
|
public Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
|
|
|
|
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 FROM DM_OPERATION o " +
|
|
|
|
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
|
|
|
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_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");
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setInt(1, enrolmentId);
|
|
|
|
stmt.setInt(1, enrolmentId);
|
|
|
|
stmt.setString(2, Operation.Status.PENDING.toString());
|
|
|
|
stmt.setString(2, Operation.Status.PENDING.toString());
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
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(this.getType(rs.getString("TYPE")));
|
|
|
@ -398,28 +355,24 @@ public class OperationDAOImpl implements OperationDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<? extends Operation> getOperationsByDeviceStatusAndType(int enrolmentId,
|
|
|
|
public List<? extends Operation> getOperationsByDeviceStatusAndType(
|
|
|
|
Operation.Status status, Operation.Type type) throws OperationManagementDAOException {
|
|
|
|
int enrolmentId, Operation.Status status, Operation.Type type) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
Operation operation;
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
List<Operation> operationList = 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 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_OPERATION_MAPPING dm " +
|
|
|
|
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING dm " +
|
|
|
|
"where dm.ENROLMENT_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, type.toString());
|
|
|
|
stmt.setString(1, type.toString());
|
|
|
|
stmt.setInt(2, enrolmentId);
|
|
|
|
stmt.setInt(2, enrolmentId);
|
|
|
|
stmt.setString(3, status.toString());
|
|
|
|
stmt.setString(3, status.toString());
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
@ -433,22 +386,16 @@ public class OperationDAOImpl 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"));
|
|
|
|
operationList.add(operation);
|
|
|
|
operations.add(operation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
|
|
|
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " +
|
|
|
|
"' with status '" + status.toString();
|
|
|
|
"for the device'" + enrolmentId + "' with status '" + status.toString(), e);
|
|
|
|
log.error(errorMsg);
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operationList;
|
|
|
|
return operations;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Operation.Status getStatus(String status) {
|
|
|
|
|
|
|
|
return Operation.Status.valueOf(status);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Operation.Type getType(String type) {
|
|
|
|
private Operation.Type getType(String type) {
|
|
|
|