From c04e4d3c42a80f52a8ac2ad2c59c6631b95690de Mon Sep 17 00:00:00 2001 From: sinthuja Date: Tue, 29 Aug 2017 12:39:21 +0530 Subject: [PATCH 1/5] Committing initial refactoring for visibility change. --- .../application/mgt/common/Visibility.java | 65 +++---------------- .../VisibilityManagementException.java} | 20 +++++- .../common/services/VisibilityManager.java | 11 +++- .../services/VisibilityTypeManager.java | 26 -------- .../mgt/core/dao/ResourceTypeDAO.java | 22 ------- .../GenericLifecycleStateImpl.java | 4 +- .../mgt/core/impl/VisibilityManagerImpl.java | 25 ++++++- 7 files changed, 61 insertions(+), 112 deletions(-) rename components/application-mgt/{org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityTypeManagerImpl.java => org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/VisibilityManagementException.java} (53%) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityTypeManager.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ResourceTypeDAO.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Visibility.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Visibility.java index e8d361d5b8..c2992aa670 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Visibility.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Visibility.java @@ -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 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 getAllowedList() { + return allowedList; } - public void setApplicationRelease(ApplicationRelease applicationRelease) { - this.applicationRelease = applicationRelease; + public void setAllowedList(List 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 } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityTypeManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/VisibilityManagementException.java similarity index 53% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityTypeManagerImpl.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/VisibilityManagementException.java index 5396a67000..660d18f1c5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityTypeManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/VisibilityManagementException.java @@ -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); + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java index 3e22b6f4de..670ad5ce79 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java @@ -18,9 +18,18 @@ package org.wso2.carbon.device.application.mgt.common.services; +import org.wso2.carbon.device.application.mgt.common.Visibility; + /** - * This interface manages all the operations related with Application Visibility. + * This interface manages all the operations related with Application Visibility, and in the case of the restr */ public interface VisibilityManager { + void addVisibilityMapping(String applicationId, Visibility visibility); + + Visibility getVisibility(String applicationId); + + void updateVisibilityMapping(String applicationId, Visibility visibility); + + void removeVisibilityMapping(String applicationId); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityTypeManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityTypeManager.java deleted file mode 100644 index 83018ad1d4..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityTypeManager.java +++ /dev/null @@ -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 { -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ResourceTypeDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ResourceTypeDAO.java deleted file mode 100644 index d4cf3b3ac6..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ResourceTypeDAO.java +++ /dev/null @@ -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 { -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateImpl.java index a772ba8583..dcadb97a30 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateImpl.java @@ -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); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java index 315d3c6122..612b041233 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java @@ -17,7 +17,30 @@ */ 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.services.VisibilityManager; -public class VisibilityManagerImpl implements VisibilityManager{ +/** + * This is the defaut implementation for the visibility manager. + */ +public class VisibilityManagerImpl implements VisibilityManager { + @Override + public void addVisibilityMapping(String applicationId, Visibility visibility) { + + } + + @Override + public Visibility getVisibility(String applicationId) { + return null; + } + + @Override + public void updateVisibilityMapping(String applicationId, Visibility visibility) { + + } + + @Override + public void removeVisibilityMapping(String applicationId) { + + } } From 887675fda27fb63d60f6dec3ce54728fd39f1ab7 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Wed, 6 Sep 2017 12:17:07 +0530 Subject: [PATCH 2/5] Committing first cut of modifications to the visibility manager. --- .../application/mgt/common/Application.java | 12 +- .../common/services/VisibilityManager.java | 34 +++- .../mgt/core/dao/VisibilityDAO.java | 18 ++ .../mgt/core/dao/common/DAOFactory.java | 19 +++ .../application/mgt/core/dao/common/Util.java | 1 - .../mgt/core/dao/impl/AbstractDAOImpl.java | 5 - .../GenericApplicationDAOImpl.java | 9 +- .../visibility/GenericVisibilityDAOImpl.java | 156 ++++++++++++++++++ .../VisibilityManagementDAOException.java | 35 ++++ .../mgt/core/impl/ApplicationManagerImpl.java | 22 ++- .../mgt/core/impl/VisibilityManagerImpl.java | 100 +++++++++-- .../mgt/core/internal/DataHolder.java | 11 -- .../mgt/core/internal/ServiceComponent.java | 5 - .../core/util/ApplicationManagementUtil.java | 7 - .../mgt/core/util/ConnectionManagerUtil.java | 5 + .../dbscripts/cdm/application-mgt/mysql.sql | 13 +- 16 files changed, 373 insertions(+), 79 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/VisibilityManagementDAOException.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java index 77c84bdf6a..4ec135b074 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java @@ -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(); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java index 670ad5ce79..f8983ef85d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java @@ -19,17 +19,39 @@ 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, 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 { - void addVisibilityMapping(String applicationId, Visibility visibility); - - Visibility getVisibility(String applicationId); + /** + * 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 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; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/VisibilityDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/VisibilityDAO.java index 933219888e..6d93e091f0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/VisibilityDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/VisibilityDAO.java @@ -18,5 +18,23 @@ */ 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 allowedList) + throws VisibilityManagementDAOException; + + void delete(int applicationId) throws VisibilityManagementDAOException; + + Visibility get(int applicationID) throws VisibilityManagementDAOException; + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java index 4a29ee90a7..8ba6eb7daf 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java @@ -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.ApplicationReleaseDAO; 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.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.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; @@ -118,6 +120,23 @@ public class DAOFactory { 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. * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index 769e8a50ed..2743a120c6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -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")); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/AbstractDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/AbstractDAOImpl.java index bbc1f85c0e..cc89f0e69b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/AbstractDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/AbstractDAOImpl.java @@ -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(); - } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index de6896921c..3aca533e85 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -67,7 +67,7 @@ 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 " @@ -75,7 +75,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); 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()); @@ -133,7 +132,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { 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, " + "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 " @@ -222,7 +221,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 "; @@ -266,7 +265,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { 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, " + "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS " + "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java new file mode 100644 index 0000000000..86bfd3ad8f --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java @@ -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 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 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); + } + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/VisibilityManagementDAOException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/VisibilityManagementDAOException.java new file mode 100644 index 0000000000..0b4209658e --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/VisibilityManagementDAOException.java @@ -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()); + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 6b2e0411f7..72eff22a86 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -74,7 +74,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.beginDBTransaction(); // Validating the platform - Platform platform = DAOFactory.getPlatformDAO() + Platform platform = DataHolder.getInstance().getPlatformManager() .getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier()); if (platform == null) { throw new NotFoundException("Invalid platform"); @@ -122,8 +122,7 @@ public class ApplicationManagerImpl implements ApplicationManager { 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(); @@ -136,6 +135,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); application.setModifiedAt(new Date()); Application modifiedApplication = applicationDAO.editApplication(application, tenantId); + DataHolder.getInstance().getVisibilityManager().put(application.getUuid(), application.getVisibility()); ConnectionManagerUtil.commitDBTransaction(); return modifiedApplication; } catch (ApplicationManagementDAOException e) { @@ -161,6 +161,7 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationDAO.deleteTags(appId); applicationDAO.deleteProperties(appId); applicationDAO.deleteApplication(uuid, tenantId); + DataHolder.getInstance().getVisibilityManager().remove(uuid); ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); @@ -189,7 +190,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.getUuid())); + } + return applicationList; } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -206,7 +211,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 +307,9 @@ public class ApplicationManagerImpl implements ApplicationManager { } try { 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 { ConnectionManagerUtil.closeDBConnection(); } @@ -344,12 +351,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 * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java index 612b041233..18c487208e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java @@ -17,30 +17,108 @@ */ package org.wso2.carbon.device.application.mgt.core.impl; +import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Visibility; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException; +import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException; import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; +import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; +import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; +import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; /** - * This is the defaut implementation for the visibility manager. + * This is the default implementation for the visibility manager. */ public class VisibilityManagerImpl implements VisibilityManager { - @Override - public void addVisibilityMapping(String applicationId, Visibility visibility) { - - } @Override - public Visibility getVisibility(String applicationId) { - return null; + public void put(String applicationUUID, Visibility visibility) throws VisibilityManagementException { + 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 - 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 - 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(); + } + } } + } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java index 426b13b02e..a153b0bc14 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java @@ -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; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java index 1a808090ef..3ea5dcf23f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java @@ -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); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java index de1a03255b..8f8868a000 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java @@ -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); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java index ce957da19e..5122f5e137 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java @@ -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 getCurrentConnection() { return currentConnection; diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 4845697026..5c6d5558a3 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -352,27 +352,20 @@ CREATE TABLE IF NOT EXISTS `APPM_VISIBILITY` ( `ID` INT NOT NULL AUTO_INCREMENT, `VALUE` VARCHAR(255) NOT NULL, `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; From 2d4de10c6c5d3d481ada47e756a567fe0230c5ae Mon Sep 17 00:00:00 2001 From: sinthuja Date: Wed, 6 Sep 2017 17:43:44 +0530 Subject: [PATCH 3/5] Adding some fixes for the application management and visibility management. --- .../common/services/ApplicationManager.java | 16 ++-- .../common/services/VisibilityManager.java | 12 +-- .../GenericApplicationDAOImpl.java | 6 +- .../visibility/GenericVisibilityDAOImpl.java | 34 +++---- .../mgt/core/impl/ApplicationManagerImpl.java | 49 +++++----- .../mgt/core/impl/VisibilityManagerImpl.java | 91 ++++++++----------- .../dbscripts/cdm/application-mgt/h2.sql | 25 +++-- .../dbscripts/cdm/application-mgt/mssql.sql | 1 - .../dbscripts/cdm/application-mgt/mysql.sql | 9 +- .../dbscripts/cdm/application-mgt/oracle.sql | 1 - .../cdm/application-mgt/postgresql.sql | 1 - 11 files changed, 115 insertions(+), 130 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 89a46e8bd8..7fd542e1d7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -37,7 +37,7 @@ public interface ApplicationManager { * @return Created application * @throws ApplicationManagementException Application Management Exception */ - public Application createApplication(Application application) throws ApplicationManagementException; + Application createApplication(Application application) throws ApplicationManagementException; /** * Updates an already existing application. @@ -45,14 +45,14 @@ public interface ApplicationManager { * @return Updated Application * @throws ApplicationManagementException Application Management Exception */ - public Application editApplication(Application application) throws ApplicationManagementException; + Application editApplication(Application application) throws ApplicationManagementException; /** * Delete an application identified by the unique ID. * @param uuid Unique ID for tha application * @throws ApplicationManagementException Application Management Exception */ - public void deleteApplication(String uuid) throws ApplicationManagementException; + void deleteApplication(String uuid) throws ApplicationManagementException; /** * To get the applications based on the search filter. @@ -60,7 +60,7 @@ public interface ApplicationManager { * @return Applications that matches the given filter criteria. * @throws ApplicationManagementException Application Management Exception */ - public ApplicationList getApplications(Filter filter) throws ApplicationManagementException; + ApplicationList getApplications(Filter filter) throws ApplicationManagementException; /** * To change the lifecycle of the Application. @@ -69,7 +69,7 @@ public interface ApplicationManager { * @param lifecycleIdentifier New life-cycle that need to be changed. * @throws ApplicationManagementException Application Management Exception. */ - public void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws + void changeLifecycle(String applicationUuid, String lifecycleIdentifier) throws ApplicationManagementException; /** @@ -79,7 +79,7 @@ public interface ApplicationManager { * @return the List of possible states * @throws ApplicationManagementException Application Management Exception */ - public List getLifeCycleStates(String applicationUUID) + List getLifeCycleStates(String applicationUUID) throws ApplicationManagementException; /** @@ -89,7 +89,5 @@ public interface ApplicationManager { * @return the Application identified by the UUID * @throws ApplicationManagementException Application Management Exception. */ - public Application getApplication(String uuid) throws ApplicationManagementException; - - + Application getApplication(String uuid) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java index f8983ef85d..e8eedb666d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/VisibilityManager.java @@ -35,23 +35,23 @@ public interface VisibilityManager { * Update (if there is already existing configuration for the application) * the visibility related configuration for the application * - * @param applicationUUID The ID of the application + * @param applicationID The ID of the application * @param visibility The visibility configuration for the particular application. */ - void put(String applicationUUID, Visibility visibility) throws VisibilityManagementException; + Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException; /** * Returns the Visibility configuration of the provided applicationUUID. * - * @param applicationUUID The ID of the application + * @param applicationID The ID of the application * @return Visibility configuration */ - Visibility get(String applicationUUID) throws VisibilityManagementException; + Visibility get(int applicationID) throws VisibilityManagementException; /** * Remove the visibility configuration mapping for the provided application. * - * @param applicationUUID The ID of the application + * @param applicationID The ID of the application */ - void remove(String applicationUUID) throws VisibilityManagementException; + void remove(int applicationID) throws VisibilityManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 3aca533e85..966873f957 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -71,7 +71,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "VIDEO_NAME, SCREEN_SHOT_COUNT, CREATED_BY, CREATED_AT, MODIFIED_AT, " + "APPLICATION_CATEGORY_ID, PLATFORM_ID, TENANT_ID, LIFECYCLE_STATE_ID, " + "LIFECYCLE_STATE_MODIFIED_AT, LIFECYCLE_STATE_MODIFIED_BY) VALUES " - + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt.setString(++index, application.getUuid()); @@ -132,7 +132,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); - sql += "SELECT APP.*, APL.NAME AS APL_NAME, " + sql += "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER," + "CAT.ID AS CAT_ID, CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, " + "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS " + "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON " @@ -265,7 +265,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); - sql += "SELECT APP.*, APL.NAME AS APL_NAME, " + sql += "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER," + "CAT.ID AS CAT_ID, CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, " + "LS.DESCRIPTION AS LS_DESCRIPTION FROM APPM_APPLICATION AS APP INNER JOIN APPM_PLATFORM AS " + "APL ON APP.PLATFORM_ID = APL.ID INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON " diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java index 86bfd3ad8f..82c07f5dea 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java @@ -51,11 +51,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil } return -1; } catch (DBConnectionException e) { - throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + - "for the visibility management of applicatons"); + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " + + "for the visibility management of applications", e); } catch (SQLException e) { - throw new VisibilityManagementDAOException("Error occured when trying to get the ID of the" + - " visibility type - " + visibilityType.toString()); + throw new VisibilityManagementDAOException("Error occurred when trying to get the ID of the" + + " visibility type - " + visibilityType.toString(), e); } finally { Util.cleanupResources(stmt, resultSet); } @@ -67,7 +67,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil PreparedStatement stmt = null; try { Connection connection = getDBConnection(); - String sql = "INSERT INTO APPM_VISIBILITY (?, ?, ?)"; + String sql = "INSERT INTO APPM_VISIBILITY (VALUE, RESOURCE_TYPE_ID, APPLICATION_ID) VALUES (?, ?, ?)"; stmt = connection.prepareStatement(sql); if (allowedList == null) { stmt.setString(1, null); @@ -84,11 +84,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil stmt.executeBatch(); } } catch (DBConnectionException e) { - throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + - "for adding the visibility mapping for the application ID - " + applicationID); + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " + + "for adding the visibility mapping for the application ID - " + applicationID, e); } catch (SQLException e) { - throw new VisibilityManagementDAOException("Error occured while adding the visibility mapping " + - "for the application ID - " + applicationID); + throw new VisibilityManagementDAOException("Error occurred while adding the visibility mapping " + + "for the application ID - " + applicationID, e); } finally { Util.cleanupResources(stmt, null); } @@ -104,11 +104,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil stmt.setInt(1, applicationId); stmt.execute(); } catch (DBConnectionException e) { - throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + - "for deleting the visibility mapping for the application ID - " + applicationId); + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " + + "for deleting the visibility mapping for the application ID - " + applicationId, e); } catch (SQLException e) { - throw new VisibilityManagementDAOException("Error occured while deleting the visibility mapping " + - "for the application ID - " + applicationId); + throw new VisibilityManagementDAOException("Error occurred while deleting the visibility mapping " + + "for the application ID - " + applicationId, e); } finally { Util.cleanupResources(stmt, null); } @@ -144,11 +144,11 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil } return visibility; } catch (DBConnectionException e) { - throw new VisibilityManagementDAOException("Error occured while obtaining the connection " + - "for getting the visibility mapping for the application ID - " + applicationId); + throw new VisibilityManagementDAOException("Error occurred while obtaining the connection " + + "for getting the visibility mapping for the application ID - " + applicationId, e); } catch (SQLException e) { - throw new VisibilityManagementDAOException("Error occured while getting the visibility mapping " + - "for the application ID - " + applicationId); + throw new VisibilityManagementDAOException("Error occurred while getting the visibility mapping " + + "for the application ID - " + applicationId, e); } finally { Util.cleanupResources(stmt, resultSet); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 72eff22a86..fb3ea6b54f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -22,19 +22,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.Application; -import org.wso2.carbon.device.application.mgt.common.ApplicationList; -import org.wso2.carbon.device.application.mgt.common.Filter; -import org.wso2.carbon.device.application.mgt.common.Lifecycle; -import org.wso2.carbon.device.application.mgt.common.LifecycleState; -import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; -import org.wso2.carbon.device.application.mgt.common.Platform; -import org.wso2.carbon.device.application.mgt.common.User; +import org.wso2.carbon.device.application.mgt.common.*; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; -import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; @@ -71,14 +63,15 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setCreatedAt(new Date()); application.setModifiedAt(new Date()); try { - ConnectionManagerUtil.beginDBTransaction(); + Platform platform = DataHolder.getInstance().getPlatformManager().getPlatform(application.getUser() + .getTenantId(), application.getPlatform().getIdentifier()); - // Validating the platform - Platform platform = DataHolder.getInstance().getPlatformManager() - .getPlatform(application.getUser().getTenantId(), application.getPlatform().getIdentifier()); if (platform == null) { throw new NotFoundException("Invalid platform"); } + ConnectionManagerUtil.beginDBTransaction(); + + // Validating the platform application.setPlatform(platform); if (log.isDebugEnabled()) { log.debug("Application creation pre-conditions are met and the platform mentioned by identifier " @@ -97,6 +90,7 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setCurrentLifecycle(lifecycle); application = DAOFactory.getApplicationDAO().createApplication(application); + DataHolder.getInstance().getVisibilityManager().put(application.getId(), application.getVisibility()); ConnectionManagerUtil.commitDBTransaction(); return application; } catch (ApplicationManagementException e) { @@ -120,24 +114,27 @@ public class ApplicationManagerImpl implements ApplicationManager { + "application with the UUID " + application.getUuid()); } try { - ConnectionManagerUtil.beginDBTransaction(); if (application.getPlatform() != null && application.getPlatform().getIdentifier() != null) { Platform platform = DataHolder.getInstance().getPlatformManager() .getPlatform(tenantId, application.getPlatform().getIdentifier()); if (platform == null) { - ConnectionManagerUtil.commitDBTransaction(); throw new NotFoundException( "Platform specified by identifier " + application.getPlatform().getIdentifier() + " is not found. Please give a valid platform identifier."); } application.setPlatform(platform); + ConnectionManagerUtil.beginDBTransaction(); + ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); + application.setModifiedAt(new Date()); + Application modifiedApplication = applicationDAO.editApplication(application, tenantId); + Visibility visibility = DataHolder.getInstance().getVisibilityManager().put(application.getId(), + application.getVisibility()); + modifiedApplication.setVisibility(visibility); + ConnectionManagerUtil.commitDBTransaction(); + return modifiedApplication; + } else { + throw new NotFoundException("Platform information not available with the application!"); } - ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); - application.setModifiedAt(new Date()); - Application modifiedApplication = applicationDAO.editApplication(application, tenantId); - DataHolder.getInstance().getVisibilityManager().put(application.getUuid(), application.getVisibility()); - ConnectionManagerUtil.commitDBTransaction(); - return modifiedApplication; } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); throw e; @@ -160,8 +157,8 @@ public class ApplicationManagerImpl implements ApplicationManager { int appId = applicationDAO.getApplicationId(uuid, tenantId); applicationDAO.deleteTags(appId); applicationDAO.deleteProperties(appId); + DataHolder.getInstance().getVisibilityManager().remove(appId); applicationDAO.deleteApplication(uuid, tenantId); - DataHolder.getInstance().getVisibilityManager().remove(uuid); ConnectionManagerUtil.commitDBTransaction(); } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); @@ -192,7 +189,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO(); ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); for (Application application : applicationList.getApplications()) { - application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getUuid())); + application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId())); } return applicationList; } finally { @@ -307,8 +304,10 @@ public class ApplicationManagerImpl implements ApplicationManager { } try { ConnectionManagerUtil.openDBConnection(); - Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName); - application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(uuid)); + Application application = DAOFactory.getApplicationDAO().getApplication(uuid, tenantId, userName); + if (application != null) { + application.setVisibility(DataHolder.getInstance().getVisibilityManager().get(application.getId())); + } return application; } finally { ConnectionManagerUtil.closeDBConnection(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java index 18c487208e..e12a20fab0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java @@ -17,16 +17,12 @@ */ package org.wso2.carbon.device.application.mgt.core.impl; -import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Visibility; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; -import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; -import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException; import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException; import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.DAOFactory; -import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; /** @@ -35,36 +31,35 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; public class VisibilityManagerImpl implements VisibilityManager { @Override - public void put(String applicationUUID, Visibility visibility) throws VisibilityManagementException { + public Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException { + if (visibility == null){ + visibility = new Visibility(); + visibility.setType(Visibility.Type.PUBLIC); + } if (visibility.getAllowedList() == null && !visibility.getType().equals(Visibility.Type.PUBLIC)) { throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType() + "' but doesn't have any allowed list provided!"); } boolean isTransactionStarted = false; try { - Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID); - if (application != null) { - isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); - if (!isTransactionStarted) { - ConnectionManagerUtil.beginDBTransaction(); - } - int id = application.getId(); - VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); - int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType()); - visibilityDAO.delete(id); - visibilityDAO.add(id, visibilityTypeId, visibility.getAllowedList()); - if (!isTransactionStarted) { - ConnectionManagerUtil.commitDBTransaction(); - } - } else { - throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID); + isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); + if (!isTransactionStarted) { + ConnectionManagerUtil.beginDBTransaction(); } + VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); + int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType()); + visibilityDAO.delete(applicationID); + visibilityDAO.add(applicationID, visibilityTypeId, visibility.getAllowedList()); + if (!isTransactionStarted) { + ConnectionManagerUtil.commitDBTransaction(); + } + return visibility; } catch (ApplicationManagementException e) { - if (!isTransactionStarted){ + if (!isTransactionStarted) { ConnectionManagerUtil.rollbackDBTransaction(); } - throw new VisibilityManagementException("Problem occured when trying to fetch the application with UUID - " - + applicationUUID, e); + throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - " + + applicationID, e); } finally { if (!isTransactionStarted) { ConnectionManagerUtil.closeDBConnection(); @@ -73,47 +68,39 @@ public class VisibilityManagerImpl implements VisibilityManager { } @Override - public Visibility get(String applicationUUID) throws VisibilityManagementException { + public Visibility get(int applicationID) throws VisibilityManagementException { try { - Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID); - if (application != null) { - int id = application.getId(); - VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); - return visibilityDAO.get(id); - } else { - throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID); + VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); + Visibility visibility = visibilityDAO.get(applicationID); + if (visibility.getType() == null && (visibility.getAllowedList() == null || visibility.getAllowedList().isEmpty())){ + visibility.setType(Visibility.Type.PUBLIC); } + return visibility; } catch (ApplicationManagementException e) { - throw new VisibilityManagementException("Problem occured when trying to fetch the application with UUID - " - + applicationUUID, e); + throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - " + + applicationID, e); } } @Override - public void remove(String applicationUUID) throws VisibilityManagementException { + public void remove(int applicationID) throws VisibilityManagementException { boolean isTransactionStarted = false; try { - Application application = DataHolder.getInstance().getApplicationManager().getApplication(applicationUUID); - if (application != null) { - isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); - if (!isTransactionStarted) { - ConnectionManagerUtil.beginDBTransaction(); - } - int id = application.getId(); - VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); - visibilityDAO.delete(id); - if (!isTransactionStarted) { - ConnectionManagerUtil.commitDBTransaction(); - } - } else { - throw new VisibilityManagementException("No application was found with application UUID - " + applicationUUID); + isTransactionStarted = ConnectionManagerUtil.isTransactionStarted(); + if (!isTransactionStarted) { + ConnectionManagerUtil.beginDBTransaction(); + } + VisibilityDAO visibilityDAO = DAOFactory.getVisibilityDAO(); + visibilityDAO.delete(applicationID); + if (!isTransactionStarted) { + ConnectionManagerUtil.commitDBTransaction(); } } catch (ApplicationManagementException e) { - if (!isTransactionStarted){ + if (!isTransactionStarted) { ConnectionManagerUtil.rollbackDBTransaction(); } - throw new VisibilityManagementException("Problem occurred when trying to fetch the application with UUID - " - + applicationUUID, e); + throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - " + + applicationID, e); } finally { if (!isTransactionStarted) { ConnectionManagerUtil.closeDBConnection(); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 809efada34..994d61a08b 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -7,7 +7,6 @@ -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( ID INT NOT NULL AUTO_INCREMENT UNIQUE, -IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN, @@ -220,6 +219,13 @@ CREATE TABLE IF NOT EXISTS APPM_RESOURCE_TYPE ( DESCRIPTION TEXT NULL, PRIMARY KEY (ID)); +INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('PUBLIC', 'OPEN VISIBILITY, CAN BE VIEWED BY ALL LOGGED IN USERS'); +INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('ROLES', 'ROLE BASED RESTRICTION, CAN BE VIEWED BY ONLY GIVEN + SET OF USER WHO HAVE THE SPECIFIED ROLE'); +INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('DEVICE_GROUPS', 'DEVICE GROUP LEVEL RESTRICTION, +CAN BE VIEWED BY THE DEVICES/ROLES BELONG TO THE GROUP'); + + -- ----------------------------------------------------- -- Table APPM_SUBSCRIPTION -- ----------------------------------------------------- @@ -310,29 +316,22 @@ CREATE INDEX FK_APPLICATION_TAG_APPLICATION ON APPM_APPLICATION_TAG(APPLICATION_ -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_VISIBILITY ( ID INT NOT NULL AUTO_INCREMENT, - VALUE VARCHAR(255) NOT NULL, + VALUE VARCHAR(255), RESOURCE_TYPE_ID INT NOT NULL, - APPLICATION_RELEASE_ID INT NULL, APPLICATION_ID INT NULL, PRIMARY KEY (ID, RESOURCE_TYPE_ID), CONSTRAINT fk_APPM_VISIBILITY_APPM_RESOURCE_TYPE1 FOREIGN KEY (RESOURCE_TYPE_ID) REFERENCES APPM_RESOURCE_TYPE (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION, - CONSTRAINT fk_APPM_VISIBILITY_APPM_APPLICATION_RELEASE1 - FOREIGN KEY (APPLICATION_RELEASE_ID) - REFERENCES APPM_APPLICATION_RELEASE (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION, + ON DELETE CASCADE, + ON UPDATE CASCADE, CONSTRAINT fk_APPM_VISIBILITY_APPM_APPLICATION1 FOREIGN KEY (APPLICATION_ID) REFERENCES APPM_APPLICATION (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION); + ON DELETE CASCADE, + ON UPDATE CASCADE); CREATE INDEX FK_APPM_VISIBILITY_RESOURCE_TYPE ON APPM_VISIBILITY(RESOURCE_TYPE_ID ASC); -CREATE INDEX FK_VISIBILITY_APPLICATION_RELEASE ON APPM_VISIBILITY(APPLICATION_RELEASE_ID ASC); CREATE INDEX FK_VISIBILITY_APPLICATION ON APPM_VISIBILITY(APPLICATION_ID ASC); -- ----------------------------------------------------- diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index d8c578a585..e427751956 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -1,7 +1,6 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM]') AND TYPE IN (N'U')) CREATE TABLE APPM_PLATFORM ( ID INT IDENTITY(1,1) NOT NULL UNIQUE, - IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BIT, diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 5c6d5558a3..52fe5701e0 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -16,7 +16,6 @@ SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( ID INT NOT NULL AUTO_INCREMENT UNIQUE, -IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN, @@ -233,6 +232,12 @@ CREATE TABLE IF NOT EXISTS `APPM_RESOURCE_TYPE` ( PRIMARY KEY (`ID`)) ENGINE = InnoDB; +INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('PUBLIC', 'OPEN VISIBILITY, CAN BE VIEWED BY ALL LOGGED IN USERS'); +INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('ROLES', 'ROLE BASED RESTRICTION, CAN BE VIEWED BY ONLY GIVEN + SET OF USER WHO HAVE THE SPECIFIED ROLE'); +INSERT INTO APPM_RESOURCE_TYPE (NAME , DESCRIPTION) VALUES ('DEVICE_GROUPS', 'DEVICE GROUP LEVEL RESTRICTION, +CAN BE VIEWED BY THE DEVICES/ROLES BELONG TO THE GROUP'); + -- ----------------------------------------------------- -- Table `APPM_SUBSCRIPTION` @@ -350,7 +355,7 @@ CREATE TABLE IF NOT EXISTS `APPM_APPLICATION_TAG` ( -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `APPM_VISIBILITY` ( `ID` INT NOT NULL AUTO_INCREMENT, - `VALUE` VARCHAR(255) NOT NULL, + `VALUE` VARCHAR(255), `RESOURCE_TYPE_ID` INT NOT NULL, `APPLICATION_ID` INT NULL, PRIMARY KEY (`ID`), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql index b4b845e77c..dde3b71e3f 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql @@ -7,7 +7,6 @@ -- ----------------------------------------------------- CREATE TABLE APPM_PLATFORM ( ID INT UNIQUE, -IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED NUMBER (1), diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index 6616a56c2a..3569edfbbf 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -4,7 +4,6 @@ CREATE SEQUENCE APPM_PLATFORM_PK_SEQ; CREATE TABLE APPM_PLATFORM ( ID INT DEFAULT NEXTVAL('APPM_PLATFORM_PK_SEQ') UNIQUE, -IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN, From d0edbb8aa7715d8e0bd06e278e4e85893fc60925 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Thu, 7 Sep 2017 12:25:54 +0530 Subject: [PATCH 4/5] Committing the fixes for the database schema. --- .../resources/dbscripts/cdm/application-mgt/h2.sql | 13 +++++++------ .../dbscripts/cdm/application-mgt/mssql.sql | 3 ++- .../dbscripts/cdm/application-mgt/mysql.sql | 4 ++-- .../dbscripts/cdm/application-mgt/oracle.sql | 3 ++- .../dbscripts/cdm/application-mgt/postgresql.sql | 4 ++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 994d61a08b..323bacca5c 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -7,6 +7,7 @@ -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( ID INT NOT NULL AUTO_INCREMENT UNIQUE, +IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN, @@ -14,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, @@ -120,7 +122,6 @@ INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSIO 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, @@ -319,16 +320,16 @@ CREATE TABLE IF NOT EXISTS APPM_VISIBILITY ( VALUE VARCHAR(255), RESOURCE_TYPE_ID INT NOT 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 CASCADE, - ON UPDATE CASCADE, + ON DELETE NO ACTION + ON UPDATE NO ACTION, CONSTRAINT fk_APPM_VISIBILITY_APPM_APPLICATION1 FOREIGN KEY (APPLICATION_ID) REFERENCES APPM_APPLICATION (ID) - ON DELETE CASCADE, + ON DELETE CASCADE ON UPDATE CASCADE); CREATE INDEX FK_APPM_VISIBILITY_RESOURCE_TYPE ON APPM_VISIBILITY(RESOURCE_TYPE_ID ASC); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index e427751956..42fd4cb36b 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -1,6 +1,7 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM]') AND TYPE IN (N'U')) CREATE TABLE APPM_PLATFORM ( ID INT IDENTITY(1,1) NOT NULL UNIQUE, + IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BIT, @@ -8,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')) diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 52fe5701e0..f11791f007 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -16,6 +16,7 @@ SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( ID INT NOT NULL AUTO_INCREMENT UNIQUE, +IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN, @@ -23,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 ( @@ -121,7 +122,6 @@ INSERT INTO APPM_LIFECYCLE_STATE_TRANSITION(INITIAL_STATE, NEXT_STATE, PERMISSIO 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, diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql index dde3b71e3f..4489a04987 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql @@ -7,6 +7,7 @@ -- ----------------------------------------------------- CREATE TABLE APPM_PLATFORM ( ID INT UNIQUE, +IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED NUMBER (1), @@ -14,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) ) / diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index 3569edfbbf..7a309c09fb 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -4,6 +4,7 @@ CREATE SEQUENCE APPM_PLATFORM_PK_SEQ; CREATE TABLE APPM_PLATFORM ( ID INT DEFAULT NEXTVAL('APPM_PLATFORM_PK_SEQ') UNIQUE, +IDENTIFIER VARCHAR (100) NOT NULL, TENANT_ID INT NOT NULL , NAME VARCHAR (255), FILE_BASED BOOLEAN, @@ -11,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; @@ -137,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, From 9656b9b74702334364d386b8c9b60c7c378e5e15 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Thu, 7 Sep 2017 14:26:50 +0530 Subject: [PATCH 5/5] Fixing the error reported by check styles plugin. --- .../application/mgt/core/dao/CommentDAO.java | 3 + .../mgt/core/dao/SubscriptionDAO.java | 4 ++ .../mgt/core/dao/VisibilityDAO.java | 4 +- .../mgt/core/dao/common/DAOFactory.java | 68 ++++++++++--------- .../GenericApplicationDAOImpl.java | 1 - .../GenericApplicationReleaseDAOImpl.java | 24 +++---- .../visibility/GenericVisibilityDAOImpl.java | 14 ++-- .../mgt/core/impl/ApplicationManagerImpl.java | 10 ++- .../mgt/core/impl/CategoryManagerImpl.java | 4 ++ .../mgt/core/impl/CommentsManagerImpl.java | 3 + .../core/impl/SubscriptionManagerImpl.java | 17 +++-- .../mgt/core/impl/VisibilityManagerImpl.java | 7 +- 12 files changed, 97 insertions(+), 62 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java index f4999c020f..27cbe337e3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java @@ -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 { } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java index 1991c68f9e..010e50203b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/SubscriptionDAO.java @@ -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 { } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/VisibilityDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/VisibilityDAO.java index 6d93e091f0..c1c6a1fd30 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/VisibilityDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/VisibilityDAO.java @@ -24,7 +24,9 @@ import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagemen import java.util.List; /** - * This interface provides the list of operations that are performed in the database layer with respect to the visibility. + * This interface provides the list of operations that are performed in the database + * layer with respect to the visibility. + * */ public interface VisibilityDAO { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java index aad3ab53f4..51a4b39347 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java @@ -25,8 +25,8 @@ 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.ApplicationReleaseDAO; 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.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; @@ -61,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."); @@ -77,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."); @@ -94,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."); @@ -108,18 +108,19 @@ 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."); @@ -127,9 +128,10 @@ public class DAOFactory { /** * To get the instance of VisibilityDAOImplementation of the particular database engine. + * * @return specific VisibilityDAOImplementation */ - public static VisibilityDAO getVisibilityDAO(){ + public static VisibilityDAO getVisibilityDAO() { if (databaseEngine != null) { switch (databaseEngine) { case Constants.DataBaseTypes.DB_TYPE_H2: diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 76a9e33e2e..db1f7fe928 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -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; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java index fd9b2deaef..fb9f371a50 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java @@ -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 { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java index 82c07f5dea..06e9902d8b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java @@ -117,12 +117,12 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil 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"; + final String visibilityTypeColumn = "VISIBILITY_TYPE"; + final String allowedValColumn = "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 " + + 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); @@ -132,14 +132,14 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil List allowedVal = new ArrayList<>(); while (resultSet.next()) { if (visibility.getType() == null) { - visibility.setType(Visibility.Type.valueOf(resultSet.getString(VISIBILITY_TYPE))); + visibility.setType(Visibility.Type.valueOf(resultSet.getString(visibilityTypeColumn))); } - String val = resultSet.getString(ALLOWED_VAL); + String val = resultSet.getString(allowedValColumn); if (val != null) { allowedVal.add(val); } } - if (!allowedVal.isEmpty()){ + if (!allowedVal.isEmpty()) { visibility.setAllowedList(allowedVal); } return visibility; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index fb3ea6b54f..8e2190d117 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -22,7 +22,15 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.*; +import org.wso2.carbon.device.application.mgt.common.Application; +import org.wso2.carbon.device.application.mgt.common.ApplicationList; +import org.wso2.carbon.device.application.mgt.common.Filter; +import org.wso2.carbon.device.application.mgt.common.Lifecycle; +import org.wso2.carbon.device.application.mgt.common.LifecycleState; +import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; +import org.wso2.carbon.device.application.mgt.common.Platform; +import org.wso2.carbon.device.application.mgt.common.User; +import org.wso2.carbon.device.application.mgt.common.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; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java index c165a58fc0..58089fa300 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CategoryManagerImpl.java @@ -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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index fbecc5a7eb..23c5903344 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -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 { } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java index 29adbbab6c..0c89f63114 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -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 installApplicationForDevices(String applicationUUID, List deviceList) throws ApplicationManagementException { + public List installApplicationForDevices(String applicationUUID, + List 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 installApplicationForUsers(String applicationUUID, List userList) throws ApplicationManagementException { + public List installApplicationForUsers(String applicationUUID, List 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 installApplicationForRoles(String applicationUUID, List roleList) throws ApplicationManagementException { + public List installApplicationForRoles(String applicationUUID, List 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 uninstallApplication(String applicationUUID, List deviceList) throws ApplicationManagementException { + public List uninstallApplication(String applicationUUID, + List deviceList) + throws ApplicationManagementException { return null; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java index e12a20fab0..85d032c561 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/VisibilityManagerImpl.java @@ -32,7 +32,7 @@ public class VisibilityManagerImpl implements VisibilityManager { @Override public Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException { - if (visibility == null){ + if (visibility == null) { visibility = new Visibility(); visibility.setType(Visibility.Type.PUBLIC); } @@ -71,8 +71,9 @@ public class VisibilityManagerImpl implements VisibilityManager { 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 visibility = visibilityDAO.get(applicationID); + if (visibility.getType() == null && (visibility.getAllowedList() == null || + visibility.getAllowedList().isEmpty())) { visibility.setType(Visibility.Type.PUBLIC); } return visibility;