Fix issues in APPM subscription flow

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent 4989ac2d0c
commit 7eb3a5d762

@ -26,6 +26,7 @@ public class SubscribingDeviceIdHolder {
private Map<DeviceIdentifier, Integer> appInstalledDevices = new HashMap<>(); private Map<DeviceIdentifier, Integer> appInstalledDevices = new HashMap<>();
private Map<DeviceIdentifier, Integer> appInstallableDevices = new HashMap<>(); private Map<DeviceIdentifier, Integer> appInstallableDevices = new HashMap<>();
private Map<DeviceIdentifier, Integer> appReInstallableDevices = new HashMap<>(); private Map<DeviceIdentifier, Integer> appReInstallableDevices = new HashMap<>();
private Map<DeviceIdentifier, Integer> appReUnInstallableDevices = new HashMap<>();
private Map<DeviceIdentifier, Integer> skippedDevices = new HashMap<>(); private Map<DeviceIdentifier, Integer> skippedDevices = new HashMap<>();
public Map<DeviceIdentifier, Integer> getAppInstalledDevices() { public Map<DeviceIdentifier, Integer> getAppInstalledDevices() {
@ -57,4 +58,12 @@ public class SubscribingDeviceIdHolder {
public void setSkippedDevices(Map<DeviceIdentifier, Integer> skippedDevices) { public void setSkippedDevices(Map<DeviceIdentifier, Integer> skippedDevices) {
this.skippedDevices = skippedDevices; this.skippedDevices = skippedDevices;
} }
public Map<DeviceIdentifier, Integer> getAppReUnInstallableDevices() {
return appReUnInstallableDevices;
}
public void setAppReUnInstallableDevices(Map<DeviceIdentifier, Integer> appReUnInstallableDevices) {
this.appReUnInstallableDevices = appReUnInstallableDevices;
}
} }

@ -97,7 +97,7 @@ public interface SubscriptionManager {
* given application * given application
* @link org.wso2.carbon.device.application.mgt.common.SubscriptionType}} * @link org.wso2.carbon.device.application.mgt.common.SubscriptionType}}
*/ */
<T> void performEntAppInstall(String applicationUUID, List<T> params, String subType) <T> void performEntAppSubscription(String applicationUUID, List<T> params, String subType, String action)
throws ApplicationManagementException; throws ApplicationManagementException;
/*** /***
@ -123,7 +123,7 @@ public interface SubscriptionManager {
* @return {@link PaginationResult} pagination result of the category details. * @return {@link PaginationResult} pagination result of the category details.
* @throws {@link ApplicationManagementException} Exception of the application management * @throws {@link ApplicationManagementException} Exception of the application management
*/ */
PaginationResult getAppInstalledCategories(int offsetValue, int limitValue, String appUUID, PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID,
String subType) throws ApplicationManagementException; String subType) throws ApplicationManagementException;
/** /**

@ -33,7 +33,7 @@ import java.util.Map;
*/ */
public interface SubscriptionDAO { public interface SubscriptionDAO {
List<Integer> addDeviceSubscription(String subscribedBy, List<Integer> deviceIds, String subscribedFrom, void addDeviceSubscription(String subscribedBy, List<Integer> deviceIds, String subscribedFrom,
String installStatus, int releaseId, int tenantId ) throws ApplicationManagementDAOException; String installStatus, int releaseId, int tenantId ) throws ApplicationManagementDAOException;
void updateDeviceSubscription(String updateBy, List<Integer> deviceIds, String action, String actionTriggeredFrom, void updateDeviceSubscription(String updateBy, List<Integer> deviceIds, String action, String actionTriggeredFrom,
@ -66,13 +66,13 @@ public interface SubscriptionDAO {
Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int appReleaseId, int tenantId) Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int appReleaseId, int tenantId)
throws ApplicationManagementDAOException; throws ApplicationManagementDAOException;
List<String> getSubscribedUserNames(List<String> users, int tenantId) throws List<String> getAppSubscribedUserNames(List<String> users, int appReleaseId, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
List<String> getSubscribedRoleNames(List<String> roles, int tenantId) throws List<String> getAppSubscribedRoleNames(List<String> roles, int appReleaseId, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
List<String> getSubscribedGroupNames(List<String> groups, int tenantId) throws List<String> getAppSubscribedGroupNames(List<String> groups, int appReleaseId, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
void updateSubscriptions(int tenantId, String updateBy, List<String> paramList, void updateSubscriptions(int tenantId, String updateBy, List<String> paramList,
@ -81,7 +81,8 @@ public interface SubscriptionDAO {
List<Integer> getDeviceSubIds(List<Integer> deviceIds, int applicationReleaseId, int tenantId) List<Integer> getDeviceSubIds(List<Integer> deviceIds, int applicationReleaseId, int tenantId)
throws ApplicationManagementDAOException; throws ApplicationManagementDAOException;
List<Integer> getDeviceSubIdsForOperation (int operationId, int tenantId) throws ApplicationManagementDAOException; List<Integer> getDeviceSubIdsForOperation(int operationId, int deviceID, int tenantId)
throws ApplicationManagementDAOException;
boolean updateDeviceSubStatus(int deviceId, List<Integer> deviceSubIds, String status, int tenantcId) boolean updateDeviceSubStatus(int deviceId, List<Integer> deviceSubIds, String status, int tenantcId)
throws ApplicationManagementDAOException; throws ApplicationManagementDAOException;

@ -49,7 +49,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
private static Log log = LogFactory.getLog(GenericSubscriptionDAOImpl.class); private static Log log = LogFactory.getLog(GenericSubscriptionDAOImpl.class);
@Override @Override
public List<Integer> addDeviceSubscription(String subscribedBy, List<Integer> deviceIds, public void addDeviceSubscription(String subscribedBy, List<Integer> deviceIds,
String subscribedFrom, String installStatus, int releaseId, int tenantId) String subscribedFrom, String installStatus, int releaseId, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
String sql = "INSERT INTO " String sql = "INSERT INTO "
@ -82,13 +82,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
} }
stmt.executeBatch(); stmt.executeBatch();
try (ResultSet rs = stmt.getGeneratedKeys()) {
List<Integer> deviceSubIds = new ArrayList<>();
while (rs.next()) {
deviceSubIds.add(rs.getInt(1));
}
return deviceSubIds;
}
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
String msg = "Error occured while obtaining database connection to add device subscription for application " String msg = "Error occured while obtaining database connection to add device subscription for application "
@ -425,8 +418,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
} }
@Override public List<String> getAppSubscribedUserNames(List<String> users, int appReleaseId, int tenantId)
public List<String> getSubscribedUserNames(List<String> users, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed users for given list of user names."); log.debug("Request received in DAO Layer to get already subscribed users for given list of user names.");
@ -438,13 +430,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
StringJoiner joiner = new StringJoiner(",", StringJoiner joiner = new StringJoiner(",",
"SELECT US.USER_NAME AS USER_NAME " "SELECT US.USER_NAME AS USER_NAME "
+ "FROM AP_USER_SUBSCRIPTION US " + "FROM AP_USER_SUBSCRIPTION US "
+ "WHERE US.USER_NAME IN (", ") AND TENANT_ID = ?"); + "WHERE US.USER_NAME IN (", ") AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?");
users.stream().map(ignored -> "?").forEach(joiner::add); users.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) { try (PreparedStatement ps = conn.prepareStatement(query)) {
for (String username : users) { for (String username : users) {
ps.setObject(index++, username); ps.setObject(index++, username);
} }
ps.setInt(index++, appReleaseId);
ps.setInt(index, tenantId); ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) { while (rs.next()) {
@ -465,8 +458,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
} }
@Override public List<String> getAppSubscribedRoleNames(List<String> roles, int appReleaseId, int tenantId)
public List<String> getSubscribedRoleNames(List<String> roles, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed role names for given list of roles."); log.debug("Request received in DAO Layer to get already subscribed role names for given list of roles.");
@ -478,13 +470,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
StringJoiner joiner = new StringJoiner(",", StringJoiner joiner = new StringJoiner(",",
"SELECT RS.ROLE_NAME AS ROLE " "SELECT RS.ROLE_NAME AS ROLE "
+ "FROM AP_ROLE_SUBSCRIPTION RS " + "FROM AP_ROLE_SUBSCRIPTION RS "
+ "WHERE RS.ROLE_NAME IN (", ") AND TENANT_ID = ?"); + "WHERE RS.ROLE_NAME IN (", ") AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?");
roles.stream().map(ignored -> "?").forEach(joiner::add); roles.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) { try (PreparedStatement ps = conn.prepareStatement(query)) {
for (String roleName : roles) { for (String roleName : roles) {
ps.setObject(index++, roleName); ps.setObject(index++, roleName);
} }
ps.setInt(index++, appReleaseId);
ps.setInt(index, tenantId); ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) { while (rs.next()) {
@ -506,7 +499,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
@Override @Override
public List<String> getSubscribedGroupNames(List<String> groups, int tenantId) public List<String> getAppSubscribedGroupNames(List<String> groups, int appReleaseId, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get already subscribed groups for given list of groups."); log.debug("Request received in DAO Layer to get already subscribed groups for given list of groups.");
@ -518,13 +511,14 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
StringJoiner joiner = new StringJoiner(",", StringJoiner joiner = new StringJoiner(",",
"SELECT GS.GROUP_NAME AS GROUP_NAME " "SELECT GS.GROUP_NAME AS GROUP_NAME "
+ "FROM AP_GROUP_SUBSCRIPTION GS " + "FROM AP_GROUP_SUBSCRIPTION GS "
+ "WHERE GS.GROUP_NAME IN (", ") AND TENANT_ID = ?"); + "WHERE GS.GROUP_NAME IN (", ") AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?");
groups.stream().map(ignored -> "?").forEach(joiner::add); groups.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) { try (PreparedStatement ps = conn.prepareStatement(query)) {
for (String groupName : groups) { for (String groupName : groups) {
ps.setObject(index++, groupName); ps.setObject(index++, groupName);
} }
ps.setInt(index++, appReleaseId);
ps.setInt(index, tenantId); ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) { while (rs.next()) {
@ -647,20 +641,22 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
@Override @Override
public List<Integer> getDeviceSubIdsForOperation(int operationId, int tenantId) public List<Integer> getDeviceSubIdsForOperation(int operationId, int deviceId, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
List<Integer> deviceSubIds = new ArrayList<>(); List<Integer> deviceSubIds = new ArrayList<>();
String sql = "SELECT " String sql = "SELECT AP_APP_SUB_OP_MAPPING.AP_DEVICE_SUBSCRIPTION_ID "
+ "AP_DEVICE_SUBSCRIPTION_ID " + "FROM "
+ "FROM AP_APP_SUB_OP_MAPPING " + "AP_APP_SUB_OP_MAPPING INNER JOIN AP_DEVICE_SUBSCRIPTION "
+ "WHERE " + "ON AP_APP_SUB_OP_MAPPING.AP_DEVICE_SUBSCRIPTION_ID = AP_DEVICE_SUBSCRIPTION.ID "
+ "OPERATION_ID = ? AND " + "WHERE AP_APP_SUB_OP_MAPPING.OPERATION_ID = ? AND "
+ "TENANT_ID = ?"; + "AP_DEVICE_SUBSCRIPTION.DM_DEVICE_ID = ? AND "
+ "AP_APP_SUB_OP_MAPPING.TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setInt(2, tenantId); stmt.setInt(2, deviceId);
stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery()) { try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) { while (rs.next()) {
deviceSubIds.add(rs.getInt("AP_DEVICE_SUBSCRIPTION_ID")); deviceSubIds.add(rs.getInt("AP_DEVICE_SUBSCRIPTION_ID"));

@ -159,58 +159,4 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override
public List<Integer> addDeviceSubscription(String subscribedBy, List<Integer> deviceIds,
String subscribedFrom, String installStatus, int releaseId, int tenantId)
throws ApplicationManagementDAOException {
String sql = "INSERT INTO "
+ "AP_DEVICE_SUBSCRIPTION("
+ "SUBSCRIBED_BY, "
+ "SUBSCRIBED_TIMESTAMP, "
+ "ACTION_TRIGGERED_FROM, "
+ "STATUS, "
+ "DM_DEVICE_ID, "
+ "AP_APP_RELEASE_ID,"
+ "TENANT_ID) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?)";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
List<Integer> deviceSubIds = new ArrayList<>();
for (Integer deviceId : deviceIds) {
stmt.setString(1, subscribedBy);
stmt.setTimestamp(2, timestamp);
stmt.setString(3, subscribedFrom);
stmt.setString(4, installStatus);
stmt.setInt(5, deviceId);
stmt.setInt(6, releaseId);
stmt.setInt(7, tenantId);
if (log.isDebugEnabled()) {
log.debug("Adding a device subscription for device id " + deviceId + " and application "
+ "release which has release id" + releaseId);
}
stmt.executeUpdate();
try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) {
deviceSubIds.add(rs.getInt(1));
}
}
}
return deviceSubIds;
}
} catch (DBConnectionException e) {
String msg = "Error occured while obtaining database connection to add device subscription for application "
+ "release which has release Id" + releaseId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occured when processing SQL to add device subscription for application release which"
+ " has release Id " + releaseId;
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
} }

@ -3163,7 +3163,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, tenantId); List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, deviceId, tenantId);
if (deviceSubIds.isEmpty()){ if (deviceSubIds.isEmpty()){
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Couldn't find device subscription for operation id " + operationId; String msg = "Couldn't find device subscription for operation id " + operationId;

@ -319,7 +319,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public <T> void performEntAppInstall(String applicationUUID, List<T> params, String subType) public <T> void performEntAppSubscription(String applicationUUID, List<T> params, String subType, String action)
throws ApplicationManagementException { throws ApplicationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Google Ent app Install operation is received to application which has UUID " log.debug("Google Ent app Install operation is received to application which has UUID "
@ -358,8 +358,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<Device> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();
List<String> subscribers = new ArrayList<>(); List<String> subscribers = new ArrayList<>();
List<Integer> appInstallingDeviceIds; List<Integer> appSubscribingDeviceIds;
List<Integer> appReInstallingDeviceIds = new ArrayList<>(); List<Integer> appReSubscribingDeviceIds = new ArrayList<>();
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
//todo validate users, groups and roles //todo validate users, groups and roles
@ -409,14 +409,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
appInstallingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = getDeviceSubscriptions(appInstallingDeviceIds,
applicationReleaseId);
for (Map.Entry<Integer, DeviceSubscriptionDTO> deviceSubscription: deviceSubscriptions.entrySet()){
appReInstallingDeviceIds.add(deviceSubscription.getKey());
appInstallingDeviceIds.remove(deviceSubscription.getKey());
}
/*If subscription type is not device we need to crete device identifiers object list by referring retrieved /*If subscription type is not device we need to crete device identifiers object list by referring retrieved
list of devices.*/ list of devices.*/
if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) { if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) {
@ -436,11 +428,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO(); ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
applicationPolicyDTO.setApplicationDTO(applicationDTO); applicationPolicyDTO.setApplicationDTO(applicationDTO);
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers); applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
applicationPolicyDTO.setAction(SubAction.INSTALL.toString()); applicationPolicyDTO.setAction(action);
installEnrollmentApplications(applicationPolicyDTO); installEnrollmentApplications(applicationPolicyDTO);
updateSubscriptionsForEntInstall(applicationReleaseId, appInstallingDeviceIds, appReInstallingDeviceIds, appSubscribingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
subscribers, subType); Map<Integer, DeviceSubscriptionDTO> deviceSubscriptions = getDeviceSubscriptions(appSubscribingDeviceIds,
applicationReleaseId);
for (Map.Entry<Integer, DeviceSubscriptionDTO> deviceSubscription: deviceSubscriptions.entrySet()){
appReSubscribingDeviceIds.add(deviceSubscription.getKey());
appSubscribingDeviceIds.remove(deviceSubscription.getKey());
}
updateSubscriptionsForEntInstall(applicationReleaseId, appSubscribingDeviceIds, appReSubscribingDeviceIds,
subscribers, subType, action);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while getting devices of given users or given roles."; String msg = "Error occurred while getting devices of given users or given roles.";
log.error(msg, e); log.error(msg, e);
@ -459,10 +459,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
* @param params subscribers. If subscription is performed via user, group or role, params is a list of * @param params subscribers. If subscription is performed via user, group or role, params is a list of
* {@link String} * {@link String}
* @param subType Subscription type. i.e USER, GROUP, ROLE or DEVICE * @param subType Subscription type. i.e USER, GROUP, ROLE or DEVICE
* @param action Performing action. (i.e INSTALL or UNINSTALL)
* @throws ApplicationManagementException if error occurred while getting or updating subscription data. * @throws ApplicationManagementException if error occurred while getting or updating subscription data.
*/ */
private void updateSubscriptionsForEntInstall(int applicationReleaseId, List<Integer> appInstallingDeviceIds, private void updateSubscriptionsForEntInstall(int applicationReleaseId, List<Integer> appSubscribingDeviceIds,
List<Integer> appReInstallingDeviceIds, List<String> params, String subType) List<Integer> appReSubscribingDeviceIds, List<String> params, String subType, String action)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -470,11 +471,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
List<String> subscribedEntities = new ArrayList<>(); List<String> subscribedEntities = new ArrayList<>();
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId); subscribedEntities = subscriptionDAO.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { } else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId); subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { } else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId); subscribedEntities = subscriptionDAO.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
} }
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
@ -484,17 +485,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!subscribedEntities.isEmpty()) { if (!subscribedEntities.isEmpty()) {
subscriptionDAO subscriptionDAO
.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, .updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
SubAction.INSTALL.toString()); action);
} }
if (!appInstallingDeviceIds.isEmpty()) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action) && !appSubscribingDeviceIds.isEmpty()) {
subscriptionDAO.addDeviceSubscription(username, appInstallingDeviceIds, subType, subscriptionDAO.addDeviceSubscription(username, appSubscribingDeviceIds, subType,
Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId); Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
} }
if (!appReInstallingDeviceIds.isEmpty()) { if (!appReSubscribingDeviceIds.isEmpty()) {
subscriptionDAO subscriptionDAO.updateDeviceSubscription(username, appReSubscribingDeviceIds, action, subType,
.updateDeviceSubscription(username, appReInstallingDeviceIds, SubAction.INSTALL.toString(), Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
subType, Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
} }
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
@ -578,10 +578,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet())); deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet())); deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet()));
ignoredDeviceIdentifiers deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet())); deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
deviceIdentifiers
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReUnInstallableDevices().keySet()));
ignoredDeviceIdentifiers ignoredDeviceIdentifiers
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet())); .addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
} }
@ -636,10 +637,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
*/ */
private SubscribingDeviceIdHolder getSubscribingDeviceIdHolder(List<Device> devices, int appReleaseId) private SubscribingDeviceIdHolder getSubscribingDeviceIdHolder(List<Device> devices, int appReleaseId)
throws ApplicationManagementException { throws ApplicationManagementException {
Map<DeviceIdentifier, Integer> appInstalledDevices = new HashMap<>();
Map<DeviceIdentifier, Integer> appInstallableDevices = new HashMap<>(); SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder();
Map<DeviceIdentifier, Integer> appReInstallableDevices = new HashMap<>(); subscribingDeviceIdHolder.setAppInstallableDevices(new HashMap<>());
Map<DeviceIdentifier, Integer> skippedDevices = new HashMap<>(); subscribingDeviceIdHolder.setAppInstalledDevices(new HashMap<>());
subscribingDeviceIdHolder.setAppReInstallableDevices(new HashMap<>());
subscribingDeviceIdHolder.setAppReUnInstallableDevices(new HashMap<>());
subscribingDeviceIdHolder.setSkippedDevices(new HashMap<>());
List<Integer> deviceIds = devices.stream().map(Device::getId).collect(Collectors.toList()); List<Integer> deviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
//get device subscriptions for given device id list. //get device subscriptions for given device id list.
@ -650,23 +654,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (deviceSubscriptionDTO != null) { if (deviceSubscriptionDTO != null) {
if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString() if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
.equals(deviceSubscriptionDTO.getStatus())) { .equals(deviceSubscriptionDTO.getStatus())) {
appInstalledDevices.put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppInstalledDevices().put(deviceIdentifier, device.getId());
} else if (deviceSubscriptionDTO.isUnsubscribed() && !Operation.Status.COMPLETED.toString()
.equals(deviceSubscriptionDTO.getStatus())) {
subscribingDeviceIdHolder.getAppReUnInstallableDevices().put(deviceIdentifier, device.getId());
} else if (Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus()) } else if (Operation.Status.PENDING.toString().equals(deviceSubscriptionDTO.getStatus())
|| Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) { || Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) {
skippedDevices.put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getSkippedDevices().put(deviceIdentifier, device.getId());
} else { } else {
appReInstallableDevices.put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
} }
} else { } else {
appInstallableDevices.put(deviceIdentifier, device.getId()); subscribingDeviceIdHolder.getAppInstallableDevices().put(deviceIdentifier, device.getId());
} }
} }
SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder();
subscribingDeviceIdHolder.setAppInstallableDevices(appInstallableDevices);
subscribingDeviceIdHolder.setAppInstalledDevices(appInstalledDevices);
subscribingDeviceIdHolder.setAppReInstallableDevices(appReInstallableDevices);
subscribingDeviceIdHolder.setSkippedDevices(skippedDevices);
return subscribingDeviceIdHolder; return subscribingDeviceIdHolder;
} }
@ -756,7 +757,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
List<String> subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId); List<String> subscribedEntities = subscriptionDAO
.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId); subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
@ -764,7 +766,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
action); action);
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) { } else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
List<String> subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId); List<String> subscribedEntities = subscriptionDAO
.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId); subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId);
@ -772,7 +775,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
action); action);
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) { } else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
List<String> subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId); List<String> subscribedEntities = subscriptionDAO
.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities); params.removeAll(subscribedEntities);
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId); subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId);
@ -785,11 +789,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]); int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
List<Integer> subUpdatingDeviceIds = new ArrayList<>(); List<Integer> subUpdatingDeviceIds = new ArrayList<>();
List<Integer> subInsertingDeviceIds = new ArrayList<>(); List<Integer> subInsertingDeviceIds = new ArrayList<>();
List<Integer> deviceSubIds = new ArrayList<>();
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppReInstallableDevices())); subscribingDeviceIdHolder.getAppReInstallableDevices()));
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppInstalledDevices()));
subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity, subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppInstallableDevices())); subscribingDeviceIdHolder.getAppInstallableDevices()));
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { } else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
@ -797,20 +802,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscribingDeviceIdHolder.getAppInstalledDevices())); subscribingDeviceIdHolder.getAppInstalledDevices()));
} }
List<Integer> subscribingDevices = subscriptionDAO subscriptionDAO.addDeviceSubscription(username, subInsertingDeviceIds, subType,
.addDeviceSubscription(username, subInsertingDeviceIds, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
if (!subUpdatingDeviceIds.isEmpty()) {
subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType, subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId); Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
if (!subUpdatingDeviceIds.isEmpty()) {
deviceSubIds.addAll(subscriptionDAO
.getDeviceSubIds(subUpdatingDeviceIds, applicationReleaseId, tenantId));
} }
deviceSubIds.addAll(subscribingDevices); subUpdatingDeviceIds.addAll(subInsertingDeviceIds);
if (!subUpdatingDeviceIds.isEmpty()) {
List<Integer> deviceSubIds = new ArrayList<>(
subscriptionDAO.getDeviceSubIds(subUpdatingDeviceIds, applicationReleaseId, tenantId));
subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId); subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId);
} }
}
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -1059,14 +1063,21 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId); .getDeviceSubscriptions(applicationReleaseId, tenantId);
if (deviceSubscriptionDTOS.isEmpty()) { if (deviceSubscriptionDTOS.isEmpty()) {
String msg = "Couldn't found an subscribed devices for application release id: " PaginationResult paginationResult = new PaginationResult();
+ applicationReleaseId; paginationResult.setData(new ArrayList<>());
log.info(msg); paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0);
return paginationResult;
} }
List<Integer> deviceIdList = new ArrayList<>(); List<Integer> deviceIdList = new ArrayList<>();
for (DeviceSubscriptionDTO deviceIds : deviceSubscriptionDTOS) { deviceSubscriptionDTOS.forEach(deviceSubscriptionDTO -> {
deviceIdList.add(deviceIds.getDeviceId()); if ((!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
.equalsIgnoreCase(deviceSubscriptionDTO.getStatus())) || (deviceSubscriptionDTO.isUnsubscribed()
&& !Operation.Status.COMPLETED.toString()
.equalsIgnoreCase(deviceSubscriptionDTO.getStatus()))) {
deviceIdList.add(deviceSubscriptionDTO.getDeviceId());
} }
});
if (deviceIdList.isEmpty()){ if (deviceIdList.isEmpty()){
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
@ -1109,7 +1120,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
@Override @Override
public PaginationResult getAppInstalledCategories(int offsetValue, int limitValue, String appUUID, String subType) public PaginationResult getAppInstalledSubscribers(int offsetValue, int limitValue, String appUUID, String subType)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1178,18 +1189,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId); .getDeviceSubscriptions(applicationReleaseId, tenantId);
if (deviceSubscriptionDTOS.isEmpty()) { if (deviceSubscriptionDTOS.isEmpty()) {
String msg = "Couldn't found an subscribed devices for application release id: " + applicationReleaseId;
log.info(msg);
}
List<Integer> deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId)
.collect(Collectors.toList());
if (deviceIdList.isEmpty()) {
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(deviceIdList); paginationResult.setData(new ArrayList<>());
paginationResult.setRecordsFiltered(0); paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0); paginationResult.setRecordsTotal(0);
return paginationResult; return paginationResult;
} }
List<Integer> deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId)
.collect(Collectors.toList());
try { try {
//pass the device id list to device manager service method //pass the device id list to device manager service method
PaginationResult paginationResult = deviceManagementProviderService PaginationResult paginationResult = deviceManagementProviderService

@ -954,7 +954,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
applicationArtifact.setInstallerName(installerFileName); applicationArtifact.setInstallerName(installerFileName.replaceAll("\\s", ""));
applicationArtifact.setInstallerStream(installerStream); applicationArtifact.setInstallerStream(installerStream);
} }

