revert-70aa11f8
kamidu 8 years ago
commit cd77ce692e

@ -40,6 +40,7 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@Consumes(APPLICATION_JSON) @Consumes(APPLICATION_JSON)
public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, MessageBodyReader<Object> { public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, MessageBodyReader<Object> {
public static final String DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
private Gson gson; private Gson gson;
private static final String UTF_8 = "UTF-8"; private static final String UTF_8 = "UTF-8";
@ -50,7 +51,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter<Object>, Messag
private Gson getGson() { private Gson getGson() {
if (gson == null) { if (gson == null) {
final GsonBuilder gsonBuilder = new GsonBuilder(); final GsonBuilder gsonBuilder = new GsonBuilder();
gson = gsonBuilder.create(); gson = gsonBuilder.setDateFormat(DATE_FORMAT).create();
} }
return gson; return gson;
} }

@ -30,7 +30,7 @@ import java.util.List;
public class ActivityStatus { public class ActivityStatus {
public enum Status { public enum Status {
IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED, INVALID, UNAUTHORIZED
} }
@ApiModelProperty( @ApiModelProperty(

@ -24,10 +24,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.*;
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.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
@ -90,7 +87,8 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public Activity addOperation(Operation operation, public Activity addOperation(Operation operation,
List<DeviceIdentifier> deviceIds) throws OperationManagementException, InvalidDeviceException { List<DeviceIdentifier> deviceIds)
throws OperationManagementException, InvalidDeviceException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("operation:[" + operation.toString() + "]"); log.debug("operation:[" + operation.toString() + "]");
for (DeviceIdentifier deviceIdentifier : deviceIds) { for (DeviceIdentifier deviceIdentifier : deviceIds) {
@ -99,13 +97,19 @@ public class OperationManagerImpl implements OperationManager {
} }
} }
try { try {
DeviceIDHolder deviceIDHolder = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds); DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
List<DeviceIdentifier> validDeviceIds = deviceIDHolder.getValidDeviceIDList(); List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
if (validDeviceIds.size() > 0) { if (validDeviceIds.size() > 0) {
List<DeviceIdentifier> authorizedDeviceList = this.getAuthorizedDevices(operation, validDeviceIds); DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
List<DeviceIdentifier> authorizedDeviceList = deviceAuthorizationResult.getValidDeviceIDList();
if (authorizedDeviceList.size() <= 0) { if (authorizedDeviceList.size() <= 0) {
log.info("User : " + getUser() + " is not authorized to perform operations on given device-list."); log.info("User : " + getUser() + " is not authorized to perform operations on given device-list.");
return null; Activity activity = new Activity();
//Send the operation statuses only for admin triggered operations
String deviceType = validDeviceIds.get(0).getType();
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult,
deviceType));
return activity;
} }
OperationManagementDAOFactory.beginTransaction(); OperationManagementDAOFactory.beginTransaction();
@ -157,6 +161,12 @@ public class OperationManagerImpl implements OperationManager {
activity.setCode(operationCode); activity.setCode(operationCode);
activity.setCreatedTimeStamp(new Date().toString()); activity.setCreatedTimeStamp(new Date().toString());
activity.setType(Activity.Type.valueOf(operationDto.getType().toString())); activity.setType(Activity.Type.valueOf(operationDto.getType().toString()));
//For now set the operation statuses only for admin triggered operations
if (!isScheduledOperation) {
//Get the device-type from 1st valid DeviceIdentifier. We know the 1st element is definitely there.
String deviceType = validDeviceIds.get(0).getType();
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult, deviceType));
}
return activity; return activity;
} else { } else {
throw new InvalidDeviceException("Invalid device Identifiers found."); throw new InvalidDeviceException("Invalid device Identifiers found.");
@ -171,21 +181,64 @@ public class OperationManagerImpl implements OperationManager {
} }
} }
private List<DeviceIdentifier> getAuthorizedDevices( private List<ActivityStatus> getActivityStatus(DeviceIDHolder deviceIdValidationResult, DeviceIDHolder deviceAuthResult,
String deviceType) {
List<ActivityStatus> activityStatuses = new ArrayList<>();
ActivityStatus activityStatus;
//Add the invalid DeviceIds
for (String id : deviceIdValidationResult.getErrorDeviceIdList()) {
activityStatus = new ActivityStatus();
activityStatus.setDeviceIdentifier(new DeviceIdentifier(id,deviceType));
activityStatus.setStatus(ActivityStatus.Status.INVALID);
activityStatuses.add(activityStatus);
}
//Add the unauthorized DeviceIds
for (String id : deviceAuthResult.getErrorDeviceIdList()) {
activityStatus = new ActivityStatus();
activityStatus.setDeviceIdentifier(new DeviceIdentifier(id, deviceType));
activityStatus.setStatus(ActivityStatus.Status.UNAUTHORIZED);
activityStatuses.add(activityStatus);
}
//Add the authorized DeviceIds
for (DeviceIdentifier id : deviceAuthResult.getValidDeviceIDList()) {
activityStatus = new ActivityStatus();
activityStatus.setDeviceIdentifier(id);
activityStatus.setStatus(ActivityStatus.Status.PENDING);
activityStatuses.add(activityStatus);
}
return activityStatuses;
}
private DeviceIDHolder authorizeDevices(
Operation operation, List<DeviceIdentifier> deviceIds) throws OperationManagementException { Operation operation, List<DeviceIdentifier> deviceIds) throws OperationManagementException {
List<DeviceIdentifier> authorizedDeviceList; List<DeviceIdentifier> authorizedDeviceList;
List<String> unAuthorizedDeviceList = new ArrayList<>();
DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
try { try {
if (operation != null && isAuthenticationSkippedOperation(operation)) { if (operation != null && isAuthenticationSkippedOperation(operation)) {
authorizedDeviceList = deviceIds; authorizedDeviceList = deviceIds;
} else { } else {
authorizedDeviceList = DeviceManagementDataHolder.getInstance(). boolean isAuthorized;
getDeviceAccessAuthorizationService().isUserAuthorized(deviceIds).getAuthorizedDevices(); authorizedDeviceList = new ArrayList<>();
for (DeviceIdentifier devId : deviceIds) {
isAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
isUserAuthorized(devId);
if (isAuthorized) {
authorizedDeviceList.add(devId);
} else {
unAuthorizedDeviceList.add(devId.getId());
}
}
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" + throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
this.getUser(), e); this.getUser(), e);
} }
return authorizedDeviceList; deviceIDHolder.setValidDeviceIDList(authorizedDeviceList);
deviceIDHolder.setErrorDeviceIdList(unAuthorizedDeviceList);
return deviceIDHolder;
} }
private Device getDevice(DeviceIdentifier deviceId) throws OperationManagementException { private Device getDevice(DeviceIdentifier deviceId) throws OperationManagementException {
@ -211,7 +264,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getId() + "'"); deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'");
} }
int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE); int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE);
@ -250,7 +304,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getId() + "'"); deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'");
} }
int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE); int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE);
@ -298,7 +353,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getId() + "'"); deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'");
} }
int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE); int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE);
@ -346,7 +402,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getId() + "'"); deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'");
} }
int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE); int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE);
@ -359,23 +416,30 @@ public class OperationManagerImpl implements OperationManager {
try { try {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
getNextOperation(enrolmentId); getNextOperation(
enrolmentId);
if (dtoOperation != null) { if (dtoOperation != null) {
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND. if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.
equals(dtoOperation.getType())) { equals(dtoOperation
.getType())) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(
dtoOperation
.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.
equals(dtoOperation.getType())) { equals(dtoOperation
.getType())) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.
equals(dtoOperation.getType())) { equals(dtoOperation
.getType())) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.
equals(dtoOperation.getType())) { equals(dtoOperation
.getType())) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
@ -400,7 +464,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getId() + "'"); deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'");
} }
int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE); int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE);
@ -410,8 +475,10 @@ public class OperationManagerImpl implements OperationManager {
boolean isUpdated = false; boolean isUpdated = false;
if (operation.getStatus() != null) { if (operation.getStatus() != null) {
isUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId, isUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
valueOf(operation.getStatus().toString())); .
valueOf(operation.getStatus()
.toString()));
} }
if (isUpdated && operation.getOperationResponse() != null) { if (isUpdated && operation.getOperationResponse() != null) {
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse()); operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
@ -461,7 +528,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getId() + "'"); deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'");
} }
int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE); int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE);
@ -473,13 +541,17 @@ public class OperationManagerImpl implements OperationManager {
try { try {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
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(enrolmentId, operationId); getOperationByDeviceAndId(
enrolmentId,
operationId);
if (dtoOperation.getType(). if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(
dtoOperation
.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType(). } else if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
@ -519,7 +591,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getId() + "'"); deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'");
} }
int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE); int enrolmentId = this.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE);
@ -568,16 +641,20 @@ public class OperationManagerImpl implements OperationManager {
try { try {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
getOperation(operationId); getOperation(
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);
} }
if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { if (dtoOperation.getType()
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(
dtoOperation
.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType(). } else if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
@ -601,61 +678,61 @@ public class OperationManagerImpl implements OperationManager {
return operation; return operation;
} }
// @Override // @Override
// public Operation getOperationByActivityId(String activity) throws OperationManagementException { // public Operation getOperationByActivityId(String activity) throws OperationManagementException {
// // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer. // // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer.
// Operation operation; // Operation operation;
// int enrollmentOpMappingId = Integer.parseInt( // int enrollmentOpMappingId = Integer.parseInt(
// activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); // activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
// if (enrollmentOpMappingId == 0) { // if (enrollmentOpMappingId == 0) {
// throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); // throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
// } // }
// try { // try {
// OperationManagementDAOFactory.openConnection(); // OperationManagementDAOFactory.openConnection();
// org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = // org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation =
// operationDAO.getOperationFromEnrollment(enrollmentOpMappingId); // operationDAO.getOperationFromEnrollment(enrollmentOpMappingId);
// //
// if (dtoOperation == null) { // if (dtoOperation == null) {
// throw new OperationManagementException("Operation not found for given activity Id:" + activity); // throw new OperationManagementException("Operation not found for given activity Id:" + activity);
// } // }
// org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status status = dtoOperation.getStatus(); // org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status status = dtoOperation.getStatus();
// if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { // if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
// org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; // org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
// commandOperation = // commandOperation =
// (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. // (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
// getOperation(dtoOperation.getId()); // getOperation(dtoOperation.getId());
// dtoOperation.setEnabled(commandOperation.isEnabled()); // dtoOperation.setEnabled(commandOperation.isEnabled());
// } else if (dtoOperation.getType(). // } else if (dtoOperation.getType().
// equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { // equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
// dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); // dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
// } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. // } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
// PROFILE)) { // PROFILE)) {
// dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); // dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
// } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. // } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
// POLICY)) { // POLICY)) {
// dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); // dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
// } // }
// operation = OperationDAOUtil.convertOperation(dtoOperation); // operation = OperationDAOUtil.convertOperation(dtoOperation);
// int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId); // int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId);
// if (enrolmentId != 0) { // if (enrolmentId != 0) {
// operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId())); // operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId()));
// } // }
// //
// operation.setStatus(Operation.Status.valueOf(status.toString())); // operation.setStatus(Operation.Status.valueOf(status.toString()));
// operation.setActivityId(activity); // operation.setActivityId(activity);
// //
// } catch (SQLException e) { // } catch (SQLException e) {
// throw new OperationManagementException("Error occurred while opening a connection to the data source", e); // throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
// } catch (OperationManagementDAOException e) { // } catch (OperationManagementDAOException e) {
// throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" + // throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" +
// activity, e); // activity, e);
// } finally { // } finally {
// OperationManagementDAOFactory.closeConnection(); // OperationManagementDAOFactory.closeConnection();
// } // }
// //
// // return this.getOperation(operationId); // // return this.getOperation(operationId);
// return operation; // return operation;
// } // }
@Override @Override
public Activity getOperationByActivityId(String activity) throws OperationManagementException { public Activity getOperationByActivityId(String activity) throws OperationManagementException {

@ -409,14 +409,15 @@ public class GenericOperationDAOImpl implements OperationDAO {
String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n" + String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n" +
"op.OPERATION_CODE, op.TYPE as OPERATION_TYPE, opm.STATUS, en.DEVICE_ID,\n" + "op.OPERATION_CODE, op.TYPE as OPERATION_TYPE, opm.STATUS, en.DEVICE_ID,\n" +
"op.RECEIVED_TIMESTAMP, ops.ID as OP_RES_ID, ops.OPERATION_RESPONSE,\n" + "ops.RECEIVED_TIMESTAMP, ops.ID as OP_RES_ID, ops.OPERATION_RESPONSE,\n" +
"de.DEVICE_IDENTIFICATION, dt.NAME as DEVICE_TYPE\n" + "de.DEVICE_IDENTIFICATION, dt.NAME as DEVICE_TYPE\n" +
"FROM DM_ENROLMENT_OP_MAPPING AS opm\n" + "FROM DM_ENROLMENT_OP_MAPPING AS opm\n" +
"LEFT JOIN DM_OPERATION AS op ON opm.OPERATION_ID = op.ID\n" + "LEFT JOIN DM_OPERATION AS op ON opm.OPERATION_ID = op.ID \n" +
"LEFT JOIN DM_ENROLMENT as en ON opm.ENROLMENT_ID = en.ID\n" + "LEFT JOIN DM_ENROLMENT as en ON opm.ENROLMENT_ID = en.ID \n" +
"LEFT JOIN DM_DEVICE as de ON en.DEVICE_ID = de.ID\n" + "LEFT JOIN DM_DEVICE as de ON en.DEVICE_ID = de.ID \n" +
"LEFT JOIN DM_DEVICE_TYPE as dt ON dt.ID = de.DEVICE_TYPE_ID\n" + "LEFT JOIN DM_DEVICE_TYPE as dt ON dt.ID = de.DEVICE_TYPE_ID \n" +
"LEFT JOIN DM_DEVICE_OPERATION_RESPONSE as ops ON ops.ID = opm.OPERATION_ID\n" + "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE as ops ON \n" +
"opm.ENROLMENT_ID = ops.ENROLMENT_ID AND opm.OPERATION_ID = ops.OPERATION_ID \n" +
"WHERE opm.UPDATED_TIMESTAMP > ? \n" + "WHERE opm.UPDATED_TIMESTAMP > ? \n" +
"AND de.TENANT_ID = ? \n"; "AND de.TENANT_ID = ? \n";

@ -342,12 +342,10 @@ public final class DeviceManagerUtil {
if (isValidDeviceIdentifier(deviceIdentifier)) { if (isValidDeviceIdentifier(deviceIdentifier)) {
validDeviceIDList.add(deviceIdentifier); validDeviceIDList.add(deviceIdentifier);
} else { } else {
errorDeviceIdList.add(String.format(OperationMgtConstants.DeviceConstants. errorDeviceIdList.add(deviceID);
DEVICE_ID_NOT_FOUND, deviceID));
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
errorDeviceIdList.add(String.format(OperationMgtConstants.DeviceConstants.DEVICE_ID_SERVICE_NOT_FOUND, errorDeviceIdList.add(deviceID);
deviceIDCounter));
} }
} }

Loading…
Cancel
Save