mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Update Operation manager implementation
This commit is contained in:
parent
4a9a27ab7e
commit
416ef5a745
@ -58,7 +58,6 @@ public interface OperationManager {
|
||||
|
||||
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException;
|
||||
|
||||
public Operation updateOperation(
|
||||
int id, DeviceIdentifier deviceIdentifier, String payLoad) throws OperationManagementException;
|
||||
public void updateOperation(int operationId, Operation.Status operationStatus) throws OperationManagementException;
|
||||
|
||||
}
|
||||
@ -361,9 +361,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation updateOperation(int id, DeviceIdentifier deviceIdentifier,
|
||||
String payLoad) throws OperationManagementException {
|
||||
return operationManager.updateOperation(id, deviceIdentifier, payLoad);
|
||||
public void updateOperation(int operationId, Operation.Status operationStatus)
|
||||
throws OperationManagementException {
|
||||
operationManager.updateOperation(operationId,operationStatus);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -155,9 +155,19 @@ public class OperationManagerImpl implements OperationManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation updateOperation(int id, DeviceIdentifier deviceIdentifier,
|
||||
String responsePayLoad) throws OperationManagementException {
|
||||
return null;
|
||||
public void updateOperation(int operationId, Operation.Status operationStatus)
|
||||
throws OperationManagementException {
|
||||
try {
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
Operation operation = operationDAO.getOperation(operationId);
|
||||
operation.setStatus(operationStatus);
|
||||
operationDAO.updateOperation(operation);
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
}catch(OperationManagementDAOException ex){
|
||||
log.error("Error occurred while updating the operation: "+operationId);
|
||||
throw new OperationManagementException("Error occurred while update operation", ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private OperationDAO lookupOperationDAO(Operation operation) {
|
||||
|
||||
@ -35,7 +35,7 @@ public interface OperationDAO {
|
||||
|
||||
Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException;
|
||||
|
||||
Operation getOperation(DeviceIdentifier deviceId, Operation.Status status) throws OperationManagementDAOException;
|
||||
Operation getOperation(DeviceIdentifier deviceIdentifier, Operation.Status status) throws OperationManagementDAOException;
|
||||
|
||||
List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException;
|
||||
|
||||
|
||||
@ -55,6 +55,44 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.openConnection();
|
||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE," +
|
||||
"co.ENABLED FROM DM_OPERATION o INNER JOIN DM_COMMAND_OPERATION co ON " +
|
||||
"co.OPERATION_ID = o.ID WHERE o.ID=?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, id);
|
||||
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.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operation.setCode(rs.getString("OPERATIONCODE"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while retrieving the operation object " +
|
||||
"available for the id '" + id + "'", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
@ -64,8 +102,10 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.openConnection();
|
||||
String sql = "SELECT po.OPERATION_ID, po.TYPE, po.CREATED_TIMESTAMP, po.RECEIVED_TIMESTAMP, po.STATUS, " +
|
||||
"co.ENABLED,o.OPERATIONCODE FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, " +
|
||||
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o INNER JOIN (" +
|
||||
"co.ENABLED,o.OPERATIONCODE FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, "
|
||||
+
|
||||
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o INNER JOIN ("
|
||||
+
|
||||
"SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN " +
|
||||
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND " +
|
||||
"d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = " +
|
||||
@ -83,7 +123,12 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
operation.setId(rs.getInt("OPERATION_ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
|
||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
} else {
|
||||
operation.setCreatedTimeStamp(null);
|
||||
}
|
||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operation.setEnabled(rs.getBoolean("ENABLED"));
|
||||
operation.setCode(rs.getString("OPERATIONCODE"));
|
||||
@ -107,8 +152,10 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.openConnection();
|
||||
String sql = "SELECT po.OPERATION_ID, po.TYPE, po.CREATED_TIMESTAMP, po.RECEIVED_TIMESTAMP, po.STATUS, " +
|
||||
"co.ENABLED.o.OPERATIONCODE FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, " +
|
||||
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o INNER JOIN (" +
|
||||
"co.ENABLED.o.OPERATIONCODE FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, "
|
||||
+
|
||||
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM DM_OPERATION o INNER JOIN ("
|
||||
+
|
||||
"SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN " +
|
||||
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND " +
|
||||
"d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = " +
|
||||
@ -117,7 +164,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, deviceId.getType());
|
||||
stmt.setString(1, deviceId.getId());
|
||||
stmt.setString(2, deviceId.getId());
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
List<CommandOperation> operations = new ArrayList<CommandOperation>();
|
||||
@ -125,6 +172,13 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
CommandOperation operation = new CommandOperation();
|
||||
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(null);
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operation.setEnabled(Boolean.parseBoolean(rs.getString("ENABLED")));
|
||||
operation.setCode(rs.getString("OPERATIONCODE"));
|
||||
|
||||
@ -67,8 +67,8 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.openConnection();
|
||||
stmt = connection.prepareStatement(
|
||||
"UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=?,O.STATUS=? WHERE O.ID=?");
|
||||
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=?,O.STATUS=? " +
|
||||
"WHERE O.ID=?");
|
||||
|
||||
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
||||
stmt.setString(2, operation.getStatus().toString());
|
||||
@ -84,6 +84,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
|
||||
@Override
|
||||
public void deleteOperation(int id) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.openConnection();
|
||||
@ -98,13 +99,90 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||
return null;
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.openConnection();
|
||||
String sql =
|
||||
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM " +
|
||||
"DM_OPERATION o WHERE o.ID=?";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, id);
|
||||
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.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operation.setCode(rs.getString("OPERATIONCODE"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while retrieving the operation object " +
|
||||
"available for the id '" + id + "'", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException {
|
||||
public Operation getOperation(DeviceIdentifier deviceIdentifier, int operationId)
|
||||
throws OperationManagementDAOException {
|
||||
|
||||
return null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation = null;
|
||||
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.openConnection();
|
||||
String sql =
|
||||
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATIONCODE FROM " +
|
||||
"DM_OPERATION o " +
|
||||
"INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM " +
|
||||
"(SELECT d.ID FROM DM_DEVICE d INNER " +
|
||||
"JOIN " +
|
||||
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND d" +
|
||||
".DEVICE_IDENTIFICATION = ?) d1 " +
|
||||
"INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = dom.DEVICE_ID) ois " +
|
||||
"ON o.ID = ois.OP_ID WHERE o.ID=?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, deviceIdentifier.getType());
|
||||
stmt.setString(2, deviceIdentifier.getId());
|
||||
stmt.setInt(3, operationId);
|
||||
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("CREATED_TIMESTAMP") == null) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operation.setCode(rs.getString("OPERATIONCODE"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while retrieving the operation list " +
|
||||
"available for the '" + deviceIdentifier.getType() + "' with id '" + deviceIdentifier.getId() + "'", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,8 +193,8 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
List<Operation> operations;
|
||||
|
||||
List<Operation> operations;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
@ -199,7 +277,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getString("RECEIVED_TIMESTAMP").toString());
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setCode(rs.getString("OPERATIONCODE"));
|
||||
}
|
||||
|
||||
@ -157,11 +157,14 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||
ois = new ObjectInputStream(bais);
|
||||
return (ProfileOperation) ois.readObject();
|
||||
} catch (SQLException e) {
|
||||
log.error("SQL error occurred while retrieving profile operation", e);
|
||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error("Class not found error occurred while retrieving profile operation", e);
|
||||
throw new OperationManagementDAOException("Error occurred while casting retrieved payload as a " +
|
||||
"ProfileOperation object", e);
|
||||
} catch (IOException e) {
|
||||
log.error("IO error occurred while de serialize profile operation", e);
|
||||
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
@ -178,8 +181,8 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.openConnection();
|
||||
stmt = connection.prepareStatement(
|
||||
"UPDATE DM_PROFILE_OPERATION O SET O.OPERATIONDETAILS=? WHERE O.OPERATION_ID=?");
|
||||
stmt = connection.prepareStatement("UPDATE DM_PROFILE_OPERATION O SET O.OPERATIONDETAILS=? " +
|
||||
"WHERE O.OPERATION_ID=?");
|
||||
|
||||
bao = new ByteArrayOutputStream();
|
||||
oos = new ObjectOutputStream(bao);
|
||||
|
||||
@ -137,10 +137,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation updateOperation(int operationId, DeviceIdentifier deviceIdentifier,
|
||||
String responsePayLoad) throws OperationManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
|
||||
updateOperation(operationId, deviceIdentifier, responsePayLoad);
|
||||
public void updateOperation(int operationId, Operation.Status operationStatus) throws OperationManagementException {
|
||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().updateOperation(operationId,
|
||||
operationStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -150,5 +149,4 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
.sendEnrolmentInvitation(emailMessageProperties);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user