Committing first cut of modifications to the visibility manager.

feature/appm-store/pbac
sinthuja 7 years ago
parent 78f8507bf3
commit 887675fda2

@ -35,8 +35,6 @@ public class Application {
private String uuid; private String uuid;
private String identifier;
private String name; private String name;
private String shortDescription; private String shortDescription;
@ -119,14 +117,6 @@ public class Application {
this.uuid = uuid; this.uuid = uuid;
} }
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -233,7 +223,7 @@ public class Application {
@Override @Override
public String toString() { public String toString() {
return "UUID : " + uuid + "\tIdentifier : " + identifier + "\tName : " + name + "\tShort Description : " return "UUID : " + uuid + "\tName : " + name + "\tShort Description : "
+ shortDescription + "\tLifecycle State : " + currentLifecycle.getLifecycleState(); + shortDescription + "\tLifecycle State : " + currentLifecycle.getLifecycleState();
} }
} }

@ -19,17 +19,39 @@
package org.wso2.carbon.device.application.mgt.common.services; package org.wso2.carbon.device.application.mgt.common.services;
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.VisibilityManagementException;
import java.sql.Connection;
/** /**
* This interface manages all the operations related with Application Visibility, and in the case of the restr * This interface manages all the operations related with Application Visibility.
* This will be invoking the necessary backend calls for the data bases layer
* and provide the functional implementation.
*/ */
public interface VisibilityManager { public interface VisibilityManager {
void addVisibilityMapping(String applicationId, Visibility visibility); /**
* Add (if there is no visibility configuration for the application) or
Visibility getVisibility(String applicationId); * 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 visibility The visibility configuration for the particular application.
*/
void put(String applicationUUID, Visibility visibility) throws VisibilityManagementException;
void updateVisibilityMapping(String applicationId, Visibility visibility); /**
* Returns the Visibility configuration of the provided applicationUUID.
*
* @param applicationUUID The ID of the application
* @return Visibility configuration
*/
Visibility get(String applicationUUID) throws VisibilityManagementException;
void removeVisibilityMapping(String applicationId); /**
* Remove the visibility configuration mapping for the provided application.
*
* @param applicationUUID The ID of the application
*/
void remove(String applicationUUID) throws VisibilityManagementException;
} }

@ -18,5 +18,23 @@
*/ */
package org.wso2.carbon.device.application.mgt.core.dao; package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.Visibility;
import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagementDAOException;
import java.util.List;
/**
* This interface provides the list of operations that are performed in the database layer with respect to the visibility.
*/
public interface VisibilityDAO { public interface VisibilityDAO {
int getVisibilityID(Visibility.Type visibilityType) throws VisibilityManagementDAOException;
void add(int applicationID, int visibilityTypeID, List<String> allowedList)
throws VisibilityManagementDAOException;
void delete(int applicationId) throws VisibilityManagementDAOException;
Visibility get(int applicationID) throws VisibilityManagementDAOException;
} }

