Adding some fixes for the application management and visibility management.

feature/appm-store/pbac
sinthuja 7 years ago
parent 887675fda2
commit 2d4de10c6c

@ -37,7 +37,7 @@ public interface ApplicationManager {
* @return Created application * @return Created application
* @throws ApplicationManagementException Application Management Exception * @throws ApplicationManagementException Application Management Exception
*/ */
public Application createApplication(Application application) throws ApplicationManagementException; Application createApplication(Application application) throws ApplicationManagementException;
/** /**
* Updates an already existing application. * Updates an already existing application.
@ -45,14 +45,14 @@ public interface ApplicationManager {
* @return Updated Application * @return Updated Application
* @throws ApplicationManagementException Application Management Exception * @throws ApplicationManagementException Application Management Exception
*/ */
public Application editApplication(Application application) throws ApplicationManagementException; Application editApplication(Application application) throws ApplicationManagementException;
/** /**
* Delete an application identified by the unique ID. * Delete an application identified by the unique ID.
* @param uuid Unique ID for tha application * @param uuid Unique ID for tha application
* @throws ApplicationManagementException Application Management Exception * @throws ApplicationManagementException Application Management Exception
*/ */
public void deleteApplication(String uuid) throws ApplicationManagementException; void deleteApplication(String uuid) throws ApplicationManagementException;
/** /**
* To get the applications based on the search filter. * To get the applications based on the search filter.
@ -60,7 +60,7 @@ public interface ApplicationManager {
* @return Applications that matches the given filter criteria. * @return Applications that matches the given filter criteria.
* @throws ApplicationManagementException Application Management Exception * @throws ApplicationManagementException Application Management Exception
*/ */
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException; ApplicationList getApplications(Filter filter) throws ApplicationManagementException;
/** /**
* To change the lifecycle of the Application. * To change the lifecycle of the Application.
@ -69,7 +69,7 @@ public interface ApplicationManager {
* @param lifecycleIdentifier New life-cycle that need to be changed. * @param lifecycleIdentifier New life-cycle that need to be changed.
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
public void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws
ApplicationManagementException; ApplicationManagementException;
/** /**
@ -79,7 +79,7 @@ public interface ApplicationManager {
* @return the List of possible states * @return the List of possible states
* @throws ApplicationManagementException Application Management Exception * @throws ApplicationManagementException Application Management Exception
*/ */
public List<LifecycleStateTransition> getLifeCycleStates(String applicationUUID) List<LifecycleStateTransition> getLifeCycleStates(String applicationUUID)
throws ApplicationManagementException; throws ApplicationManagementException;
/** /**
@ -89,7 +89,5 @@ public interface ApplicationManager {
* @return the Application identified by the UUID * @return the Application identified by the UUID
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
public Application getApplication(String uuid) throws ApplicationManagementException; Application getApplication(String uuid) throws ApplicationManagementException;
} }

@ -35,23 +35,23 @@ public interface VisibilityManager {
* Update (if there is already existing configuration for the application) * Update (if there is already existing configuration for the application)
* the visibility related configuration for the application * the visibility related configuration for the application
* *
* @param applicationUUID The ID of the application * @param applicationID The ID of the application
* @param visibility The visibility configuration for the particular application. * @param visibility The visibility configuration for the particular application.
*/ */
void put(String applicationUUID, Visibility visibility) throws VisibilityManagementException; Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException;
/** /**
* Returns the Visibility configuration of the provided applicationUUID. * Returns the Visibility configuration of the provided applicationUUID.
* *
* @param applicationUUID The ID of the application * @param applicationID The ID of the application
* @return Visibility configuration * @return Visibility configuration
*/ */
Visibility get(String applicationUUID) throws VisibilityManagementException; Visibility get(int applicationID) throws VisibilityManagementException;
/** /**
* Remove the visibility configuration mapping for the provided application. * Remove the visibility configuration mapping for the provided application.
* *
* @param applicationUUID The ID of the application * @param applicationID The ID of the application
*/ */
void remove(String applicationUUID) throws VisibilityManagementException; void remove(int applicationID) throws VisibilityManagementException;
} }

