Merge pull request #953 from sinthuja/application-mgt

Adding visibility support for applications.
4.x.x
sinthuja 7 years ago committed by GitHub
commit 3d337ed537

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

@ -18,6 +18,8 @@
*/
package org.wso2.carbon.device.application.mgt.common;
import java.util.List;
/**
* This class represents the visibility details of an Application.
*/
@ -25,19 +27,7 @@ public class Visibility {
private Type type;
private String value;
private Application application;
private ApplicationRelease applicationRelease;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
private List<String> allowedList;
public Type getType() {
return type;
@ -47,55 +37,18 @@ public class Visibility {
this.type = type;
}
public Application getApplication() {
return application;
}
public void setApplication(Application application) {
this.application = application;
}
public ApplicationRelease getApplicationRelease() {
return applicationRelease;
public List<String> getAllowedList() {
return allowedList;
}
public void setApplicationRelease(ApplicationRelease applicationRelease) {
this.applicationRelease = applicationRelease;
public void setAllowedList(List<String> allowedList) {
this.allowedList = allowedList;
}
/**
* Type of the visibility of the application.
*/
public class Type {
private String id;
private String name;
private String description;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public enum Type {
PUBLIC, ROLES, DEVICE_GROUPS
}
}

@ -15,9 +15,23 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.impl;
package org.wso2.carbon.device.application.mgt.common.exception;
import org.wso2.carbon.device.application.mgt.common.services.VisibilityTypeManager;
/**
* This specialized exception is thrown by the Visibility Manager during unexpected behaviour
* or unsupported parameters.
*/
public class VisibilityManagementException extends ApplicationManagementException {
public class VisibilityTypeManagerImpl implements VisibilityTypeManager {
public VisibilityManagementException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
public VisibilityManagementException(String message, Throwable cause) {
super(message, cause);
}
public VisibilityManagementException(String msg) {
super(msg);
}
}

@ -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<LifecycleStateTransition> getLifeCycleStates(String applicationUUID)
List<LifecycleStateTransition> 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;
}

@ -18,9 +18,40 @@
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.exception.VisibilityManagementException;
import java.sql.Connection;
/**
* 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 {
/**
* Add (if there is no visibility configuration for the application) or
* Update (if there is already existing configuration for the application)
* the visibility related configuration for the application
*
* @param applicationID The ID of the application
* @param visibility The visibility configuration for the particular application.
*/
Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException;
/**
* Returns the Visibility configuration of the provided applicationUUID.
*
* @param applicationID The ID of the application
* @return Visibility configuration
*/
Visibility get(int applicationID) throws VisibilityManagementException;
/**
* Remove the visibility configuration mapping for the provided application.
*
* @param applicationID The ID of the application
*/
void remove(int applicationID) throws VisibilityManagementException;
}

@ -1,26 +0,0 @@
/*
* 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.common.services;
/**
* VisibilityTypeManager is responsible for handling all the operations related to VisibilityType, this includes
* creating, updating and viewing the {@link org.wso2.carbon.device.application.mgt.common.Visibility.Type}
*/
public interface VisibilityTypeManager {
}

@ -18,5 +18,8 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
/**
* This interface specifies the database access operations performed for comments.
*/
public interface CommentDAO {
}

@ -1,22 +0,0 @@
/*
* 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;
public interface ResourceTypeDAO {
}

@ -18,5 +18,9 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
/**
* This interface provides the list of operations that are supported with subscription database.
*
*/
public interface SubscriptionDAO {
}

@ -18,5 +18,25 @@
*/
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 {
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;
}

@ -26,12 +26,14 @@ 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.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
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.OracleApplicationDAOImpl;
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.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.util.ApplicationMgtDatabaseCreator;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
@ -59,14 +61,14 @@ public class DAOFactory {
public static ApplicationDAO getApplicationDAO() {
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new GenericApplicationDAOImpl();
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
return new OracleApplicationDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new GenericApplicationDAOImpl();
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
return new OracleApplicationDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
@ -75,15 +77,15 @@ public class DAOFactory {
public static PlatformDAO getPlatformDAO() {
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new GenericPlatformDAOImpl();
case Constants.DataBaseTypes.DB_TYPE_MSSQL:
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
return new OracleMsSQLPlatformDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new GenericPlatformDAOImpl();
case Constants.DataBaseTypes.DB_TYPE_MSSQL:
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
return new OracleMsSQLPlatformDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
@ -92,13 +94,13 @@ public class DAOFactory {
public static LifecycleStateDAO getLifecycleStateDAO() {
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
return new GenericLifecycleStateImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
return new GenericLifecycleStateImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
@ -106,18 +108,37 @@ public class DAOFactory {
/**
* To get the instance of ApplicationReleaseDAOImplementation of the particular database engine.
*
* @return specific ApplicationReleaseDAOImplementation
*/
public static ApplicationReleaseDAO getApplicationReleaseDAO() {
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
return new GenericApplicationReleaseDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
return new GenericApplicationReleaseDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
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.");

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

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

@ -39,7 +39,6 @@ import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -68,15 +67,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
int index = 0;
try {
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, "
+ "APPLICATION_CATEGORY_ID, PLATFORM_ID, TENANT_ID, LIFECYCLE_STATE_ID, "
+ "LIFECYCLE_STATE_MODIFIED_AT, LIFECYCLE_STATE_MODIFIED_BY) VALUES "
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, generatedColumns);
stmt.setString(++index, application.getUuid());
stmt.setString(++index, application.getIdentifier());
stmt.setString(++index, application.getName());
stmt.setString(++index, application.getShortDescription());
stmt.setString(++index, application.getDescription());
@ -240,7 +238,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
try {
conn = this.getConnection();
conn = this.getDBConnection();
sql += "SELECT COUNT(APP.ID) AS APP_COUNT ";
sql += "FROM APPM_APPLICATION AS APP ";
sql += "INNER JOIN APPM_PLATFORM AS APL ON APP.PLATFORM_ID = APL.ID ";

@ -32,7 +32,6 @@ import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -41,7 +40,7 @@ import java.util.Map;
/**
* GenericApplicationReleaseDAOImpl holds the implementation of ApplicationRelease related DAO operations.
*/
public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO {
public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO {
@Override
public ApplicationRelease createRelease(ApplicationRelease applicationRelease) throws
@ -56,7 +55,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
String sql = "insert into APPM_APPLICATION_RELEASE(VERSION_NAME, RELEASE_RESOURCE, RELEASE_CHANNEL ,"
+ "RELEASE_DETAILS, CREATED_AT, APPM_APPLICATION_ID, IS_DEFAULT) values (?, ?, ?, ?, ?, ?, ?)";
int index = 0;
String generatedColumns[] = { "ID" };
String generatedColumns[] = {"ID"};
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql, generatedColumns);
@ -134,7 +133,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
versionName, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error while getting release details of the application " +
applicationUuid + " and version " + versionName + " , while executing the query " + sql, e);
applicationUuid + " and version " + versionName + " , while executing the query " + sql, e);
} finally {
Util.cleanupResources(statement, resultSet);
Util.cleanupResources(null, rsProperties);
@ -199,9 +198,9 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "UPDATE APPM_APPLICATION_RELEASE SET RELEASE_RESOURCE = IFNULL (?, RELEASE_RESOURCE), RELEASE_CHANNEL = IFNULL "
+ "(?, RELEASE_CHANNEL), RELEASE_DETAILS = IFNULL (?, RELEASE_DETAILS), IS_DEFAULT = IFNULL "
+ "(?, IS_DEFAULT) WHERE APPM_APPLICATION_ID = ? AND VERSION_NAME = ?";
String sql = "UPDATE APPM_APPLICATION_RELEASE SET RELEASE_RESOURCE = IFNULL (?, RELEASE_RESOURCE)," +
" RELEASE_CHANNEL = IFNULL (?, RELEASE_CHANNEL), RELEASE_DETAILS = IFNULL (?, RELEASE_DETAILS), " +
"IS_DEFAULT = IFNULL (?, IS_DEFAULT) WHERE APPM_APPLICATION_ID = ? AND VERSION_NAME = ?";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
@ -277,7 +276,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
@Override
public void changeReleaseDefault(String uuid, String version, boolean isDefault, String releaseChannel,
int tenantId) throws ApplicationManagementDAOException {
int tenantId) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "UPDATE APPM_APPLICATION_RELEASE SET IS_DEFAULT = ? AND RELEASE_CHANNEL = ? WHERE "
@ -311,7 +310,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
/**
* To insert the application release properties.
* @param connection Database Connection
*
* @param connection Database Connection
* @param applicationRelease Application Release the properties of which that need to be inserted.
* @throws SQLException SQL Exception.
*/
@ -343,11 +343,11 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
/**
* To make all the releases of particular release channel as non-default ones.
*
* @param uuid UUID of the Application.
* @param uuid UUID of the Application.
* @param releaseChannel ReleaseChannel for which we need to make all the releases as non-default ones.
* @param tenantId ID of the tenant.
* @param tenantId ID of the tenant.
* @throws DBConnectionException Database Connection Exception.
* @throws SQLException SQL Exception.
* @throws SQLException SQL Exception.
*/
private void removeDefaultReleases(String uuid, String releaseChannel, int tenantId)
throws DBConnectionException, SQLException {

@ -44,11 +44,9 @@ public class GenericLifecycleStateImpl extends AbstractDAOImpl implements Lifecy
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
try {
conn = this.getDBConnection();
sql += "SELECT * FROM APPM_LIFECYCLE_STATE WHERE IDENTIFIER = ? ";
String sql = "SELECT * FROM APPM_LIFECYCLE_STATE WHERE IDENTIFIER = ? ";
stmt = conn.prepareStatement(sql);
stmt.setString(1, identifier);

@ -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 occurred while obtaining the connection " +
"for the visibility management of applications", e);
} catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occurred when trying to get the ID of the" +
" visibility type - " + visibilityType.toString(), e);
} 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 (VALUE, RESOURCE_TYPE_ID, APPLICATION_ID) VALUES (?, ?, ?)";
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 occurred while obtaining the connection " +
"for adding the visibility mapping for the application ID - " + applicationID, e);
} catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occurred while adding the visibility mapping " +
"for the application ID - " + applicationID, e);
} 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 occurred while obtaining the connection " +
"for deleting the visibility mapping for the application ID - " + applicationId, e);
} catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occurred while deleting the visibility mapping " +
"for the application ID - " + applicationId, e);
} finally {
Util.cleanupResources(stmt, null);
}
}
public Visibility get(int applicationId) throws VisibilityManagementDAOException {
PreparedStatement stmt = null;
ResultSet resultSet = null;
final String visibilityTypeColumn = "VISIBILITY_TYPE";
final String allowedValColumn = "ALLOWED_VAL";
try {
Connection connection = getDBConnection();
String sql = "SELECT APPM_VISIBILITY.VALUE as " + allowedValColumn + ", APPM_RESOURCE_TYPE.NAME AS " +
visibilityTypeColumn + " 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(visibilityTypeColumn)));
}
String val = resultSet.getString(allowedValColumn);
if (val != null) {
allowedVal.add(val);
}
}
if (!allowedVal.isEmpty()) {
visibility.setAllowedList(allowedVal);
}
return visibility;
} catch (DBConnectionException e) {
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 occurred while getting the visibility mapping " +
"for the application ID - " + applicationId, e);
} 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());
}
}