@ -25,12 +25,14 @@ import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
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.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
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.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO; import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OracleMsSQLPlatformDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OracleMsSQLPlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl;
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.util.ApplicationMgtDatabaseCreator; import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
@ -118,6 +120,23 @@ public class DAOFactory {
throw new IllegalStateException("Database engine has not initialized properly."); throw new IllegalStateException("Database engine has not initialized properly.");
} }
/**
* To get the instance of VisibilityDAOImplementation of the particular database engine.
* @return specific VisibilityDAOImplementation
*/
public static VisibilityDAO getVisibilityDAO(){
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericVisibilityDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
}
/** /**
* This method initializes the databases by creating the database. * This method initializes the databases by creating the database.
* *

@ -59,7 +59,6 @@ public class Util {
application.setId(rs.getInt("ID")); application.setId(rs.getInt("ID"));
application.setName(rs.getString("NAME")); application.setName(rs.getString("NAME"));
application.setUuid(rs.getString("UUID")); application.setUuid(rs.getString("UUID"));
application.setIdentifier(rs.getString("IDENTIFIER"));
application.setShortDescription(rs.getString("SHORT_DESCRIPTION")); application.setShortDescription(rs.getString("SHORT_DESCRIPTION"));
application.setDescription(rs.getString("DESCRIPTION")); application.setDescription(rs.getString("DESCRIPTION"));
application.setScreenShotCount(rs.getInt("SCREEN_SHOT_COUNT")); application.setScreenShotCount(rs.getInt("SCREEN_SHOT_COUNT"));

@ -31,9 +31,4 @@ public abstract class AbstractDAOImpl {
protected Connection getDBConnection() throws DBConnectionException { protected Connection getDBConnection() throws DBConnectionException {
return ConnectionManagerUtil.getDBConnection(); return ConnectionManagerUtil.getDBConnection();
} }
@Deprecated
protected Connection getConnection() throws DBConnectionException {
return ConnectionManagerUtil.getConnection();
}
} }

@ -67,7 +67,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
int index = 0; int index = 0;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "INSERT INTO APPM_APPLICATION (UUID, IDENTIFIER, NAME, SHORT_DESCRIPTION, DESCRIPTION, " sql += "INSERT INTO APPM_APPLICATION (UUID, NAME, SHORT_DESCRIPTION, DESCRIPTION, "
+ "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 "
@ -75,7 +75,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
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());
stmt.setString(++index, application.getIdentifier());
stmt.setString(++index, application.getName()); stmt.setString(++index, application.getName());
stmt.setString(++index, application.getShortDescription()); stmt.setString(++index, application.getShortDescription());
stmt.setString(++index, application.getDescription()); stmt.setString(++index, application.getDescription());
@ -133,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, APL.IDENTIFIER AS APL_IDENTIFIER, " sql += "SELECT APP.*, APL.NAME AS APL_NAME, "
+ "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 "
@ -222,7 +221,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
try { try {
conn = this.getConnection(); conn = this.getDBConnection();
sql += "SELECT COUNT(APP.ID) AS APP_COUNT "; sql += "SELECT COUNT(APP.ID) AS APP_COUNT ";
sql += "FROM APPM_APPLICATION AS APP "; sql += "FROM APPM_APPLICATION AS APP ";
sql += "INNER JOIN APPM_PLATFORM AS APL ON APP.PLATFORM_ID = APL.ID "; sql += "INNER JOIN APPM_PLATFORM AS APL ON APP.PLATFORM_ID = APL.ID ";
@ -266,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, APL.IDENTIFIER AS APL_IDENTIFIER, " sql += "SELECT APP.*, APL.NAME AS APL_NAME, "
+ "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 "

@ -0,0 +1,156 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.dao.impl.visibility;
import org.wso2.carbon.device.application.mgt.common.Visibility;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagementDAOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* Generic database level implementation for the DAO which can be used by different databases.
*/
public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements VisibilityDAO {
@Override
public int getVisibilityID(Visibility.Type visibilityType) throws VisibilityManagementDAOException {
PreparedStatement stmt = null;
ResultSet resultSet = null;
try {
Connection connection = getDBConnection();
String sql = "SELECT ID FROM APPM_RESOURCE_TYPE WHERE NAME = ?";
stmt = connection.prepareStatement(sql);
stmt.setString(1, visibilityType.toString().toUpperCase());
resultSet = stmt.executeQuery();
if (resultSet.next()) {
return resultSet.getInt("ID");
}
return -1;
} catch (DBConnectionException e) {
throw new VisibilityManagementDAOException("Error occured while obtaining the connection " +
"for the visibility management of applicatons");
} catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occured when trying to get the ID of the" +
" visibility type - " + visibilityType.toString());
} finally {
Util.cleanupResources(stmt, resultSet);
}
}
@Override
public void add(int applicationID, int visibilityTypeID, List<String> allowedList)
throws VisibilityManagementDAOException {
PreparedStatement stmt = null;
try {
Connection connection = getDBConnection();
String sql = "INSERT INTO APPM_VISIBILITY (?, ?, ?)";
stmt = connection.prepareStatement(sql);
if (allowedList == null) {
stmt.setString(1, null);
stmt.setInt(2, visibilityTypeID);
stmt.setInt(3, applicationID);
stmt.execute();
} else {
for (String allowed : allowedList) {
stmt.setString(1, allowed);
stmt.setInt(2, visibilityTypeID);
stmt.setInt(3, applicationID);
stmt.addBatch();
}
stmt.executeBatch();
}
} catch (DBConnectionException e) {
throw new VisibilityManagementDAOException("Error occured while obtaining the connection " +
"for adding the visibility mapping for the application ID - " + applicationID);
} catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occured while adding the visibility mapping " +
"for the application ID - " + applicationID);
} finally {
Util.cleanupResources(stmt, null);
}
}
@Override
public void delete(int applicationId) throws VisibilityManagementDAOException {
PreparedStatement stmt = null;
try {
Connection connection = getDBConnection();
String sql = "DELETE FROM APPM_VISIBILITY WHERE APPLICATION_ID = ?";
stmt = connection.prepareStatement(sql);
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);
} catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occured while deleting the visibility mapping " +
"for the application ID - " + applicationId);
} finally {
Util.cleanupResources(stmt, null);
}
}
public Visibility get(int applicationId) throws VisibilityManagementDAOException {
PreparedStatement stmt = null;
ResultSet resultSet = null;
final String VISIBILITY_TYPE = "VISIBILITY_TYPE";
final String ALLOWED_VAL = "ALLOWED_VAL";
try {
Connection connection = getDBConnection();
String sql = "SELECT APPM_VISIBILITY.VALUE as " + ALLOWED_VAL + ", APPM_RESOURCE_TYPE.NAME AS " +
VISIBILITY_TYPE + " FROM APPM_VISIBILITY JOIN APPM_RESOURCE_TYPE " +
"ON APPM_VISIBILITY.RESOURCE_TYPE_ID = APPM_RESOURCE_TYPE.ID " +
"WHERE APPM_VISIBILITY.APPLICATION_ID = ?";
stmt = connection.prepareStatement(sql);
stmt.setInt(1, applicationId);
resultSet = stmt.executeQuery();
Visibility visibility = new Visibility();
List<String> allowedVal = new ArrayList<>();
while (resultSet.next()) {
if (visibility.getType() == null) {
visibility.setType(Visibility.Type.valueOf(resultSet.getString(VISIBILITY_TYPE)));
}
String val = resultSet.getString(ALLOWED_VAL);
if (val != null) {
allowedVal.add(val);
}
}
if (!allowedVal.isEmpty()){
visibility.setAllowedList(allowedVal);
}
return visibility;
} catch (DBConnectionException e) {
throw new VisibilityManagementDAOException("Error occured while obtaining the connection " +
"for getting the visibility mapping for the application ID - " + applicationId);
} catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occured while getting the visibility mapping " +
"for the application ID - " + applicationId);
} finally {
Util.cleanupResources(stmt, resultSet);
}
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
/**
* This is the specialized exception which is thrown when there are database level problems encountered
* when performing the visibility management
*/
public class VisibilityManagementDAOException extends ApplicationManagementException {
public VisibilityManagementDAOException(String message, Throwable throwable) {
super(message, throwable);
}
public VisibilityManagementDAOException(String message) {
super(message, new Exception());
}
}

