From 030d7cd26d93907c404af62d3087df7f865e002f Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Fri, 13 Oct 2017 19:07:19 +0530 Subject: [PATCH] Removed unused code --- .../mgt/common/PolicyAdministratorPoint.java | 6 - .../policy/mgt/core/dao/FeatureDAO.java | 16 +- .../dao/impl/feature/AbstractFeatureDAO.java | 29 +-- .../impl/PolicyAdministratorPointImpl.java | 16 -- .../policy/mgt/core/mgt/FeatureManager.java | 19 +- .../mgt/core/mgt/impl/FeatureManagerImpl.java | 195 +++++------------- 6 files changed, 62 insertions(+), 219 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java index 91e1eff05c7..eab6f6214fb 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java @@ -154,11 +154,5 @@ public interface PolicyAdministratorPoint { List getProfiles() throws PolicyManagementException; -// Feature addFeature(Feature feature) throws FeatureManagementException; -// -// Feature updateFeature(Feature feature) throws FeatureManagementException; - - boolean deleteFeature(int featureId) throws FeatureManagementException; - int getPolicyCount() throws PolicyManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java index e64b8214df7..00d7280a9d4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java @@ -96,15 +96,6 @@ public interface FeatureDAO { */ List getFeaturesForProfile(int profileId) throws FeatureManagerDAOException; - /** - * This method is used remove a feature. - * - * @param featureId id of the removing feature. - * @return returns true if success. - * @throws FeatureManagerDAOException - */ - boolean deleteFeature(int featureId) throws FeatureManagerDAOException; - /** * This method is used to remove set of features of given profile. * @@ -123,6 +114,13 @@ public interface FeatureDAO { */ boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException; + /** + * This method is used to remove a profile feature of given feature id. + * + * @param featureId id of the feature. + * @return returns true if success. + * @throws FeatureManagerDAOException + */ boolean deleteProfileFeatures(int featureId) throws FeatureManagerDAOException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/feature/AbstractFeatureDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/feature/AbstractFeatureDAO.java index 2c3da0e30c5..8d04fdec5b5 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/feature/AbstractFeatureDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/feature/AbstractFeatureDAO.java @@ -30,6 +30,7 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; +import javax.naming.OperationNotSupportedException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; @@ -49,13 +50,13 @@ public abstract class AbstractFeatureDAO implements FeatureDAO { @Override public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException { - return null; + throw new UnsupportedOperationException(); } @Override public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException { - return null; + throw new UnsupportedOperationException(); } @Override @@ -311,30 +312,6 @@ public abstract class AbstractFeatureDAO implements FeatureDAO { return featureList; } - @Override - public boolean deleteFeature(int featureId) throws FeatureManagerDAOException { - Connection conn; - PreparedStatement stmt = null; - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - - try { - conn = this.getConnection(); - String query = "DELETE FROM DM_FEATURES WHERE ID = ? AND TENANT_ID = ?"; - stmt = conn.prepareStatement(query); - stmt.setInt(1, featureId); - stmt.setInt(2, tenantId); - if(stmt.executeUpdate() > 0) { - return true; - } - return false; - } catch (SQLException e) { - throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " + - "from database.", e); - } finally { - PolicyManagementDAOUtil.cleanupResources(stmt, null); - } - } - private Connection getConnection() throws FeatureManagerDAOException { return PolicyManagementDAOFactory.getConnection(); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index 50d58c3bf48..d595a3c4eb3 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -338,22 +338,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { } } - /* @Override - public Feature addFeature(Feature feature) throws FeatureManagementException { - return featureManager.addFeature(feature); - } - - @Override - public Feature updateFeature(Feature feature) throws FeatureManagementException { - return featureManager.updateFeature(feature); - - }*/ - - @Override - public boolean deleteFeature(int featureId) throws FeatureManagementException { - return featureManager.deleteFeature(featureId); - } - @Override public int getPolicyCount() throws PolicyManagementException { return PolicyCacheManagerImpl.getInstance().getAllPolicies().size(); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/FeatureManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/FeatureManager.java index 9c4673a84a3..e0c6f3fdbed 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/FeatureManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/FeatureManager.java @@ -21,36 +21,27 @@ package org.wso2.carbon.policy.mgt.core.mgt; import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import java.util.List; public interface FeatureManager { - /*Feature addFeature(Feature feature) throws FeatureManagementException; - - public List addFeatures(List features) throws FeatureManagementException; - - Feature updateFeature(Feature feature) throws FeatureManagementException;*/ - - boolean deleteFeature(Feature feature) throws FeatureManagementException; - ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException; ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException; - List addProfileFeatures(List features, int profileId) throws FeatureManagementException; - - List updateProfileFeatures(List features, int profileId) throws FeatureManagementException; + List addProfileFeatures(List features, int profileId) + throws FeatureManagementException; + List updateProfileFeatures(List features, int profileId) + throws FeatureManagementException; List getAllFeatures(String deviceType) throws FeatureManagementException; List getFeaturesForProfile(int profileId) throws FeatureManagementException; - boolean deleteFeature(int featureId) throws FeatureManagementException; - boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImpl.java index edaceae3f8b..e507999633d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/FeatureManagerImpl.java @@ -21,13 +21,15 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.device.mgt.common.policy.mgt.Profile; import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO; import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; +import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO; +import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException; import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager; import java.sql.SQLException; @@ -36,130 +38,28 @@ import java.util.List; public class FeatureManagerImpl implements FeatureManager { private FeatureDAO featureDAO; + private ProfileDAO profileDAO; private static Log log = LogFactory.getLog(FeatureManagerImpl.class); public FeatureManagerImpl() { featureDAO = PolicyManagementDAOFactory.getFeatureDAO(); - } - - /*@Override - public Feature addFeature(Feature feature) throws FeatureManagementException { - try { - PolicyManagementDAOFactory.beginTransaction(); - feature = featureDAO.addFeature(feature); - PolicyManagementDAOFactory.commitTransaction(); - - } catch (PolicyManagerDAOException e) { - try { - PolicyManagementDAOFactory.rollbackTransaction(); - } catch (PolicyManagerDAOException e1) { - log.warn("Unable to roll back the transaction"); - } - String msg = "Error occurred while adding feature (" + feature.getName() + ")"; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } catch (FeatureManagerDAOException e) { - try { - PolicyManagementDAOFactory.rollbackTransaction(); - } catch (PolicyManagerDAOException e1) { - log.warn("Unable to roll back the transaction"); - } - String msg = "Error occurred while adding feature (" + feature.getName() + ")"; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } - return feature; - }*/ - - /*@Override - public List addFeatures(List features) throws FeatureManagementException { - try { - PolicyManagementDAOFactory.beginTransaction(); - features = featureDAO.addFeatures(features); - PolicyManagementDAOFactory.commitTransaction(); - - } catch (PolicyManagerDAOException e) { - try { - PolicyManagementDAOFactory.rollbackTransaction(); - } catch (PolicyManagerDAOException e1) { - log.warn("Unable to roll back the transaction"); - } - String msg = "Error occurred while adding feature (" + features.size()+ ")"; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } catch (FeatureManagerDAOException e) { - try { - PolicyManagementDAOFactory.rollbackTransaction(); - } catch (PolicyManagerDAOException e1) { - log.warn("Unable to roll back the transaction"); - } - String msg = "Error occurred while adding feature (" + features.size() + ")"; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } - - return features; - }*/ - - /* @Override - public Feature updateFeature(Feature feature) throws FeatureManagementException { - try { - PolicyManagementDAOFactory.beginTransaction(); - feature = featureDAO.updateFeature(feature); - PolicyManagementDAOFactory.commitTransaction(); - - } catch (PolicyManagerDAOException e) { - try { - PolicyManagementDAOFactory.rollbackTransaction(); - } catch (PolicyManagerDAOException e1) { - log.warn("Unable to roll back the transaction"); - } - String msg = "Error occurred while updating feature (" + feature.getName() + ")"; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } catch (FeatureManagerDAOException e) { - try { - PolicyManagementDAOFactory.rollbackTransaction(); - } catch (PolicyManagerDAOException e1) { - log.warn("Unable to roll back the transaction"); - } - String msg = "Error occurred while updating feature (" + feature.getName() + ")"; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } - return feature; - }*/ - - @Override - public boolean deleteFeature(Feature feature) throws FeatureManagementException { - boolean bool; - try { - PolicyManagementDAOFactory.beginTransaction(); - bool = featureDAO.deleteFeature(feature.getId()); - PolicyManagementDAOFactory.commitTransaction(); - } catch (FeatureManagerDAOException e) { - PolicyManagementDAOFactory.rollbackTransaction(); - throw new FeatureManagementException("Error occurred while deleting the feature (" + feature.getName() + - ")", e); - } catch (PolicyManagerDAOException e) { - PolicyManagementDAOFactory.rollbackTransaction(); - throw new FeatureManagementException("Error occurred while deleting the feature (" + feature.getName() + - ") from database", e); - } finally { - PolicyManagementDAOFactory.closeConnection(); - } - return bool; + profileDAO = PolicyManagementDAOFactory.getProfileDAO(); } @Override public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException { try { PolicyManagementDAOFactory.beginTransaction(); + Profile profile = profileDAO.getProfile(profileId); + if (profile == null) { + throw new FeatureManagementException( + "Could not find a profile with the profile id: " + profileId); + } feature = featureDAO.addProfileFeature(feature, profileId); PolicyManagementDAOFactory.commitTransaction(); - } catch (PolicyManagerDAOException | FeatureManagerDAOException e) { + } catch (ProfileManagerDAOException | PolicyManagerDAOException | FeatureManagerDAOException e) { throw new FeatureManagementException("Error occurred while adding profile feature (" + - feature.getFeatureCode() + " - " + profileId + ")", e); + feature.getFeatureCode() + " - " + profileId + ")", e); } finally { PolicyManagementDAOFactory.closeConnection(); } @@ -168,16 +68,22 @@ public class FeatureManagerImpl implements FeatureManager { @Override public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws - FeatureManagementException { + FeatureManagementException { try { PolicyManagementDAOFactory.beginTransaction(); + Profile profile = profileDAO.getProfile(profileId); + if (profile == null) { + throw new FeatureManagementException( + "Could not find a profile with the profile id: " + profileId); + } feature = featureDAO.updateProfileFeature(feature, profileId); PolicyManagementDAOFactory.commitTransaction(); - } catch (FeatureManagerDAOException | PolicyManagerDAOException e) { + } catch (ProfileManagerDAOException | FeatureManagerDAOException | PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new FeatureManagementException("Error occurred while updating feature (" + - feature.getFeatureCode() + " - " + profileId + ") in database.", e); + feature.getFeatureCode() + " - " + profileId + + ") in database.", e); } finally { PolicyManagementDAOFactory.closeConnection(); } @@ -186,19 +92,24 @@ public class FeatureManagerImpl implements FeatureManager { @Override public List addProfileFeatures(List features, int profileId) throws - FeatureManagementException { + FeatureManagementException { try { PolicyManagementDAOFactory.beginTransaction(); + Profile profile = profileDAO.getProfile(profileId); + if (profile == null) { + throw new FeatureManagementException( + "Could not find a profile with the profile id: " + profileId); + } features = featureDAO.addProfileFeatures(features, profileId); PolicyManagementDAOFactory.commitTransaction(); - } catch (FeatureManagerDAOException e) { + } catch (ProfileManagerDAOException | FeatureManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new FeatureManagementException("Error occurred while adding the features to profile id (" + - profileId + ")", e); + profileId + ")", e); } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new FeatureManagementException("Error occurred while adding the features to profile id (" + - profileId + ") to the database", e); + profileId + ") to the database", e); } finally { PolicyManagementDAOFactory.closeConnection(); } @@ -207,25 +118,29 @@ public class FeatureManagerImpl implements FeatureManager { @Override public List updateProfileFeatures(List features, int profileId) throws - FeatureManagementException { + FeatureManagementException { try { PolicyManagementDAOFactory.beginTransaction(); + Profile profile = profileDAO.getProfile(profileId); + if (profile == null) { + throw new FeatureManagementException( + "Could not find a profile with the profile id: " + profileId); + } features = featureDAO.updateProfileFeatures(features, profileId); PolicyManagementDAOFactory.commitTransaction(); - } catch (FeatureManagerDAOException e) { + } catch (ProfileManagerDAOException | FeatureManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new FeatureManagementException("Error occurred while updating the features to profile id (" + - profileId + ")", e); + profileId + ")", e); } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new FeatureManagementException("Error occurred while updating the features to profile id (" + - profileId + ") to the database", e); + profileId + ") to the database", e); } finally { PolicyManagementDAOFactory.closeConnection(); } return features; } - @Override public List getAllFeatures(String deviceType) throws FeatureManagementException { @@ -245,8 +160,13 @@ public class FeatureManagerImpl implements FeatureManager { public List getFeaturesForProfile(int profileId) throws FeatureManagementException { try { PolicyManagementDAOFactory.openConnection(); + Profile profile = profileDAO.getProfile(profileId); + if (profile == null) { + throw new FeatureManagementException( + "Could not find a profile with the profile id: " + profileId); + } return featureDAO.getFeaturesForProfile(profileId); - } catch (FeatureManagerDAOException e) { + } catch (ProfileManagerDAOException | FeatureManagerDAOException e) { throw new FeatureManagementException("Error occurred while getting the features", e); } catch (SQLException e) { throw new FeatureManagementException("Error occurred while opening a connection to the data source", e); @@ -255,27 +175,6 @@ public class FeatureManagerImpl implements FeatureManager { } } - @Override - public boolean deleteFeature(int featureId) throws FeatureManagementException { - boolean bool; - try { - PolicyManagementDAOFactory.beginTransaction(); - bool = featureDAO.deleteFeature(featureId); - PolicyManagementDAOFactory.commitTransaction(); - } catch (FeatureManagerDAOException e) { - PolicyManagementDAOFactory.rollbackTransaction(); - throw new FeatureManagementException("Error occurred while deleting the feature - id (" + - featureId + ")", e); - } catch (PolicyManagerDAOException e) { - PolicyManagementDAOFactory.rollbackTransaction(); - throw new FeatureManagementException("Error occurred while deleting the feature - id (" + featureId + - ") from database.", e); - } finally { - PolicyManagementDAOFactory.closeConnection(); - } - return bool; - } - @Override public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException { boolean bool; @@ -286,11 +185,11 @@ public class FeatureManagerImpl implements FeatureManager { } catch (FeatureManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new FeatureManagementException("Error occurred while deleting the feature of - profile (" + - profile.getProfileName() + ")", e); + profile.getProfileName() + ")", e); } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new FeatureManagementException("Error occurred while deleting the feature of - profile (" + - profile.getProfileName() + ") from database", e); + profile.getProfileName() + ") from database", e); } finally { PolicyManagementDAOFactory.closeConnection(); }