@ -186,7 +186,7 @@ public interface SubscriptionManagementAPI {
); );
@POST @POST
@Path("/{uuid}/devices/ent-app-install") @Path("/{uuid}/devices/ent-app-install/{action}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
@ -206,13 +206,19 @@ public interface SubscriptionManagementAPI {
value = { value = {
}) })
Response performEntAppInstallationOnDevices( Response performEntAppSubscriptionOnDevices(
@ApiParam( @ApiParam(
name = "UUID", name = "UUID",
value = "The application UUID", value = "The application UUID",
required = true required = true
) )
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@ApiParam(
name = "action",
value = "Performing action.",
required = true
)
@PathParam("action") String action,
@ApiParam( @ApiParam(
name = "installationDetails", name = "installationDetails",
value = "The list of device identifiers", value = "The list of device identifiers",
@ -227,7 +233,7 @@ public interface SubscriptionManagementAPI {
); );
@POST @POST
@Path("/{uuid}/{subType}/ent-app-install") @Path("/{uuid}/{subType}/ent-app-install/{action}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
@ -247,7 +253,7 @@ public interface SubscriptionManagementAPI {
value = { value = {
}) })
Response performBulkEntAppInstallation( Response performBulkEntAppSubscription(
@ApiParam( @ApiParam(
name = "uuid", name = "uuid",
value = "The application release UUID", value = "The application release UUID",
@ -260,6 +266,12 @@ public interface SubscriptionManagementAPI {
required = true required = true
) )
@PathParam("subType") String subType, @PathParam("subType") String subType,
@ApiParam(
name = "action",
value = "Performing action.",
required = true
)
@PathParam("action") String action,
@ApiParam( @ApiParam(
name = "subscribers", name = "subscribers",
value = "Subscriber list of the application release.", value = "Subscriber list of the application release.",

@ -92,7 +92,7 @@ public interface SubscriptionManagementAdminAPI {
tags = "Subscription Management", tags = "Subscription Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:subscription:view") @ExtensionProperty(name = SCOPE, value = "perm:admin:app:subscription:view")
}) })
} }
) )