@ -71,7 +71,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "VIDEO_NAME, SCREEN_SHOT_COUNT, CREATED_BY, CREATED_AT, MODIFIED_AT, " + "VIDEO_NAME, SCREEN_SHOT_COUNT, CREATED_BY, CREATED_AT, MODIFIED_AT, "
+ "APPLICATION_CATEGORY_ID, PLATFORM_ID, TENANT_ID, LIFECYCLE_STATE_ID, " + "APPLICATION_CATEGORY_ID, PLATFORM_ID, TENANT_ID, LIFECYCLE_STATE_ID, "
+ "LIFECYCLE_STATE_MODIFIED_AT, LIFECYCLE_STATE_MODIFIED_BY) VALUES " + "LIFECYCLE_STATE_MODIFIED_AT, LIFECYCLE_STATE_MODIFIED_BY) VALUES "
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(++index, application.getUuid()); stmt.setString(++index, application.getUuid());
@ -132,7 +132,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT APP.*, APL.NAME AS APL_NAME, " sql += "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER,"
+ "CAT.ID AS CAT_ID, CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, " + "CAT.ID AS CAT_ID, CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, "
+ "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS " + "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS "
+ "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON " + "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON "
@ -265,7 +265,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT APP.*, APL.NAME AS APL_NAME, " sql += "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER,"
+ "CAT.ID AS CAT_ID, CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, " + "CAT.ID AS CAT_ID, CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, "
+ "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS " + "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS "
+ "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON " + "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON "

@ -51,11 +51,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
} }
return -1; return -1;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " +
"for the visibility management of applicatons"); "for the visibility management of applications", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occured when trying to get the ID of the" + throw new VisibilityManagementDAOException("Error occurred when trying to get the ID of the" +
" visibility type - " + visibilityType.toString()); " visibility type - " + visibilityType.toString(), e);
} finally { } finally {
Util.cleanupResources(stmt, resultSet); Util.cleanupResources(stmt, resultSet);
} }
@ -67,7 +67,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = getDBConnection(); Connection connection = getDBConnection();
String sql = "INSERT INTO APPM_VISIBILITY (?, ?, ?)"; String sql = "INSERT INTO APPM_VISIBILITY (VALUE, RESOURCE_TYPE_ID, APPLICATION_ID) VALUES (?, ?, ?)";
stmt = connection.prepareStatement(sql); stmt = connection.prepareStatement(sql);
if (allowedList == null) { if (allowedList == null) {
stmt.setString(1, null); stmt.setString(1, null);
@ -84,11 +84,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
stmt.executeBatch(); stmt.executeBatch();
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " +
"for adding the visibility mapping for the application ID - " + applicationID); "for adding the visibility mapping for the application ID - " + applicationID, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occured while adding the visibility mapping " + throw new VisibilityManagementDAOException("Error occurred while adding the visibility mapping " +
"for the application ID - " + applicationID); "for the application ID - " + applicationID, e);
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
} }
@ -104,11 +104,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
stmt.setInt(1, applicationId); stmt.setInt(1, applicationId);
stmt.execute(); stmt.execute();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " +
"for deleting the visibility mapping for the application ID - " + applicationId); "for deleting the visibility mapping for the application ID - " + applicationId, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occured while deleting the visibility mapping " + throw new VisibilityManagementDAOException("Error occurred while deleting the visibility mapping " +
"for the application ID - " + applicationId); "for the application ID - " + applicationId, e);
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
} }
@ -144,11 +144,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
} }
return visibility; return visibility;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " +
"for getting the visibility mapping for the application ID - " + applicationId); "for getting the visibility mapping for the application ID - " + applicationId, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occured while getting the visibility mapping " + throw new VisibilityManagementDAOException("Error occurred while getting the visibility mapping " +
"for the application ID - " + applicationId); "for the application ID - " + applicationId, e);
} finally { } finally {
Util.cleanupResources(stmt, resultSet); Util.cleanupResources(stmt, resultSet);
} }

