mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Improve app manager app installing functionality.
This commit is contained in:
parent
66db919702
commit
406b79a7e8
@ -42,22 +42,42 @@ public interface SubscriptionDAO {
|
||||
void addOperationMapping (int operationId, List<Integer> deviceSubscriptionId, int tenantId) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* Adds a mapping between user and the application which the application is installed on. This mapping will be
|
||||
* added when an enterprise installation triggered to the user.
|
||||
* Adds a mapping between user and the application which the application is subscribed on. This mapping will be
|
||||
* added when an app subscription triggered to the user.
|
||||
*
|
||||
* @param tenantId id of the tenant
|
||||
* @param subscribedBy username of the user who subscribe the application
|
||||
* @param users list of user names of the users whose devices are subscribed to the application
|
||||
* @param releaseId id of the {@link ApplicationReleaseDTO}
|
||||
* @throws ApplicationManagementDAOException If unable to add a mapping between device and application
|
||||
* @throws ApplicationManagementDAOException If unable to add a mapping between user and application
|
||||
*/
|
||||
void addUserSubscriptions(int tenantId, String subscribedBy, List<String> users, int releaseId)
|
||||
void addUserSubscriptions(int tenantId, String subscribedBy, List<String> users, int releaseId, String action)
|
||||
throws ApplicationManagementDAOException;
|
||||
|
||||
void addRoleSubscriptions(int tenantId, String subscribedBy, List<String> roles, int releaseId)
|
||||
/**
|
||||
* Adds a mapping between role and the application which the application is subscribed on. This mapping will be
|
||||
* added when an app subscription triggered to the role.
|
||||
*
|
||||
* @param tenantId id of the tenant
|
||||
* @param subscribedBy username of the user who subscribe the application
|
||||
* @param roles list of role names of the roles whose devices are subscribed to the application
|
||||
* @param releaseId id of the {@link ApplicationReleaseDTO}
|
||||
* @throws ApplicationManagementDAOException If unable to add a mapping between role and application
|
||||
*/
|
||||
void addRoleSubscriptions(int tenantId, String subscribedBy, List<String> roles, int releaseId, String action)
|
||||
throws ApplicationManagementDAOException;
|
||||
|
||||
void addGroupSubscriptions(int tenantId, String subscribedBy, List<String> groups, int releaseId)
|
||||
/**
|
||||
* Adds a mapping between group and the application which the application is subscribed on. This mapping will be
|
||||
* added when an app subscription triggered to the user.
|
||||
*
|
||||
* @param tenantId id of the tenant
|
||||
* @param subscribedBy username of the user who subscribe the application
|
||||
* @param groups list of group names of the groups whose devices are subscribed to the application
|
||||
* @param releaseId id of the {@link ApplicationReleaseDTO}
|
||||
* @throws ApplicationManagementDAOException If unable to add a mapping between group and application
|
||||
*/
|
||||
void addGroupSubscriptions(int tenantId, String subscribedBy, List<String> groups, int releaseId, String action)
|
||||
throws ApplicationManagementDAOException;
|
||||
|
||||
List<DeviceSubscriptionDTO> getDeviceSubscriptions(int appReleaseId, int tenantId) throws
|
||||
|
||||
@ -188,27 +188,32 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUserSubscriptions(int tenantId, String subscribedBy, List<String> users, int releaseId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "INSERT INTO "
|
||||
+ "AP_USER_SUBSCRIPTION("
|
||||
+ "TENANT_ID, "
|
||||
+ "SUBSCRIBED_BY, "
|
||||
+ "SUBSCRIBED_TIMESTAMP, "
|
||||
+ "USER_NAME, "
|
||||
+ "AP_APP_RELEASE_ID) "
|
||||
+ "VALUES (?, ?, ?, ?, ?)";
|
||||
public void addUserSubscriptions(int tenantId, String subscribedBy, List<String> users, int releaseId,
|
||||
String action) throws ApplicationManagementDAOException {
|
||||
try {
|
||||
boolean isUnsubscribed = false;
|
||||
String sql = "INSERT INTO AP_USER_SUBSCRIPTION(TENANT_ID, ";
|
||||
|
||||
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
|
||||
sql += "UNSUBSCRIBED, UNSUBSCRIBED_BY, UNSUBSCRIBED_TIMESTAMP, ";
|
||||
isUnsubscribed = true;
|
||||
} else {
|
||||
sql += "UNSUBSCRIBED, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, ";
|
||||
}
|
||||
|
||||
sql += "USER_NAME, AP_APP_RELEASE_ID) VALUES (?, ?, ?, ?, ?,?)";
|
||||
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
||||
for (String user : users) {
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, subscribedBy);
|
||||
stmt.setTimestamp(3, timestamp);
|
||||
stmt.setString(4, user);
|
||||
stmt.setInt(5, releaseId);
|
||||
stmt.setBoolean(2, isUnsubscribed);
|
||||
stmt.setString(3, subscribedBy);
|
||||
stmt.setTimestamp(4, timestamp);
|
||||
stmt.setString(5, user);
|
||||
stmt.setInt(6, releaseId);
|
||||
stmt.addBatch();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding an user subscription for user " + user + " and application release which "
|
||||
@ -224,34 +229,39 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to add user subscription. Subscribing user is "
|
||||
+ subscribedBy + " and executed query: " + sql;
|
||||
+ subscribedBy;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoleSubscriptions(int tenantId, String subscribedBy, List<String> roles, int releaseId)
|
||||
public void addRoleSubscriptions(int tenantId, String subscribedBy, List<String> roles, int releaseId, String action)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "INSERT INTO "
|
||||
+ "AP_ROLE_SUBSCRIPTION("
|
||||
+ "TENANT_ID, "
|
||||
+ "SUBSCRIBED_BY, "
|
||||
+ "SUBSCRIBED_TIMESTAMP, "
|
||||
+ "ROLE_NAME, "
|
||||
+ "AP_APP_RELEASE_ID) "
|
||||
+ "VALUES (?, ?, ?, ?, ?)";
|
||||
try {
|
||||
boolean isUnsubscribed = false;
|
||||
String sql = "INSERT INTO AP_ROLE_SUBSCRIPTION(TENANT_ID, ";
|
||||
|
||||
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
|
||||
sql += "UNSUBSCRIBED, UNSUBSCRIBED_BY, UNSUBSCRIBED_TIMESTAMP, ";
|
||||
isUnsubscribed = true;
|
||||
} else {
|
||||
sql += "UNSUBSCRIBED, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, ";
|
||||
}
|
||||
|
||||
sql += "ROLE_NAME, AP_APP_RELEASE_ID) VALUES (?, ?, ?, ?, ?,?)";
|
||||
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
||||
for (String role : roles) {
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, subscribedBy);
|
||||
stmt.setTimestamp(3, timestamp);
|
||||
stmt.setString(4, role);
|
||||
stmt.setInt(5, releaseId);
|
||||
stmt.setBoolean(2, isUnsubscribed);
|
||||
stmt.setString(3, subscribedBy);
|
||||
stmt.setTimestamp(4, timestamp);
|
||||
stmt.setString(5, role);
|
||||
stmt.setInt(6, releaseId);
|
||||
stmt.addBatch();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding a role subscription for role " + role + " and application release which "
|
||||
@ -267,34 +277,39 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to add role subscription. Subscribing role is "
|
||||
+ subscribedBy + " and executed query: " + sql;
|
||||
+ subscribedBy;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroupSubscriptions(int tenantId, String subscribedBy, List<String> groups, int releaseId)
|
||||
throws ApplicationManagementDAOException {
|
||||
String sql = "INSERT INTO "
|
||||
+ "AP_GROUP_SUBSCRIPTION("
|
||||
+ "TENANT_ID, "
|
||||
+ "SUBSCRIBED_BY, "
|
||||
+ "SUBSCRIBED_TIMESTAMP, "
|
||||
+ "GROUP_NAME, "
|
||||
+ "AP_APP_RELEASE_ID) "
|
||||
+ "VALUES (?, ?, ?, ?, ?)";
|
||||
public void addGroupSubscriptions(int tenantId, String subscribedBy, List<String> groups, int releaseId,
|
||||
String action) throws ApplicationManagementDAOException {
|
||||
try {
|
||||
boolean isUnsubscribed = false;
|
||||
String sql = "INSERT INTO AP_GROUP_SUBSCRIPTION(TENANT_ID, ";
|
||||
|
||||
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
|
||||
sql += "UNSUBSCRIBED, UNSUBSCRIBED_BY, UNSUBSCRIBED_TIMESTAMP, ";
|
||||
isUnsubscribed = true;
|
||||
} else {
|
||||
sql += "UNSUBSCRIBED, SUBSCRIBED_BY, SUBSCRIBED_TIMESTAMP, ";
|
||||
}
|
||||
|
||||
sql += "GROUP_NAME, AP_APP_RELEASE_ID) VALUES (?, ?, ?, ?, ?,?)";
|
||||
|
||||
Connection conn = this.getDBConnection();
|
||||
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
||||
for (String group : groups) {
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, subscribedBy);
|
||||
stmt.setTimestamp(3, timestamp);
|
||||
stmt.setString(4, group);
|
||||
stmt.setInt(5, releaseId);
|
||||
stmt.setBoolean(2, isUnsubscribed);
|
||||
stmt.setString(3, subscribedBy);
|
||||
stmt.setTimestamp(4, timestamp);
|
||||
stmt.setString(5, group);
|
||||
stmt.setInt(6, releaseId);
|
||||
stmt.addBatch();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding a group subscription for role " + group + " and application release which "
|
||||
@ -310,7 +325,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while executing query to add group subscription. Subscribing group is "
|
||||
+ subscribedBy + " and executed query: " + sql;
|
||||
+ subscribedBy;
|
||||
log.error(msg, e);
|
||||
throw new ApplicationManagementDAOException(msg, e);
|
||||
}
|
||||
|
||||
@ -471,24 +471,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
List<String> subscribedEntities = new ArrayList<>();
|
||||
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
|
||||
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
|
||||
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
|
||||
}
|
||||
|
||||
params.removeAll(subscribedEntities);
|
||||
if (!params.isEmpty()) {
|
||||
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
|
||||
}
|
||||
if (!subscribedEntities.isEmpty()) {
|
||||
subscriptionDAO
|
||||
.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
||||
action);
|
||||
}
|
||||
updateBulkSubscribers(applicationReleaseId, params, subType, action, tenantId, username);
|
||||
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action) && !appSubscribingDeviceIds.isEmpty()) {
|
||||
subscriptionDAO.addDeviceSubscription(username, appSubscribingDeviceIds, subType,
|
||||
@ -760,35 +743,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
|
||||
List<String> subscribedEntities = subscriptionDAO
|
||||
.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
||||
params.removeAll(subscribedEntities);
|
||||
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
|
||||
}
|
||||
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
||||
action);
|
||||
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
|
||||
List<String> subscribedEntities = subscriptionDAO
|
||||
.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
||||
params.removeAll(subscribedEntities);
|
||||
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId);
|
||||
}
|
||||
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
||||
action);
|
||||
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
|
||||
List<String> subscribedEntities = subscriptionDAO
|
||||
.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
|
||||
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
|
||||
params.removeAll(subscribedEntities);
|
||||
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId);
|
||||
}
|
||||
subscriptionDAO.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType,
|
||||
action);
|
||||
}
|
||||
|
||||
updateBulkSubscribers(applicationReleaseId, params, subType, action, tenantId, username);
|
||||
for (Activity activity : activities) {
|
||||
int operationId = Integer.parseInt(activity.getActivityId().split("ACTIVITY_")[1]);
|
||||
List<Integer> subUpdatingDeviceIds = new ArrayList<>();
|
||||
@ -840,6 +795,48 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is responsible to update bulk subscriber's data. i.e USER, ROLE, GROUP. Before invoke this method it
|
||||
* is required to start DB transaction
|
||||
*
|
||||
* @param applicationReleaseId Application release Id
|
||||
* @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. ie INSTALL or UNINSTALL>
|
||||
* @param tenantId Tenant Id
|
||||
* @param username Username
|
||||
* @throws ApplicationManagementDAOException if error occurred while updating or inserting subscriber entities
|
||||
*/
|
||||
private void updateBulkSubscribers(int applicationReleaseId, List<String> params, String subType, String action,
|
||||
int tenantId, String username) throws ApplicationManagementDAOException {
|
||||
List<String> subscribedEntities = new ArrayList<>();
|
||||
if (SubscriptionType.USER.toString().equalsIgnoreCase(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getAppSubscribedUserNames(params, applicationReleaseId, tenantId);
|
||||
params.removeAll(subscribedEntities);
|
||||
if (!params.isEmpty()) {
|
||||
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId, action);
|
||||
}
|
||||
} else if (SubscriptionType.ROLE.toString().equalsIgnoreCase(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getAppSubscribedRoleNames(params, applicationReleaseId, tenantId);
|
||||
params.removeAll(subscribedEntities);
|
||||
if (!params.isEmpty()) {
|
||||
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId, action);
|
||||
}
|
||||
} else if (SubscriptionType.GROUP.toString().equalsIgnoreCase(subType)) {
|
||||
subscribedEntities = subscriptionDAO.getAppSubscribedGroupNames(params, applicationReleaseId, tenantId);
|
||||
params.removeAll(subscribedEntities);
|
||||
if (!params.isEmpty()) {
|
||||
subscriptionDAO.addGroupSubscriptions(tenantId, username, params, applicationReleaseId, action);
|
||||
}
|
||||
}
|
||||
|
||||
if (!subscribedEntities.isEmpty()) {
|
||||
subscriptionDAO
|
||||
.updateSubscriptions(tenantId, username, subscribedEntities, applicationReleaseId, subType, action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is responsible to get device IDs thta operation has added.
|
||||
*
|
||||
|
||||
@ -423,13 +423,13 @@ public class APIUtil {
|
||||
}
|
||||
|
||||
public static String getArtifactDownloadBaseURL() throws ApplicationManagementException {
|
||||
String host = System.getProperty(Constants.IOT_HOST_PROPERTY);
|
||||
String host = System.getProperty(Constants.IOT_CORE_HOST);
|
||||
MDMConfig mdmConfig = ConfigurationManager.getInstance().getConfiguration().getMdmConfig();
|
||||
String port;
|
||||
if (Constants.HTTP_PROTOCOL.equals(mdmConfig.getArtifactDownloadProtocol())){
|
||||
port = System.getProperty(Constants.IOT_HTTP_PORT_PROPERTY);
|
||||
port = System.getProperty(Constants.IOT_CORE_HTTP_PORT);
|
||||
} else if( Constants.HTTPS_PROTOCOL.equals(mdmConfig.getArtifactDownloadProtocol())){
|
||||
port = System.getProperty(Constants.IOT_HTTPS_PORT_PROPERTY);
|
||||
port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT);
|
||||
} else {
|
||||
String msg = "In order to download application artifacts invalid protocols are defined.";
|
||||
log.error(msg);
|
||||
|
||||
@ -36,9 +36,9 @@ public class Constants {
|
||||
public static final String PLIST_NAME = "Info.plist";
|
||||
public static final String CF_BUNDLE_VERSION = "CFBundleVersion";
|
||||
public static final String APP_EXTENSION = ".app";
|
||||
public static final String IOT_HOST_PROPERTY = "iot.core.host";
|
||||
public static final String IOT_HTTP_PORT_PROPERTY = "iot.core.http.port";
|
||||
public static final String IOT_HTTPS_PORT_PROPERTY = "iot.core.https.port";
|
||||
public static final String IOT_CORE_HOST = "iot.core.host";
|
||||
public static final String IOT_CORE_HTTP_PORT = "iot.core.http.port";
|
||||
public static final String IOT_CORE_HTTPS_PORT = "iot.core.https.port";
|
||||
public static final String HTTPS_PROTOCOL = "https";
|
||||
public static final String HTTP_PROTOCOL = "http";
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS AP_APP(
|
||||
ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
NAME VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(350) NOT NULL,
|
||||
DESCRIPTION CLOB NULL,
|
||||
TYPE VARCHAR(200) NOT NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE AP_APP(
|
||||
ID INTEGER NOT NULL IDENTITY,
|
||||
NAME VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(350) NOT NULL,
|
||||
DESCRIPTION VARCHAR(max) NULL,
|
||||
TYPE VARCHAR(200) NOT NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS AP_APP(
|
||||
ID INTEGER NOT NULL AUTO_INCREMENT,
|
||||
NAME VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(350) NOT NULL,
|
||||
DESCRIPTION VARCHAR(200) NOT NULL,
|
||||
TYPE VARCHAR(200) NOT NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user