Changing apis to return activity when an operation is added

merge-requests/7/head
geethkokila 9 years ago
parent afba711969
commit c64a6e0ec5

@ -20,6 +20,7 @@
package org.wso2.carbon.device.mgt.common.app.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.List;
@ -66,12 +67,12 @@ public interface ApplicationManager {
throws ApplicationManagementException;
void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
Activity installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIdentifiers)
throws ApplicationManagementException;
void installApplicationForUsers(Operation operation, List<String> userNameList)
Activity installApplicationForUsers(Operation operation, List<String> userNameList)
throws ApplicationManagementException;
void installApplicationForUserRoles(Operation operation, List<String> userRoleList)
Activity installApplicationForUserRoles(Operation operation, List<String> userRoleList)
throws ApplicationManagementException;
}

@ -0,0 +1,65 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common.operation.mgt;
public class Activity {
public enum Type {
CONFIG, MESSAGE, INFO, COMMAND, PROFILE, POLICY
}
private String activityId;
private String code;
private Type type;
private String createdTimeStamp;
public String getActivityId() {
return activityId;
}
public void setActivityId(String activityId) {
this.activityId = activityId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getCreatedTimeStamp() {
return createdTimeStamp;
}
public void setCreatedTimeStamp(String createdTimeStamp) {
this.createdTimeStamp = createdTimeStamp;
}
}

@ -0,0 +1,68 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.common.operation.mgt;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.util.List;
public class ActivityStatus {
public enum Status {
IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED
}
private DeviceIdentifier deviceIdentifier;
private Status status;
private List<OperationResponse> responses;
private String updatedTimestamp;
public DeviceIdentifier getDeviceIdentifier() {
return deviceIdentifier;
}
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
this.deviceIdentifier = deviceIdentifier;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public List<OperationResponse> getResponses() {
return responses;
}
public void setResponses(List<OperationResponse> responses) {
this.responses = responses;
}
public String getUpdatedTimestamp() {
return updatedTimestamp;
}
public void setUpdatedTimestamp(String updatedTimestamp) {
this.updatedTimestamp = updatedTimestamp;
}
}

@ -38,7 +38,7 @@ public interface OperationManager {
* @throws OperationManagementException If some unusual behaviour is observed while adding the
* operation
*/
int addOperation(Operation operation, List<DeviceIdentifier> devices) throws OperationManagementException;
Activity addOperation(Operation operation, List<DeviceIdentifier> devices) throws OperationManagementException;
/**
* Method to retrieve the list of all operations to a device.

@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
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.core.DeviceManagementConstants;
@ -91,7 +92,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
}
@Override
public void installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIds)
public Activity installApplicationForDevices(Operation operation, List<DeviceIdentifier> deviceIds)
throws ApplicationManagementException {
try {
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
@ -99,10 +100,11 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (deviceIds.size() > 0) {
type = deviceIds.get(0).getType();
}
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation,
deviceIds);
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
addOperation(type, operation, deviceIds);
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().notifyOperationToDevices
(operation, deviceIds);
return activity;
} catch (OperationManagementException e) {
throw new ApplicationManagementException("Error in add operation at app installation", e);
} catch (DeviceManagementException e) {
@ -111,7 +113,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
}
@Override
public void installApplicationForUsers(Operation operation, List<String> userNameList)
public Activity installApplicationForUsers(Operation operation, List<String> userNameList)
throws ApplicationManagementException {
String userName = null;
@ -138,9 +140,10 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (deviceIdentifierList.size() > 0) {
type = deviceIdentifierList.get(0).getType();
}
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.addOperation(type, operation, deviceIdentifierList);
return activity;
} catch (DeviceManagementException e) {
throw new ApplicationManagementException("Error in get devices for user: " + userName +
" in app installation", e);
@ -152,7 +155,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
}
@Override
public void installApplicationForUserRoles(Operation operation, List<String> userRoleList)
public Activity installApplicationForUserRoles(Operation operation, List<String> userRoleList)
throws ApplicationManagementException {
String userRole = null;
@ -178,9 +181,9 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
if (deviceIdentifierList.size() > 0) {
type = deviceIdentifierList.get(0).getType();
}
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation,
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(type, operation,
deviceIdentifierList);
return activity;
} catch (DeviceManagementException e) {
throw new ApplicationManagementException("Error in get devices for user role " + userRole +
" in app installation", e);

@ -24,6 +24,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.*;
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.operation.mgt.Activity;
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;
@ -47,6 +48,7 @@ import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
@ -83,8 +85,8 @@ public class OperationManagerImpl implements OperationManager {
}
@Override
public int addOperation(Operation operation,
List<DeviceIdentifier> deviceIds) throws OperationManagementException {
public Activity addOperation(Operation operation,
List<DeviceIdentifier> deviceIds) throws OperationManagementException {
if (log.isDebugEnabled()) {
log.debug("operation:[" + operation.toString() + "]");
for (DeviceIdentifier deviceIdentifier : deviceIds) {
@ -96,7 +98,7 @@ public class OperationManagerImpl implements OperationManager {
List<DeviceIdentifier> authorizedDeviceList = this.getAuthorizedDevices(operation, deviceIds);
if (authorizedDeviceList.size() <= 0) {
log.info("User : " + getUser() + " is not authorized to perform operations on given device-list.");
return -1;
return null;
}
List<EnrolmentInfo> enrolments = this.getEnrollmentsByStatus(deviceIds);
@ -128,7 +130,12 @@ public class OperationManagerImpl implements OperationManager {
}
}
OperationManagementDAOFactory.commitTransaction();
return operationId;
Activity activity = new Activity();
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
activity.setCode(operationDto.getCode());
activity.setCreatedTimeStamp(new Date().toString());
activity.setType(Activity.Type.valueOf(operationDto.getType().toString()));
return activity;
} catch (OperationManagementDAOException e) {
OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException("Error occurred while adding operation", e);

@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
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;
@ -43,9 +44,9 @@ public class PushNotificationBasedOperationManager implements OperationManager {
}
@Override
public int addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException {
int operationId = this.operationManager.addOperation(operation, devices);
public Activity addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException {
Activity activity = this.operationManager.addOperation(operation, devices);
for (DeviceIdentifier deviceId : devices) {
try {
this.notificationProvider.execute(new NotificationContext(deviceId));
@ -53,7 +54,7 @@ public class PushNotificationBasedOperationManager implements OperationManager {
throw new OperationManagementException("Error occurred while sending push notification to device", e);
}
}
return operationId;
return activity;
}
@Override

@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
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;
@ -216,8 +217,8 @@ public interface DeviceManagementProviderService {
void notifyOperationToDevices(Operation operation,
List<DeviceIdentifier> deviceIds) throws DeviceManagementException;
int addOperation(String type, Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException;
Activity addOperation(String type, Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException;
List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException;

@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
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.push.notification.NotificationStrategy;
@ -816,8 +817,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
public int addOperation(String type, Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException {
public Activity addOperation(String type, Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
}

Loading…
Cancel
Save