Improve app subscription functionality

Further integrate app management component with device mgt
feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent dd707b98f2
commit e41742b777

@ -1,51 +0,0 @@
/*
* Copyright (c) 2018, 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.application.mgt.common;
import com.google.gson.Gson;
import org.wso2.carbon.device.application.mgt.common.exception.DeviceConnectorException;
public class AndroidApplication {
private String type;
private String appIdentifier;
private static final long serialVersionUID = 760343716452548282L;
public String getAppIdentifier() {
return appIdentifier;
}
public void setAppIdentifier(String appIdentifier) {
this.appIdentifier = appIdentifier;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String toJSON() throws DeviceConnectorException {
Gson gson = new Gson();
return gson.toJson(this);
}
}

@ -1,42 +0,0 @@
package org.wso2.carbon.device.application.mgt.common;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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.
*/
import java.util.List;
public class ApplicationReleaseArtifactPaths {
private String installerPath;
private String iconPath;
private String bannerPath;
private List<String> screenshotPaths;
public String getInstallerPath() { return installerPath; }
public void setInstallerPath(String installerPath) { this.installerPath = installerPath; }
public String getIconPath() { return iconPath; }
public void setIconPath(String iconPath) { this.iconPath = iconPath; }
public String getBannerPath() { return bannerPath; }
public void setBannerPath(String bannerPath) { this.bannerPath = bannerPath; }
public List<String> getScreenshotPaths() { return screenshotPaths; }
public void setScreenshotPaths(List<String> screenshotPaths) { this.screenshotPaths = screenshotPaths; }
}

@ -0,0 +1,22 @@
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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.application.mgt.common;
public enum SubAction {
INSTALL, UNINSTALL
}

