From d7abfbc19b79b36cc03d8ae833c5aa2d61f830bd Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Wed, 18 Mar 2015 12:10:52 +0530 Subject: [PATCH] Adding the missed classes --- .../carbon/policy/mgt/core/PolicyManager.java | 50 +++++ .../policy/mgt/core/PolicyManagerImpl.java | 93 +++++++++ .../impl/PolicyAdministratorPointImpl.java | 196 ++++++++++++++++++ .../core/service/PolicyManagementService.java | 87 ++++++++ 4 files changed, 426 insertions(+) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java new file mode 100644 index 0000000000..4aa1a1b828 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2015 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.policy.mgt.core; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.*; + +import java.util.List; + +public interface PolicyManager { + + Feature addFeature(Feature feature) throws FeatureManagementException; + + Feature updateFeature(Feature feature) throws FeatureManagementException; + + Profile addProfile(Profile profile) throws PolicyManagementException; + + Profile updateProfile(Profile profile) throws PolicyManagementException; + + Policy addPolicy(Policy policy) throws PolicyManagementException; + + Policy updatePolicy(Policy policy) throws PolicyManagementException; + + Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; + + Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException; + + List getPolicies(String deviceType) throws PolicyManagementException; + + List getFeatures() throws FeatureManagementException; + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java new file mode 100644 index 0000000000..7b86d252e3 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java @@ -0,0 +1,93 @@ +/* +* Copyright (c) 2015 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.policy.mgt.core; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl; + +import java.util.List; + +public class PolicyManagerImpl implements PolicyManager { + + private static final Log log = LogFactory.getLog(PolicyManagerImpl.class); + + PolicyAdministratorPointImpl policyAdministratorPoint; + + public PolicyManagerImpl() { + policyAdministratorPoint = new PolicyAdministratorPointImpl(); + } + + @Override + public Feature addFeature(Feature feature) throws FeatureManagementException { + return policyAdministratorPoint.addFeature(feature); + } + + @Override + public Feature updateFeature(Feature feature) throws FeatureManagementException { + return policyAdministratorPoint.updateFeature(feature); + } + + @Override + public Profile addProfile(Profile profile) throws PolicyManagementException { + return policyAdministratorPoint.addProfile(profile); + } + + @Override + public Profile updateProfile(Profile profile) throws PolicyManagementException { + return policyAdministratorPoint.updateProfile(profile); + } + + @Override + public Policy addPolicy(Policy policy) throws PolicyManagementException { + return policyAdministratorPoint.addPolicy(policy); + } + + @Override + public Policy updatePolicy(Policy policy) throws PolicyManagementException { + return policyAdministratorPoint.updatePolicy(policy); + } + + @Override + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + return null; + } + + @Override + public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException { + return null; + } + + @Override + public List getPolicies(String deviceType) throws PolicyManagementException { + return null; + } + + @Override + public List getFeatures() throws FeatureManagementException { + return null; + } +} 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 new file mode 100644 index 0000000000..3cb9ceaff1 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -0,0 +1,196 @@ +/* +* Copyright (c) 2015 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.policy.mgt.core.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; +import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; + +public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { + + private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class); + PolicyDAOImpl policyDAO; + + public PolicyAdministratorPointImpl() { + policyDAO = new PolicyDAOImpl(); + } + + @Override + public Policy addPolicy(Policy policy) throws PolicyManagementException { + try { + policy = policyDAO.addPolicy(policy); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + return policy; + } + + public Policy updatePolicy(Policy policy) throws PolicyManagementException { + try { + policy = policyDAO.updatePolicy(policy); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while updating the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + return policy; + } + + @Override + public Policy addPolicyToDevice(String deviceId, String deviceType, Policy policy) + throws FeatureManagementException, PolicyManagementException { + + try { + policy = policyDAO.addPolicy(deviceId, deviceType, policy); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + return policy; + } + + @Override + public Policy addPolicyToRole(String roleName, Policy policy) + throws FeatureManagementException, PolicyManagementException { + try { + policy = policyDAO.addPolicyToRole(roleName, policy); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + return policy; + } + + @Override + public Policy getPolicy() { + return null; + } + + @Override + public Policy getPolicyOfDevice(String deviceId, String deviceType) + throws FeatureManagementException, PolicyManagementException { + return null; + } + + @Override + public Policy getPolicyOfDeviceType(String deviceType) + throws FeatureManagementException, PolicyManagementException { + return null; + } + + @Override + public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException { + return null; + } + + @Override + public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException { + return false; + } + + @Override + public boolean isPolicyApplied(String deviceId, String deviceType) throws PolicyManagementException { + return false; + } + + @Override + public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException { + + } + + @Override + public Profile addProfile(Profile profile) throws PolicyManagementException { + try { + profile = policyDAO.addProfile(profile); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + + return profile; + } + + @Override + public boolean deleteProfile(int profileId) throws PolicyManagementException { + return false; + } + + @Override + public Profile updateProfile(Profile profile) throws PolicyManagementException { + try { + profile = policyDAO.updateProfile(profile); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the profile."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + + return profile; + } + + @Override + public Feature addFeature(Feature feature) throws FeatureManagementException { + try { + feature = policyDAO.addFeature(feature); + } catch (FeatureManagementException e) { + String msg = "Error occurred while persisting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } + + return feature; + } + + @Override + public Feature updateFeature(Feature feature) throws FeatureManagementException { + try { + feature = policyDAO.updateFeature(feature); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } catch (FeatureManagementException e) { + String msg = "Error occurred while persisting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } + return feature; + } + + @Override + public void deleteFeature(int featureId) throws FeatureManagementException { + + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java new file mode 100644 index 0000000000..4154c2bc84 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2015 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.policy.mgt.core.service; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.*; +import org.wso2.carbon.policy.mgt.core.PolicyManager; +import org.wso2.carbon.policy.mgt.core.PolicyManagerImpl; + +import java.util.List; + +public class PolicyManagementService implements PolicyManager { + + + PolicyManager policyManager; + + public PolicyManagementService() { + policyManager = new PolicyManagerImpl(); + } + + @Override + public Feature addFeature(Feature feature) throws FeatureManagementException { + return policyManager.addFeature(feature); + } + + @Override + public Feature updateFeature(Feature feature) throws FeatureManagementException { + return policyManager.updateFeature(feature); + } + + @Override + public Profile addProfile(Profile profile) throws PolicyManagementException { + return policyManager.addProfile(profile); + } + + @Override + public Profile updateProfile(Profile profile) throws PolicyManagementException { + return policyManager.updateProfile(profile); + } + + @Override + public Policy addPolicy(Policy policy) throws PolicyManagementException { + return policyManager.addPolicy(policy); + } + + @Override + public Policy updatePolicy(Policy policy) throws PolicyManagementException { + return policyManager.updatePolicy(policy); + } + + @Override + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + return policyManager.getEffectivePolicy(deviceIdentifier); + } + + @Override + public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException { + return policyManager.getEffectiveFeatures(deviceIdentifier); + } + + @Override + public List getPolicies(String deviceType) throws PolicyManagementException { + return policyManager.getPolicies(deviceType); + } + + @Override + public List getFeatures() throws FeatureManagementException { + return policyManager.getFeatures(); + } +}