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

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

Loading…
Cancel
Save