diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 89a46e8bd8f..7fd542e1d7e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -37,7 +37,7 @@ public interface ApplicationManager { * @return Created application * @throws ApplicationManagementException Application Management Exception */ - public Application createApplication(Application application) throws ApplicationManagementException; + Application createApplication(Application application) throws ApplicationManagementException; /** * Updates an already existing application. @@ -45,14 +45,14 @@ public interface ApplicationManager { * @return Updated Application * @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. * @param uuid Unique ID for tha application * @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. @@ -60,7 +60,7 @@ public interface ApplicationManager { * @return Applications that matches the given filter criteria. * @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. @@ -69,7 +69,7 @@ public interface ApplicationManager { * @param lifecycleIdentifier New life-cycle that need to be changed. * @throws ApplicationManagementException Application Management Exception. */ - public void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws + void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws ApplicationManagementException; /** @@ -79,7 +79,7 @@ public interface ApplicationManager { * @return the List of possible states * @throws ApplicationManagementException Application Management Exception */ - public List getLifeCycleStates(String applicationUUID) + List getLifeCycleStates(String applicationUUID) throws ApplicationManagementException; /** @@ -89,7 +89,5 @@ public interface ApplicationManager { * @return the Application identified by the UUID * @throws ApplicationManagementException Application Management Exception. */ - public Application getApplication(String uuid) throws ApplicationManagementException; - - + Application getApplication(String uuid) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java index f8983ef85d0..e8eedb666de 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java @@ -35,23 +35,23 @@ public interface VisibilityManager { * Update (if there is already existing 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. */ - void put(String applicationUUID, Visibility visibility) throws VisibilityManagementException; + Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException; /** * 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 */ - Visibility get(String applicationUUID) throws VisibilityManagementException; + Visibility get(int applicationID) throws VisibilityManagementException; /** * 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; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 3aca533e853..966873f9573 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -71,7 +71,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "VIDEO_NAME, SCREEN_SHOT_COUNT, CREATED_BY, CREATED_AT, MODIFIED_AT, " + "APPLICATION_CATEGORY_ID, PLATFORM_ID, TENANT_ID, LIFECYCLE_STATE_ID, " + "LIFECYCLE_STATE_MODIFIED_AT, LIFECYCLE_STATE_MODIFIED_BY) VALUES " - + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt.setString(++index, application.getUuid()); @@ -132,7 +132,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { 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, " + "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 " @@ -265,7 +265,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { 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, " + "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 " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java index 86bfd3ad8f3..82c07f5deaa 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java @@ -51,11 +51,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil } return -1; } catch (DBConnectionException e) { - throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + - "for the visibility management of applicatons"); + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " + + "for the visibility management of applications", e); } catch (SQLException e) { - throw new VisibilityManagementDAOException("Error occured when trying to get the ID of the" + - " visibility type - " + visibilityType.toString()); + throw new VisibilityManagementDAOException("Error occurred when trying to get the ID of the" + + " visibility type - " + visibilityType.toString(), e); } finally { Util.cleanupResources(stmt, resultSet); } @@ -67,7 +67,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil PreparedStatement stmt = null; try { 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); if (allowedList == null) { stmt.setString(1, null); @@ -84,11 +84,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil stmt.executeBatch(); } } catch (DBConnectionException e) { - throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + - "for adding the visibility mapping for the application ID - " + applicationID); + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " + + "for adding the visibility mapping for the application ID - " + applicationID, e); } catch (SQLException e) { - throw new VisibilityManagementDAOException("Error occured while adding the visibility mapping " + - "for the application ID - " + applicationID); + throw new VisibilityManagementDAOException("Error occurred while adding the visibility mapping " + + "for the application ID - " + applicationID, e); } finally { Util.cleanupResources(stmt, null); } @@ -104,11 +104,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil stmt.setInt(1, applicationId); stmt.execute(); } catch (DBConnectionException e) { - throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + - "for deleting the visibility mapping for the application ID - " + applicationId); + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " + + "for deleting the visibility mapping for the application ID - " + applicationId, e); } catch (SQLException e) { - throw new VisibilityManagementDAOException("Error occured while deleting the visibility mapping " + - "for the application ID - " + applicationId); + throw new VisibilityManagementDAOException("Error occurred while deleting the visibility mapping " + + "for the application ID - " + applicationId, e); } finally { Util.cleanupResources(stmt, null); } @@ -144,11 +144,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil } return visibility; } catch (DBConnectionException e) { - throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + - "for getting the visibility mapping for the application ID - " + applicationId); + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " + + "for getting the visibility mapping for the application ID - " + applicationId, e); } catch (SQLException e) { - throw new VisibilityManagementDAOException("Error occured while getting the visibility mapping " + - "for the application ID - " + applicationId); + throw new VisibilityManagementDAOException("Error occurred while getting the visibility mapping " + + "for the application ID - " + applicationId, e); } finally { Util.cleanupResources(stmt, resultSet); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 72eff22a869..fb3ea6b54f5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -22,19 +22,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.Application; -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.*; 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.core.dao.ApplicationDAO; 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.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; @@ -71,14 +63,15 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setCreatedAt(new Date()); application.setModifiedAt(new Date()); 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) { throw new NotFoundException("Invalid platform"); } + ConnectionManagerUtil.beginDBTransaction(); + + // Validating the platform application.setPlatform(platform); if (log.isDebugEnabled()) { 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 = DAOFactory.getApplicationDAO().createApplication(application); + DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility()); ConnectionManagerUtil.commitDBTransaction(); return application; } catch (ApplicationManagementException e) { @@ -120,24 +114,27 @@ public class ApplicationManagerImpl implements ApplicationManager { + "application with the UUID " + application.getUuid()); } try { - ConnectionManagerUtil.beginDBTransaction(); if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) { Platform platform = DataHolder.getInstance().getPlatformManager() .getPlatform(tenantId, application.getPlatform().getIdentifier()); if (platform == null) { - ConnectionManagerUtil.commitDBTransaction(); throw new NotFoundException( "Platform specified by identifier " + application.getPlatform().getIdentifier() + " is not found. Please give a valid platform identifier."); } application.setPlatform(platform); + ConnectionManagerUtil.beginDBTransaction(); + ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); + application.setModifiedAt(new Date()); + Application modifiedApplication = applicationDAO.editApplication(application, tenantId); + Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(), + application.getVisibility()); + modifiedApplication.setVisibility(visibility); + ConnectionManagerUtil.commitDBTransaction(); + return modifiedApplication; + } else { + throw new NotFoundException("Platform information not available with the application!"); } - ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); - application.setModifiedAt(new Date()); - Application modifiedApplication = applicationDAO.editApplication(application, tenantId); - DataHolder.getInstance().getVisibilityManager().put(application.getUuid(), application.getVisibility()); - ConnectionManagerUtil.commitDBTransaction(); - return modifiedApplication; } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); throw e; @@ -160,8 +157,8 @@ public class ApplicationManagerImpl implements ApplicationManager { int appId = applicationDAO.getApplicationId(uuid, tenantId); applicationDAO.deleteTags(appId); applicationDAO.deleteProperties(appId); + DataHolder.getInstance().getVisibilityManager().remove(appId); applicationDAO.deleteApplication(uuid, tenantId); - DataHolder.getInstance().getVisibilityManager().remove(uuid); ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); @@ -192,7 +189,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); for (Application application : applicationList.getApplications()) { - application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getUuid())); + application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId())); } return applicationList; } finally { @@ -307,8 +304,10 @@ public class ApplicationManagerImpl implements ApplicationManager { } try { ConnectionManagerUtil.openDBConnection(); - Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName); - application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(uuid)); + Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName); + if (application != null) { + application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId())); + } return application; } finally { ConnectionManagerUtil.closeDBConnection(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java index 18c487208eb..e12a20fab03 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java @@ -17,16 +17,12 @@ */ 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.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.services.VisibilityManager; 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.internal.DataHolder; 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 { @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)) { throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType() + "' but doesn't have any allowed list provided!"); } boolean isTransactionStarted = false; try { - Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID); - if (application != null) { - isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); - if (!isTransactionStarted) { - ConnectionManagerUtil.beginDBTransaction(); - } - int id = application.getId(); - VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); - int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType()); - visibilityDAO.delete(id); - visibilityDAO.add(id, visibilityTypeId, visibility.getAllowedList()); - if (!isTransactionStarted) { - ConnectionManagerUtil.commitDBTransaction(); - } - } else { - throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID); + isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); + if (!isTransactionStarted) { + ConnectionManagerUtil.beginDBTransaction(); } + VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); + int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType()); + visibilityDAO.delete(applicationID); + visibilityDAO.add(applicationID, visibilityTypeId, visibility.getAllowedList()); + if (!isTransactionStarted) { + ConnectionManagerUtil.commitDBTransaction(); + } + return visibility; } catch (ApplicationManagementException e) { - if (!isTransactionStarted){ + if (!isTransactionStarted) { ConnectionManagerUtil.rollbackDBTransaction(); } - throw new VisibilityManagementException("Problem occured when trying to fetch the application with UUID - " - + applicationUUID, e); + throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - " + + applicationID, e); } finally { if (!isTransactionStarted) { ConnectionManagerUtil.closeDBConnection(); @@ -73,47 +68,39 @@ public class VisibilityManagerImpl implements VisibilityManager { } @Override - public Visibility get(String applicationUUID) throws VisibilityManagementException { + public Visibility get(int applicationID) throws VisibilityManagementException { try { - Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID); - if (application != null) { - int id = application.getId(); - VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); - return visibilityDAO.get(id); - } else { - throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID); + VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); + Visibility visibility = visibilityDAO.get(applicationID); + if (visibility.getType() == null && (visibility.getAllowedList() == null || visibility.getAllowedList().isEmpty())){ + visibility.setType(Visibility.Type.PUBLIC); } + return visibility; } catch (ApplicationManagementException e) { - throw new VisibilityManagementException("Problem occured when trying to fetch the application with UUID - " - + applicationUUID, e); + throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - " + + applicationID, e); } } @Override - public void remove(String applicationUUID) throws VisibilityManagementException { + public void remove(int applicationID) throws VisibilityManagementException { boolean isTransactionStarted = false; try { - Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID); - if (application != null) { - isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); - if (!isTransactionStarted) { - ConnectionManagerUtil.beginDBTransaction(); - } - int id = application.getId(); - VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); - visibilityDAO.delete(id); - if (!isTransactionStarted) { - ConnectionManagerUtil.commitDBTransaction(); - } - } else { - throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID); + isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); + if (!isTransactionStarted) { + ConnectionManagerUtil.beginDBTransaction(); + } + VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); + visibilityDAO.delete(applicationID); + if (!isTransactionStarted) { + ConnectionManagerUtil.commitDBTransaction(); } } catch (ApplicationManagementException e) { - if (!isTransactionStarted){ + if (!isTransactionStarted) { ConnectionManagerUtil.rollbackDBTransaction(); } - throw new VisibilityManagementException("Problem occurred when trying to fetch the application with UUID - " - + applicationUUID, e); + throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - " + + applicationID, e); } finally { if (!isTransactionStarted) { ConnectionManagerUtil.closeDBConnection(); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 809efada346..994d61a08bc 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -7,7 +7,6 @@ -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( ID INT NOT NULL AUTO_INCREMENT UNIQUE, -IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN, @@ -220,6 +219,13 @@ CREATE TABLE IF NOT EXISTS APPM_RESOURCE_TYPE ( DESCRIPTION TEXT NULL, 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 -- ----------------------------------------------------- @@ -310,29 +316,22 @@ CREATE INDEX FK_APPLICATION_TAG_APPLICATION ON APPM_APPLICATION_TAG(APPLICATION_ -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_VISIBILITY ( ID INT NOT NULL AUTO_INCREMENT, - VALUE VARCHAR(255) NOT NULL, + VALUE VARCHAR(255), RESOURCE_TYPE_ID INT NOT NULL, - APPLICATION_RELEASE_ID INT NULL, APPLICATION_ID INT NULL, PRIMARY KEY (ID, RESOURCE_TYPE_ID), CONSTRAINT fk_APPM_VISIBILITY_APPM_RESOURCE_TYPE1 FOREIGN KEY (RESOURCE_TYPE_ID) REFERENCES APPM_RESOURCE_TYPE (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - 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, + ON DELETE CASCADE, + ON UPDATE CASCADE, CONSTRAINT fk_APPM_VISIBILITY_APPM_APPLICATION1 FOREIGN KEY (APPLICATION_ID) REFERENCES APPM_APPLICATION (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION); + ON DELETE CASCADE, + ON UPDATE CASCADE); 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); -- ----------------------------------------------------- diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index d8c578a5851..e4277519561 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -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')) CREATE TABLE APPM_PLATFORM ( ID INT IDENTITY(1,1) NOT NULL UNIQUE, - IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BIT, diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 5c6d5558a30..52fe5701e07 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -16,7 +16,6 @@ SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( ID INT NOT NULL AUTO_INCREMENT UNIQUE, -IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN, @@ -233,6 +232,12 @@ CREATE TABLE IF NOT EXISTS `APPM_RESOURCE_TYPE` ( PRIMARY KEY (`ID`)) 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` @@ -350,7 +355,7 @@ CREATE TABLE IF NOT EXISTS `APPM_APPLICATION_TAG` ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `APPM_VISIBILITY` ( `ID` INT NOT NULL AUTO_INCREMENT, - `VALUE` VARCHAR(255) NOT NULL, + `VALUE` VARCHAR(255), `RESOURCE_TYPE_ID` INT NOT NULL, `APPLICATION_ID` INT NULL, PRIMARY KEY (`ID`), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql index b4b845e77c7..dde3b71e3f9 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql @@ -7,7 +7,6 @@ -- ----------------------------------------------------- CREATE TABLE APPM_PLATFORM ( ID INT UNIQUE, -IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED NUMBER (1), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index 6616a56c2a6..3569edfbbfe 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -4,7 +4,6 @@ CREATE SEQUENCE APPM_PLATFORM_PK_SEQ; CREATE TABLE APPM_PLATFORM ( ID INT DEFAULT NEXTVAL('APPM_PLATFORM_PK_SEQ') UNIQUE, -IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN,