Fix issues in APPM subscription flow

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

@ -85,19 +85,19 @@ public interface SubscriptionManager {
/**
* Perform google enterprise app install
* @param applicationUUID UUID of the application to subscribe/unsubscribe
* @param applicationUUID UUID of the application to subscribe/unsubscribe
* @param params list of subscribers. This list can be of either
* {@link org.wso2.carbon.device.mgt.common.DeviceIdentifier} if {@param subType} is equal
* to DEVICE or {@link String} if {@param subType} is USER, ROLE or GROUP
* @param subType subscription type. E.g. <code>DEVICE, USER, ROLE, GROUP</code> {@see {
* @param action subscription action. E.g. <code>INSTALL/UNINSTALL</code> {@see {
* @param <T> generic type of the method.
* @return {@link ApplicationInstallResponse}
* @throws ApplicationManagementException ApplicationManagementException if error occurs when subscribing to the
* given application
* @link org.wso2.carbon.device.application.mgt.common.SubscriptionType}}
* @param action subscription action. E.g. <code>INSTALL/UNINSTALL</code> {@see {
* @param <T> generic type of the method.
* @return {@link ApplicationInstallResponse}
* @throws ApplicationManagementException ApplicationManagementException if error occurs when subscribing to the
* given application
* @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;
/***
@ -123,7 +123,7 @@ public interface SubscriptionManager {
* @return {@link PaginationResult} pagination result of the category details.
* @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;
/**

@ -33,7 +33,7 @@ import java.util.Map;
*/
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;
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)
throws ApplicationManagementDAOException;
List<String> getSubscribedUserNames(List<String> users, int tenantId) throws
List<String> getAppSubscribedUserNames(List<String> users, int appReleaseId, int tenantId) throws
ApplicationManagementDAOException;
List<String> getSubscribedRoleNames(List<String> roles, int tenantId) throws
List<String> getAppSubscribedRoleNames(List<String> roles, int appReleaseId, int tenantId) throws
ApplicationManagementDAOException;
List<String> getSubscribedGroupNames(List<String> groups, int tenantId) throws
List<String> getAppSubscribedGroupNames(List<String> groups, int appReleaseId, int tenantId) throws
ApplicationManagementDAOException;
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)
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)
throws ApplicationManagementDAOException;

