Fixed for JIRA MDM-372

revert-70aa11f8
milanperera 9 years ago
parent 7313ba1e7e
commit de6572d819

@ -53,4 +53,6 @@ public interface FeatureDAO {
boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException; boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException;
boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException;
} }

@ -32,6 +32,8 @@ public interface ProfileDAO {
boolean deleteProfile(Profile profile) throws ProfileManagerDAOException; boolean deleteProfile(Profile profile) throws ProfileManagerDAOException;
boolean deleteProfile(int policyId) throws ProfileManagerDAOException;
Profile getProfiles(int profileId) throws ProfileManagerDAOException; Profile getProfiles(int profileId) throws ProfileManagerDAOException;
List<Profile> getAllProfiles() throws ProfileManagerDAOException; List<Profile> getAllProfiles() throws ProfileManagerDAOException;

@ -261,6 +261,28 @@ public class FeatureDAOImpl implements FeatureDAO {
} }
} }
@Override
public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "DELETE FROM DM_PROFILE_FEATURES WHERE PROFILE_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId);
stmt.executeUpdate();
return true;
} catch (SQLException e) {
String msg = "Error occurred while deleting the feature related to a profile.";
log.error(msg);
throw new FeatureManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
}
@Override @Override
public List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException { public List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException {

@ -154,6 +154,29 @@ public class ProfileDAOImpl implements ProfileDAO {
} }
} }
@Override
public boolean deleteProfile(int profileId) throws ProfileManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId);
stmt.executeUpdate();
return true;
} catch (SQLException e) {
String msg = "Error occurred while deleting the profile from the data base.";
log.error(msg);
throw new ProfileManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
}
@Override @Override
public Profile getProfiles(int profileId) throws ProfileManagerDAOException { public Profile getProfiles(int profileId) throws ProfileManagerDAOException {

@ -236,12 +236,14 @@ public class PolicyManagerImpl implements PolicyManager {
@Override @Override
public boolean deletePolicy(Policy policy) throws PolicyManagementException { public boolean deletePolicy(Policy policy) throws PolicyManagementException {
boolean bool;
try { try {
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
bool = policyDAO.deletePolicy(policy); policyDAO.deleteAllPolicyRelatedConfigs(policy.getId());
policyDAO.deletePolicy(policy.getId());
featureDAO.deleteFeaturesOfProfile(policy.getProfileId());
profileDAO.deleteProfile(policy.getProfileId());
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
return true;
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
try { try {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
@ -252,18 +254,48 @@ public class PolicyManagerImpl implements PolicyManager {
+ policy.getId() + " - " + policy.getPolicyName() + ")"; + policy.getId() + " - " + policy.getPolicyName() + ")";
log.error(msg, e); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
} catch (ProfileManagerDAOException e) {
try {
PolicyManagementDAOFactory.rollbackTransaction();
} catch (PolicyManagerDAOException e1) {
log.warn("Error occurred while roll backing the transaction.");
} }
return bool; String msg = "Error occurred while deleting the profile for policy ("
+ policy.getId() + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (FeatureManagerDAOException e) {
try {
PolicyManagementDAOFactory.rollbackTransaction();
} catch (PolicyManagerDAOException e1) {
log.warn("Error occurred while roll backing the transaction.");
}
String msg = "Error occurred while deleting the profile features for policy ("
+ policy.getId() + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
} }
@Override @Override
public boolean deletePolicy(int policyId) throws PolicyManagementException { public boolean deletePolicy(int policyId) throws PolicyManagementException {
boolean bool;
try { try {
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
Policy policy = policyDAO.getPolicy(policyId);
policyDAO.deleteAllPolicyRelatedConfigs(policyId); policyDAO.deleteAllPolicyRelatedConfigs(policyId);
bool = policyDAO.deletePolicy(policyId); policyDAO.deletePolicy(policyId);
if(log.isDebugEnabled()){
log.debug(policy.getProfileId() + " ----------------------------------");
}
featureDAO.deleteFeaturesOfProfile(policy.getProfileId());
profileDAO.deleteProfile(policy.getProfileId());
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
return true;
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
try { try {
@ -275,8 +307,27 @@ public class PolicyManagerImpl implements PolicyManager {
+ policyId + ")"; + policyId + ")";
log.error(msg, e); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
} catch (ProfileManagerDAOException e) {
try {
PolicyManagementDAOFactory.rollbackTransaction();
} catch (PolicyManagerDAOException e1) {
log.warn("Error occurred while roll backing the transaction.");
}
String msg = "Error occurred while deleting the profile for policy ("
+ policyId + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (FeatureManagerDAOException e) {
try {
PolicyManagementDAOFactory.rollbackTransaction();
} catch (PolicyManagerDAOException e1) {
log.warn("Error occurred while roll backing the transaction.");
}
String msg = "Error occurred while deleting the profile features for policy ("
+ policyId + ")";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} }
return bool;
} }
@Override @Override

@ -99,8 +99,10 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
} }
@Test(dependsOnMethods = ("addProfileFeatures")) @Test(dependsOnMethods = ("addProfileFeatures"))
public void addPolicy() throws PolicyManagementException { public void addPolicy() throws PolicyManagementException, ProfileManagementException {
ProfileManager profileManager = new ProfileManagerImpl();
profile = ProfileCreator.getProfile(featureList);
profileManager.addProfile(profile);
PolicyManager policyManager = new PolicyManagerImpl(); PolicyManager policyManager = new PolicyManagerImpl();
policy = PolicyCreator.createPolicy(profile); policy = PolicyCreator.createPolicy(profile);
policyManager.addPolicy(policy); policyManager.addPolicy(policy);
@ -135,8 +137,10 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
} }
@Test(dependsOnMethods = ("addPolicyToDevice")) @Test(dependsOnMethods = ("addPolicyToDevice"))
public void addNewPolicy() throws PolicyManagementException { public void addNewPolicy() throws PolicyManagementException, ProfileManagementException {
ProfileManager profileManager = new ProfileManagerImpl();
profile = ProfileCreator.getProfile(featureList);
profileManager.addProfile(profile);
PolicyManager policyManager = new PolicyManagerImpl(); PolicyManager policyManager = new PolicyManagerImpl();
policy = PolicyCreator.createPolicy2(profile); policy = PolicyCreator.createPolicy2(profile);
policyManager.addPolicy(policy); policyManager.addPolicy(policy);
@ -144,8 +148,10 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
@Test(dependsOnMethods = ("addPolicyToDevice")) @Test(dependsOnMethods = ("addPolicyToDevice"))
public void addThirdPolicy() throws PolicyManagementException { public void addThirdPolicy() throws PolicyManagementException, ProfileManagementException {
ProfileManager profileManager = new ProfileManagerImpl();
profile = ProfileCreator.getProfile(featureList);
profileManager.addProfile(profile);
PolicyManager policyManager = new PolicyManagerImpl(); PolicyManager policyManager = new PolicyManagerImpl();
policy = PolicyCreator.createPolicy4(profile); policy = PolicyCreator.createPolicy4(profile);
policyManager.addPolicy(policy); policyManager.addPolicy(policy);
@ -239,7 +245,10 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
} }
@Test(dependsOnMethods = ("getRoleRelatedPolicy")) @Test(dependsOnMethods = ("getRoleRelatedPolicy"))
public void addSecondPolicy() throws PolicyManagementException { public void addSecondPolicy() throws PolicyManagementException, ProfileManagementException {
ProfileManager profileManager = new ProfileManagerImpl();
profile = ProfileCreator.getProfile(featureList);
profileManager.addProfile(profile);
PolicyManager policyManager = new PolicyManagerImpl(); PolicyManager policyManager = new PolicyManagerImpl();
policy = PolicyCreator.createPolicy3(profile); policy = PolicyCreator.createPolicy3(profile);
policyManager.addPolicy(policy); policyManager.addPolicy(policy);

Loading…
Cancel
Save