@ -74,7 +74,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
// Validating the platform // Validating the platform
Platform platform = DAOFactory.getPlatformDAO() Platform platform = DataHolder.getInstance().getPlatformManager()
.getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier()); .getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier());
if (platform == null) { if (platform == null) {
throw new NotFoundException("Invalid platform"); throw new NotFoundException("Invalid platform");
@ -122,8 +122,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) { if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
PlatformDAO platformDAO = DAOFactory.getPlatformDAO(); Platform platform = DataHolder.getInstance().getPlatformManager()
Platform platform = platformDAO
.getPlatform(tenantId, application.getPlatform().getIdentifier()); .getPlatform(tenantId, application.getPlatform().getIdentifier());
if (platform == null) { if (platform == null) {
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
@ -136,6 +135,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
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());
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return modifiedApplication; return modifiedApplication;
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
@ -161,6 +161,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationDAO.deleteTags(appId); applicationDAO.deleteTags(appId);
applicationDAO.deleteProperties(appId); applicationDAO.deleteProperties(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();
@ -189,7 +190,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
return applicationDAO.getApplications(filter, tenantId); ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId);
for (Application application : applicationList.getApplications()) {
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getUuid()));
}
return applicationList;
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -206,7 +211,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
for (LifecycleStateTransition lifecycleStateTransition : nextLifeCycles) { for (LifecycleStateTransition lifecycleStateTransition : nextLifeCycles) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Lifecycle state of the application " + applicationUuid + " can be changed to" log.debug("Lifecycle state of the application " + applicationUuid + " can be changed to"
+ lifecycleStateTransition.getNextState()); + lifecycleStateTransition.getNextState());
} }
if (lifecycleStateTransition.getNextState().equalsIgnoreCase(lifecycleIdentifier)) { if (lifecycleStateTransition.getNextState().equalsIgnoreCase(lifecycleIdentifier)) {
isAvailableNextState = true; isAvailableNextState = true;
@ -302,7 +307,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
return DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName); Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName);
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(uuid));
return application;
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -344,12 +351,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @return true if the current user has the permission, otherwise false. * @return true if the current user has the permission, otherwise false.
* @throws UserStoreException UserStoreException * @throws UserStoreException UserStoreException
*/ */
private boolean isAuthorized (String username, int tenantId, String permission) throws UserStoreException { private boolean isAuthorized(String username, int tenantId, String permission) throws UserStoreException {
UserRealm userRealm = DataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId); UserRealm userRealm = DataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
return userRealm != null && userRealm.getAuthorizationManager() != null && userRealm.getAuthorizationManager() return userRealm != null && userRealm.getAuthorizationManager() != null && userRealm.getAuthorizationManager()
.isUserAuthorized(MultitenantUtils.getTenantAwareUsername(username), .isUserAuthorized(MultitenantUtils.getTenantAwareUsername(username),
permission, CarbonConstants.UI_PERMISSION_ACTION); permission, CarbonConstants.UI_PERMISSION_ACTION);
} }
/** /**
* To validate the application * To validate the application
* *

@ -17,30 +17,108 @@
*/ */
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.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.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;
/** /**
* This is the defaut implementation for the visibility manager. * This is the default implementation for the visibility manager.
*/ */
public class VisibilityManagerImpl implements VisibilityManager { public class VisibilityManagerImpl implements VisibilityManager {
@Override
public void addVisibilityMapping(String applicationId, Visibility visibility) {
}
@Override @Override
public Visibility getVisibility(String applicationId) { public void put(String applicationUUID, Visibility visibility) throws VisibilityManagementException {
return null; 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);
}
} catch (ApplicationManagementException e) {
if (!isTransactionStarted){
ConnectionManagerUtil.rollbackDBTransaction();
}
throw new VisibilityManagementException("Problem occured when trying to fetch the application with UUID - "
+ applicationUUID, e);
} finally {
if (!isTransactionStarted) {
ConnectionManagerUtil.closeDBConnection();
}
}
} }
@Override @Override
public void updateVisibilityMapping(String applicationId, Visibility visibility) { public Visibility get(String applicationUUID) 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);
}
} catch (ApplicationManagementException e) {
throw new VisibilityManagementException("Problem occured when trying to fetch the application with UUID - "
+ applicationUUID, e);
}
} }
@Override @Override
public void removeVisibilityMapping(String applicationId) { public void remove(String applicationUUID) 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);
}
} catch (ApplicationManagementException e) {
if (!isTransactionStarted){
ConnectionManagerUtil.rollbackDBTransaction();
}
throw new VisibilityManagementException("Problem occurred when trying to fetch the application with UUID - "
+ applicationUUID, e);
} finally {
if (!isTransactionStarted) {
ConnectionManagerUtil.closeDBConnection();
}
}
} }
} }

