|
|
@ -1,22 +1,23 @@
|
|
|
|
/*
|
|
|
|
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
|
|
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
|
|
*
|
|
|
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
|
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
|
|
|
* Version 2.0 (the "License"); you may not use this file except
|
|
|
|
* Version 2.0 (the "License"); you may not use this file except
|
|
|
|
* in compliance with the License.
|
|
|
|
* in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.application.mgt.core.impl;
|
|
|
|
package org.wso2.carbon.device.application.mgt.core.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
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.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
@ -24,6 +25,7 @@ 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.ApplicationInstallResponse;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationType;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.SubsciptionType;
|
|
|
|
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;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponseTmp;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponseTmp;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
|
|
|
@ -55,9 +57,9 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
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.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.util.DeviceIDHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
@ -85,59 +87,168 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
|
|
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public ApplicationInstallResponse installApplicationForDevices(String applicationUUID,
|
|
|
|
public ApplicationInstallResponse installApplicationForDevices(String applicationUUID,
|
|
|
|
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Install application which has UUID: " + applicationUUID + " to " + deviceIdentifiers.size()
|
|
|
|
log.debug("Install application which has UUID: " + applicationUUID + " to " + deviceIdentifiers.size()
|
|
|
|
+ "devices.");
|
|
|
|
+ "devices.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
|
|
|
|
|
.getDeviceManagementProviderService();
|
|
|
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
|
|
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
|
|
|
List<Integer> operationTriggeredDeviceIds = new ArrayList<>();
|
|
|
|
DeviceIDHolder filteredDeviceHolder = filterDeviceIdentifiers(applicationDTO, deviceIdentifiers);
|
|
|
|
List <Device> filteredDevices = validateAppInstallingForDevicesRequest(applicationDTO, deviceIdentifiers);
|
|
|
|
List<DeviceIdentifier> errorDeviceIdentifiers = filteredDeviceHolder.getErrorDeviceIdList();
|
|
|
|
List<Integer> filteredDeviceIds = new ArrayList<>();
|
|
|
|
List<Device> filteredDeviceObjs = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> installedDeviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<DeviceIdentifier , Integer> compatibleDevices = new HashMap<>();
|
|
|
|
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Device device : filteredDevices){
|
|
|
|
//getting device objects by using device identifiers
|
|
|
|
filteredDeviceIds.add(device.getId());
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
deviceSubscriptions = getDeviceSubscriptions(filteredDeviceIds);
|
|
|
|
@Override
|
|
|
|
for (Device device : filteredDevices) {
|
|
|
|
public ApplicationInstallResponse addBulkApInstallation(String applicationUUID, List<String> subscriberList,
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(),
|
|
|
|
String subType) throws ApplicationManagementException {
|
|
|
|
device.getType());
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
DeviceSubscriptionDTO deviceSubscriptionDTO = deviceSubscriptions.get(device.getId());
|
|
|
|
log.debug("Install application release which has UUID " + applicationUUID + " to " + subscriberList.size()
|
|
|
|
if (deviceSubscriptionDTO != null && !deviceSubscriptionDTO.isUnsubscribed()
|
|
|
|
+ " users.");
|
|
|
|
&& Operation.Status.COMPLETED.toString().equals(deviceSubscriptionDTO.getStatus())) {
|
|
|
|
}
|
|
|
|
installedDeviceIdentifiers.add(deviceIdentifier);
|
|
|
|
|
|
|
|
|
|
|
|
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.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SubsciptionType.USER.toString().equals(subType) && !SubsciptionType.ROLE.toString().equals(subType)
|
|
|
|
|
|
|
|
&& SubsciptionType.GROUP.toString().equals(subType)) {
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
|
|
|
|
|
|
|
|
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
|
|
|
|
String deviceTypeName = deviceType.getName();
|
|
|
|
|
|
|
|
for (Device device : subscriberDevices) {
|
|
|
|
|
|
|
|
if (deviceTypeName.equals(device.getType())) {
|
|
|
|
|
|
|
|
filteredDevices.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return installToDevices(deviceTypeName, filteredDevices, applicationDTO, subType, subscriberList);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
compatibleDevices.put(deviceIdentifier, device.getId());
|
|
|
|
//todo improve this
|
|
|
|
|
|
|
|
return installToDevices(null, subscriberDevices, applicationDTO, subType, subscriberList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting devices of given users or given roles.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (GroupManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting devices of given groups";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Activity activity = installToDevices(applicationDTO, deviceIdentifiers, deviceIdentifiers.get(0).getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
|
|
|
|
private ApplicationInstallResponse installToDevices(String deviceType, List<Device> devices,
|
|
|
|
for (ActivityStatus status : activityStatuses) {
|
|
|
|
ApplicationDTO applicationDTO, String subType, List<String> subscribers)
|
|
|
|
if (status.getStatus().equals(ActivityStatus.Status.PENDING)){
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
operationTriggeredDeviceIds.add(compatibleDevices.get(status.getDeviceIdentifier()));
|
|
|
|
|
|
|
|
}
|
|
|
|
SubscribingDeviceIdHolder subscribingDeviceIdHolder = getSubscribingDeviceIdHolder(devices);
|
|
|
|
|
|
|
|
if (subscribingDeviceIdHolder.getCompatibleDevices().isEmpty()) {
|
|
|
|
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(subscribingDeviceIdHolder.getInstalledDevices());
|
|
|
|
|
|
|
|
return applicationInstallResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Activity activity = addAppInstallOperationToDevices(applicationDTO,
|
|
|
|
|
|
|
|
new ArrayList<>(subscribingDeviceIdHolder.getCompatibleDevices().keySet()), deviceType);
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
applicationInstallResponse.setActivity(activity);
|
|
|
|
applicationInstallResponse.setActivity(activity);
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers);
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(subscribingDeviceIdHolder.getInstalledDevices());
|
|
|
|
|
|
|
|
|
|
|
|
// int operationId = Integer
|
|
|
|
addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity,
|
|
|
|
// .parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]);
|
|
|
|
subscribingDeviceIdHolder.getCompatibleDevices(),
|
|
|
|
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
|
|
|
|
new ArrayList<>(subscribingDeviceIdHolder.getDeviceSubscriptions().keySet()), subscribers, subType);
|
|
|
|
addDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(),
|
|
|
|
|
|
|
|
operationTriggeredDeviceIds, new ArrayList<>(deviceSubscriptions.keySet()), null, operationId,
|
|
|
|
|
|
|
|
SubsciptionType.DEVICE.toString());
|
|
|
|
|
|
|
|
return applicationInstallResponse;
|
|
|
|
return applicationInstallResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SubscribingDeviceIdHolder getSubscribingDeviceIdHolder(List<Device> devices)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
List<DeviceIdentifier> installedDevices = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<DeviceIdentifier, Integer> compatibleDevices = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> filteredDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = getDeviceSubscriptions(filteredDeviceIds);
|
|
|
|
|
|
|
|
for (Device device : devices) {
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
|
|
|
|
|
|
|
|
DeviceSubscriptionDTO deviceSubscriptionDTO = deviceSubscriptions.get(device.getId());
|
|
|
|
|
|
|
|
if (deviceSubscriptionDTO != null && !deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED
|
|
|
|
|
|
|
|
.toString().equals(deviceSubscriptionDTO.getStatus())) {
|
|
|
|
|
|
|
|
installedDevices.add(deviceIdentifier);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
compatibleDevices.put(deviceIdentifier, device.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder();
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setCompatibleDevices(compatibleDevices);
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setInstalledDevices(installedDevices);
|
|
|
|
|
|
|
|
subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions);
|
|
|
|
|
|
|
|
return subscribingDeviceIdHolder;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationDTO getApplicationDTO(String uuid) throws ApplicationManagementException {
|
|
|
|
private ApplicationDTO getApplicationDTO(String uuid) throws ApplicationManagementException {
|
|
|
|
ApplicationDTO applicationDTO;
|
|
|
|
ApplicationDTO applicationDTO;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
@ -173,117 +284,54 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List <Device> validateAppInstallingForDevicesRequest(ApplicationDTO applicationDTO,
|
|
|
|
private DeviceIDHolder filterDeviceIdentifiers(ApplicationDTO applicationDTO,
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
|
|
|
DeviceType deviceType = null;
|
|
|
|
List<DeviceIdentifier> errorDeviceIdList = new ArrayList<>();
|
|
|
|
List <Device> existingDevices = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> validDeviceIDList = new ArrayList<>();
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
|
|
|
|
|
.getDeviceManagementProviderService();
|
|
|
|
|
|
|
|
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
|
|
|
|
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
|
|
|
|
deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
}
|
|
|
|
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils.isEmpty(deviceIdentifier.getType())) {
|
|
|
|
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
|
|
|
|
log.warn("Found a device identifier which has either empty identity of the device or empty device "
|
|
|
|
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType()) && deviceType != null
|
|
|
|
+ "type. Hence ignoring the device identifier. ");
|
|
|
|
&& !deviceType.getName().equals(deviceIdentifier.getType())) {
|
|
|
|
continue;
|
|
|
|
String msg =
|
|
|
|
}
|
|
|
|
"Found a device identifier which is not matched with the application device Type. Application "
|
|
|
|
if (!deviceType.getName().equals(deviceIdentifier.getType())) {
|
|
|
|
+ "device type is " + deviceType.getName()
|
|
|
|
String msg =
|
|
|
|
+ " and identifier which has different device" + " type is " + deviceIdentifier.getId();
|
|
|
|
"Found a device identifier which is not matched with the application device Type. Application "
|
|
|
|
log.error(msg);
|
|
|
|
+ "device type is " + deviceType.getName() + " and the identifier of which has a "
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
+ "different device type is " + deviceIdentifier.getId();
|
|
|
|
}
|
|
|
|
log.warn(msg);
|
|
|
|
try {
|
|
|
|
errorDeviceIdList.add(deviceIdentifier);
|
|
|
|
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.error(msg);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
existingDevices.add(device);
|
|
|
|
validDeviceIDList.add(deviceIdentifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occuered when getting device data for divice identifier " + deviceIdentifier.getId()
|
|
|
|
|
|
|
|
+ " and device type " + deviceIdentifier.getType();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return existingDevices;
|
|
|
|
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(deviceIdentifier.getId()) || StringUtils.isEmpty(deviceIdentifier.getType())) {
|
|
|
|
|
|
|
|
log.warn("Found a device identifier which has either empty identity of the device or empty device "
|
|
|
|
@Override
|
|
|
|
+ "type. Hence ignoring the device identifier. ");
|
|
|
|
public ApplicationInstallResponse installApplicationForUsers(String applicationUUID,
|
|
|
|
continue;
|
|
|
|
List<String> userList) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Install application release which has UUID " + applicationUUID + " to " + userList.size()
|
|
|
|
|
|
|
|
+ " users.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo check valid user list - throw BadRequest exception
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
|
|
|
|
|
|
|
DeviceType appDeviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
|
|
|
|
Map<DeviceIdentifier , Integer> compatibleDevices = new HashMap<>();
|
|
|
|
|
|
|
|
List<Integer> operationTriggeredDeviceIds = new ArrayList<>();
|
|
|
|
|
|
|
|
List<DeviceIdentifier> installedDeviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String user : userList) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<Device> userDevices = HelperUtil.getDeviceManagementProviderService().getDevicesOfUser(user);
|
|
|
|
|
|
|
|
List<Integer> filteredDeviceIds = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Device> filteredDevices = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo improve for web clips
|
|
|
|
|
|
|
|
for (Device device : userDevices) {
|
|
|
|
|
|
|
|
if (appDeviceType.getName().equals(device.getType())) {
|
|
|
|
|
|
|
|
filteredDevices.add(device);
|
|
|
|
|
|
|
|
filteredDeviceIds.add(device.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deviceSubscriptions = getDeviceSubscriptions(filteredDeviceIds);
|
|
|
|
validDeviceIDList.add(deviceIdentifier);
|
|
|
|
for (Device device : filteredDevices) {
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(),
|
|
|
|
|
|
|
|
device.getType());
|
|
|
|
|
|
|
|
DeviceSubscriptionDTO deviceSubscriptionDTO = deviceSubscriptions.get(device.getId());
|
|
|
|
|
|
|
|
if (deviceSubscriptionDTO != null && !deviceSubscriptionDTO.isUnsubscribed()
|
|
|
|
|
|
|
|
&& Operation.Status.COMPLETED.toString().equals(deviceSubscriptionDTO.getStatus())) {
|
|
|
|
|
|
|
|
installedDeviceIdentifiers.add(deviceIdentifier);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
compatibleDevices.put(deviceIdentifier, device.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when extracting the device list of user[" + user + "].";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Activity activity = installToDevices(applicationDTO, new ArrayList<>(compatibleDevices.keySet()),
|
|
|
|
|
|
|
|
appDeviceType.getName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
|
|
|
|
if (validDeviceIDList.isEmpty()) {
|
|
|
|
for (ActivityStatus status : activityStatuses) {
|
|
|
|
String msg = "Couldn't found at least one valid device identifier to install the application.";
|
|
|
|
if (status.getStatus().equals(ActivityStatus.Status.PENDING)){
|
|
|
|
log.error(msg);
|
|
|
|
operationTriggeredDeviceIds.add(compatibleDevices.get(status.getDeviceIdentifier()));
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
|
|
|
|
applicationInstallResponse.setActivity(activity);
|
|
|
|
deviceIDHolder.setValidDeviceIDList(validDeviceIDList);
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers);
|
|
|
|
deviceIDHolder.setErrorDeviceIdList(errorDeviceIdList);
|
|
|
|
|
|
|
|
return deviceIDHolder;
|
|
|
|
// int operationId = Integer
|
|
|
|
|
|
|
|
// .parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]);
|
|
|
|
|
|
|
|
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addDeviceSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(),
|
|
|
|
|
|
|
|
operationTriggeredDeviceIds, new ArrayList<>(deviceSubscriptions.keySet()), userList, operationId, SubsciptionType.USER.toString());
|
|
|
|
|
|
|
|
return applicationInstallResponse;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void addDeviceSubscriptions(int applicationReleaseId, List<Integer> deviceIds,
|
|
|
|
private void addSubscriptions(int applicationReleaseId, Activity activity,
|
|
|
|
List<Integer> subDeviceIds, List<String> subscribers, int operationId, String subType)
|
|
|
|
Map<DeviceIdentifier, Integer> compatibleDevices, List<Integer> subDeviceIds, List<String> subscribers,
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
String subType) throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -291,7 +339,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
List<Integer> deviceResubscribingIds = new ArrayList<>();
|
|
|
|
List<Integer> deviceResubscribingIds = new ArrayList<>();
|
|
|
|
List<Integer> deviceSubscriptingIds;
|
|
|
|
List<Integer> deviceSubscriptingIds;
|
|
|
|
|
|
|
|
|
|
|
|
if (SubsciptionType.USER.toString().equals(subType)){
|
|
|
|
if (SubsciptionType.USER.toString().equals(subType)) {
|
|
|
|
List<String> subscribedUsers = subscriptionDAO.getSubscribedUsernames(subscribers, tenantId);
|
|
|
|
List<String> subscribedUsers = subscriptionDAO.getSubscribedUsernames(subscribers, tenantId);
|
|
|
|
if (!subscribedUsers.isEmpty()) {
|
|
|
|
if (!subscribedUsers.isEmpty()) {
|
|
|
|
subscriptionDAO
|
|
|
|
subscriptionDAO
|
|
|
@ -301,10 +349,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
subscriptionDAO.subscribeUserToApplication(tenantId, subscriber, subscribers, applicationReleaseId);
|
|
|
|
subscriptionDAO.subscribeUserToApplication(tenantId, subscriber, subscribers, applicationReleaseId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo add for other subscription types
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> deviceIds = new ArrayList<>();
|
|
|
|
|
|
|
|
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
|
|
|
|
|
|
|
|
for (ActivityStatus status : activityStatuses) {
|
|
|
|
|
|
|
|
if (status.getStatus().equals(ActivityStatus.Status.PENDING)) {
|
|
|
|
|
|
|
|
deviceIds.add(compatibleDevices.get(status.getDeviceIdentifier()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
|
|
|
|
if (!subDeviceIds.isEmpty()) {
|
|
|
|
if (!subDeviceIds.isEmpty()) {
|
|
|
|
deviceResubscribingIds = subscriptionDAO
|
|
|
|
deviceResubscribingIds = subscriptionDAO.updateDeviceSubscription(subscriber, subDeviceIds, subType,
|
|
|
|
.updateDeviceSubscription(subscriber, subDeviceIds, subType, Operation.Status.PENDING.toString(),
|
|
|
|
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
|
|
|
|
applicationReleaseId, tenantId);
|
|
|
|
|
|
|
|
deviceIds.removeAll(subDeviceIds);
|
|
|
|
deviceIds.removeAll(subDeviceIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deviceSubscriptingIds = subscriptionDAO
|
|
|
|
deviceSubscriptingIds = subscriptionDAO
|
|
|
@ -315,8 +373,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
String msg =
|
|
|
|
String msg = "Error occurred when adding subscription data for application release UUID: "
|
|
|
|
"Error occurred when adding subscription data for application release UUID: " + applicationReleaseId;
|
|
|
|
+ applicationReleaseId;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
@ -334,14 +392,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions (List<Integer> filteredDeviceIds)
|
|
|
|
private Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> filteredDeviceIds)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
return this.subscriptionDAO
|
|
|
|
return this.subscriptionDAO.getDeviceSubscriptions(filteredDeviceIds, tenantId);
|
|
|
|
.getDeviceSubscriptions(filteredDeviceIds, tenantId);
|
|
|
|
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
} catch (ApplicationManagementDAOException e) {
|
|
|
|
String msg = "Error occured when getting device subscriptions for given device IDs";
|
|
|
|
String msg = "Error occured when getting device subscriptions for given device IDs";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -356,9 +413,66 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
//todo remove below methods
|
|
|
|
public ApplicationInstallResponseTmp installApplicationForRoles(String applicationUUID, List<String> roleList)
|
|
|
|
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
@Override public ApplicationInstallResponse installApplicationForUsers(String applicationUUID,
|
|
|
|
|
|
|
|
List<String> userList) throws ApplicationManagementException {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Install application release which has UUID " + applicationUUID + " to " + userList.size()
|
|
|
|
|
|
|
|
+ " users.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo check valid user list - throw BadRequest exception
|
|
|
|
|
|
|
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
|
|
|
|
|
|
|
DeviceType appDeviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
|
|
|
|
Map<DeviceIdentifier, Integer> compatibleDevices = new HashMap<>();
|
|
|
|
|
|
|
|
List<DeviceIdentifier> installedDeviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String user : userList) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
List<Device> userDevices = HelperUtil.getDeviceManagementProviderService().getDevicesOfUser(user);
|
|
|
|
|
|
|
|
List<Device> filteredDevices = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo improve for web clips
|
|
|
|
|
|
|
|
for (Device device : userDevices) {
|
|
|
|
|
|
|
|
if (appDeviceType.getName().equals(device.getType())) {
|
|
|
|
|
|
|
|
filteredDevices.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SubscribingDeviceIdHolder subscribingDeviceIdHolder = getSubscribingDeviceIdHolder(filteredDevices);
|
|
|
|
|
|
|
|
compatibleDevices.putAll(subscribingDeviceIdHolder.getCompatibleDevices());
|
|
|
|
|
|
|
|
deviceSubscriptions.putAll(subscribingDeviceIdHolder.getDeviceSubscriptions());
|
|
|
|
|
|
|
|
installedDeviceIdentifiers.addAll(subscribingDeviceIdHolder.getInstalledDevices());
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred when extracting the device list of user[" + user + "].";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ApplicationManagementException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (compatibleDevices.keySet().isEmpty()) {
|
|
|
|
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers);
|
|
|
|
|
|
|
|
return applicationInstallResponse;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Activity activity = addAppInstallOperationToDevices(applicationDTO, new ArrayList<>(compatibleDevices.keySet()),
|
|
|
|
|
|
|
|
appDeviceType.getName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
|
|
|
|
applicationInstallResponse.setActivity(activity);
|
|
|
|
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, compatibleDevices,
|
|
|
|
|
|
|
|
new ArrayList<>(deviceSubscriptions.keySet()), userList, SubsciptionType.USER.toString());
|
|
|
|
|
|
|
|
return applicationInstallResponse;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo not implemented below code properly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public ApplicationInstallResponseTmp installApplicationForRoles(String applicationUUID,
|
|
|
|
|
|
|
|
List<String> roleList) throws ApplicationManagementException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Install application: " + applicationUUID + " to " + roleList.size() + " roles.");
|
|
|
|
log.debug("Install application: " + applicationUUID + " to " + roleList.size() + " roles.");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -400,9 +514,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
return response;
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override public ApplicationInstallResponseTmp installApplicationForGroups(String applicationUUID,
|
|
|
|
public ApplicationInstallResponseTmp installApplicationForGroups(String applicationUUID, List<String> deviceGroupList)
|
|
|
|
List<String> deviceGroupList) throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Install application: " + applicationUUID + " to " + deviceGroupList.size() + " groups.");
|
|
|
|
log.debug("Install application: " + applicationUUID + " to " + deviceGroupList.size() + " groups.");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -452,25 +565,23 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Activity installToDevices(ApplicationDTO application,
|
|
|
|
private Activity addAppInstallOperationToDevices(ApplicationDTO application,
|
|
|
|
List<DeviceIdentifier> deviceIdentifierList, String deviceType) throws ApplicationManagementException {
|
|
|
|
List<DeviceIdentifier> deviceIdentifierList, String deviceType) throws ApplicationManagementException {
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
|
.getDeviceManagementProviderService();
|
|
|
|
.getDeviceManagementProviderService();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Operation operation = generateOperationPayloadByDeviceType(deviceType, application);
|
|
|
|
Operation operation = generateOperationPayloadByDeviceType(deviceType, application);
|
|
|
|
//todo refactor add operation code to get successful operations
|
|
|
|
//todo refactor add operation code to get successful operations
|
|
|
|
return deviceManagementProviderService
|
|
|
|
return deviceManagementProviderService.addOperation(deviceType, operation, deviceIdentifierList);
|
|
|
|
.addOperation(deviceType, operation, deviceIdentifierList);
|
|
|
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
throw new ApplicationManagementException("Error occurred while adding the application install "
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
+ "operation to devices", e);
|
|
|
|
"Error occurred while adding the application install " + "operation to devices", e);
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
//This exception should not occur because the validation has already been done.
|
|
|
|
//This exception should not occur because the validation has already been done.
|
|
|
|
throw new ApplicationManagementException("The list of device identifiers are invalid");
|
|
|
|
throw new ApplicationManagementException("The list of device identifiers are invalid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationInstallResponseTmp installToDevicesTmp(ApplicationDTO application,
|
|
|
|
private ApplicationInstallResponseTmp installToDevicesTmp(ApplicationDTO application,
|
|
|
|
List<DeviceIdentifier> deviceIdentifierList) throws ApplicationManagementException {
|
|
|
|
List<DeviceIdentifier> deviceIdentifierList) throws ApplicationManagementException {
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
@ -493,8 +604,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
response.setSuccessfulDevices(null);
|
|
|
|
response.setSuccessfulDevices(null);
|
|
|
|
response.setFailedDevices(deviceIdentifierList);
|
|
|
|
response.setFailedDevices(deviceIdentifierList);
|
|
|
|
throw new ApplicationManagementException("Error occurred while adding the application install "
|
|
|
|
throw new ApplicationManagementException(
|
|
|
|
+ "operation to devices", e);
|
|
|
|
"Error occurred while adding the application install " + "operation to devices", e);
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
//This exception should not occur because the validation has already been done.
|
|
|
|
//This exception should not occur because the validation has already been done.
|
|
|
|
throw new ApplicationManagementException("The list of device identifiers are invalid");
|
|
|
|
throw new ApplicationManagementException("The list of device identifiers are invalid");
|
|
|
@ -541,7 +652,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Validates the preconditions which is required to satisfy from the device which is required to install the
|
|
|
|
* Validates the preconditions which is required to satisfy from the device which is required to install the
|
|
|
|
* application.
|
|
|
|
* application.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* This method check two preconditions whether the application type is compatible to install in the device and
|
|
|
|
* This method check two preconditions whether the application type is compatible to install in the device and
|
|
|
|
* whether the device is enrolled in the system.
|
|
|
|
* whether the device is enrolled in the system.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -572,5 +683,4 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
return applicationInstallResponseTmp;
|
|
|
|
return applicationInstallResponseTmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|