From de6572d81931c8a768c32dc9ed4fa9c110eac595 Mon Sep 17 00:00:00 2001 From: milanperera Date: Wed, 22 Jul 2015 17:46:40 +0530 Subject: [PATCH 1/6] Fixed for JIRA MDM-372 --- .../policy/mgt/core/dao/FeatureDAO.java | 2 + .../policy/mgt/core/dao/ProfileDAO.java | 2 + .../mgt/core/dao/impl/FeatureDAOImpl.java | 22 +++++ .../mgt/core/dao/impl/ProfileDAOImpl.java | 23 +++++ .../mgt/core/mgt/impl/PolicyManagerImpl.java | 99 ++++++++++++++----- .../policy/mgt/core/PolicyDAOTestCase.java | 23 +++-- 6 files changed, 140 insertions(+), 31 deletions(-) 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 1c08a18789e..19c9c137158 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 @@ -53,4 +53,6 @@ public interface FeatureDAO { boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException; + boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException; + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java index 811a52d1ace..174ca08c48b 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java @@ -32,6 +32,8 @@ public interface ProfileDAO { boolean deleteProfile(Profile profile) throws ProfileManagerDAOException; + boolean deleteProfile(int policyId) throws ProfileManagerDAOException; + Profile getProfiles(int profileId) throws ProfileManagerDAOException; List getAllProfiles() throws ProfileManagerDAOException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java index e6e5b93abe3..f5933350cf4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java @@ -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 public List getAllProfileFeatures() 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/ProfileDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java index 1ec9c10e00e..6755878cccc 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java @@ -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 public Profile getProfiles(int profileId) throws ProfileManagerDAOException { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index f80f6964fba..353e26ef347 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -122,7 +122,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while adding the policy (" + - policy.getId() + " - " + policy.getPolicyName() + ")"; + policy.getId() + " - " + policy.getPolicyName() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); @@ -133,7 +133,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while adding the profile related to policy (" + - policy.getId() + " - " + policy.getPolicyName() + ")"; + policy.getId() + " - " + policy.getPolicyName() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (FeatureManagerDAOException e) { @@ -143,7 +143,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while adding the features of profile related to policy (" + - policy.getId() + " - " + policy.getPolicyName() + ")"; + policy.getId() + " - " + policy.getPolicyName() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } @@ -206,7 +206,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while updating the policy (" - + policy.getId() + " - " + policy.getPolicyName() + ")"; + + policy.getId() + " - " + policy.getPolicyName() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } @@ -236,12 +236,14 @@ public class PolicyManagerImpl implements PolicyManager { @Override public boolean deletePolicy(Policy policy) throws PolicyManagementException { - boolean bool; try { PolicyManagementDAOFactory.beginTransaction(); - bool = policyDAO.deletePolicy(policy); + policyDAO.deleteAllPolicyRelatedConfigs(policy.getId()); + policyDAO.deletePolicy(policy.getId()); + featureDAO.deleteFeaturesOfProfile(policy.getProfileId()); + profileDAO.deleteProfile(policy.getProfileId()); PolicyManagementDAOFactory.commitTransaction(); - + return true; } catch (PolicyManagerDAOException e) { try { PolicyManagementDAOFactory.rollbackTransaction(); @@ -249,21 +251,51 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while deleting the policy (" - + policy.getId() + " - " + policy.getPolicyName() + ")"; + + policy.getId() + " - " + policy.getPolicyName() + ")"; + log.error(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 (" + + 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); } - return bool; + } @Override public boolean deletePolicy(int policyId) throws PolicyManagementException { - boolean bool; + try { PolicyManagementDAOFactory.beginTransaction(); + Policy policy = policyDAO.getPolicy(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(); + return true; } catch (PolicyManagerDAOException e) { try { @@ -272,16 +304,35 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while deleting the policy (" - + policyId + ")"; + + policyId + ")"; + log.error(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 public Policy addPolicyToDevice(List deviceIdentifierList, Policy policy) throws - PolicyManagementException { + PolicyManagementException { try { PolicyManagementDAOFactory.beginTransaction(); @@ -315,7 +366,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while adding the policy (" - + policy.getId() + " - " + policy.getPolicyName() + ")"; + + policy.getId() + " - " + policy.getPolicyName() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (DeviceManagementDAOException e) { @@ -362,7 +413,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while adding the policy (" - + policy.getId() + " - " + policy.getPolicyName() + ")"; + + policy.getId() + " - " + policy.getPolicyName() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } @@ -400,7 +451,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while adding the policy (" - + policy.getId() + " - " + policy.getPolicyName() + ") to user list."; + + policy.getId() + " - " + policy.getPolicyName() + ") to user list."; log.error(msg, e); throw new PolicyManagementException(msg, e); } @@ -534,12 +585,12 @@ public class PolicyManagerImpl implements PolicyManager { Collections.sort(policies); } catch (PolicyManagerDAOException e) { String msg = "Error occurred while getting the policies for device identifier (" + - deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")"; + deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (DeviceManagementDAOException e) { String msg = "Error occurred while getting device related to device identifier (" + - deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")"; + deviceIdentifier.getId() + " - " + deviceIdentifier.getType() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } @@ -655,7 +706,7 @@ public class PolicyManagerImpl implements PolicyManager { @Override public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, List profileFeatures) throws - PolicyManagementException { + PolicyManagementException { int deviceId = -1; try { @@ -677,7 +728,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while adding the evaluated policy to device (" + - deviceId + " - " + policyId + ")"; + deviceId + " - " + policyId + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (DeviceManagementDAOException e) { @@ -690,7 +741,7 @@ public class PolicyManagerImpl implements PolicyManager { @Override public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws - PolicyManagementException { + PolicyManagementException { int deviceId = -1; try { @@ -717,7 +768,7 @@ public class PolicyManagerImpl implements PolicyManager { log.warn("Error occurred while roll backing the transaction."); } String msg = "Error occurred while adding the evaluated policy to device (" + - deviceId + " - " + policy.getId() + ")"; + deviceId + " - " + policy.getId() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (DeviceManagementDAOException e) { @@ -757,7 +808,7 @@ public class PolicyManagerImpl implements PolicyManager { return true; } catch (PolicyManagerDAOException e) { String msg = "Error occurred while setting the policy has applied to device (" + - deviceIdentifier.getId() + ")"; + deviceIdentifier.getId() + ")"; log.error(msg, e); throw new PolicyManagementException(msg, e); } catch (DeviceManagementDAOException e) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java index 7276c82b5d0..14b472c8a8f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java @@ -99,8 +99,10 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest { } @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(); policy = PolicyCreator.createPolicy(profile); policyManager.addPolicy(policy); @@ -135,8 +137,10 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest { } @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(); policy = PolicyCreator.createPolicy2(profile); policyManager.addPolicy(policy); @@ -144,8 +148,10 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest { @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(); policy = PolicyCreator.createPolicy4(profile); policyManager.addPolicy(policy); @@ -239,7 +245,10 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest { } @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(); policy = PolicyCreator.createPolicy3(profile); policyManager.addPolicy(policy); From 35ac8ec6c958c2f96acfaa188c9cae6254a5c29a Mon Sep 17 00:00:00 2001 From: milanperera Date: Wed, 22 Jul 2015 17:53:58 +0530 Subject: [PATCH 2/6] Fixed formating issues in PolicyManagerImpl --- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 353e26ef347..fea263bd281 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -287,8 +287,8 @@ public class PolicyManagerImpl implements PolicyManager { policyDAO.deleteAllPolicyRelatedConfigs(policyId); policyDAO.deletePolicy(policyId); - if(log.isDebugEnabled()){ - log.debug(policy.getProfileId() + " ----------------------------------"); + if (log.isDebugEnabled()) { + log.debug("Profile ID: " + policy.getProfileId()); } featureDAO.deleteFeaturesOfProfile(policy.getProfileId()); @@ -331,8 +331,8 @@ public class PolicyManagerImpl implements PolicyManager { } @Override - public Policy addPolicyToDevice(List deviceIdentifierList, Policy policy) throws - PolicyManagementException { + public Policy addPolicyToDevice(List deviceIdentifierList, Policy policy) + throws PolicyManagementException { try { PolicyManagementDAOFactory.beginTransaction(); @@ -705,8 +705,7 @@ public class PolicyManagerImpl implements PolicyManager { @Override public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, - List profileFeatures) throws - PolicyManagementException { + List profileFeatures) throws PolicyManagementException { int deviceId = -1; try { @@ -740,8 +739,8 @@ public class PolicyManagerImpl implements PolicyManager { } @Override - public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws - PolicyManagementException { + public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) + throws PolicyManagementException { int deviceId = -1; try { From 15d56e29c3eed4d82816f2874e4adf3d01971eed Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 22 Jul 2015 23:41:05 +0530 Subject: [PATCH 3/6] temporarily commenting out test cases till tenancy-test bits are properly added --- .../src/test/resources/testng.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml index cf107283b8f..1eee2b18ebf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml @@ -24,17 +24,17 @@ - - - - - + + + + + - - + + \ No newline at end of file From e4fd0607e8a3c003bd52cb5f794bd94064634cef Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 22 Jul 2015 23:43:12 +0530 Subject: [PATCH 4/6] Removing some hack used to workaround issues that popped up while writing unit tests upon tenant-enabled code --- ...ApplicationManagerProviderServiceImpl.java | 53 +++++++------------ .../DeviceManagementProviderServiceImpl.java | 27 ++-------- .../mgt/core/util/DeviceManagerUtil.java | 1 - .../DeviceManagementProviderServiceTest.java | 1 - 4 files changed, 22 insertions(+), 60 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 6dbf00e15bb..8a0fb9e5d97 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -180,10 +180,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem @Override public void updateApplicationListInstalledInDevice( DeviceIdentifier deviceIdentifier, List applications) throws ApplicationManagementException { - - int tenantId = getTenantId(); - try { + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); DeviceManagementDAOFactory.beginTransaction(); Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); @@ -199,8 +197,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem List appsToAdd = new ArrayList(); List appIdsToRemove = new ArrayList(); - for(Application installedApp:installedAppList){ - if (!applications.contains(installedApp)){ + for (Application installedApp : installedAppList) { + if (!applications.contains(installedApp)) { if (log.isDebugEnabled()) { log.debug("Remove app Id:" + installedApp.getId()); } @@ -211,12 +209,12 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem Application installedApp; List applicationIds = new ArrayList<>(); - for(Application application:applications){ + for (Application application : applications) { if (!installedAppList.contains(application)) { installedApp = applicationDAO.getApplication(application.getApplicationIdentifier(), tenantId); - if (installedApp == null){ + if (installedApp == null) { appsToAdd.add(application); - }else{ + } else { applicationIds.add(installedApp.getId()); } } @@ -234,7 +232,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem if (log.isDebugEnabled()) { log.debug("num of remove app Ids:" + appIdsToRemove.size()); } - applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove,tenantId); + applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove, tenantId); DeviceManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException deviceDaoEx) { String errorMsg = "Error occurred saving application list to the device"; @@ -242,37 +240,24 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem try { DeviceManagementDAOFactory.rollbackTransaction(); } catch (DeviceManagementDAOException e) { - log.error("Error occurred while roll back transaction",e); + log.error("Error occurred while roll back transaction", e); } throw new ApplicationManagementException(errorMsg, deviceDaoEx); } } - private int getTenantId() { - - int tenantId = 0; - if (isTest){ - tenantId = DeviceManagerUtil.currentTenant.get(); - }else{ - tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - } - - return tenantId; - } - @Override - public List getApplicationListForDevice(DeviceIdentifier deviceIdentifier) - throws ApplicationManagementException { - Device device = null; - try { - int tenantId = getTenantId(); - device = deviceDAO.getDevice(deviceIdentifier, tenantId); - return applicationDAO.getInstalledApplications(device.getId()); - }catch (DeviceManagementDAOException deviceDaoEx) { - String errorMsg = "Error occured while fetching the Application List of device : " + device.getId(); - log.error(errorMsg, deviceDaoEx); - throw new ApplicationManagementException(errorMsg, deviceDaoEx); - } + public List getApplicationListForDevice( + DeviceIdentifier deviceId) throws ApplicationManagementException { + Device device = null; + try { + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + device = deviceDAO.getDevice(deviceId, tenantId); + return applicationDAO.getInstalledApplications(device.getId()); + } catch (DeviceManagementDAOException e) { + throw new ApplicationManagementException("Error occured while fetching the Application List of '" + + deviceId.getType() + "' device carrying the identifier'" + deviceId.getId(), e); + } } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 0538923cdfd..ce6713678ef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -53,7 +53,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv private DeviceTypeDAO deviceTypeDAO; private EnrolmentDAO enrolmentDAO; private DeviceManagementPluginRepository pluginRepository; - private boolean isTest = false; private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class); private int tenantId; @@ -75,7 +74,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test){ this.pluginRepository = pluginRepo; initDataAccessObjects(); - isTest = test; } private void initDataAccessObjects() { @@ -108,7 +106,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } else { device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE); } - int tenantId = getTenantId(); + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); DeviceManagementDAOFactory.beginTransaction(); @@ -724,14 +722,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.getConnection(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); allDevices = deviceDAO.getDevicesByStatus(status, tenantId); - } catch (DeviceManagementDAOException e) { - String errorMsg = "Error occurred while fetching the list of devices that matches to status: '" - + status + "'"; - log.error(errorMsg, e); - throw new DeviceManagementException(errorMsg, e); + throw new DeviceManagementException( + "Error occurred while fetching the list of devices that matches to status: '" + status + "'", e); } finally { - try { DeviceManagementDAOFactory.closeConnection(); } catch (DeviceManagementDAOException e) { @@ -753,19 +747,4 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return devices; } - - - private int getTenantId() { - - ThreadLocal tenantId = new ThreadLocal(); - int tenant = 0; - - if (isTest){ - tenant = DeviceManagerUtil.currentTenant.get(); - }else{ - tenant = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - } - return tenant; - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index 8fc16db4ec9..dc895d8581a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -49,7 +49,6 @@ import java.util.*; public final class DeviceManagerUtil { private static final Log log = LogFactory.getLog(DeviceManagerUtil.class); - public static ThreadLocal currentTenant = new ThreadLocal(); enum HTTPMethod { GET, POST, DELETE, PUT, OPTIONS diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java index 8322684d07c..e79930ee04f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceTest.java @@ -58,7 +58,6 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes deviceManagementProviderService = new DeviceManagementProviderServiceImpl(deviceManagementPluginRepository, true); DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE); - DeviceManagerUtil.currentTenant.set(TestDataHolder.SUPER_TENANT_ID); Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE); boolean isEnrolled = deviceManagementProviderService.enrollDevice(device); From 9e5e3cf73d500618c943273c0ffc558585636d51 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 23 Jul 2015 09:57:50 +0530 Subject: [PATCH 5/6] Enforcing proxy port to be used when configured --- .../mgt/core/startup/handler/URLPrinterStartupHandler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/startup/handler/URLPrinterStartupHandler.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/startup/handler/URLPrinterStartupHandler.java index 17a5b0dc172..83250c0d22b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/startup/handler/URLPrinterStartupHandler.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/startup/handler/URLPrinterStartupHandler.java @@ -51,11 +51,14 @@ public class URLPrinterStartupHandler implements ServerStartupObserver { String mgtConsoleTransport = CarbonUtils.getManagementTransport(); ConfigurationContextService configContextService = DeviceManagementDataHolder.getInstance().getConfigurationContextService(); - int httpsPort = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport); + int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport); int httpsProxyPort = CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(), mgtConsoleTransport); - return "https://" + hostName + ":" + httpsPort + "/mdm"; + if (httpsProxyPort > 0) { + port = httpsProxyPort; + } + return "https://" + hostName + ":" + port + "/mdm"; } } From fac53e48144c357fe1268d446b873d4985c7d678 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 23 Jul 2015 10:01:56 +0530 Subject: [PATCH 6/6] Upgrading tomcat version usd in carbon-devicemgt --- .../device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 7 +++++-- .../pom.xml | 4 ++-- pom.xml | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 71fea6c747a..9d5069b8a99 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -83,8 +83,7 @@ org.wso2.carbon.identity.oauth.stub, org.wso2.carbon.identity.oauth.stub.dto, org.wso2.carbon.ndatasource.core, - org.wso2.carbon.base, - org.wso2.carbon.base.api + org.apache.catalina !org.wso2.carbon.device.mgt.core.internal, @@ -209,6 +208,10 @@ org.wso2.carbon.identity org.wso2.carbon.identity.oauth.stub + + org.wso2.tomcat + tomcat + diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index bc2360aa32f..ebf27bf99ff 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -64,11 +64,11 @@ - org.apache.tomcat.wso2 + org.wso2.tomcat tomcat - org.apache.tomcat.wso2 + org.wso2.tomcat tomcat-servlet-api diff --git a/pom.xml b/pom.xml index ffd4eda2ebe..6fc2e332a3d 100644 --- a/pom.xml +++ b/pom.xml @@ -748,7 +748,7 @@ - org.apache.tomcat.wso2 + org.wso2.tomcat tomcat ${orbit.version.tomcat} @@ -815,7 +815,7 @@ ${tomcat.jdbc.pooling.version} - org.apache.tomcat.wso2 + org.wso2.tomcat tomcat-servlet-api ${orbit.version.tomcat.servlet.api} @@ -1137,8 +1137,8 @@ 1.2.140.wso2v3 - 7.0.52.wso2v5 - 7.0.52.wso2v1 + 7.0.59.wso2v1 + 7.0.59.wso2v1 7.0.34.wso2v2