@ -22,19 +22,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.*;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.Lifecycle;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.common.Platform;
import org.wso2.carbon.device.application.mgt.common.User;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
@ -71,14 +63,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
application.setCreatedAt(new Date()); application.setCreatedAt(new Date());
application.setModifiedAt(new Date()); application.setModifiedAt(new Date());
try { try {
ConnectionManagerUtil.beginDBTransaction(); Platform platform = DataHolder.getInstance().getPlatformManager().getPlatform(application.getUser()
.getTenantId(), application.getPlatform().getIdentifier());
// Validating the platform
Platform platform = DataHolder.getInstance().getPlatformManager()
.getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier());
if (platform == null) { if (platform == null) {
throw new NotFoundException("Invalid platform"); throw new NotFoundException("Invalid platform");
} }
ConnectionManagerUtil.beginDBTransaction();
// Validating the platform
application.setPlatform(platform); application.setPlatform(platform);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Application creation pre-conditions are met and the platform mentioned by identifier " log.debug("Application creation pre-conditions are met and the platform mentioned by identifier "
@ -97,6 +90,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
application.setCurrentLifecycle(lifecycle); application.setCurrentLifecycle(lifecycle);
application = DAOFactory.getApplicationDAO().createApplication(application); application = DAOFactory.getApplicationDAO().createApplication(application);
DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility());
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return application; return application;
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
@ -120,24 +114,27 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ "application with the UUID " + application.getUuid()); + "application with the UUID " + application.getUuid());
} }
try { try {
ConnectionManagerUtil.beginDBTransaction();
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) { if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
Platform platform = DataHolder.getInstance().getPlatformManager() Platform platform = DataHolder.getInstance().getPlatformManager()
.getPlatform(tenantId, application.getPlatform().getIdentifier()); .getPlatform(tenantId, application.getPlatform().getIdentifier());
if (platform == null) { if (platform == null) {
ConnectionManagerUtil.commitDBTransaction();
throw new NotFoundException( throw new NotFoundException(
"Platform specified by identifier " + application.getPlatform().getIdentifier() "Platform specified by identifier " + application.getPlatform().getIdentifier()
+ " is not found. Please give a valid platform identifier."); + " is not found. Please give a valid platform identifier.");
} }
application.setPlatform(platform); application.setPlatform(platform);
} ConnectionManagerUtil.beginDBTransaction();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
application.setModifiedAt(new Date()); application.setModifiedAt(new Date());
Application modifiedApplication = applicationDAO.editApplication(application, tenantId); Application modifiedApplication = applicationDAO.editApplication(application, tenantId);
DataHolder.getInstance().getVisibilityManager().put(application.getUuid(), application.getVisibility()); Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(),
application.getVisibility());
modifiedApplication.setVisibility(visibility);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return modifiedApplication; return modifiedApplication;
} else {
throw new NotFoundException("Platform information not available with the application!");
}
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw e; throw e;
@ -160,8 +157,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
int appId = applicationDAO.getApplicationId(uuid, tenantId); int appId = applicationDAO.getApplicationId(uuid, tenantId);
applicationDAO.deleteTags(appId); applicationDAO.deleteTags(appId);
applicationDAO.deleteProperties(appId); applicationDAO.deleteProperties(appId);
DataHolder.getInstance().getVisibilityManager().remove(appId);
applicationDAO.deleteApplication(uuid, tenantId); applicationDAO.deleteApplication(uuid, tenantId);
DataHolder.getInstance().getVisibilityManager().remove(uuid);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -192,7 +189,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId);
for (Application application : applicationList.getApplications()) { for (Application application : applicationList.getApplications()) {
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getUuid())); application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId()));
} }
return applicationList; return applicationList;
} finally { } finally {
@ -308,7 +305,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName); Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName);
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(uuid)); if (application != null) {
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId()));
}
return application; return application;
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();