@ -39,8 +39,8 @@ public interface SubscriptionManager {
ApplicationInstallResponse installApplicationForDevices(String applicationUUID, List<DeviceIdentifier> deviceList)
throws ApplicationManagementException;
ApplicationInstallResponse addBulkApInstallation(String applicationUUID, List<String> subscriberList,
String subType) throws ApplicationManagementException;
<T> ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List<T> params, String subType)
throws ApplicationManagementException;
/**
* To install an application to given list of users.

@ -619,7 +619,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationList applicationList = new ApplicationList();
List<ApplicationDTO> appDTOs;

@ -24,6 +24,8 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.AppOperation;
import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse;
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.DeviceTypes;
import org.wso2.carbon.device.application.mgt.common.SubAction;
import org.wso2.carbon.device.application.mgt.common.SubsciptionType;
import org.wso2.carbon.device.application.mgt.common.SubscribingDeviceIdHolder;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
@ -65,6 +67,7 @@ import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -87,7 +90,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
}
@Override public ApplicationInstallResponse installApplicationForDevices(String applicationUUID,
@Override
public ApplicationInstallResponse installApplicationForDevices(String applicationUUID,
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Install application which has UUID: " + applicationUUID + " to " + deviceIdentifiers.size()
@ -99,102 +103,94 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg);
throw new BadRequestException(msg);
}
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
DeviceIDHolder filteredDeviceHolder = filterDeviceIdentifiers(applicationDTO, deviceIdentifiers);
List<DeviceIdentifier> errorDeviceIdentifiers = filteredDeviceHolder.getErrorDeviceIdList();
List<Device> filteredDeviceObjs = new ArrayList<>();
//getting device objects by using device identifiers
for (DeviceIdentifier deviceIdentifier : filteredDeviceHolder.getValidDeviceIDList()) {
try {
Device device = deviceManagementProviderService.getDevice(deviceIdentifier, false);
if (device == null) {
String msg = "Couldn't found an device for device identifier " + deviceIdentifier.getId()
+ " and device type: " + deviceIdentifier.getType();
log.warn(msg);
errorDeviceIdentifiers.add(deviceIdentifier);
} else {
filteredDeviceObjs.add(device);
}
} catch (DeviceManagementException e) {
String msg = "Error occurred when getting device data for device identifier " + deviceIdentifier.getId()
+ " and device type " + deviceIdentifier.getType();
log.warn(msg);
errorDeviceIdentifiers.add(deviceIdentifier);
throw new ApplicationManagementException(msg, e);
}
}
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
String deviceTypeName = deviceType.getName();
ApplicationInstallResponse applicationInstallResponse = installToDevices(deviceTypeName, filteredDeviceObjs,
applicationDTO, SubsciptionType.DEVICE.toString(), null);
applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers);
return applicationInstallResponse;
} else {
//todo improve thos
ApplicationInstallResponse applicationInstallResponse = installToDevices(null, filteredDeviceObjs,
applicationDTO, SubsciptionType.DEVICE.toString(), null);
applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers);
return applicationInstallResponse;
}
ApplicationInstallResponse applicationInstallResponse = performBulkAppInstallation(applicationUUID,
filteredDeviceHolder.getValidDeviceIDList(), SubsciptionType.DEVICE.toString());
applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers);
return applicationInstallResponse;
}
@Override
public ApplicationInstallResponse addBulkApInstallation(String applicationUUID, List<String> subscriberList,
public <T> ApplicationInstallResponse performBulkAppInstallation(String applicationUUID, List<T> params,
String subType) throws ApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Install application release which has UUID " + applicationUUID + " to " + subscriberList.size()
log.debug("Install application release which has UUID " + applicationUUID + " to " + params.size()
+ " users.");
}
try {
if (subscriberList.isEmpty()) {
String msg = "In order to install application release which has UUID " + applicationUUID + ", you shou"
+ "ld provide list of subscribers. But found an empty list of users.";
if (params.isEmpty()) {
String msg = "In order to install application release which has UUID " + applicationUUID + ", you should"
+ " provide list of subscribers. But found an empty list of users.";
log.error(msg);
throw new BadRequestException(msg);
}
if (SubsciptionType.USER.toString().equals(subType) && !SubsciptionType.ROLE.toString().equals(subType)
&& SubsciptionType.GROUP.toString().equals(subType)) {
boolean isValidSubType = Arrays.stream(SubsciptionType.values())
.anyMatch(sub -> sub.name().equalsIgnoreCase(subType));
if (!isValidSubType) {
String msg = "Found invalid subscription type to install application release witch has UUID: "
+ applicationUUID + ". Subscription type is " + subType;
log.error(msg);
throw new BadRequestException(msg);
}
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
GroupManagementProviderService groupManagementProviderService = HelperUtil
.getGroupManagementProviderService();
List<Device> filteredDevices = new ArrayList<>();
List<Device> subscriberDevices = new ArrayList<>();
for (String subscriber : subscriberList) {
if (SubsciptionType.USER.toString().equals(subType)) {
subscriberDevices.addAll(deviceManagementProviderService.getDevicesOfUser(subscriber));
} else if (SubsciptionType.ROLE.toString().equals(subType)) {
subscriberDevices.addAll(deviceManagementProviderService.getAllDevicesOfRole(subscriber));
} else if (SubsciptionType.GROUP.toString().equals(subType)) {
subscriberDevices.addAll(groupManagementProviderService.getAllDevicesOfGroup(subscriber));
List<Device> devices = new ArrayList<>();
List<String> subscribers = new ArrayList<>();
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
if (SubsciptionType.DEVICE.toString().equals(subType)) {
for (T param : params) {
DeviceIdentifier deviceIdentifier = (DeviceIdentifier) param;
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
}
} else if (SubsciptionType.USER.toString().equals(subType)) {
for (T param : params) {
String username = (String) param;
subscribers.add(username);
devices.addAll(deviceManagementProviderService.getDevicesOfUser(username));
}
} else if (SubsciptionType.ROLE.toString().equals(subType)) {
for (T param : params) {
String roleName = (String) param;
subscribers.add(roleName);
devices.addAll(deviceManagementProviderService.getAllDevicesOfRole(roleName));
}
} else if (SubsciptionType.GROUP.toString().equals(subType)) {
for (T param : params) {
String groupName = (String) param;
subscribers.add(groupName);
devices.addAll(groupManagementProviderService.getAllDevicesOfGroup(groupName));
}
}
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
String deviceTypeName = deviceType.getName();
for (Device device : subscriberDevices) {
for (Device device : devices) {
if (deviceTypeName.equals(device.getType())) {
filteredDevices.add(device);
}
}
return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, subscriberList);
// if (SubsciptionType.DEVICE.toString().equals(subType)) {
// return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, null);
//
// }
return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, subscribers);
} else {
//todo improve this
return installToDevices(null, subscriberDevices, applicationDTO, subType, subscriberList);
// if (SubsciptionType.DEVICE.toString().equals(subType)) {
// return installToDevices(null, filteredDevices, applicationDTO, subType, null);
// }
return installToDevices(null, devices, applicationDTO, subType, subscribers);
}
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting devices of given users or given roles.";
@ -207,6 +203,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
@Override
public List<DeviceIdentifier> uninstallApplication(String applicationUUID,
List<DeviceIdentifier> deviceList) throws ApplicationManagementException {
return null;
}
private ApplicationInstallResponse installToDevices(String deviceType, List<Device> devices,
ApplicationDTO applicationDTO, String subType, List<String> subscribers)
throws ApplicationManagementException {
@ -566,17 +568,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
return response;
}
@Override public List<DeviceIdentifier> uninstallApplication(String applicationUUID,
List<DeviceIdentifier> deviceList) throws ApplicationManagementException {
return null;
}
private Activity addAppInstallOperationToDevices(ApplicationDTO application,
List<DeviceIdentifier> deviceIdentifierList, String deviceType) throws ApplicationManagementException {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService();
try {
Operation operation = generateOperationPayloadByDeviceType(deviceType, application);
Operation operation = generateOperationPayloadByDeviceType(deviceType, application, null);
//todo refactor add operation code to get successful operations
return deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifierList);
} catch (OperationManagementException e) {
@ -602,7 +599,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
.collect(Collectors.groupingBy(DeviceIdentifier::getType));
for (Map.Entry<String, List<DeviceIdentifier>> entry : deviceTypeIdentifierMap.entrySet()) {
Operation operation = generateOperationPayloadByDeviceType(entry.getKey(), application);
Operation operation = generateOperationPayloadByDeviceType(entry.getKey(), application, null);
try {
Activity activity = deviceManagementProviderService
.addOperation(entry.getKey(), operation, entry.getValue());
@ -643,11 +640,57 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
return response;
}
private Operation generateOperationPayloadByDeviceType(String deviceType, ApplicationDTO application) {
private Operation generateOperationPayloadByDeviceType(String deviceType, ApplicationDTO application, String action) {
ProfileOperation operation = new ProfileOperation();
operation.setCode(INSTALL_APPLICATION);
operation.setType(Operation.Type.PROFILE);
// if (DeviceTypes.ANDROID.toString().equalsIgnoreCase(deviceType)) {
// if (ApplicationType.ENTERPRISE.toString().equalsIgnoreCase(application.getType())) {
// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// }
// } else if (ApplicationType.PUBLIC.toString().equalsIgnoreCase(application.getType())) {
// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// }
//
// } else if (ApplicationType.WEB_CLIP.toString().equalsIgnoreCase(application.getType())) {
// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// }
// }
// } else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
// if (ApplicationType.ENTERPRISE.toString().equalsIgnoreCase(application.getType())) {
// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// }
// } else if (ApplicationType.PUBLIC.toString().equalsIgnoreCase(application.getType())) {
// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// }
// } else if (ApplicationType.WEB_CLIP.toString().equalsIgnoreCase())
// application.getType() {
// if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
// log.error("aaaa");
// }
// }
//
// }
//todo: generate operation payload correctly for all types of devices.
operation.setPayLoad(
"{'type':'enterprise', 'url':'" + application.getApplicationReleaseDTOs().get(0).getInstallerName()

@ -129,7 +129,7 @@ public interface SubscriptionManagementAPI {
);
@POST
@Path("/install/{uuid}/{subType}")
@Path("/install/{uuid}/{subType}/{action}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
@ -149,7 +149,7 @@ public interface SubscriptionManagementAPI {
value = {
})
Response addBulkAppInstalltion(
Response performBulkAppInstallation(
@ApiParam(
name = "uuid",
value = "The application release UUID",
@ -162,6 +162,12 @@ public interface SubscriptionManagementAPI {
required = true
)
@PathParam("subType") String subType,
@ApiParam(
name = "action",
value = "Performing action.",
required = true
)
@PathParam("action") String action,
@ApiParam(
name = "subscribers",
value = "Subscriber list of the application release.",

@ -49,7 +49,7 @@ import javax.ws.rs.core.Response;
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Admin Review Management Admin Service",
title = "Review Management Admin Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ReviewManagementAdminService"),

@ -80,14 +80,15 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@Override
@POST
@Path("/install/{uuid}/{subType}")
public Response addBulkAppInstalltion(
@Path("/install/{uuid}/{subType}/{action}")
public Response performBulkAppInstallation(
@PathParam("uuid") String uuid,
@PathParam("uuid") String subType,
@PathParam("subType") String subType,
@PathParam("action") String sction,
@Valid List<String> subscribers) {
try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
ApplicationInstallResponse response = subscriptionManager.addBulkApInstallation(uuid, subscribers, subType);
ApplicationInstallResponse response = subscriptionManager.performBulkAppInstallation(uuid, subscribers, subType);
return Response.status(Response.Status.OK).entity(response).build();
} catch (NotFoundException e) {
String msg = "Couldn't found an application release for UUID: " + uuid + ". Hence, verify the payload";

@ -18,12 +18,12 @@
package org.wso2.carbon.device.mgt.jaxrs.util;
import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp;
import org.wso2.carbon.device.mgt.jaxrs.beans.android.AppStoreApplication;
import org.wso2.carbon.device.mgt.jaxrs.beans.android.EnterpriseApplication;
import org.wso2.carbon.device.mgt.common.app.mgt.android.AppStoreApplication;
import org.wso2.carbon.device.mgt.common.app.mgt.android.EnterpriseApplication;
import org.wso2.carbon.device.mgt.common.app.mgt.android.WebApplication;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.jaxrs.beans.android.WebApplication;
import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp;
import org.wso2.carbon.device.mgt.jaxrs.exception.UnknownApplicationTypeException;
/**

@ -18,11 +18,11 @@
package org.wso2.carbon.device.mgt.jaxrs.util;
import org.wso2.carbon.device.mgt.common.app.mgt.ios.AppStoreApplication;
import org.wso2.carbon.device.mgt.common.app.mgt.ios.EnterpriseApplication;
import org.wso2.carbon.device.mgt.common.app.mgt.ios.RemoveApplication;
import org.wso2.carbon.device.mgt.common.app.mgt.ios.WebClip;
import org.wso2.carbon.device.mgt.jaxrs.beans.MobileApp;
import org.wso2.carbon.device.mgt.jaxrs.beans.ios.AppStoreApplication;
import org.wso2.carbon.device.mgt.jaxrs.beans.ios.EnterpriseApplication;
import org.wso2.carbon.device.mgt.jaxrs.beans.ios.RemoveApplication;
import org.wso2.carbon.device.mgt.jaxrs.beans.ios.WebClip;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;

Loading…
Cancel
Save