@ -106,7 +106,6 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
} }
} }
@Override @Override
@POST @POST
@Path("/{uuid}/{subType}/{action}") @Path("/{uuid}/{subType}/{action}")
@ -151,16 +150,17 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@Override @Override
@POST @POST
@Path("/{uuid}/devices/ent-app-install") @Path("/{uuid}/devices/ent-app-install/{action}")
public Response performEntAppInstallationOnDevices( public Response performEntAppSubscriptionOnDevices(
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@PathParam("action") String action,
@Valid List<DeviceIdentifier> deviceIdentifiers, @Valid List<DeviceIdentifier> deviceIdentifiers,
@QueryParam("timestamp") String timestamp) { @QueryParam("timestamp") String timestamp) {
try { try {
if (StringUtils.isEmpty(timestamp)) { if (StringUtils.isEmpty(timestamp)) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
subscriptionManager subscriptionManager
.performEntAppInstall(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString()); .performEntAppSubscription(uuid, deviceIdentifiers, SubscriptionType.DEVICE.toString(), action);
String msg = "Application release which has UUID " + uuid + " is installed to given valid device " String msg = "Application release which has UUID " + uuid + " is installed to given valid device "
+ "identifiers."; + "identifiers.";
return Response.status(Response.Status.OK).entity(msg).build(); return Response.status(Response.Status.OK).entity(msg).build();
@ -194,16 +194,17 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@Override @Override
@POST @POST
@Path("/{uuid}/{subType}/ent-app-install") @Path("/{uuid}/{subType}/ent-app-install/{action}")
public Response performBulkEntAppInstallation( public Response performBulkEntAppSubscription(
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@PathParam("subType") String subType, @PathParam("subType") String subType,
@PathParam("action") String action,
@Valid List<String> subscribers, @Valid List<String> subscribers,
@QueryParam("timestamp") String timestamp) { @QueryParam("timestamp") String timestamp) {
try { try {
if (StringUtils.isEmpty(timestamp)) { if (StringUtils.isEmpty(timestamp)) {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
subscriptionManager.performEntAppInstall(uuid, subscribers, subType); subscriptionManager.performEntAppSubscription(uuid, subscribers, subType, action);
String msg = "Application release which has UUID " + uuid + " is installed to subscriber's valid device" String msg = "Application release which has UUID " + uuid + " is installed to subscriber's valid device"
+ " identifiers."; + " identifiers.";
return Response.status(Response.Status.OK).entity(msg).build(); return Response.status(Response.Status.OK).entity(msg).build();
@ -277,15 +278,11 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
@QueryParam("status") String status) { @QueryParam("status") String status) {
try { try {
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscribedDeviceDetails = subscriptionManager PaginationResult subscribedDeviceDetails = subscriptionManager
.getAppInstalledDevices(offset, limit, uuid, status); .getAppInstalledDevices(offset, limit, uuid, status);
DeviceList devices = new DeviceList(); DeviceList devices = new DeviceList();
devices.setList((List<Device>) subscribedDeviceDetails.getData()); devices.setList((List<Device>) subscribedDeviceDetails.getData());
devices.setCount(subscribedDeviceDetails.getRecordsTotal()); devices.setCount(subscribedDeviceDetails.getRecordsTotal());
return Response.status(Response.Status.OK).entity(devices).build(); return Response.status(Response.Status.OK).entity(devices).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found"; String msg = "Application with application release UUID: " + uuid + " is not found";
@ -324,7 +321,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager(); SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscribedCategoryDetails = subscriptionManager PaginationResult subscribedCategoryDetails = subscriptionManager
.getAppInstalledCategories(offset, limit, uuid, subType); .getAppInstalledSubscribers(offset, limit, uuid, subType);
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) { if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
BasicUserInfoList users = new BasicUserInfoList(); BasicUserInfoList users = new BasicUserInfoList();

Loading…
Cancel
Save