|
|
@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.mobile.impl.android;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.common.*;
|
|
|
|
import org.wso2.carbon.device.mgt.common.*;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
|
|
@ -35,160 +37,156 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class AndroidMobileOperationManager extends AbstractMobileOperationManager {
|
|
|
|
public class AndroidMobileOperationManager extends AbstractMobileOperationManager {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(AndroidMobileOperationManager.class);
|
|
|
|
private static final Log log = LogFactory.getLog(AndroidMobileOperationManager.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices) throws
|
|
|
|
public boolean addOperation(Operation operation,
|
|
|
|
OperationManagementException {
|
|
|
|
List<DeviceIdentifier> devices) throws OperationManagementException {
|
|
|
|
boolean status = false;
|
|
|
|
boolean status = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
MobileDeviceOperationMapping mobileDeviceOperationMapping = null;
|
|
|
|
MobileDeviceOperationMapping mobileDeviceOperationMapping = null;
|
|
|
|
MobileOperation mobileOperation =
|
|
|
|
MobileOperation mobileOperation =
|
|
|
|
MobileDeviceManagementUtil.convertToMobileOperation(operation);
|
|
|
|
MobileDeviceManagementUtil.convertToMobileOperation(operation);
|
|
|
|
int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
|
|
|
int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
|
|
|
.addMobileOperation(mobileOperation);
|
|
|
|
.addMobileOperation(mobileOperation);
|
|
|
|
if (operationId > 0) {
|
|
|
|
if (operationId > 0) {
|
|
|
|
for (MobileOperationProperty operationProperty : mobileOperation.getProperties()) {
|
|
|
|
for (MobileOperationProperty operationProperty : mobileOperation.getProperties()) {
|
|
|
|
operationProperty.setOperationId(operationId);
|
|
|
|
operationProperty.setOperationId(operationId);
|
|
|
|
status = MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO()
|
|
|
|
status = MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO()
|
|
|
|
.addMobileOperationProperty(
|
|
|
|
.addMobileOperationProperty(
|
|
|
|
operationProperty);
|
|
|
|
operationProperty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (DeviceIdentifier deviceIdentifier : devices) {
|
|
|
|
for (DeviceIdentifier deviceIdentifier : devices) {
|
|
|
|
mobileDeviceOperationMapping = new MobileDeviceOperationMapping();
|
|
|
|
mobileDeviceOperationMapping = new MobileDeviceOperationMapping();
|
|
|
|
mobileDeviceOperationMapping.setOperationId(operationId);
|
|
|
|
mobileDeviceOperationMapping.setOperationId(operationId);
|
|
|
|
mobileDeviceOperationMapping.setDeviceId(deviceIdentifier.getId());
|
|
|
|
mobileDeviceOperationMapping.setDeviceId(deviceIdentifier.getId());
|
|
|
|
mobileDeviceOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW);
|
|
|
|
mobileDeviceOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW);
|
|
|
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
|
|
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
|
|
|
.addMobileDeviceOperationMapping(
|
|
|
|
.addMobileDeviceOperationMapping(
|
|
|
|
mobileDeviceOperationMapping);
|
|
|
|
mobileDeviceOperationMapping);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
String msg =
|
|
|
|
String msg = "Error while adding an operation " + operation.getCode() + "to Android devices";
|
|
|
|
"Error while adding an operation " + operation.getCode() + "to Android devices";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new OperationManagementException(msg, e);
|
|
|
|
throw new OperationManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
|
|
|
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
|
|
|
throws OperationManagementException {
|
|
|
|
throws OperationManagementException {
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
|
|
|
|
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
|
|
|
|
List<MobileOperationProperty> operationProperties = null;
|
|
|
|
List<MobileOperationProperty> operationProperties = null;
|
|
|
|
MobileOperation mobileOperation = null;
|
|
|
|
MobileOperation mobileOperation = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
|
|
|
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
|
|
|
.getAllMobileDeviceOperationMappingsOfDevice(
|
|
|
|
.getAllMobileDeviceOperationMappingsOfDevice(
|
|
|
|
deviceIdentifier
|
|
|
|
deviceIdentifier
|
|
|
|
.getId());
|
|
|
|
.getId());
|
|
|
|
if (mobileDeviceOperationMappings.size() > 0) {
|
|
|
|
if (mobileDeviceOperationMappings.size() > 0) {
|
|
|
|
List<Integer> operationIds = MobileDeviceManagementUtil
|
|
|
|
List<Integer> operationIds = MobileDeviceManagementUtil
|
|
|
|
.getMobileOperationIdsFromMobileDeviceOperations(
|
|
|
|
.getMobileOperationIdsFromMobileDeviceOperations(
|
|
|
|
mobileDeviceOperationMappings);
|
|
|
|
mobileDeviceOperationMappings);
|
|
|
|
for (Integer operationId : operationIds) {
|
|
|
|
for (Integer operationId : operationIds) {
|
|
|
|
mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
|
|
|
mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO().getMobileOperation(
|
|
|
|
.getMobileOperation(
|
|
|
|
operationId);
|
|
|
|
operationId);
|
|
|
|
operationProperties =
|
|
|
|
operationProperties =
|
|
|
|
MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO()
|
|
|
|
MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO()
|
|
|
|
.getAllMobileOperationPropertiesOfOperation(
|
|
|
|
.getAllMobileOperationPropertiesOfOperation(
|
|
|
|
operationId);
|
|
|
|
operationId);
|
|
|
|
mobileOperation.setProperties(operationProperties);
|
|
|
|
mobileOperation.setProperties(operationProperties);
|
|
|
|
operations.add(MobileDeviceManagementUtil.convertMobileOperationToOperation(mobileOperation));
|
|
|
|
operations.add(MobileDeviceManagementUtil
|
|
|
|
}
|
|
|
|
.convertMobileOperationToOperation(mobileOperation));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
}
|
|
|
|
String msg =
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
"Error while fetching the operations for the android device " +
|
|
|
|
String msg =
|
|
|
|
deviceIdentifier.getId();
|
|
|
|
"Error while fetching the operations for the android device " +
|
|
|
|
log.error(msg, e);
|
|
|
|
deviceIdentifier.getId();
|
|
|
|
throw new OperationManagementException(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
}
|
|
|
|
throw new OperationManagementException(msg, e);
|
|
|
|
return operations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operations;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
|
|
|
|
public List<Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
|
|
|
|
throws OperationManagementException {
|
|
|
|
throws OperationManagementException {
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
List<Operation> operations = new ArrayList<Operation>();
|
|
|
|
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
|
|
|
|
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
|
|
|
|
List<MobileOperationProperty> operationProperties = null;
|
|
|
|
List<MobileOperationProperty> operationProperties = null;
|
|
|
|
MobileOperation mobileOperation = null;
|
|
|
|
MobileOperation mobileOperation = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//Get the list of pending operations for the given device
|
|
|
|
//Get the list of pending operations for the given device
|
|
|
|
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
|
|
|
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
|
|
|
.getAllPendingOperationMappingsOfMobileDevice(
|
|
|
|
.getAllPendingOperationMappingsOfMobileDevice(
|
|
|
|
deviceIdentifier
|
|
|
|
deviceIdentifier
|
|
|
|
.getId());
|
|
|
|
.getId());
|
|
|
|
//Go through each operation mapping for retrieving the data corresponding to each operation
|
|
|
|
//Go through each operation mapping for retrieving the data corresponding to each operation
|
|
|
|
for (MobileDeviceOperationMapping operation : mobileDeviceOperationMappings) {
|
|
|
|
for (MobileDeviceOperationMapping operation : mobileDeviceOperationMappings) {
|
|
|
|
//Get the MobileOperation data
|
|
|
|
//Get the MobileOperation data
|
|
|
|
mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
|
|
|
mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
|
|
|
.getMobileOperation(operation
|
|
|
|
.getMobileOperation(operation
|
|
|
|
.getOperationId());
|
|
|
|
.getOperationId());
|
|
|
|
//Get properties of the operation
|
|
|
|
//Get properties of the operation
|
|
|
|
operationProperties =
|
|
|
|
operationProperties =
|
|
|
|
MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO()
|
|
|
|
MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO()
|
|
|
|
.getAllMobileOperationPropertiesOfOperation(
|
|
|
|
.getAllMobileOperationPropertiesOfOperation(
|
|
|
|
operation.getOperationId());
|
|
|
|
operation.getOperationId());
|
|
|
|
mobileOperation.setProperties(operationProperties);
|
|
|
|
mobileOperation.setProperties(operationProperties);
|
|
|
|
operations.add(MobileDeviceManagementUtil
|
|
|
|
operations.add(MobileDeviceManagementUtil
|
|
|
|
.convertMobileOperationToOperation(mobileOperation));
|
|
|
|
.convertMobileOperationToOperation(mobileOperation));
|
|
|
|
//Update the MobileDeviceOperationMapping data to the In-Progress state
|
|
|
|
//Update the MobileDeviceOperationMapping data to the In-Progress state
|
|
|
|
operation.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS);
|
|
|
|
operation.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS);
|
|
|
|
operation.setSentDate(new Date().getTime());
|
|
|
|
operation.setSentDate(new Date().getTime());
|
|
|
|
MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
|
|
|
MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
|
|
|
.updateMobileDeviceOperationMappingToInProgress(
|
|
|
|
.updateMobileDeviceOperationMappingToInProgress(
|
|
|
|
operation.getDeviceId(),
|
|
|
|
operation.getDeviceId(),
|
|
|
|
operation.getOperationId());
|
|
|
|
operation.getOperationId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
String msg =
|
|
|
|
String msg =
|
|
|
|
"Error while fetching the operations for the android device " +
|
|
|
|
"Error while fetching the operations for the android device " +
|
|
|
|
deviceIdentifier.getId();
|
|
|
|
deviceIdentifier.getId();
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new OperationManagementException(msg, e);
|
|
|
|
throw new OperationManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operations;
|
|
|
|
return operations;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException {
|
|
|
|
|
|
|
|
MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO();
|
|
|
|
|
|
|
|
MobileFeaturePropertyDAO featurePropertyDAO = MobileDeviceManagementDAOFactory.getFeaturePropertyDAO();
|
|
|
|
|
|
|
|
List<Feature> features = new ArrayList<Feature>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<MobileFeature> mobileFeatures = featureDAO.getMobileFeatureByDeviceType(deviceType);
|
|
|
|
|
|
|
|
for (MobileFeature mobileFeature : mobileFeatures) {
|
|
|
|
|
|
|
|
Feature feature = new Feature();
|
|
|
|
|
|
|
|
feature.setId(mobileFeature.getId());
|
|
|
|
|
|
|
|
feature.setDeviceType(mobileFeature.getDeviceType());
|
|
|
|
|
|
|
|
feature.setName(mobileFeature.getName());
|
|
|
|
|
|
|
|
feature.setDescription(mobileFeature.getDescription());
|
|
|
|
|
|
|
|
List<Feature.MetadataEntry> metadataEntries = new ArrayList<Feature.MetadataEntry>();
|
|
|
|
|
|
|
|
List<MobileFeatureProperty> properties =
|
|
|
|
|
|
|
|
featurePropertyDAO.getFeaturePropertiesOfFeature(mobileFeature.getId());
|
|
|
|
|
|
|
|
for (MobileFeatureProperty property : properties) {
|
|
|
|
|
|
|
|
Feature.MetadataEntry metaEntry = new Feature.MetadataEntry();
|
|
|
|
|
|
|
|
metaEntry.setId(property.getFeatureID());
|
|
|
|
|
|
|
|
metaEntry.setValue(property.getProperty());
|
|
|
|
|
|
|
|
metadataEntries.add(metaEntry);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
feature.setMetadataEntries(metadataEntries);
|
|
|
|
|
|
|
|
features.add(feature);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error while fetching the features for the device type " + deviceType;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new FeatureManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return features;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Feature> getFeaturesForDeviceType(String deviceType) throws FeatureManagementException {
|
|
|
|
|
|
|
|
MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO();
|
|
|
|
|
|
|
|
MobileFeaturePropertyDAO featurePropertyDAO = MobileDeviceManagementDAOFactory.getFeaturePropertyDAO();
|
|
|
|
|
|
|
|
List<Feature> features = new ArrayList<Feature>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<MobileFeature> mobileFeatures = featureDAO.getMobileFeatureByDeviceType(deviceType);
|
|
|
|
|
|
|
|
for (MobileFeature mobileFeature : mobileFeatures) {
|
|
|
|
|
|
|
|
Feature feature = new Feature();
|
|
|
|
|
|
|
|
feature.setId(mobileFeature.getId());
|
|
|
|
|
|
|
|
feature.setDeviceType(mobileFeature.getDeviceType());
|
|
|
|
|
|
|
|
feature.setName(mobileFeature.getName());
|
|
|
|
|
|
|
|
feature.setDescription(mobileFeature.getDescription());
|
|
|
|
|
|
|
|
List<Feature.MetadataEntry> metadataEntries = new ArrayList<Feature.MetadataEntry>();
|
|
|
|
|
|
|
|
List<MobileFeatureProperty> properties =
|
|
|
|
|
|
|
|
featurePropertyDAO.getFeaturePropertiesOfFeature(mobileFeature.getId());
|
|
|
|
|
|
|
|
for (MobileFeatureProperty property : properties) {
|
|
|
|
|
|
|
|
Feature.MetadataEntry metaEntry = new Feature.MetadataEntry();
|
|
|
|
|
|
|
|
metaEntry.setId(property.getFeatureID());
|
|
|
|
|
|
|
|
metaEntry.setValue(property.getProperty());
|
|
|
|
|
|
|
|
metadataEntries.add(metaEntry);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
feature.setMetadataEntries(metadataEntries);
|
|
|
|
|
|
|
|
features.add(feature);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MobileDeviceManagementDAOException e) {
|
|
|
|
|
|
|
|
String msg =
|
|
|
|
|
|
|
|
"Error while fetching the features for the device type " +
|
|
|
|
|
|
|
|
deviceType;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new FeatureManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return features;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|