From c64a6e0ec52826cb7379b7bb34ac64a0785fe135 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Wed, 25 May 2016 11:42:44 +0530 Subject: [PATCH] Changing apis to return activity when an operation is added --- .../common/app/mgt/ApplicationManager.java | 7 +- .../mgt/common/operation/mgt/Activity.java | 65 ++++++++++++++++++ .../common/operation/mgt/ActivityStatus.java | 68 +++++++++++++++++++ .../operation/mgt/OperationManager.java | 2 +- ...ApplicationManagerProviderServiceImpl.java | 19 +++--- .../operation/mgt/OperationManagerImpl.java | 15 ++-- ...PushNotificationBasedOperationManager.java | 9 +-- .../DeviceManagementProviderService.java | 5 +- .../DeviceManagementProviderServiceImpl.java | 5 +- 9 files changed, 171 insertions(+), 24 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Activity.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/ActivityStatus.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java index bf660566f8..e9da177cdd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/ApplicationManager.java @@ -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 deviceIdentifiers) + Activity installApplicationForDevices(Operation operation, List deviceIdentifiers) throws ApplicationManagementException; - void installApplicationForUsers(Operation operation, List userNameList) + Activity installApplicationForUsers(Operation operation, List userNameList) throws ApplicationManagementException; - void installApplicationForUserRoles(Operation operation, List userRoleList) + Activity installApplicationForUserRoles(Operation operation, List userRoleList) throws ApplicationManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Activity.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Activity.java new file mode 100644 index 0000000000..2669876af2 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Activity.java @@ -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; + } +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/ActivityStatus.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/ActivityStatus.java new file mode 100644 index 0000000000..b053710725 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/ActivityStatus.java @@ -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 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 getResponses() { + return responses; + } + + public void setResponses(List responses) { + this.responses = responses; + } + + public String getUpdatedTimestamp() { + return updatedTimestamp; + } + + public void setUpdatedTimestamp(String updatedTimestamp) { + this.updatedTimestamp = updatedTimestamp; + } +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index 26ed93bddb..9e3689f402 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -38,7 +38,7 @@ public interface OperationManager { * @throws OperationManagementException If some unusual behaviour is observed while adding the * operation */ - int addOperation(Operation operation, List devices) throws OperationManagementException; + Activity addOperation(Operation operation, List devices) throws OperationManagementException; /** * Method to retrieve the list of all operations to a device. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 2df1177d20..78782e55d9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -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 deviceIds) + public Activity installApplicationForDevices(Operation operation, List 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 userNameList) + public Activity installApplicationForUsers(Operation operation, List 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 userRoleList) + public Activity installApplicationForUserRoles(Operation operation, List 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); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index f0dfbe95dc..c883e98b26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -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 deviceIds) throws OperationManagementException { + public Activity addOperation(Operation operation, + List 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 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 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); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java index 94486be464..c8644f39e3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/push/notification/mgt/PushNotificationBasedOperationManager.java @@ -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 devices) throws OperationManagementException { - int operationId = this.operationManager.addOperation(operation, devices); + public Activity addOperation(Operation operation, + List 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 diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 69e49d2c9e..a333c199c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -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 deviceIds) throws DeviceManagementException; - int addOperation(String type, Operation operation, - List devices) throws OperationManagementException; + Activity addOperation(String type, Operation operation, + List devices) throws OperationManagementException; List getOperations(DeviceIdentifier deviceId) throws OperationManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 8543b76e79..7439652b73 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -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 devices) throws OperationManagementException { + public Activity addOperation(String type, Operation operation, + List devices) throws OperationManagementException { return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices); }