Adding support to retrieve the next available operation to be installed

merge-requests/7/head
prabathabey 10 years ago
parent e6d74ac9b4
commit 5f7e4306de

@ -27,8 +27,7 @@ public class AppManagementServiceImpl implements AppManagerConnector {
@Override @Override
public Application[] getApplicationList(String domain, int pageNumber, public Application[] getApplicationList(String domain, int pageNumber,
int size) throws AppManagerConnectorException { int size) throws AppManagerConnectorException {
return DeviceManagementDataHolder.getInstance().getAppManager() return DeviceManagementDataHolder.getInstance().getAppManager().getApplicationList(domain, pageNumber, size);
.getApplicationList(domain, pageNumber, size);
} }
@Override @Override
@ -48,4 +47,5 @@ public class AppManagementServiceImpl implements AppManagerConnector {
public Credential getClientCredentials() throws AppManagerConnectorException { public Credential getClientCredentials() throws AppManagerConnectorException {
return DeviceManagementDataHolder.getInstance().getAppManager().getClientCredentials(); return DeviceManagementDataHolder.getInstance().getAppManager().getClientCredentials();
} }
} }

@ -104,9 +104,7 @@ public class OperationManagerImpl implements OperationManager {
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException { public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
try { try {
OperationManagementDAOFactory.beginTransaction(); OperationManagementDAOFactory.beginTransaction();
profileOperationDAO.getNextOperation(deviceId);
operationDAO.getNextOperation(deviceId);
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
return null; return null;
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.*; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.*;
import javax.sql.DataSource; import javax.sql.DataSource;

@ -107,7 +107,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
if (rs.next()) { if (rs.next()) {
payload = rs.getBytes("PAYLOAD"); payload = rs.getBytes("PAYLOAD");
} }
bais = new ByteArrayInputStream(payload); bais = new ByteArrayInputStream(payload);
ois = new ObjectInputStream(bais); ois = new ObjectInputStream(bais);
return (ProfileOperation) ois.readObject(); return (ProfileOperation) ois.readObject();
@ -149,7 +148,41 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException {
return null; PreparedStatement stmt = null;
ResultSet rs = null;
ByteArrayInputStream bais;
ObjectInputStream ois;
try {
Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement(
"SELECT o.ID AS OPERATION_ID, o.CREATED_TIMESTAMP AS CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP AS " +
"RECEIVED_TIMESTAMP, po.PAYLOAD AS PAYLOAD FROM DM_OPERATION o " +
"INNER JOIN DM_PROFILE_OPERATION po ON o.ID = po.OPERATION_ID AND o.ID IN (" +
"SELECT dom.OPERATION_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) ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1;");
stmt.setString(1, deviceId.getType());
stmt.setString(2, deviceId.getId());
rs = stmt.executeQuery();
byte[] payload = new byte[0];
if (rs.next()) {
payload = rs.getBytes("PAYLOAD");
}
bais = new ByteArrayInputStream(payload);
ois = new ObjectInputStream(bais);
return (ProfileOperation) ois.readObject();
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
} catch (ClassNotFoundException e) {
throw new OperationManagementDAOException("Error occurred while casting retrieved payload as a " +
"ProfileOperation object", e);
} catch (IOException e) {
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
} }
} }

Loading…
Cancel
Save