|
|
@ -86,15 +86,55 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationInstallResponseTmp 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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
|
|
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
|
|
|
validateAppInstallingForDevicesRequest(applicationDTO, deviceIdentifiers);
|
|
|
|
List<Integer> operationTriggeredDeviceIds = new ArrayList<>();
|
|
|
|
return installToDevicesTmp(applicationDTO, deviceIdentifiers);
|
|
|
|
List <Device> filteredDevices = validateAppInstallingForDevicesRequest(applicationDTO, deviceIdentifiers);
|
|
|
|
|
|
|
|
List<Integer> filteredDeviceIds = new ArrayList<>();
|
|
|
|
|
|
|
|
List<DeviceIdentifier> installedDeviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<DeviceIdentifier , Integer> compatibleDevices = new HashMap<>();
|
|
|
|
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Device device : filteredDevices){
|
|
|
|
|
|
|
|
filteredDeviceIds.add(device.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deviceSubscriptions = getDeviceSubscriptions(filteredDeviceIds);
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Activity activity = installToDevices(applicationDTO, deviceIdentifiers, deviceIdentifiers.get(0).getType());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
|
|
|
|
|
|
|
|
for (ActivityStatus status : activityStatuses) {
|
|
|
|
|
|
|
|
if (status.getStatus().equals(ActivityStatus.Status.PENDING)){
|
|
|
|
|
|
|
|
operationTriggeredDeviceIds.add(compatibleDevices.get(status.getDeviceIdentifier()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
|
|
|
|
applicationInstallResponse.setActivity(activity);
|
|
|
|
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int operationId = Integer
|
|
|
|
|
|
|
|
.parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]);
|
|
|
|
|
|
|
|
addDeviceSubscriptionForUser(applicationDTO.getApplicationReleaseDTOs().get(0).getId(),
|
|
|
|
|
|
|
|
operationTriggeredDeviceIds, new ArrayList<>(deviceSubscriptions.keySet()), null, operationId,
|
|
|
|
|
|
|
|
SubsciptionType.DEVICE.toString());
|
|
|
|
|
|
|
|
return applicationInstallResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationDTO getApplicationDTO(String uuid) throws ApplicationManagementException {
|
|
|
|
private ApplicationDTO getApplicationDTO(String uuid) throws ApplicationManagementException {
|
|
|
@ -132,9 +172,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void validateAppInstallingForDevicesRequest(ApplicationDTO applicationDTO,
|
|
|
|
private List <Device> validateAppInstallingForDevicesRequest(ApplicationDTO applicationDTO,
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers) throws ApplicationManagementException {
|
|
|
|
DeviceType deviceType = null;
|
|
|
|
DeviceType deviceType = null;
|
|
|
|
|
|
|
|
List <Device> existingDevices = 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 = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -149,8 +192,24 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.error(msg);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
existingDevices.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return existingDevices;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ApplicationInstallResponse installApplicationForUsers(String applicationUUID,
|
|
|
|
public ApplicationInstallResponse installApplicationForUsers(String applicationUUID,
|
|
|
@ -163,10 +222,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
//todo check valid user list - throw BadRequest exception
|
|
|
|
//todo check valid user list - throw BadRequest exception
|
|
|
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
|
|
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
|
|
|
DeviceType appDeviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
DeviceType appDeviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
|
|
|
List<DeviceIdentifier> operationTriggeredDeviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<DeviceIdentifier , Integer> compatibleDevices = new HashMap<>();
|
|
|
|
Map<DeviceIdentifier , Integer> compatibleDevices = new HashMap<>();
|
|
|
|
List<Integer> operationTriggeredDeviceIds = new ArrayList<>();
|
|
|
|
List<Integer> operationTriggeredDeviceIds = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> installedDeviceIdentifiers = new ArrayList<>();
|
|
|
|
List<DeviceIdentifier> installedDeviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
for (String user : userList) {
|
|
|
|
for (String user : userList) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -174,13 +233,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
List<Integer> filteredDeviceIds = new ArrayList<>();
|
|
|
|
List<Integer> filteredDeviceIds = new ArrayList<>();
|
|
|
|
List<Device> filteredDevices = new ArrayList<>();
|
|
|
|
List<Device> filteredDevices = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo improve for web clips
|
|
|
|
for (Device device : userDevices) {
|
|
|
|
for (Device device : userDevices) {
|
|
|
|
if (appDeviceType.getName().equals(device.getType())) {
|
|
|
|
if (appDeviceType.getName().equals(device.getType())) {
|
|
|
|
filteredDevices.add(device);
|
|
|
|
filteredDevices.add(device);
|
|
|
|
filteredDeviceIds.add(device.getId());
|
|
|
|
filteredDeviceIds.add(device.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = getDeviceSubscriptions(filteredDeviceIds);
|
|
|
|
deviceSubscriptions = getDeviceSubscriptions(filteredDeviceIds);
|
|
|
|
for (Device device : filteredDevices) {
|
|
|
|
for (Device device : filteredDevices) {
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(),
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(),
|
|
|
|
device.getType());
|
|
|
|
device.getType());
|
|
|
@ -205,22 +265,21 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
for (ActivityStatus status : activityStatuses) {
|
|
|
|
for (ActivityStatus status : activityStatuses) {
|
|
|
|
if (status.getStatus().equals(ActivityStatus.Status.PENDING)){
|
|
|
|
if (status.getStatus().equals(ActivityStatus.Status.PENDING)){
|
|
|
|
operationTriggeredDeviceIds.add(compatibleDevices.get(status.getDeviceIdentifier()));
|
|
|
|
operationTriggeredDeviceIds.add(compatibleDevices.get(status.getDeviceIdentifier()));
|
|
|
|
operationTriggeredDeviceIdentifiers.add(status.getDeviceIdentifier());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
|
|
|
applicationInstallResponse.setActivity(activity);
|
|
|
|
applicationInstallResponse.setActivity(activity);
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers);
|
|
|
|
applicationInstallResponse.setAlreadyInstalledDevices(installedDeviceIdentifiers);
|
|
|
|
applicationInstallResponse.setInstalledDevices(operationTriggeredDeviceIdentifiers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int operationId = Integer
|
|
|
|
int operationId = Integer
|
|
|
|
.parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]);
|
|
|
|
.parseInt(activity.getActivityId().split(DeviceManagementConstants.OperationAttributes.ACTIVITY)[1]);
|
|
|
|
addDeviceSubscriptionForUser(applicationDTO.getApplicationReleaseDTOs().get(0).getId(),
|
|
|
|
addDeviceSubscriptionForUser(applicationDTO.getApplicationReleaseDTOs().get(0).getId(),
|
|
|
|
operationTriggeredDeviceIds, userList, operationId);
|
|
|
|
operationTriggeredDeviceIds, new ArrayList<>(deviceSubscriptions.keySet()), userList, operationId, SubsciptionType.USER.toString());
|
|
|
|
return applicationInstallResponse;
|
|
|
|
return applicationInstallResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void addDeviceSubscriptionForUser(int applicationReleaseId, List<Integer> deviceIds, List<String> userList, int operationId)
|
|
|
|
private void addDeviceSubscriptionForUser(int applicationReleaseId, List<Integer> deviceIds,
|
|
|
|
|
|
|
|
List<Integer> subDeviceIds, List<String> userList, int operationId, String subType)
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
throws ApplicationManagementException {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
|
|
|
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
@ -229,6 +288,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)){
|
|
|
|
List<String> subscribedUsers = subscriptionDAO.getSubscribedUsernames(userList, tenantId);
|
|
|
|
List<String> subscribedUsers = subscriptionDAO.getSubscribedUsernames(userList, tenantId);
|
|
|
|
if (!subscribedUsers.isEmpty()) {
|
|
|
|
if (!subscribedUsers.isEmpty()) {
|
|
|
|
subscriptionDAO
|
|
|
|
subscriptionDAO
|
|
|
@ -236,17 +296,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|
|
|
userList.removeAll(subscribedUsers);
|
|
|
|
userList.removeAll(subscribedUsers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
subscriptionDAO.subscribeUserToApplication(tenantId, subscriber, userList, applicationReleaseId);
|
|
|
|
subscriptionDAO.subscribeUserToApplication(tenantId, subscriber, userList, applicationReleaseId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> subscribedDevices = subscriptionDAO.getSubscribedDeviceIds(deviceIds, tenantId);
|
|
|
|
if (!subDeviceIds.isEmpty()) {
|
|
|
|
if (!subscribedDevices.isEmpty()) {
|
|
|
|
|
|
|
|
deviceResubscribingIds = subscriptionDAO
|
|
|
|
deviceResubscribingIds = subscriptionDAO
|
|
|
|
.updateDeviceSubscription(subscriber, deviceIds, SubsciptionType.USER.toString(),
|
|
|
|
.updateDeviceSubscription(subscriber, subDeviceIds, subType, Operation.Status.PENDING.toString(),
|
|
|
|
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
|
|
|
|
applicationReleaseId, tenantId);
|
|
|
|
deviceIds.removeAll(subscribedDevices);
|
|
|
|
deviceIds.removeAll(subDeviceIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deviceSubscriptingIds = subscriptionDAO
|
|
|
|
deviceSubscriptingIds = subscriptionDAO
|
|
|
|
.subscribeDeviceToApplication(subscriber, deviceIds, SubsciptionType.USER.toString(),
|
|
|
|
.subscribeDeviceToApplication(subscriber, deviceIds, subType, Operation.Status.PENDING.toString(),
|
|
|
|
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
|
|
|
|
applicationReleaseId, tenantId);
|
|
|
|
deviceSubscriptingIds.addAll(deviceResubscribingIds);
|
|
|
|
deviceSubscriptingIds.addAll(deviceResubscribingIds);
|
|
|
|
subscriptionDAO.addOperationMapping(operationId, deviceSubscriptingIds, tenantId);
|
|
|
|
subscriptionDAO.addOperationMapping(operationId, deviceSubscriptingIds, tenantId);
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|