Improve APPm sub storing method

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent dd78035227
commit f1c783cdb9

@ -26,7 +26,7 @@ import java.util.Map;
public class SubscribingDeviceIdHolder {
private Map<DeviceIdentifier, Integer> subscribedDevices = new HashMap<>();
private Map<DeviceIdentifier, Integer> subscribableDevices = new HashMap<>();
private Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = new HashMap<>();
// private Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = new HashMap<>();
public Map<DeviceIdentifier, Integer> getSubscribedDevices() {
return subscribedDevices;
@ -44,11 +44,11 @@ public class SubscribingDeviceIdHolder {
this.subscribableDevices = subscribableDevices;
}
public Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions() {
return deviceSubscriptions;
}
public void setDeviceSubscriptions(Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions) {
this.deviceSubscriptions = deviceSubscriptions;
}
// public Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions() {
// return deviceSubscriptions;
// }
//
// public void setDeviceSubscriptions(Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions) {
// this.deviceSubscriptions = deviceSubscriptions;
// }
}

@ -131,7 +131,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
if (!deviceType.getName().equals(deviceIdentifier.getType())) {
String msg =
"Found a device identifier which is not matched with the application device Type. "
@ -238,9 +237,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
for (String type : deviceIdentifierMap.keySet()) {
for (Map.Entry<String, List<DeviceIdentifier>> entry : deviceIdentifierMap.entrySet()) {
Activity activity = addAppInstallOperationToDevices(applicationDTO,
new ArrayList<>(deviceIdentifierMap.get(type)), type);
new ArrayList<>(entry.getValue()), entry.getKey());
activityList.add(activity);
}
@ -259,9 +258,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers);
//todo
addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity,
subscribingDeviceIdHolder.getSubscribableDevices(),
new ArrayList<>(subscribingDeviceIdHolder.getDeviceSubscriptions().keySet()), subscribers, subType);
addSubscriptions(applicationDTO.getApplicationReleaseDTOs().get(0).getId(), activity, subscribingDeviceIdHolder,
subscribers, subType, action);
return applicationInstallResponse;
}
@ -287,7 +285,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder();
subscribingDeviceIdHolder.setSubscribableDevices(subscribableDevices);
subscribingDeviceIdHolder.setSubscribedDevices(subscribedDevices);
subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions);
// subscribingDeviceIdHolder.setDeviceSubscriptions(deviceSubscriptions);
return subscribingDeviceIdHolder;
}
@ -326,9 +324,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
//todo pass SubscribingDeviceIdHolder and action
private void addSubscriptions(int applicationReleaseId, Activity activity,
Map<DeviceIdentifier, Integer> compatibleDevices, List<Integer> subDeviceIds, List<String> subscribers,
String subType) throws ApplicationManagementException {
SubscribingDeviceIdHolder subscribingDeviceIdHolder, List<String> subscribers, String subType, String action)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String subscriber = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
@ -337,6 +336,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<Integer> deviceSubscriptingIds;
if (SubsciptionType.USER.toString().equals(subType)) {
//todo check action
List<String> subscribedUsers = subscriptionDAO.getSubscribedUsernames(subscribers, tenantId);
if (!subscribedUsers.isEmpty()) {
subscriptionDAO
@ -352,16 +352,22 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
for (ActivityStatus status : activityStatuses) {
if (status.getStatus().equals(ActivityStatus.Status.PENDING)) {
deviceIds.add(compatibleDevices.get(status.getDeviceIdentifier()));
//todo
// deviceIds.add(compatibleDevices.get(status.getDeviceIdentifier()));
}
}
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
if (!subDeviceIds.isEmpty()) {
deviceResubscribingIds = subscriptionDAO.updateDeviceSubscription(subscriber, subDeviceIds, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
deviceIds.removeAll(subDeviceIds);
}
//todo if INSTALL get Ids of subscribable devices and update those ids and insert other ids
//todo
// if (!subDeviceIds.isEmpty()) {
// deviceResubscribingIds = subscriptionDAO.updateDeviceSubscription(subscriber, subDeviceIds, subType,
// Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
// deviceIds.removeAll(subDeviceIds);
// }
deviceSubscriptingIds = subscriptionDAO
.subscribeDeviceToApplication(subscriber, deviceIds, subType, Operation.Status.PENDING.toString(),
applicationReleaseId, tenantId);

Loading…
Cancel
Save