@ -27,7 +27,6 @@ import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateMana
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
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.common.services.VisibilityTypeManager;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
@ -52,8 +51,6 @@ public class DataHolder {
private PlatformManager platformManager; private PlatformManager platformManager;
private VisibilityTypeManager visibilityTypeManager;
private SubscriptionManager subscriptionManager; private SubscriptionManager subscriptionManager;
private VisibilityManager visibilityManager; private VisibilityManager visibilityManager;
@ -126,14 +123,6 @@ public class DataHolder {
this.platformManager = platformManager; this.platformManager = platformManager;
} }
public VisibilityTypeManager getVisibilityTypeManager() {
return visibilityTypeManager;
}
public void setVisibilityTypeManager(VisibilityTypeManager visibilityTypeManager) {
this.visibilityTypeManager = visibilityTypeManager;
}
public SubscriptionManager getSubscriptionManager() { public SubscriptionManager getSubscriptionManager() {
return subscriptionManager; return subscriptionManager;
} }

@ -32,7 +32,6 @@ import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateMana
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
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.common.services.VisibilityTypeManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
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;
@ -113,10 +112,6 @@ public class ServiceComponent {
DataHolder.getInstance().setVisibilityManager(visibilityManager); DataHolder.getInstance().setVisibilityManager(visibilityManager);
bundleContext.registerService(VisibilityManager.class.getName(), visibilityManager, null); bundleContext.registerService(VisibilityManager.class.getName(), visibilityManager, null);
VisibilityTypeManager visibilityTypeManager = ApplicationManagementUtil.getVisibilityTypeManagerInstance();
DataHolder.getInstance().setVisibilityTypeManager(visibilityTypeManager);
bundleContext.registerService(VisibilityTypeManager.class.getName(), visibilityTypeManager, null);
ApplicationStorageManager applicationStorageManager = ApplicationManagementUtil ApplicationStorageManager applicationStorageManager = ApplicationManagementUtil
.getApplicationStorageManagerInstance(); .getApplicationStorageManagerInstance();
DataHolder.getInstance().setApplicationStorageManager(applicationStorageManager); DataHolder.getInstance().setApplicationStorageManager(applicationStorageManager);

@ -30,7 +30,6 @@ import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateMana
import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; import org.wso2.carbon.device.application.mgt.common.services.PlatformManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
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.common.services.VisibilityTypeManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.Extension; import org.wso2.carbon.device.application.mgt.core.config.Extension;
@ -81,12 +80,6 @@ public class ApplicationManagementUtil {
return getInstance(extension, PlatformManager.class); return getInstance(extension, PlatformManager.class);
} }
public static VisibilityTypeManager getVisibilityTypeManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.VisibilityTypeManager);
return getInstance(extension, VisibilityTypeManager.class);
}
public static VisibilityManager getVisibilityManagerInstance() throws InvalidConfigurationException { public static VisibilityManager getVisibilityManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance(); ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.VisibilityManager); Extension extension = configurationManager.getExtension(Extension.Name.VisibilityManager);

@ -161,6 +161,11 @@ public class ConnectionManagerUtil {
return inTransaction; return inTransaction;
} }
public static boolean isTransactionStarted() throws DBConnectionException {
Connection connection = getDBConnection();
return inTransaction(connection);
}
@Deprecated @Deprecated
public static ThreadLocal<Connection> getCurrentConnection() { public static ThreadLocal<Connection> getCurrentConnection() {
return currentConnection; return currentConnection;

@ -352,27 +352,20 @@ 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) NOT NULL,
`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`),
INDEX `FK_APPM_VISIBILITY_RESOURCE_TYPE` (`RESOURCE_TYPE_ID` ASC), INDEX `FK_APPM_VISIBILITY_RESOURCE_TYPE` (`RESOURCE_TYPE_ID` ASC),
INDEX `FK_VISIBILITY_APPLICATION_RELEASE` (`APPLICATION_RELEASE_ID` ASC),
INDEX `FK_VISIBILITY_APPLICATION` (`APPLICATION_ID` ASC), INDEX `FK_VISIBILITY_APPLICATION` (`APPLICATION_ID` ASC),
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 NO ACTION
ON UPDATE 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,
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 )
ENGINE = InnoDB; ENGINE = InnoDB;

Loading…
Cancel
Save