@ -49,7 +49,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
private static Log log = LogFactory.getLog(GenericSubscriptionDAOImpl.class);
@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)
throws ApplicationManagementDAOException {
String sql = "INSERT INTO "
@ -82,13 +82,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
}
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) {
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> getSubscribedUserNames(List<String> users, int tenantId)
public List<String> getAppSubscribedUserNames(List<String> users, int appReleaseId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
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(",",
"SELECT US.USER_NAME AS USER_NAME "
+ "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);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
for (String username : users) {
ps.setObject(index++, username);
}
ps.setInt(index++, appReleaseId);
ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
@ -465,8 +458,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
}
@Override
public List<String> getSubscribedRoleNames(List<String> roles, int tenantId)
public List<String> getAppSubscribedRoleNames(List<String> roles, int appReleaseId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
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(",",
"SELECT RS.ROLE_NAME AS ROLE "
+ "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);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
for (String roleName : roles) {
ps.setObject(index++, roleName);
}
ps.setInt(index++, appReleaseId);
ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
@ -506,7 +499,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public List<String> getSubscribedGroupNames(List<String> groups, int tenantId)
public List<String> getAppSubscribedGroupNames(List<String> groups, int appReleaseId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
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(",",
"SELECT GS.GROUP_NAME AS GROUP_NAME "
+ "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);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
for (String groupName : groups) {
ps.setObject(index++, groupName);
}
ps.setInt(index++, appReleaseId);
ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
@ -647,20 +641,22 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public List<Integer> getDeviceSubIdsForOperation(int operationId, int tenantId)
public List<Integer> getDeviceSubIdsForOperation(int operationId, int deviceId, int tenantId)
throws ApplicationManagementDAOException {
try {
Connection conn = this.getDBConnection();
List<Integer> deviceSubIds = new ArrayList<>();
String sql = "SELECT "
+ "AP_DEVICE_SUBSCRIPTION_ID "
+ "FROM AP_APP_SUB_OP_MAPPING "
+ "WHERE "
+ "OPERATION_ID = ? AND "
+ "TENANT_ID = ?";
String sql = "SELECT AP_APP_SUB_OP_MAPPING.AP_DEVICE_SUBSCRIPTION_ID "
+ "FROM "
+ "AP_APP_SUB_OP_MAPPING INNER JOIN AP_DEVICE_SUBSCRIPTION "
+ "ON AP_APP_SUB_OP_MAPPING.AP_DEVICE_SUBSCRIPTION_ID = AP_DEVICE_SUBSCRIPTION.ID "
+ "WHERE AP_APP_SUB_OP_MAPPING.OPERATION_ID = ? AND "
+ "AP_DEVICE_SUBSCRIPTION.DM_DEVICE_ID = ? AND "
+ "AP_APP_SUB_OP_MAPPING.TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, operationId);
stmt.setInt(2, tenantId);
stmt.setInt(2, deviceId);
stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
deviceSubIds.add(rs.getInt("AP_DEVICE_SUBSCRIPTION_ID"));

@ -159,58 +159,4 @@ public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl {
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();
try {
ConnectionManagerUtil.beginDBTransaction();
List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, tenantId);
List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, deviceId, tenantId);
if (deviceSubIds.isEmpty()){
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Couldn't find device subscription for operation id " + operationId;

@ -319,7 +319,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@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 {
if (log.isDebugEnabled()) {
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<String> subscribers = new ArrayList<>();
List<Integer> appInstallingDeviceIds;
List<Integer> appReInstallingDeviceIds = new ArrayList<>();
List<Integer> appSubscribingDeviceIds;
List<Integer> appReSubscribingDeviceIds = new ArrayList<>();
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
//todo validate users, groups and roles
@ -409,14 +409,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
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
list of devices.*/
if (!SubscriptionType.DEVICE.toString().equalsIgnoreCase(subType)) {
@ -436,11 +428,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
applicationPolicyDTO.setApplicationDTO(applicationDTO);
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
applicationPolicyDTO.setAction(SubAction.INSTALL.toString());
applicationPolicyDTO.setAction(action);
installEnrollmentApplications(applicationPolicyDTO);
updateSubscriptionsForEntInstall(applicationReleaseId, appInstallingDeviceIds, appReInstallingDeviceIds,
subscribers, subType);
appSubscribingDeviceIds = devices.stream().map(Device::getId).collect(Collectors.toList());
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) {
String msg = "Error occurred while getting devices of given users or given roles.";
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
* {@link String}
* @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.
*/
private void updateSubscriptionsForEntInstall(int applicationReleaseId, List<Integer> appInstallingDeviceIds,
List<Integer> appReInstallingDeviceIds, List<String> params, String subType)
private void updateSubscriptionsForEntInstall(int applicationReleaseId, List<Integer> appSubscribingDeviceIds,
List<Integer> appReSubscribingDeviceIds, List<String> params, String subType, String action)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -470,11 +471,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ConnectionManagerUtil.beginDBTransaction();
List<String> subscribedEntities = new ArrayList<>();
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId);
subscribedEntities = subscriptionDAO.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
} 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)) {
subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId);
subscribedEntities = subscriptionDAO.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
}
params.removeAll(subscribedEntities);
@ -484,17 +485,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!subscribedEntities.isEmpty()) {
subscriptionDAO
.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
SubAction.INSTALL.toString());
action);
}
if (!appInstallingDeviceIds.isEmpty()) {
subscriptionDAO.addDeviceSubscription(username, appInstallingDeviceIds, subType,
if (SubAction.INSTALL.toString().equalsIgnoreCase(action) && !appSubscribingDeviceIds.isEmpty()) {
subscriptionDAO.addDeviceSubscription(username, appSubscribingDeviceIds, subType,
Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
}
if (!appReInstallingDeviceIds.isEmpty()) {
subscriptionDAO
.updateDeviceSubscription(username, appReInstallingDeviceIds, SubAction.INSTALL.toString(),
subType, Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
if (!appReSubscribingDeviceIds.isEmpty()) {
subscriptionDAO.updateDeviceSubscription(username, appReSubscribingDeviceIds, action, subType,
Operation.Status.COMPLETED.toString(), applicationReleaseId, tenantId);
}
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
@ -578,10 +578,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet()));
ignoredDeviceIdentifiers
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstalledDevices().keySet()));
deviceIdentifiers
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReUnInstallableDevices().keySet()));
ignoredDeviceIdentifiers
.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
}
@ -636,10 +637,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
*/
private SubscribingDeviceIdHolder getSubscribingDeviceIdHolder(List<Device> devices, int appReleaseId)
throws ApplicationManagementException {
Map<DeviceIdentifier, Integer> appInstalledDevices = new HashMap<>();
Map<DeviceIdentifier, Integer> appInstallableDevices = new HashMap<>();
Map<DeviceIdentifier, Integer> appReInstallableDevices = new HashMap<>();
Map<DeviceIdentifier, Integer> skippedDevices = new HashMap<>();
SubscribingDeviceIdHolder subscribingDeviceIdHolder = new SubscribingDeviceIdHolder();
subscribingDeviceIdHolder.setAppInstallableDevices(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());
//get device subscriptions for given device id list.
@ -650,23 +654,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (deviceSubscriptionDTO != null) {
if (!deviceSubscriptionDTO.isUnsubscribed() && Operation.Status.COMPLETED.toString()
.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())
|| Operation.Status.IN_PROGRESS.toString().equals(deviceSubscriptionDTO.getStatus())) {
skippedDevices.put(deviceIdentifier, device.getId());
subscribingDeviceIdHolder.getSkippedDevices().put(deviceIdentifier, device.getId());
} else {
appReInstallableDevices.put(deviceIdentifier, device.getId());
subscribingDeviceIdHolder.getAppReInstallableDevices().put(deviceIdentifier, device.getId());
}
} 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;
}
@ -756,7 +757,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
try {
ConnectionManagerUtil.beginDBTransaction();
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)) {
params.removeAll(subscribedEntities);
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
@ -764,7 +766,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
action);
} 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)) {
params.removeAll(subscribedEntities);
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId);
@ -772,7 +775,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
action);
} 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)) {
params.removeAll(subscribedEntities);
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId);
@ -785,11 +789,12 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
List<Integer> subUpdatingDeviceIds = new ArrayList<>();
List<Integer> subInsertingDeviceIds = new ArrayList<>();
List<Integer> deviceSubIds = new ArrayList<>();
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppReInstallableDevices()));
subUpdatingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppInstalledDevices()));
subInsertingDeviceIds.addAll(getOperationAddedDeviceIds(activity,
subscribingDeviceIdHolder.getAppInstallableDevices()));
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
@ -797,19 +802,18 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscribingDeviceIdHolder.getAppInstalledDevices()));
}
List<Integer> subscribingDevices = subscriptionDAO
.addDeviceSubscription(username, subInsertingDeviceIds, subType,
subscriptionDAO.addDeviceSubscription(username, subInsertingDeviceIds, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
if (!subUpdatingDeviceIds.isEmpty()) {
deviceSubIds.addAll(subscriptionDAO
.getDeviceSubIds(subUpdatingDeviceIds, applicationReleaseId, tenantId));
subscriptionDAO.updateDeviceSubscription(username, subUpdatingDeviceIds, action, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
}
subUpdatingDeviceIds.addAll(subInsertingDeviceIds);
if (!subUpdatingDeviceIds.isEmpty()) {
List<Integer> deviceSubIds = new ArrayList<>(
subscriptionDAO.getDeviceSubIds(subUpdatingDeviceIds, applicationReleaseId, tenantId));
subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId);
}
deviceSubIds.addAll(subscribingDevices);
subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId);
}
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
@ -1059,14 +1063,21 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId);
if (deviceSubscriptionDTOS.isEmpty()) {
String msg = "Couldn't found an subscribed devices for application release id: "
+ applicationReleaseId;
log.info(msg);
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(new ArrayList<>());
paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0);
return paginationResult;
}
List<Integer> deviceIdList = new ArrayList<>();
for (DeviceSubscriptionDTO deviceIds : deviceSubscriptionDTOS) {
deviceIdList.add(deviceIds.getDeviceId());
}
deviceSubscriptionDTOS.forEach(deviceSubscriptionDTO -> {
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()){
PaginationResult paginationResult = new PaginationResult();
@ -1109,7 +1120,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@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 {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1178,18 +1189,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO
.getDeviceSubscriptions(applicationReleaseId, tenantId);
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.setData(deviceIdList);
paginationResult.setData(new ArrayList<>());
paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0);
return paginationResult;
}
List<Integer> deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId)
.collect(Collectors.toList());
try {
//pass the device id list to device manager service method
PaginationResult paginationResult = deviceManagementProviderService

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

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

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

Loading…
Cancel
Save