Operations Refractor

revert-70aa11f8
manoj 10 years ago
parent d0b553d26a
commit 4f4240f176

@ -67,10 +67,11 @@ public class OperationManagerImpl implements OperationManager {
public boolean addOperation(Operation operation, public boolean addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException { List<DeviceIdentifier> devices) throws OperationManagementException {
if (log.isDebugEnabled()){ if (log.isDebugEnabled()) {
log.debug("operation:["+operation.toString()+"]"); log.debug("operation:[" + operation.toString() + "]");
for(DeviceIdentifier deviceIdentifier:devices){ for (DeviceIdentifier deviceIdentifier : devices) {
log.debug("device identifier id:["+deviceIdentifier.getId()+"] type:["+deviceIdentifier.getType()+"]"); log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType()
+ "]");
} }
} }
try { try {
@ -87,7 +88,7 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
return true; return true;
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
log.error("Error occurred while adding operation: ",e); log.error("Error occurred while adding operation: ", e);
try { try {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
} catch (OperationManagementDAOException e1) { } catch (OperationManagementDAOException e1) {
@ -95,7 +96,7 @@ public class OperationManagerImpl implements OperationManager {
} }
throw new OperationManagementException("Error occurred while adding operation", e); throw new OperationManagementException("Error occurred while adding operation", e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
log.error("Error occurred while adding operation device mapping: ",e); log.error("Error occurred while adding operation device mapping: ", e);
try { try {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
} catch (OperationManagementDAOException e1) { } catch (OperationManagementDAOException e1) {
@ -136,8 +137,8 @@ public class OperationManagerImpl implements OperationManager {
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId)
throws OperationManagementException { throws OperationManagementException {
if (log.isDebugEnabled()){ if (log.isDebugEnabled()) {
log.debug("device identifier id:["+deviceId.getId()+"] type:["+deviceId.getType()+"]"); log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
} }
try { try {
@ -168,8 +169,8 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException { public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
if (log.isDebugEnabled()){ if (log.isDebugEnabled()) {
log.debug("device identifier id:["+deviceId.getId()+"] type:["+deviceId.getType()+"]"); log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
} }
try { try {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
@ -188,16 +189,16 @@ public class OperationManagerImpl implements OperationManager {
public void updateOperation(int operationId, Operation.Status operationStatus) public void updateOperation(int operationId, Operation.Status operationStatus)
throws OperationManagementException { throws OperationManagementException {
if (log.isDebugEnabled()){ if (log.isDebugEnabled()) {
log.debug("operation Id:"+operationId+" status:"+operationStatus); log.debug("operation Id:" + operationId + " status:" + operationStatus);
} }
try { try {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation
(operationId); (operationId);
if (dtoOperation == null){ if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for operation id:"+operationId); throw new OperationManagementException("Operation not found for operation id:" + operationId);
} }
dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf dtoOperation.setStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf
(operationStatus.toString())); (operationStatus.toString()));
@ -210,7 +211,7 @@ public class OperationManagerImpl implements OperationManager {
} catch (OperationManagementDAOException e1) { } catch (OperationManagementDAOException e1) {
log.warn("Error occurred while roll-backing the update operation transaction", e1); log.warn("Error occurred while roll-backing the update operation transaction", e1);
} }
log.error("Error occurred while updating the operation: " + operationId + " status:"+operationStatus,ex); log.error("Error occurred while updating the operation: " + operationId + " status:" + operationStatus, ex);
throw new OperationManagementException("Error occurred while update operation", ex); throw new OperationManagementException("Error occurred while update operation", ex);
} }
} }
@ -223,8 +224,8 @@ public class OperationManagerImpl implements OperationManager {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation = operationDAO.getOperation org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation = operationDAO.getOperation
(operationId); (operationId);
if (operation == null){ if (operation == null) {
throw new OperationManagementException("Operation not found for operation id:"+ operationId); throw new OperationManagementException("Operation not found for operation id:" + operationId);
} }
if (operation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { if (operation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
@ -249,38 +250,42 @@ public class OperationManagerImpl implements OperationManager {
} }
@Override @Override
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId) public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceIdentifier, int operationId)
throws OperationManagementException { throws OperationManagementException {
Device device; Device device;
Operation operation; Operation operation;
if (log.isDebugEnabled()){ if (log.isDebugEnabled()) {
log.debug("Device Type:"+deviceId.getType()+" Id:"+deviceId.getId()); log.debug("Device Type:" + deviceIdentifier.getType() + " Id:" + deviceIdentifier.getId());
} }
try { try {
device = deviceDAO.getDevice(deviceId); device = deviceDAO.getDevice(deviceIdentifier);
if (device == null){ if (device == null) {
throw new OperationManagementException("Device not found for given device identifier:"+deviceId.getId throw new OperationManagementException(
()+" type:"+device.getDeviceType()); "Device not found for given device identifier:" + deviceIdentifier.getId
() + " type:" + deviceIdentifier.getType());
} }
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
.getOperationByDeviceAndId(device.getId(), operationId); .getOperationByDeviceAndId(device.getId(), operationId);
if (dtoOperation == null){ if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for operation Id:"+ operationId +" device" + throw new OperationManagementException(
" Id:"+device.getId()); "Operation not found for operation Id:" + operationId + " device" +
" Id:" + device.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (DeviceManagementDAOException deviceDAOException) { } catch (DeviceManagementDAOException deviceDAOException) {
String errorMsg = "Error occurred while retrieving the device " + String errorMsg = "Error occurred while retrieving the device " +
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId(); "for device Identifier type -'" + deviceIdentifier.getType() + "' and device Id '"
+ deviceIdentifier.getId();
log.error(errorMsg, deviceDAOException); log.error(errorMsg, deviceDAOException);
throw new OperationManagementException(errorMsg, deviceDAOException); throw new OperationManagementException(errorMsg, deviceDAOException);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId() + "'", e); "operations assigned for '" + deviceIdentifier.getType() + "' device '" + deviceIdentifier.getId()
+ "'", e);
} }
return operation; return operation;
} }
@ -293,9 +298,9 @@ public class OperationManagerImpl implements OperationManager {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
Device device = deviceDAO.getDevice(identifier); Device device = deviceDAO.getDevice(identifier);
if (device == null){ if (device == null) {
throw new DeviceManagementException("Device not found for device id:"+identifier.getId()+" " + throw new DeviceManagementException("Device not found for device id:" + identifier.getId() + " " +
"type:"+identifier.getType()); "type:" + identifier.getType());
} }
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = operationDAO List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = operationDAO
.getOperationsByDeviceAndStatus(device.getId(), .getOperationsByDeviceAndStatus(device.getId(),
@ -326,8 +331,8 @@ public class OperationManagerImpl implements OperationManager {
try { try {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation
(operationId); (operationId);
if (dtoOperation == null){ if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for given Id:"+operationId); throw new OperationManagementException("Operation not found for given Id:" + operationId);
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
@ -345,7 +350,8 @@ public class OperationManagerImpl implements OperationManager {
try { try {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
operationDAO.getOperationsForStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status operationDAO
.getOperationsForStatus(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
.valueOf(status.toString())); .valueOf(status.toString()));
Operation operation; Operation operation;
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) { for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {

@ -324,7 +324,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation = null; Operation operation;
ByteArrayInputStream bais; ByteArrayInputStream bais;
ObjectInputStream ois; ObjectInputStream ois;

@ -119,8 +119,10 @@
</importFeatureDef> </importFeatureDef>
<importFeatureDef>org.wso2.carbon.apimgt.core:${carbon.api.mgt.version} <importFeatureDef>org.wso2.carbon.apimgt.core:${carbon.api.mgt.version}
</importFeatureDef> </importFeatureDef>
<!--
<importFeatureDef>org.wso2.carbon.transaction.manager:${carbon.commons.version} <importFeatureDef>org.wso2.carbon.transaction.manager:${carbon.commons.version}
</importFeatureDef> </importFeatureDef>
-->
</importFeatures> </importFeatures>
</configuration> </configuration>
</execution> </execution>

Loading…
Cancel
Save