@ -17,16 +17,12 @@
*/ */
package org.wso2.carbon.device.application.mgt.core.impl; package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.Visibility; import org.wso2.carbon.device.application.mgt.common.Visibility;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException; import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
/** /**
@ -35,36 +31,35 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
public class VisibilityManagerImpl implements VisibilityManager { public class VisibilityManagerImpl implements VisibilityManager {
@Override @Override
public void put(String applicationUUID, Visibility visibility) throws VisibilityManagementException { public Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException {
if (visibility == null){
visibility = new Visibility();
visibility.setType(Visibility.Type.PUBLIC);
}
if (visibility.getAllowedList() == null && !visibility.getType().equals(Visibility.Type.PUBLIC)) { if (visibility.getAllowedList() == null && !visibility.getType().equals(Visibility.Type.PUBLIC)) {
throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType() throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType()
+ "' but doesn't have any allowed list provided!"); + "' but doesn't have any allowed list provided!");
} }
boolean isTransactionStarted = false; boolean isTransactionStarted = false;
try { try {
Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID);
if (application != null) {
isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
if (!isTransactionStarted) { if (!isTransactionStarted) {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
} }
int id = application.getId();
VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO();
int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType()); int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType());
visibilityDAO.delete(id); visibilityDAO.delete(applicationID);
visibilityDAO.add(id, visibilityTypeId, visibility.getAllowedList()); visibilityDAO.add(applicationID, visibilityTypeId, visibility.getAllowedList());
if (!isTransactionStarted) { if (!isTransactionStarted) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} }
} else { return visibility;
throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID);
}
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
if (!isTransactionStarted){ if (!isTransactionStarted) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
} }
throw new VisibilityManagementException("Problem occured when trying to fetch the application with UUID - " throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "
+ applicationUUID, e); + applicationID, e);
} finally { } finally {
if (!isTransactionStarted) { if (!isTransactionStarted) {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
@ -73,47 +68,39 @@ public class VisibilityManagerImpl implements VisibilityManager {
} }
@Override @Override
public Visibility get(String applicationUUID) throws VisibilityManagementException { public Visibility get(int applicationID) throws VisibilityManagementException {
try { try {
Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID);
if (application != null) {
int id = application.getId();
VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO();
return visibilityDAO.get(id); Visibility visibility = visibilityDAO.get(applicationID);
} else { if (visibility.getType() == null && (visibility.getAllowedList() == null || visibility.getAllowedList().isEmpty())){
throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID); visibility.setType(Visibility.Type.PUBLIC);
} }
return visibility;
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
throw new VisibilityManagementException("Problem occured when trying to fetch the application with UUID - " throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "
+ applicationUUID, e); + applicationID, e);
} }
} }
@Override @Override
public void remove(String applicationUUID) throws VisibilityManagementException { public void remove(int applicationID) throws VisibilityManagementException {
boolean isTransactionStarted = false; boolean isTransactionStarted = false;
try { try {
Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID);
if (application != null) {
isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
if (!isTransactionStarted) { if (!isTransactionStarted) {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
} }
int id = application.getId();
VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO();
visibilityDAO.delete(id); visibilityDAO.delete(applicationID);
if (!isTransactionStarted) { if (!isTransactionStarted) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} }
} else {
throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID);
}
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
if (!isTransactionStarted){ if (!isTransactionStarted) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
} }
throw new VisibilityManagementException("Problem occurred when trying to fetch the application with UUID - " throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - "
+ applicationUUID, e); + applicationID, e);
} finally { } finally {
if (!isTransactionStarted) { if (!isTransactionStarted) {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();

@ -7,7 +7,6 @@
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( CREATE TABLE IF NOT EXISTS APPM_PLATFORM (
ID INT NOT NULL AUTO_INCREMENT UNIQUE, ID INT NOT NULL AUTO_INCREMENT UNIQUE,
IDENTIFIER VARCHAR (100) NOT NULL,
TENANT_ID INT NOT NULL , TENANT_ID INT NOT NULL ,
NAME VARCHAR (255), NAME VARCHAR (255),
FILE_BASED BOOLEAN, FILE_BASED BOOLEAN,
@ -220,6 +219,13 @@ CREATE TABLE IF NOT EXISTS APPM_RESOURCE_TYPE (
DESCRIPTION TEXT NULL, DESCRIPTION TEXT NULL,
PRIMARY KEY (ID)); PRIMARY KEY (ID));
INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('PUBLIC', 'OPEN VISIBILITY, CAN BE VIEWED BY ALL LOGGED IN USERS');
INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('ROLES', 'ROLE BASED RESTRICTION, CAN BE VIEWED BY ONLY GIVEN
SET OF USER WHO HAVE THE SPECIFIED ROLE');
INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('DEVICE_GROUPS', 'DEVICE GROUP LEVEL RESTRICTION,
CAN BE VIEWED BY THE DEVICES/ROLES BELONG TO THE GROUP');
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table APPM_SUBSCRIPTION -- Table APPM_SUBSCRIPTION
-- ----------------------------------------------------- -- -----------------------------------------------------
@ -310,29 +316,22 @@ CREATE INDEX FK_APPLICATION_TAG_APPLICATION ON APPM_APPLICATION_TAG(APPLICATION_
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_VISIBILITY ( CREATE TABLE IF NOT EXISTS APPM_VISIBILITY (
ID INT NOT NULL AUTO_INCREMENT, ID INT NOT NULL AUTO_INCREMENT,
VALUE VARCHAR(255) NOT NULL, VALUE VARCHAR(255),
RESOURCE_TYPE_ID INT NOT NULL, RESOURCE_TYPE_ID INT NOT NULL,
APPLICATION_RELEASE_ID INT NULL,
APPLICATION_ID INT NULL, APPLICATION_ID INT NULL,
PRIMARY KEY (ID, RESOURCE_TYPE_ID), PRIMARY KEY (ID, RESOURCE_TYPE_ID),
CONSTRAINT fk_APPM_VISIBILITY_APPM_RESOURCE_TYPE1 CONSTRAINT fk_APPM_VISIBILITY_APPM_RESOURCE_TYPE1
FOREIGN KEY (RESOURCE_TYPE_ID) FOREIGN KEY (RESOURCE_TYPE_ID)
REFERENCES APPM_RESOURCE_TYPE (ID) REFERENCES APPM_RESOURCE_TYPE (ID)
ON DELETE NO ACTION ON DELETE CASCADE,
ON UPDATE NO ACTION, ON UPDATE CASCADE,
CONSTRAINT fk_APPM_VISIBILITY_APPM_APPLICATION_RELEASE1
FOREIGN KEY (APPLICATION_RELEASE_ID)
REFERENCES APPM_APPLICATION_RELEASE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_APPM_VISIBILITY_APPM_APPLICATION1 CONSTRAINT fk_APPM_VISIBILITY_APPM_APPLICATION1
FOREIGN KEY (APPLICATION_ID) FOREIGN KEY (APPLICATION_ID)
REFERENCES APPM_APPLICATION (ID) REFERENCES APPM_APPLICATION (ID)
ON DELETE NO ACTION ON DELETE CASCADE,
ON UPDATE NO ACTION); ON UPDATE CASCADE);
CREATE INDEX FK_APPM_VISIBILITY_RESOURCE_TYPE ON APPM_VISIBILITY(RESOURCE_TYPE_ID ASC); CREATE INDEX FK_APPM_VISIBILITY_RESOURCE_TYPE ON APPM_VISIBILITY(RESOURCE_TYPE_ID ASC);
CREATE INDEX FK_VISIBILITY_APPLICATION_RELEASE ON APPM_VISIBILITY(APPLICATION_RELEASE_ID ASC);
CREATE INDEX FK_VISIBILITY_APPLICATION ON APPM_VISIBILITY(APPLICATION_ID ASC); CREATE INDEX FK_VISIBILITY_APPLICATION ON APPM_VISIBILITY(APPLICATION_ID ASC);
-- ----------------------------------------------------- -- -----------------------------------------------------

@ -1,7 +1,6 @@
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM]') AND TYPE IN (N'U')) IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM]') AND TYPE IN (N'U'))
CREATE TABLE APPM_PLATFORM ( CREATE TABLE APPM_PLATFORM (
ID INT IDENTITY(1,1) NOT NULL UNIQUE, ID INT IDENTITY(1,1) NOT NULL UNIQUE,
IDENTIFIER VARCHAR (100) NOT NULL,
TENANT_ID INT NOT NULL , TENANT_ID INT NOT NULL ,
NAME VARCHAR (255), NAME VARCHAR (255),
FILE_BASED BIT, FILE_BASED BIT,

@ -16,7 +16,6 @@ SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( CREATE TABLE IF NOT EXISTS APPM_PLATFORM (
ID INT NOT NULL AUTO_INCREMENT UNIQUE, ID INT NOT NULL AUTO_INCREMENT UNIQUE,
IDENTIFIER VARCHAR (100) NOT NULL,
TENANT_ID INT NOT NULL , TENANT_ID INT NOT NULL ,
NAME VARCHAR (255), NAME VARCHAR (255),
FILE_BASED BOOLEAN, FILE_BASED BOOLEAN,
@ -233,6 +232,12 @@ CREATE TABLE IF NOT EXISTS `APPM_RESOURCE_TYPE` (
PRIMARY KEY (`ID`)) PRIMARY KEY (`ID`))
ENGINE = InnoDB; ENGINE = InnoDB;
INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('PUBLIC', 'OPEN VISIBILITY, CAN BE VIEWED BY ALL LOGGED IN USERS');
INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('ROLES', 'ROLE BASED RESTRICTION, CAN BE VIEWED BY ONLY GIVEN
SET OF USER WHO HAVE THE SPECIFIED ROLE');
INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('DEVICE_GROUPS', 'DEVICE GROUP LEVEL RESTRICTION,
CAN BE VIEWED BY THE DEVICES/ROLES BELONG TO THE GROUP');
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `APPM_SUBSCRIPTION` -- Table `APPM_SUBSCRIPTION`
@ -350,7 +355,7 @@ CREATE TABLE IF NOT EXISTS `APPM_APPLICATION_TAG` (
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `APPM_VISIBILITY` ( CREATE TABLE IF NOT EXISTS `APPM_VISIBILITY` (
`ID` INT NOT NULL AUTO_INCREMENT, `ID` INT NOT NULL AUTO_INCREMENT,
`VALUE` VARCHAR(255) NOT NULL, `VALUE` VARCHAR(255),
`RESOURCE_TYPE_ID` INT NOT NULL, `RESOURCE_TYPE_ID` INT NOT NULL,
`APPLICATION_ID` INT NULL, `APPLICATION_ID` INT NULL,
PRIMARY KEY (`ID`), PRIMARY KEY (`ID`),

@ -7,7 +7,6 @@
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE APPM_PLATFORM ( CREATE TABLE APPM_PLATFORM (
ID INT UNIQUE, ID INT UNIQUE,
IDENTIFIER VARCHAR (100) NOT NULL,
TENANT_ID INT NOT NULL , TENANT_ID INT NOT NULL ,
NAME VARCHAR (255), NAME VARCHAR (255),
FILE_BASED NUMBER (1), FILE_BASED NUMBER (1),

@ -4,7 +4,6 @@ CREATE SEQUENCE APPM_PLATFORM_PK_SEQ;
CREATE TABLE APPM_PLATFORM ( CREATE TABLE APPM_PLATFORM (
ID INT DEFAULT NEXTVAL('APPM_PLATFORM_PK_SEQ') UNIQUE, ID INT DEFAULT NEXTVAL('APPM_PLATFORM_PK_SEQ') UNIQUE,
IDENTIFIER VARCHAR (100) NOT NULL,
TENANT_ID INT NOT NULL , TENANT_ID INT NOT NULL ,
NAME VARCHAR (255), NAME VARCHAR (255),
FILE_BASED BOOLEAN, FILE_BASED BOOLEAN,

Loading…
Cancel
Save