mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Extending operation management implementation to support getPendingOperations() and getOperations() functionalities
This commit is contained in:
parent
0583695338
commit
befb9cc711
@ -26,17 +26,17 @@ import java.util.Properties;
|
||||
public class Operation {
|
||||
|
||||
public enum Type {
|
||||
CONFIG, MESSAGE, INFO, COMMAND
|
||||
CONFIG, MESSAGE, INFO, COMMAND, PROFILE
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
IN_PROGRES, PENDING, COMPLETED, ERROR
|
||||
IN_PROGRESS, PENDING, COMPLETED, ERROR
|
||||
}
|
||||
|
||||
private String code;
|
||||
private Properties properties;
|
||||
private Type type;
|
||||
private Long operationId;
|
||||
private int id;
|
||||
private String payLoad;
|
||||
private Status status;
|
||||
|
||||
@ -67,12 +67,12 @@ public class Operation {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Long getOperationId() {
|
||||
return operationId;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setOperationId(Long operationId) {
|
||||
this.operationId = operationId;
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPayLoad() {
|
||||
@ -83,11 +83,11 @@ public class Operation {
|
||||
this.payLoad = payLoad;
|
||||
}
|
||||
|
||||
public Status getOperationStates() {
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setOperationStates(Status status) {
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ public interface OperationManager {
|
||||
* @throws OperationManagementException If some unusual behaviour is observed while fetching the
|
||||
* operation list.
|
||||
*/
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException;
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException;
|
||||
|
||||
/**
|
||||
* Method to retrieve the list of available operations to a device.
|
||||
@ -53,11 +53,12 @@ public interface OperationManager {
|
||||
* @throws OperationManagementException If some unusual behaviour is observed while fetching the
|
||||
* operation list.
|
||||
*/
|
||||
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException;
|
||||
public List<? extends Operation> getPendingOperations(
|
||||
DeviceIdentifier deviceId) throws OperationManagementException;
|
||||
|
||||
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException;
|
||||
|
||||
public Operation updateOperation(Long operationId, DeviceIdentifier deviceIdentifier,
|
||||
String payLoad) throws OperationManagementException;
|
||||
public Operation updateOperation(
|
||||
int id, DeviceIdentifier deviceIdentifier, String payLoad) throws OperationManagementException;
|
||||
|
||||
}
|
||||
@ -346,12 +346,12 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return operationManager.getOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return operationManager.getPendingOperations(deviceId);
|
||||
}
|
||||
|
||||
@ -361,8 +361,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation updateOperation(Long operationId, DeviceIdentifier deviceIdentifier,
|
||||
String responsePayLoad) throws OperationManagementException {
|
||||
public Operation updateOperation(int id, DeviceIdentifier deviceIdentifier,
|
||||
String payLoad) throws OperationManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -31,9 +31,11 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl;
|
||||
import org.wso2.carbon.device.mgt.core.api.mgt.APIConfig;
|
||||
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService;
|
||||
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl;
|
||||
import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver;
|
||||
import org.wso2.carbon.device.mgt.core.api.mgt.config.APIPublisherConfig;
|
||||
import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerConnectorException;
|
||||
import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector;
|
||||
import org.wso2.carbon.device.mgt.core.app.mgt.RemoteAppManagerConnector;
|
||||
@ -156,6 +158,10 @@ public class DeviceManagementServiceComponent {
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext componentContext) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
private void initLicenseManager() throws LicenseManagementException {
|
||||
LicenseConfigurationManager.getInstance().initConfig();
|
||||
LicenseConfig licenseConfig =
|
||||
@ -175,9 +181,11 @@ public class DeviceManagementServiceComponent {
|
||||
DeviceManagementDataHolder.getInstance().setAppManager(appManager);
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext componentContext) {
|
||||
//do nothing
|
||||
}
|
||||
// private void initAPIProviders() throws DeviceManagementException {
|
||||
// for (APIConfig config : APIPublisherConfig.getInstance().getApiConfigs()) {
|
||||
// config.init();
|
||||
// }
|
||||
// }
|
||||
|
||||
private void registerServices(ComponentContext componentContext) {
|
||||
if (log.isDebugEnabled()) {
|
||||
|
||||
@ -32,4 +32,8 @@ public class CommandOperation extends Operation {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return Type.COMMAND;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -75,4 +75,8 @@ public class ConfigOperation extends Operation {
|
||||
}
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return Type.CONFIG;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOE
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -91,34 +92,73 @@ public class OperationManagerImpl implements OperationManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
try {
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
profileOperationDAO.getNextOperation(deviceId);
|
||||
operations.addAll(profileOperationDAO.getOperations(deviceId));
|
||||
operations.addAll(configOperationDAO.getOperations(deviceId));
|
||||
operations.addAll(commandOperationDAO.getOperations(deviceId));
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
return null;
|
||||
|
||||
return operations;
|
||||
} catch (OperationManagementDAOException e) {
|
||||
try {
|
||||
OperationManagementDAOFactory.rollbackTransaction();
|
||||
} catch (OperationManagementDAOException e1) {
|
||||
log.warn("Error occurred while roll-backing the transaction", e1);
|
||||
}
|
||||
throw new OperationManagementException("Error occurred while adding operation", e);
|
||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
||||
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation updateOperation(Long operationId, DeviceIdentifier deviceIdentifier,
|
||||
public List<? extends Operation> getPendingOperations(
|
||||
DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
try {
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
operations.addAll(profileOperationDAO.getOperations(deviceId, Operation.Status.PENDING));
|
||||
operations.addAll(configOperationDAO.getOperations(deviceId, Operation.Status.PENDING));
|
||||
operations.addAll(commandOperationDAO.getOperations(deviceId, Operation.Status.PENDING));
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
|
||||
return operations;
|
||||
} catch (OperationManagementDAOException e) {
|
||||
try {
|
||||
OperationManagementDAOFactory.rollbackTransaction();
|
||||
} catch (OperationManagementDAOException e1) {
|
||||
log.warn("Error occurred while roll-backing the transaction", e1);
|
||||
}
|
||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
||||
"pending operations assigned for '" + deviceId.getType() + "' device '" +
|
||||
deviceId.getId() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
try {
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
Operation operation = operationDAO.getNextOperation(deviceId);
|
||||
operation = this.lookupOperationDAO(operation.getType()).getOperation(operation.getId());
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
return operation;
|
||||
} catch (OperationManagementDAOException e) {
|
||||
try {
|
||||
OperationManagementDAOFactory.rollbackTransaction();
|
||||
} catch (OperationManagementDAOException e1) {
|
||||
log.warn("Error occurred while roll-backing the transaction", e1);
|
||||
}
|
||||
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation updateOperation(int id, DeviceIdentifier deviceIdentifier,
|
||||
String responsePayLoad) throws OperationManagementException {
|
||||
return null;
|
||||
}
|
||||
@ -133,4 +173,17 @@ public class OperationManagerImpl implements OperationManager {
|
||||
}
|
||||
}
|
||||
|
||||
private OperationDAO lookupOperationDAO(Operation.Type type) {
|
||||
switch (type) {
|
||||
case CONFIG:
|
||||
return configOperationDAO;
|
||||
case PROFILE:
|
||||
return profileOperationDAO;
|
||||
case COMMAND:
|
||||
return commandOperationDAO;
|
||||
default:
|
||||
return commandOperationDAO;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -32,4 +32,8 @@ public class ProfileOperation extends ConfigOperation implements Serializable {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return Type.PROFILE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -35,9 +35,14 @@ public interface OperationDAO {
|
||||
|
||||
Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException;
|
||||
|
||||
List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException;
|
||||
Operation getOperation(DeviceIdentifier deviceId, Operation.Status status) throws OperationManagementDAOException;
|
||||
|
||||
List<Operation> getOperations(String status) throws OperationManagementDAOException;
|
||||
List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException;
|
||||
|
||||
List<? extends Operation> getOperations(DeviceIdentifier deviceId,
|
||||
Operation.Status status) throws OperationManagementDAOException;
|
||||
|
||||
List<? extends Operation> getOperations(Operation.Status status) throws OperationManagementDAOException;
|
||||
|
||||
Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException;
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
@ -37,11 +38,11 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
||||
int operationId = super.addOperation(operation);
|
||||
CommandOperation commandOp = (CommandOperation) operation;
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_COMMAND_OPERATION(OPERATION_ID, ENABLED) VALUES(?, ?)");
|
||||
stmt.setInt(1, operationId);
|
||||
stmt.setBoolean(2, commandOp.isEnabled());
|
||||
@ -54,39 +55,71 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOperation(Operation operation) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT po.OPERATION_ID, po.TYPE, po.CREATED_TIMESTAMP, po.RECEIVED_TIMESTAMP, po.STATUS, " +
|
||||
"co.ENABLED FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, " +
|
||||
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS 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 AND o.STATUS = ? ORDER BY " +
|
||||
"o.CREATED_TIMESTAMP ASC) po ON co.OPERATION_ID = po.OPERATION_ID";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, deviceId.getType());
|
||||
stmt.setString(1, deviceId.getId());
|
||||
stmt.setString(1, status.toString());
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while retrieving the list of " +
|
||||
"operations with the status '" + status + "' available for the '" + deviceId.getType() +
|
||||
"' device '" + deviceId.getId() + "'");
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOperation(int id) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT po.OPERATION_ID, po.TYPE, po.CREATED_TIMESTAMP, po.RECEIVED_TIMESTAMP, po.STATUS, " +
|
||||
"co.ENABLED FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT o.ID AS OPERATION_ID, o.TYPE, " +
|
||||
"o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS 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 ORDER BY " +
|
||||
"o.CREATED_TIMESTAMP ASC) po ON co.OPERATION_ID = po.OPERATION_ID";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, deviceId.getType());
|
||||
stmt.setString(1, deviceId.getId());
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(String status) throws OperationManagementDAOException {
|
||||
return null;
|
||||
List<CommandOperation> operations = new ArrayList<CommandOperation>();
|
||||
while (rs.next()) {
|
||||
CommandOperation operation = new CommandOperation();
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operation.setEnabled(Boolean.parseBoolean(rs.getString("ENABLED")));
|
||||
operations.add(operation);
|
||||
}
|
||||
return operations;
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while retrieving the list of " +
|
||||
"operations available for the '" + deviceId.getType() + "' device '" + deviceId.getId() + "'");
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,12 +18,9 @@
|
||||
*/
|
||||
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.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||
|
||||
@Override
|
||||
@ -31,39 +28,4 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOperation(Operation operation) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOperation(int id) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(DeviceIdentifier deviceId, int operationId) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(String status) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,9 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.*;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -82,38 +85,92 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
public Operation getOperation(DeviceIdentifier deviceId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
List<Operation> operations;
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS 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";
|
||||
try {
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, deviceId.getType());
|
||||
stmt.setString(2, deviceId.getId());
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
operations = new ArrayList<Operation>();
|
||||
while (rs.next()) {
|
||||
Operation operation = new Operation();
|
||||
//operation.setType();
|
||||
operation.setId(rs.getInt("ID"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while retrieving the operation list " +
|
||||
"available for the '" + deviceId.getType() + "' with id '" + deviceId.getId() + "'", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(String status) throws OperationManagementDAOException {
|
||||
public List<? extends Operation> getOperations(Operation.Status status) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement(
|
||||
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS 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 " +
|
||||
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
|
||||
stmt.setString(1, deviceId.getType());
|
||||
stmt.setString(2, deviceId.getId());
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
Operation operation = null;
|
||||
if (rs.next()) {
|
||||
operation = new Operation();
|
||||
operation.setType(this.getType(rs.getString("TYPE")));
|
||||
operation.setStatus(this.getStatus(rs.getString("STATUS")));
|
||||
operation.setId(rs.getInt("ID"));
|
||||
}
|
||||
return operation;
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
private Operation.Status getStatus(String status) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Operation.Type getType(String type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -80,16 +80,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOperation(Operation operation) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOperation(int id) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int operationId) throws OperationManagementDAOException {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
@ -136,16 +126,6 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(String status) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
@ -121,12 +121,13 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
public List<? extends Operation> getPendingOperations(
|
||||
DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getPendingOperations(deviceId);
|
||||
}
|
||||
|
||||
@ -136,13 +137,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation updateOperation(Long operationId, DeviceIdentifier deviceIdentifier,
|
||||
public Operation updateOperation(int operationId, DeviceIdentifier deviceIdentifier,
|
||||
String responsePayLoad) throws OperationManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
|
||||
public void sendEnrolmentInvitation(
|
||||
EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
|
||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
|
||||
.sendEnrolmentInvitation(emailMessageProperties);
|
||||
}
|
||||
|
||||
@ -170,8 +170,9 @@ public final class DeviceManagerUtil {
|
||||
public static API getAPI(APIConfig config) throws APIManagementException {
|
||||
APIProvider provider = config.getProvider();
|
||||
APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion());
|
||||
|
||||
API api = new API(id);
|
||||
if (!provider.isAPIAvailable(id)) {
|
||||
api.setApiOwner(config.getOwner());
|
||||
api.setContext(config.getContext());
|
||||
api.setUrl(config.getEndpoint());
|
||||
api.setUriTemplates(
|
||||
@ -181,7 +182,7 @@ public final class DeviceManagerUtil {
|
||||
api.setEndpointSecured(false);
|
||||
api.setStatus(APIStatus.PUBLISHED);
|
||||
api.setTransports(config.getTransports());
|
||||
}
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
|
||||
@ -87,7 +87,7 @@ public class DeviceOperationManagementTests extends DeviceManagementBaseTest {
|
||||
DeviceIdentifier deviceId = new DeviceIdentifier();
|
||||
deviceId.setId("4892813d-0b18-4a02-b7b1-61775257400e");
|
||||
deviceId.setType("android");
|
||||
List<Operation> operations = operationManager.getOperations(deviceId);
|
||||
List<? extends Operation> operations = operationManager.getOperations(deviceId);
|
||||
Assert.assertNotNull(operations);
|
||||
boolean notEmpty = operations.size() > 0;
|
||||
Assert.assertTrue(notEmpty);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user