Removed unused code

revert-70aa11f8
Rasika Perera 7 years ago
parent 38376b5f00
commit 030d7cd26d

@ -154,11 +154,5 @@ public interface PolicyAdministratorPoint {
List<Profile> getProfiles() throws PolicyManagementException; List<Profile> 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; int getPolicyCount() throws PolicyManagementException;
} }

@ -96,15 +96,6 @@ public interface FeatureDAO {
*/ */
List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagerDAOException; List<ProfileFeature> 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. * 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; 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; boolean deleteProfileFeatures(int featureId) throws FeatureManagerDAOException;
} }

@ -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.dao.util.PolicyManagementDAOUtil;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import javax.naming.OperationNotSupportedException;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
@ -49,13 +50,13 @@ public abstract class AbstractFeatureDAO implements FeatureDAO {
@Override @Override
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException { public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
return null; throw new UnsupportedOperationException();
} }
@Override @Override
public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws
FeatureManagerDAOException { FeatureManagerDAOException {
return null; throw new UnsupportedOperationException();
} }
@Override @Override
@ -311,30 +312,6 @@ public abstract class AbstractFeatureDAO implements FeatureDAO {
return featureList; 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 { private Connection getConnection() throws FeatureManagerDAOException {
return PolicyManagementDAOFactory.getConnection(); return PolicyManagementDAOFactory.getConnection();
} }

@ -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 @Override
public int getPolicyCount() throws PolicyManagementException { public int getPolicyCount() throws PolicyManagementException {
return PolicyCacheManagerImpl.getInstance().getAllPolicies().size(); return PolicyCacheManagerImpl.getInstance().getAllPolicies().size();

@ -21,36 +21,27 @@ package org.wso2.carbon.policy.mgt.core.mgt;
import org.wso2.carbon.device.mgt.common.Feature; 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.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
import java.util.List; import java.util.List;
public interface FeatureManager { public interface FeatureManager {
/*Feature addFeature(Feature feature) throws FeatureManagementException;
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagementException;
Feature updateFeature(Feature feature) throws FeatureManagementException;*/
boolean deleteFeature(Feature feature) throws FeatureManagementException;
ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException; ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException;
ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException; ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException;
List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagementException; List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId)
throws FeatureManagementException;
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws FeatureManagementException;
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId)
throws FeatureManagementException;
List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException; List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException;
List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagementException; List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagementException;
boolean deleteFeature(int featureId) throws FeatureManagementException;
boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException; boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException;
} }

@ -21,13 +21,15 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Feature; 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.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature; 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.FeatureDAO;
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException; 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.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; 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 org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
import java.sql.SQLException; import java.sql.SQLException;
@ -36,130 +38,28 @@ import java.util.List;
public class FeatureManagerImpl implements FeatureManager { public class FeatureManagerImpl implements FeatureManager {
private FeatureDAO featureDAO; private FeatureDAO featureDAO;
private ProfileDAO profileDAO;
private static Log log = LogFactory.getLog(FeatureManagerImpl.class); private static Log log = LogFactory.getLog(FeatureManagerImpl.class);
public FeatureManagerImpl() { public FeatureManagerImpl() {
featureDAO = PolicyManagementDAOFactory.getFeatureDAO(); featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
} profileDAO = PolicyManagementDAOFactory.getProfileDAO();
/*@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<Feature> addFeatures(List<Feature> 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;
} }
@Override @Override
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException { public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagementException {
try { try {
PolicyManagementDAOFactory.beginTransaction(); 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); feature = featureDAO.addProfileFeature(feature, profileId);
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (PolicyManagerDAOException | FeatureManagerDAOException e) { } catch (ProfileManagerDAOException | PolicyManagerDAOException | FeatureManagerDAOException e) {
throw new FeatureManagementException("Error occurred while adding profile feature (" + throw new FeatureManagementException("Error occurred while adding profile feature (" +
feature.getFeatureCode() + " - " + profileId + ")", e); feature.getFeatureCode() + " - " + profileId + ")", e);
} finally { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
@ -168,16 +68,22 @@ public class FeatureManagerImpl implements FeatureManager {
@Override @Override
public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws public ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws
FeatureManagementException { FeatureManagementException {
try { try {
PolicyManagementDAOFactory.beginTransaction(); 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); feature = featureDAO.updateProfileFeature(feature, profileId);
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (FeatureManagerDAOException | PolicyManagerDAOException e) { } catch (ProfileManagerDAOException | FeatureManagerDAOException | PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new FeatureManagementException("Error occurred while updating feature (" + throw new FeatureManagementException("Error occurred while updating feature (" +
feature.getFeatureCode() + " - " + profileId + ") in database.", e); feature.getFeatureCode() + " - " + profileId +
") in database.", e);
} finally { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
@ -186,19 +92,24 @@ public class FeatureManagerImpl implements FeatureManager {
@Override @Override
public List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws public List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagementException { FeatureManagementException {
try { try {
PolicyManagementDAOFactory.beginTransaction(); 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); features = featureDAO.addProfileFeatures(features, profileId);
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (FeatureManagerDAOException e) { } catch (ProfileManagerDAOException | FeatureManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new FeatureManagementException("Error occurred while adding the features to profile id (" + throw new FeatureManagementException("Error occurred while adding the features to profile id (" +
profileId + ")", e); profileId + ")", e);
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new FeatureManagementException("Error occurred while adding the features to profile id (" + throw new FeatureManagementException("Error occurred while adding the features to profile id (" +
profileId + ") to the database", e); profileId + ") to the database", e);
} finally { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
@ -207,26 +118,30 @@ public class FeatureManagerImpl implements FeatureManager {
@Override @Override
public List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws public List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagementException { FeatureManagementException {
try { try {
PolicyManagementDAOFactory.beginTransaction(); 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); features = featureDAO.updateProfileFeatures(features, profileId);
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (FeatureManagerDAOException e) { } catch (ProfileManagerDAOException | FeatureManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new FeatureManagementException("Error occurred while updating the features to profile id (" + throw new FeatureManagementException("Error occurred while updating the features to profile id (" +
profileId + ")", e); profileId + ")", e);
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new FeatureManagementException("Error occurred while updating the features to profile id (" + throw new FeatureManagementException("Error occurred while updating the features to profile id (" +
profileId + ") to the database", e); profileId + ") to the database", e);
} finally { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
return features; return features;
} }
@Override @Override
public List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException { public List<Feature> getAllFeatures(String deviceType) throws FeatureManagementException {
try { try {
@ -245,8 +160,13 @@ public class FeatureManagerImpl implements FeatureManager {
public List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagementException { public List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagementException {
try { try {
PolicyManagementDAOFactory.openConnection(); 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); return featureDAO.getFeaturesForProfile(profileId);
} catch (FeatureManagerDAOException e) { } catch (ProfileManagerDAOException | FeatureManagerDAOException e) {
throw new FeatureManagementException("Error occurred while getting the features", e); throw new FeatureManagementException("Error occurred while getting the features", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new FeatureManagementException("Error occurred while opening a connection to the data source", 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 @Override
public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException { public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException {
boolean bool; boolean bool;
@ -286,11 +185,11 @@ public class FeatureManagerImpl implements FeatureManager {
} catch (FeatureManagerDAOException e) { } catch (FeatureManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new FeatureManagementException("Error occurred while deleting the feature of - profile (" + throw new FeatureManagementException("Error occurred while deleting the feature of - profile (" +
profile.getProfileName() + ")", e); profile.getProfileName() + ")", e);
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new FeatureManagementException("Error occurred while deleting the feature of - profile (" + throw new FeatureManagementException("Error occurred while deleting the feature of - profile (" +
profile.getProfileName() + ") from database", e); profile.getProfileName() + ") from database", e);
} finally { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }

Loading…
Cancel
Save