@ -30,11 +30,11 @@ 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.Visibility;
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 +71,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 = DAOFactory.getPlatformDAO()
.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 +98,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 +122,27 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ "application with the UUID " + application.getUuid());
}
try {
ConnectionManagerUtil.beginDBTransaction();
if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) {
PlatformDAO platformDAO = DAOFactory.getPlatformDAO();
Platform platform = platformDAO
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);
ConnectionManagerUtil.commitDBTransaction();
return modifiedApplication;
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw e;
@ -160,6 +165,7 @@ 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);
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
@ -189,7 +195,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.openDBConnection();
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.getId()));
}
return applicationList;
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -206,7 +216,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
for (LifecycleStateTransition lifecycleStateTransition : nextLifeCycles) {
if (log.isDebugEnabled()) {
log.debug("Lifecycle state of the application " + applicationUuid + " can be changed to"
+ lifecycleStateTransition.getNextState());
+ lifecycleStateTransition.getNextState());
}
if (lifecycleStateTransition.getNextState().equalsIgnoreCase(lifecycleIdentifier)) {
isAvailableNextState = true;
@ -302,7 +312,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
try {
ConnectionManagerUtil.openDBConnection();
return DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName);
Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName);
if (application != null) {
application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId()));
}
return application;
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -344,12 +358,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @return true if the current user has the permission, otherwise false.
* @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);
return userRealm != null && userRealm.getAuthorizationManager() != null && userRealm.getAuthorizationManager()
.isUserAuthorized(MultitenantUtils.getTenantAwareUsername(username),
permission, CarbonConstants.UI_PERMISSION_ACTION);
}
/**
* To validate the application
*

@ -22,6 +22,10 @@ import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
/**
* This class is the default implementation for the CategoryManager.
*
*/
public class CategoryManagerImpl implements CategoryManager {
@Override

@ -19,5 +19,8 @@ package org.wso2.carbon.device.application.mgt.core.impl;
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
/**
* This class is the default implementation for the Managing the comments.
*/
public class CommentsManagerImpl implements CommentsManager {
}

@ -25,12 +25,17 @@ import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManage
import java.util.List;
/**
* This is the default implementation for the Subscription Manager.
*/
public class SubscriptionManagerImpl implements SubscriptionManager {
private static final Log log = LogFactory.getLog(SubscriptionManagerImpl.class);
@Override
public List<DeviceIdentifier> installApplicationForDevices(String applicationUUID, List<DeviceIdentifier> deviceList) throws ApplicationManagementException {
public List<DeviceIdentifier> installApplicationForDevices(String applicationUUID,
List<DeviceIdentifier> deviceList)
throws ApplicationManagementException {
log.info("Install application: " + applicationUUID + " to: " + deviceList.size() + " devices.");
for (DeviceIdentifier device : deviceList) {
String deviceId = device.getId();
@ -42,7 +47,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List<String> installApplicationForUsers(String applicationUUID, List<String> userList) throws ApplicationManagementException {
public List<String> installApplicationForUsers(String applicationUUID, List<String> userList)
throws ApplicationManagementException {
log.info("Install application: " + applicationUUID + " to: " + userList.size() + " users.");
for (String user : userList) {
//Todo: implementation
@ -51,7 +57,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List<String> installApplicationForRoles(String applicationUUID, List<String> roleList) throws ApplicationManagementException {
public List<String> installApplicationForRoles(String applicationUUID, List<String> roleList)
throws ApplicationManagementException {
log.info("Install application: " + applicationUUID + " to: " + roleList.size() + " users.");
for (String role : roleList) {
//Todo: implementation
@ -60,7 +67,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List<DeviceIdentifier> uninstallApplication(String applicationUUID, List<DeviceIdentifier> deviceList) throws ApplicationManagementException {
public List<DeviceIdentifier> uninstallApplication(String applicationUUID,
List<DeviceIdentifier> deviceList)
throws ApplicationManagementException {
return null;
}
}

@ -17,7 +17,96 @@
*/
package org.wso2.carbon.device.application.mgt.core.impl;
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.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.util.ConnectionManagerUtil;
/**
* This is the default implementation for the visibility manager.
*/
public class VisibilityManagerImpl implements VisibilityManager {
@Override
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 {
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) {
ConnectionManagerUtil.rollbackDBTransaction();
}
throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "
+ applicationID, e);
} finally {
if (!isTransactionStarted) {
ConnectionManagerUtil.closeDBConnection();
}
}
}
@Override
public Visibility get(int applicationID) throws VisibilityManagementException {
try {
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 ID - "
+ applicationID, e);
}
}
@Override
public void remove(int applicationID) throws VisibilityManagementException {
boolean isTransactionStarted = false;
try {
isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
if (!isTransactionStarted) {
ConnectionManagerUtil.beginDBTransaction();
}
VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO();
visibilityDAO.delete(applicationID);
if (!isTransactionStarted) {
ConnectionManagerUtil.commitDBTransaction();
}
} catch (ApplicationManagementException e) {
if (!isTransactionStarted) {
ConnectionManagerUtil.rollbackDBTransaction();
}
throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - "
+ applicationID, e);
} finally {
if (!isTransactionStarted) {
ConnectionManagerUtil.closeDBConnection();
}
}
}
public class VisibilityManagerImpl implements VisibilityManager{
}

@ -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.SubscriptionManager;
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.user.core.service.RealmService;
@ -52,8 +51,6 @@ public class DataHolder {
private PlatformManager platformManager;
private VisibilityTypeManager visibilityTypeManager;
private SubscriptionManager subscriptionManager;
private VisibilityManager visibilityManager;
@ -126,14 +123,6 @@ public class DataHolder {
this.platformManager = platformManager;
}
public VisibilityTypeManager getVisibilityTypeManager() {
return visibilityTypeManager;
}
public void setVisibilityTypeManager(VisibilityTypeManager visibilityTypeManager) {
this.visibilityTypeManager = visibilityTypeManager;
}
public SubscriptionManager getSubscriptionManager() {
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.SubscriptionManager;
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.dao.common.DAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
@ -113,10 +112,6 @@ public class ServiceComponent {
DataHolder.getInstance().setVisibilityManager(visibilityManager);
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
.getApplicationStorageManagerInstance();
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.SubscriptionManager;
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.Extension;
@ -81,12 +80,6 @@ public class ApplicationManagementUtil {
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 {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.VisibilityManager);

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

@ -15,9 +15,10 @@ DESCRIPTION LONGVARCHAR,
IS_SHARED BOOLEAN,
IS_DEFAULT_TENANT_MAPPING BOOLEAN,
ICON_NAME VARCHAR (100),
PRIMARY KEY (IDENTIFIER, TENANT_ID)
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_PROPERTIES (
ID INT NOT NULL AUTO_INCREMENT,
PLATFORM_ID INT NOT NULL,
@ -121,7 +122,6 @@ INSERT INTO APPM_LC_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESC
CREATE TABLE IF NOT EXISTS `APPM_APPLICATION` (
`ID` INT NOT NULL AUTO_INCREMENT,
`UUID` VARCHAR(100) NOT NULL,
`IDENTIFIER` VARCHAR(255) NULL,
`NAME` VARCHAR(100) NOT NULL,
`SHORT_DESCRIPTION` VARCHAR(255) NULL,
`DESCRIPTION` TEXT NULL,
@ -220,6 +220,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 +317,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),
PRIMARY KEY (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,
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);
-- -----------------------------------------------------

@ -9,7 +9,7 @@ CREATE TABLE APPM_PLATFORM (
IS_SHARED BIT,
IS_DEFAULT_TENANT_MAPPING BIT,
ICON_NAME VARCHAR (100),
PRIMARY KEY (IDENTIFIER, TENANT_ID)
PRIMARY KEY (ID)
);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM_PROPERTIES]') AND TYPE IN (N'U'))

@ -24,7 +24,7 @@ DESCRIPTION VARCHAR (2048),
IS_SHARED BOOLEAN,
IS_DEFAULT_TENANT_MAPPING BOOLEAN,
ICON_NAME VARCHAR (100),
PRIMARY KEY (IDENTIFIER, TENANT_ID)
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_PROPERTIES (
@ -140,7 +140,6 @@ INSERT INTO APPM_LC_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSION, DESC
CREATE TABLE IF NOT EXISTS `APPM_APPLICATION` (
`ID` INT NOT NULL AUTO_INCREMENT,
`UUID` VARCHAR(100) NOT NULL,
`IDENTIFIER` VARCHAR(255) NULL,
`NAME` VARCHAR(100) NOT NULL,
`SHORT_DESCRIPTION` VARCHAR(255) NULL,
`DESCRIPTION` TEXT NULL,
@ -251,6 +250,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,29 +355,22 @@ 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_RELEASE_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_VISIBILITY_APPLICATION_RELEASE` (`APPLICATION_RELEASE_ID` ASC),
INDEX `FK_VISIBILITY_APPLICATION` (`APPLICATION_ID` ASC),
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,
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 )
ENGINE = InnoDB;

@ -15,7 +15,7 @@ DESCRIPTION VARCHAR (2048),
IS_SHARED NUMBER (1),
IS_DEFAULT_TENANT_MAPPING NUMBER (1),
ICON_NAME VARCHAR (100),
PRIMARY KEY (IDENTIFIER, TENANT_ID)
PRIMARY KEY (ID)
)
/

@ -12,7 +12,7 @@ DESCRIPTION VARCHAR(2048),
IS_SHARED BOOLEAN,
IS_DEFAULT_TENANT_MAPPING BOOLEAN,
ICON_NAME VARCHAR (100),
PRIMARY KEY (IDENTIFIER, TENANT_ID)
PRIMARY KEY (ID)
);
DROP TABLE IF EXISTS APPM_PLATFORM_PROPERTIES;
@ -138,7 +138,6 @@ CREATE SEQUENCE APPM_APPLICATION_PK_SEQ;
CREATE TABLE IF NOT EXISTS APPM_APPLICATION (
ID INT DEFAULT NEXTVAL('APPM_APPLICATION_PK_SEQ') UNIQUE,
UUID VARCHAR(100) NOT NULL,
IDENTIFIER VARCHAR(255) NULL,
NAME VARCHAR(100) NOT NULL,
SHORT_DESCRIPTION VARCHAR(255) NULL,
DESCRIPTION TEXT NULL,

Loading…
Cancel
Save