diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index cafadda824..f2d711b764 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -17,19 +17,17 @@ ~ under the License. --> - + device-mgt org.wso2.carbon.devicemgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.common - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT bundle WSO2 Carbon - Device Management Commons WSO2 Carbon - Device Management Commons 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 3d7c7ed651..7dde13ebe5 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 @@ -21,14 +21,14 @@ org.wso2.carbon.devicemgt device-mgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT bundle WSO2 Carbon - Device Management Core WSO2 Carbon - Device Management Core diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementService.java index 9521daf7e6..c94636fd46 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementService.java @@ -36,4 +36,6 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager, List getAllDevices(String type) throws DeviceManagementException; + List getDeviceListOfUser(String username) throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index d4f07cf5d2..51ed642899 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -51,4 +51,13 @@ public interface DeviceDAO { * @throws DeviceManagementDAOException */ List getDevices(int type) throws DeviceManagementDAOException; + + /** + * Get the list of devices belongs to a user. + * @param username Requested user. + * @return List of devices of the user. + * @throws DeviceManagementDAOException + */ + List getDeviceListOfUser(String username) throws DeviceManagementDAOException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index df80629a0f..4f665ed90f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.Status; import javax.sql.DataSource; @@ -38,6 +39,7 @@ import java.util.List; public class DeviceDAOImpl implements DeviceDAO { + private DataSource dataSource; private static final Log log = LogFactory.getLog(DeviceDAOImpl.class); @@ -210,6 +212,11 @@ public class DeviceDAOImpl implements DeviceDAO { return devicesList; } + @Override + public List getDeviceListOfUser(String username) throws DeviceManagementDAOException { + return null; + } + private Connection getConnection() throws DeviceManagementDAOException { try { return dataSource.getConnection(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java index 87e4e477e6..2a898ce7b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/Device.java @@ -33,7 +33,20 @@ public class Device implements Serializable { private String ownerId; private String ownerShip; private int tenantId; +<<<<<<< HEAD private int deviceTypeId; +======= + private Integer deviceTypeId; + private DeviceType deviceType; + + public DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceType deviceType) { + this.deviceType = deviceType; + } +>>>>>>> 4754da70be87f5a756e59ef32714355063bd6bed public int getDeviceTypeId() { return deviceTypeId; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index ba6b9df2bd..e000083e2f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.core.DeviceManagementService; import org.wso2.carbon.device.mgt.core.config.license.License; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagementException; @@ -66,7 +67,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @Override public List getAllDevices() throws DeviceManagementException { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override @@ -74,7 +75,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getAllDevices(type); } - @Override + @Override + public List getDeviceListOfUser(String username) throws DeviceManagementException{ + return null; + } + + @Override public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId); @@ -119,9 +125,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } @Override - public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeaturesForDeviceType( - deviceType); + public List getFeatures(String deviceType) throws FeatureManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeatures(deviceType); } } diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index c5b746439f..b2613923ae 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt device-mgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT pom WSO2 Carbon - Device Management Component http://wso2.org diff --git a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml index 6777e348ba..66386a9b72 100644 --- a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt policy-mgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.complex.policy.decision.point - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT bundle WSO2 Carbon - Policy Decision Point WSO2 Carbon - Policy Decision Point diff --git a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java index 04faae5f03..a43922b4ab 100644 --- a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java @@ -51,7 +51,7 @@ public class FeatureFilterImpl implements FeatureFilter { public List extractFeatures(List policyList) { List featureList = new ArrayList(); for (Policy policy : policyList) { - featureList.addAll(policy.getFeaturesList()); + featureList.addAll(policy.getProfile().getFeaturesList()); } return featureList; } diff --git a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java index cbb398654b..22af278741 100644 --- a/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java @@ -63,7 +63,7 @@ public class PolicyFilterImpl implements PolicyFilter { List policies = new ArrayList(); for (Policy policy : policyList) { - if (policy.getDeviceType().equalsIgnoreCase(deviceType)) { + if (policy.getProfile().getDeviceType().getName().equalsIgnoreCase(deviceType)) { policies.add(policy); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml index a0c41a2e6f..57ce706a77 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -1,10 +1,9 @@ - + org.wso2.carbon.devicemgt policy-mgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml @@ -12,7 +11,7 @@ 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.policy.information.point - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT bundle WSO2 Carbon - Policy Information Point WSO2 Carbon - Policy Information Point diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index 524df5869c..bf119e445d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt policy-mgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.common - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT bundle WSO2 Carbon - Policy Management Common WSO2 Carbon - Policy Management Common @@ -54,7 +54,8 @@ Policy Management Common Bundle org.wso2.carbon.policy.mgt.common.internal - org.apache.commons.logging + org.apache.commons.logging, + org.wso2.carbon.device.mgt.core.* org.wso2.carbon.policy.mgt.common.* @@ -82,6 +83,10 @@ org.testng testng + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java index 2a180ae441..0023cf6326 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Feature.java @@ -23,9 +23,18 @@ public class Feature { private int id; private String code; private String name; + private String description; private Object attribute; private String ruleValue; + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + public String getRuleValue() { return ruleValue; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/FeatureManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/FeatureManagerService.java index 172e1cd529..7f9dd8e4fd 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/FeatureManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/FeatureManagerService.java @@ -30,5 +30,5 @@ public interface FeatureManagerService { List getFeatures() throws FeatureManagementException; - List getFeaturesOfPolicy(int policyId) throws FeatureManagementException; + List getFeaturesOfPolicy(int profileId) throws FeatureManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java index f0f930f57f..130f367fd5 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java @@ -28,13 +28,12 @@ import java.util.Map; public class Policy { private int id; // Identifier of the policy. private int priorityId; // Priority of the policies. This will be used only for simple evaluation. + private Profile profile; // Profile id private String policyName; // Name of the policy. - private List featuresList; // Features included in the policies. private boolean generic; // If true, this should be applied to all related device. private List roleList; // Roles which this policy should be applied. private String ownershipType; // Ownership type (COPE, BYOD, CPE) private List DeviceList; // Individual devices this policy should be applied - private String deviceType; // Device type to apply the policy. /*Dynamic policy attributes*/ @@ -71,20 +70,20 @@ public class Policy { this.priorityId = priorityId; } - public String getPolicyName() { - return policyName; + public Profile getProfile() { + return profile; } - public void setPolicyName(String policyName) { - this.policyName = policyName; + public void setProfile(Profile profile) { + this.profile = profile; } - public List getFeaturesList() { - return featuresList; + public String getPolicyName() { + return policyName; } - public void setFeaturesList(List featuresList) { - this.featuresList = featuresList; + public void setPolicyName(String policyName) { + this.policyName = policyName; } public boolean isGeneric() { @@ -119,14 +118,6 @@ public class Policy { DeviceList = deviceList; } - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - public int getStartTime() { return startTime; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java index 4534254ad9..4fb239d1fb 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java @@ -102,6 +102,7 @@ public interface PolicyAdministratorService { /** * This method checks weather a policy is available for a device. + * * @param deviceId * @param deviceType * @return @@ -112,6 +113,7 @@ public interface PolicyAdministratorService { /** * This method checks weather a policy is used by a particular device. + * * @param deviceId * @param deviceType * @return @@ -121,11 +123,19 @@ public interface PolicyAdministratorService { /** - * * @param deviceId * @param deviceType * @param policy * @throws PolicyManagementException */ void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException; + + /** + * This method will add the profile to database, + * @param profile + * @throws PolicyManagementException + */ + void addProfile(Profile profile) throws PolicyManagementException; + + void deleteProfile(int profileId) throws PolicyManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java new file mode 100644 index 0000000000..e81dc42eb8 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java @@ -0,0 +1,91 @@ +/* +* 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.common; + +import org.wso2.carbon.device.mgt.core.dto.DeviceType; + +import java.sql.Timestamp; +import java.util.List; + +public class Profile { + + private int profileId; + private String profileName; + private int tenantId; + private DeviceType deviceType; + private Timestamp createdDate; + private Timestamp updatedDate; + private List featuresList; // Features included in the policies. + + public DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceType deviceType) { + this.deviceType = deviceType; + } + + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + public List getFeaturesList() { + return featuresList; + } + + public void setFeaturesList(List featuresList) { + this.featuresList = featuresList; + } + + public int getProfileId() { + return profileId; + } + + public void setProfileId(int profileId) { + this.profileId = profileId; + } + + public String getProfileName() { + return profileName; + } + + public void setProfileName(String profileName) { + this.profileName = profileName; + } + + public Timestamp getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Timestamp createdDate) { + this.createdDate = createdDate; + } + + public Timestamp getUpdatedDate() { + return updatedDate; + } + + public void setUpdatedDate(Timestamp updatedDate) { + this.updatedDate = updatedDate; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java index 3ec34a90f2..77ba5b6fe8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java @@ -18,10 +18,7 @@ package org.wso2.carbon.policy.mgt.common.impl; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyAdministratorService; -import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.*; public class PolicyManagement implements PolicyAdministratorService { @Override @@ -78,4 +75,14 @@ public class PolicyManagement implements PolicyAdministratorService { public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException { } + + @Override + public void addProfile(Profile profile) throws PolicyManagementException { + + } + + @Override + public void deleteProfile(int profileId) throws PolicyManagementException { + + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/resources/mysql.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/resources/mysql.sql new file mode 100644 index 0000000000..9102ed00c1 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/resources/mysql.sql @@ -0,0 +1,211 @@ +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; + +CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ; +USE `WSO2CDM` ; + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE_TYPE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ( + `ID` INT(11) NOT NULL , + `NAME` VARCHAR(300) NULL DEFAULT NULL , + PRIMARY KEY (`ID`) ) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` ( + `ID` VARCHAR(20) NOT NULL , + `DESCRIPTION` TEXT NULL DEFAULT NULL , + `NAME` VARCHAR(100) NULL DEFAULT NULL , + `DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL , + `DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL , + `OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL , + `STATUS` VARCHAR(15) NULL DEFAULT NULL , + `DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL , + `DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL , + `OWNER` VARCHAR(45) NULL DEFAULT NULL , + `TENANT_ID` INT(11) NULL DEFAULT '0' , + PRIMARY KEY (`ID`) , + INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2` (`DEVICE_TYPE_ID` ASC) , + CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2` + FOREIGN KEY (`DEVICE_TYPE_ID` ) + REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_PROFILE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE` ( + `ID` INT NOT NULL AUTO_INCREMENT , + `PROFILE_NAME` VARCHAR(45) NOT NULL , + `TENANT_ID` INT NOT NULL , + `CREATED_TIME` DATETIME NOT NULL , + `UPDATED_TIME` DATETIME NOT NULL , + PRIMARY KEY (`ID`) ) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_POLICY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `NAME` VARCHAR(45) NULL DEFAULT NULL , + `TENANT_ID` INT(11) NOT NULL , + `PROFILE_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC) , + CONSTRAINT `FK_DM_PROFILE_DM_POLICY` + FOREIGN KEY (`PROFILE_ID` ) + REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE_POLICY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `DEVICE_ID` INT(11) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC) , + CONSTRAINT `FK_POLICY_DEVICE_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` ( + `ID` INT(11) NOT NULL , + `DEVICE_TYPE_ID` INT(11) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_DEVICE_TYPE_POLICY` (`POLICY_ID` ASC) , + INDEX `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) , + CONSTRAINT `FK_DEVICE_TYPE_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` + FOREIGN KEY (`DEVICE_TYPE_ID` ) + REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_FEATURES` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `NAME` VARCHAR(256) NOT NULL , + `CODE` VARCHAR(45) NULL DEFAULT NULL , + `DESCRIPTION` TEXT NULL DEFAULT NULL , + `EVALUVATION_RULE` VARCHAR(60) NOT NULL , + PRIMARY KEY (`ID`) ) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_POLICY_FEATURES` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_FEATURES` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `PROFILE_ID` INT(11) NOT NULL , + `FEATURE_ID` INT(11) NOT NULL , + `CONTENT` BLOB NULL DEFAULT NULL , + PRIMARY KEY (`ID`) , + INDEX `fk_DM_POLICY_FEATURES_DM_FEATURES1` (`FEATURE_ID` ASC) , + INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC) , + CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1` + FOREIGN KEY (`FEATURE_ID` ) + REFERENCES `WSO2CDM`.`DM_FEATURES` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES` + FOREIGN KEY (`PROFILE_ID` ) + REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_ROLE_POLICY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ( + `ID` INT(11) NOT NULL , + `ROLE_NAME` VARCHAR(45) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC) , + CONSTRAINT `FK_ROLE_POLICY_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_LOCATION` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_LOCATION` ( + `LAT` VARCHAR(45) NOT NULL , + `LONG` VARCHAR(45) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + INDEX `FK_DM_POLICY_DM_LOCATION` (`POLICY_ID` ASC) , + CONSTRAINT `FK_DM_POLICY_DM_LOCATION` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_TIME` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_TIME` ( + `STARTING_TIME` DATETIME NOT NULL , + `ENDING_TIME` DATETIME NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + INDEX `FK_DM_POLICY_DM_TIME` (`POLICY_ID` ASC) , + CONSTRAINT `FK_DM_POLICY_DM_TIME` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java index 0f276076e4..6ea9e58422 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java @@ -20,6 +20,7 @@ package org.wos2.carbon.policy.mgt.common.utils; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.Profile; import java.util.ArrayList; import java.util.List; @@ -38,7 +39,14 @@ public class PolicyCreator { List featureList = new ArrayList(); featureList.add(feature); - policy.setFeaturesList(featureList); + Profile profile = new Profile(); + profile.setProfileId(1); + profile.setProfileName("Test-01"); + profile.setTenantId(-1234); + + policy.setProfile(profile); + profile.setFeaturesList(featureList); + policy.setPolicyName("Camera_related_policy"); return policy; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 0ea521c6ef..0a08696f4e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -18,18 +18,19 @@ ~ under the License. --> - + org.wso2.carbon.devicemgt policy-mgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.core - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT bundle WSO2 Carbon - Policy Management Core WSO2 Carbon - Policy Management Core @@ -66,7 +67,8 @@ org.w3c.dom, org.wso2.carbon.policy.mgt.common.*, org.wso2.carbon.user.core.*, - org.wso2.carbon.utils + org.wso2.carbon.utils.*, + org.wso2.carbon.device.mgt.core.* !org.wso2.carbon.policy.mgt.core.internal, @@ -75,6 +77,21 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18 + + + file:src/test/resources/log4j.properties + + + src/test/resources/testng.xml + + + + @@ -113,6 +130,30 @@ org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.common + + + + + org.testng + testng + + + org.apache.tomcat.wso2 + jdbc-pool + + + + mysql + mysql-connector-java + 5.1.34 + test + + + com.h2database.wso2 + h2-database-engine + test + + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java index f0bf968700..9fd866f51f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java @@ -18,7 +18,12 @@ package org.wso2.carbon.policy.mgt.core.dao; +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.Profile; + +import java.util.List; public interface PolicyDAO { @@ -35,4 +40,24 @@ public interface PolicyDAO { Policy getPolicy(String deviceType) throws PolicyManagerDAOException; Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException; + + void deletePolicy(Policy policy) throws PolicyManagerDAOException; + + void addProfile(Profile profile) throws PolicyManagerDAOException; + + void deleteProfile(Profile profile) throws PolicyManagerDAOException; + + List getAllProfiles() throws PolicyManagerDAOException; + + List getProfilesOfDeviceType(String deviceType) throws PolicyManagerDAOException; + + List getAllFeatures() throws PolicyManagerDAOException; + + List getFeaturesForProfile(int ProfileId) throws PolicyManagerDAOException; + + void deleteFeature(int featureId) throws PolicyManagerDAOException; + + void deleteFeaturesOfProfile(Profile profile) throws PolicyManagerDAOException; + + Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java index e1512f34b7..2df823b03c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java @@ -35,14 +35,22 @@ public class PolicyManagementDAOFactory { private static final Log log = LogFactory.getLog(PolicyManagementDAOFactory.class); - public static PolicyDAO getDeviceTypeDAO() { - return new PolicyDAOImpl(dataSource); - } public static void init(DataSourceConfig config) { dataSource = resolveDataSource(config); } + public static void init(DataSource dtSource) { + dataSource = dtSource; + } + + public static DataSource getDataSource() { + if (dataSource != null) { + return dataSource; + } + throw new RuntimeException("Data source is not yet configured."); + } + /** * Resolve data source from the data source definition * diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java index 7b8769ad86..e5afa35ec2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -20,64 +20,539 @@ package org.wso2.carbon.policy.mgt.core.dao.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.Profile; import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO; +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.util.PolicyManagementDAOUtil; -import javax.sql.DataSource; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class PolicyDAOImpl implements PolicyDAO { - private static DataSource dataSource; private static final Log log = LogFactory.getLog(PolicyDAOImpl.class); - public PolicyDAOImpl(DataSource dataSource) { - this.dataSource = dataSource; - } @Override public int addPolicy(Policy policy) throws PolicyManagerDAOException { - return 0; + persistPolicy(policy); + return policy.getId(); } @Override public int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException { - return 0; + + // First persist the policy to the data base. + persistPolicy(policy); + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + try { + conn = this.getConnection(); + String query = "INSERT INTO DM_DEVICE_TYPE_POLICY (DEVICE_TYPE_ID, POLICY_ID) VALUES (?, ?)"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, getDeviceTypeId(deviceType)); + stmt.setInt(2, policy.getId()); + + stmt.executeQuery(); + + } catch (SQLException e) { + String msg = "Error occurred while adding the device type policy to database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + + return policy.getId(); + } @Override public int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException { + + // First persist the policy to the data base. + persistPolicy(policy); + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (SQLException e) { + + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return 0; } @Override public void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (Exception e) { + + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } } @Override public Policy getPolicy() throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (Exception e) { + + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return null; } @Override public Policy getPolicy(String deviceType) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (Exception e) { + + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return null; } @Override public Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (Exception e) { + + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return null; } + @Override + public void deletePolicy(Policy policy) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + try { + conn = this.getConnection(); + String query = "DELETE FROM DM_POLICY WHERE ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, policy.getId()); + stmt.executeUpdate(); + + if (log.isDebugEnabled()) { + log.debug("Policy (" + policy.getPolicyName() + ") delete from database."); + } + } catch (Exception e) { + String msg = "Unable to delete the policy (" + policy.getPolicyName() + ") from database."; + log.error(msg); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + + } + private Connection getConnection() throws PolicyManagerDAOException { try { - return dataSource.getConnection(); + return PolicyManagementDAOFactory.getDataSource().getConnection(); } catch (SQLException e) { throw new PolicyManagerDAOException("Error occurred while obtaining a connection from the policy " + "management metadata repository datasource", e); } } + + + private void persistPolicy(Policy policy) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + // TODO : find a way to get the tenant Id. + int tenantId = -1234; + try { + conn = this.getConnection(); + String query = "IINSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID) VALUES (?, ?, ?)"; + stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); + + stmt.setString(1, policy.getPolicyName()); + stmt.setInt(2, policy.getProfile().getProfileId()); + stmt.setInt(3, tenantId); + + int affectedRows = stmt.executeUpdate(); + + if (affectedRows == 0 && log.isDebugEnabled()) { + String msg = "No rows are updated on the policy table."; + log.debug(msg); + } + generatedKeys = stmt.getGeneratedKeys(); + + if (generatedKeys.next()) { + policy.setId(generatedKeys.getInt(1)); + } + // checking policy id here, because it object could have passed with id from the calling method. + if (policy.getId() == 0) { + throw new RuntimeException("No rows were inserted, policy id cannot be null."); + } + } catch (SQLException e) { + String msg = "Error occurred while adding policy to the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + } + + + private void persistFeatures(Profile profile) throws PolicyManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_ID, CONTENT) VALUES (?, ?, ?)"; + + stmt = conn.prepareStatement(query); + for (Feature feature : profile.getFeaturesList()) { + stmt.setInt(1, profile.getProfileId()); + stmt.setInt(2, feature.getId()); + stmt.setObject(3, feature.getAttribute()); + stmt.addBatch(); + //Not adding the logic to check the size of the stmt and execute if the size records added is over 1000 + } + stmt.executeBatch(); + } catch (SQLException e) { + String msg = "Error occurred while adding the feature list to the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } + + public void addProfile(Profile profile) throws PolicyManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + // TODO : find a way to get the tenant Id. + int tenantId = -1234; + try { + conn = this.getConnection(); + String query = "INSERT INTO DM_PROFILE (PROFILE_NAME,TENANT_ID, DEVICE_TYPE_ID, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?)"; + stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); + + stmt.setString(1, profile.getProfileName()); + stmt.setInt(2, tenantId); + stmt.setLong(3, profile.getDeviceType().getId()); + stmt.setTimestamp(4, profile.getCreatedDate()); + stmt.setTimestamp(5, profile.getUpdatedDate()); + + int affectedRows = stmt.executeUpdate(); + + if (affectedRows == 0 && log.isDebugEnabled()) { + String msg = "No rows are updated on the profile table."; + log.debug(msg); + } + generatedKeys = stmt.getGeneratedKeys(); + + if (generatedKeys.next()) { + profile.setProfileId(generatedKeys.getInt(1)); + } + // Checking the profile id here, because profile id could have been passed from the calling method. + if (profile.getProfileId() == 0) { + throw new RuntimeException("Profile id is 0, this could be an issue."); + } + + persistFeatures(profile); + + } catch (SQLException e) { + String msg = "Error occurred while adding the profile to database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + } + + @Override + public void deleteProfile(Profile profile) throws PolicyManagerDAOException { + + // First delete the features related to the profile + deleteFeaturesOfProfile(profile); + Connection conn = null; + PreparedStatement stmt = null; + + try { + conn = this.getConnection(); + String query = "DELETE FROM DM_PROFILE WHERE ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, profile.getProfileId()); + stmt.executeUpdate(); + } catch (SQLException e) { + String msg = "Error occurred while deleting the profile from the data base."; + log.error(msg); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } + + @Override + public void deleteFeaturesOfProfile(Profile profile) throws PolicyManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + + try { + conn = this.getConnection(); + String query = "DELETE FROM DM_PROFILE_FEATURES WHERE PROFILE_ID = ?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, profile.getProfileId()); + stmt.executeUpdate(); + } catch (SQLException e) { + String msg = "Error occurred while deleting the feature related to a profile."; + log.error(msg); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } + + @Override + public Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + try { + conn = this.getConnection(); + String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUVATION_RULE) VALUES (?, ?, ?, ?)"; + stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); + stmt.setString(1, feature.getName()); + stmt.setString(2, feature.getCode()); + stmt.setString(3, feature.getDescription()); + stmt.setString(4, feature.getRuleValue()); + + int affectedRows = stmt.executeUpdate(); + + if (log.isDebugEnabled()) { + log.debug(affectedRows + " Features are added."); + } + generatedKeys = stmt.getGeneratedKeys(); + while (generatedKeys.next()) { + feature.setId(generatedKeys.getInt(1)); + } + } catch (SQLException e) { + String msg = "Error occurred while adding feature to the database."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return feature; + } + + @Override + public List getAllProfiles() throws PolicyManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (SQLException e) { + + } + + return null; + } + + @Override + public List getProfilesOfDeviceType(String deviceType) throws PolicyManagerDAOException { + + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (SQLException e) { + + } + + return null; + } + + @Override + public List getAllFeatures() throws PolicyManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + List featureList = new ArrayList(); + + try { + conn = this.getConnection(); + String query = "SELECT ID, NAME, CODE, EVALUVATION_RULE FROM DM_FEATURES"; + stmt = conn.prepareStatement(query); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + Feature feature = new Feature(); + feature.setId(resultSet.getInt("ID")); + feature.setCode(resultSet.getString("CODE")); + feature.setName(resultSet.getString("NAME")); + feature.setRuleValue(resultSet.getString("EVALUVATION_RULE")); + featureList.add(feature); + } + + } catch (SQLException e) { + String msg = "Unable to get the list of the features from database."; + log.error(msg); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + return featureList; + } + + @Override + public List getFeaturesForProfile(int profileId) throws PolicyManagerDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + + List featureList = new ArrayList(); + + try { + conn = this.getConnection(); + String query = "SELECT PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " + + "F.EVALUVATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " + + "JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID WHERE PROFILE_ID=?"; + stmt = conn.prepareStatement(query); + stmt.setInt(1, profileId); + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + Feature feature = new Feature(); + feature.setId(resultSet.getInt("FEATURE_ID")); + feature.setCode(resultSet.getString("CODE")); + feature.setName(resultSet.getString("NAME")); + feature.setAttribute(resultSet.getObject("CONTENT")); + feature.setRuleValue(resultSet.getString("RULE")); + featureList.add(feature); + } + + } catch (SQLException e) { + String msg = "Unable to get the list of the features from database."; + log.error(msg); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + return featureList; + } + + @Override + public void deleteFeature(int featureId) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (SQLException e) { + + } + } + + + /** + * This method returns the device type id when supplied with device type name. + * + * @param deviceType + * @return + * @throws PolicyManagerDAOException + */ + private int getDeviceTypeId(String deviceType) throws PolicyManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + int deviceTypeId = -1; + try { + conn = this.getConnection(); + String query = "SELECT ID FROM DM_DEVICE_TYPE WHERE NAME = ?"; + stmt = conn.prepareStatement(query); + stmt.setString(1, deviceType); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + deviceTypeId = resultSet.getInt("ID"); + } + } catch (SQLException e) { + String msg = "Error occurred while selecting the device type id."; + log.error(msg, e); + throw new PolicyManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + return deviceTypeId; + } + } 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 new file mode 100644 index 0000000000..cddc3f834c --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java @@ -0,0 +1,157 @@ +/* +* 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.apache.tomcat.jdbc.pool.PoolProperties; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.core.common.DBTypes; +import org.wso2.carbon.policy.mgt.core.common.TestDBConfiguration; +import org.wso2.carbon.policy.mgt.core.common.TestDBConfigurations; +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.impl.PolicyDAOImpl; +import org.wso2.carbon.policy.mgt.core.util.FeatureCreator; +import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; + +import javax.sql.DataSource; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.File; +import java.sql.Connection; +import java.sql.Statement; +import java.util.List; + +public class PolicyDAOTestCase { + + + private DataSource dataSource; + private static final Log log = LogFactory.getLog(PolicyDAOTestCase.class); + + @BeforeClass + @Parameters("dbType") + public void setUpDB(String dbTypeStr) throws Exception { + DBTypes dbType = DBTypes.valueOf(dbTypeStr); + TestDBConfiguration dbConfig = getTestDBConfiguration(dbType); + PoolProperties properties = new PoolProperties(); + + log.info("Database Type : " + dbTypeStr); + + switch (dbType) { + + case MySql: + + log.info("Mysql Called..................................................." + dbTypeStr); + + properties.setUrl(dbConfig.getConnectionUrl()); + properties.setDriverClassName(dbConfig.getDriverClass()); + properties.setUsername(dbConfig.getUserName()); + properties.setPassword(dbConfig.getPwd()); + dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties); + PolicyManagementDAOFactory.init(dataSource); + break; + + case H2: + + properties.setUrl(dbConfig.getConnectionUrl()); + properties.setDriverClassName(dbConfig.getDriverClass()); + properties.setUsername(dbConfig.getUserName()); + properties.setPassword(dbConfig.getPwd()); + dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties); + this.initH2SQLScript(); + PolicyManagementDAOFactory.init(dataSource); + break; + + default: + } + } + + private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws PolicyManagerDAOException, + PolicyManagementException { + File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml"); + Document doc; + TestDBConfigurations dbConfigs; + + doc = PolicyManagerUtil.convertToDocument(deviceMgtConfig); + JAXBContext testDBContext; + + try { + testDBContext = JAXBContext.newInstance(TestDBConfigurations.class); + Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); + dbConfigs = (TestDBConfigurations) unmarshaller.unmarshal(doc); + } catch (JAXBException e) { + throw new PolicyManagerDAOException("Error parsing test db configurations", e); + } + for (TestDBConfiguration config : dbConfigs.getDbTypesList()) { + if (config.getDbType().equals(dbType.toString())) { + return config; + } + } + return null; + } + + private void initH2SQLScript() throws Exception { + Connection conn = null; + Statement stmt = null; + try { + conn = this.getDataSource().getConnection(); + stmt = conn.createStatement(); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'"); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + + } + } + + private void initMySQlSQLScript() throws Exception { + Connection conn = null; + Statement stmt = null; + try { + conn = this.getDataSource().getConnection(); + stmt = conn.createStatement(); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateMySqlTestDB.sql'"); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + } + } + + private DataSource getDataSource() { + return dataSource; + } + + @Test + public void addFeatures() throws PolicyManagerDAOException, PolicyManagementException, FeatureManagementException { + + PolicyDAOImpl policyDAO = new PolicyDAOImpl(); + List featureList = FeatureCreator.getFeatureList(); + for (Feature feature : featureList) { + policyDAO.addFeature(feature); + } + + } + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/TestUtils.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/TestUtils.java new file mode 100644 index 0000000000..3061f38fc3 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/TestUtils.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014, 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 java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +public class TestUtils { + + private static final Log log = LogFactory.getLog(TestUtils.class); + + public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing result set", e); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing prepared statement", e); + } + } + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing database connection", e); + } + } + } + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/DBTypes.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/DBTypes.java new file mode 100644 index 0000000000..7362d80451 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/DBTypes.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2014, 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.common; + + +public enum DBTypes { + Oracle("Oracle"),H2("H2"),MySql("MySql"); + + String dbName ; + DBTypes(String dbStrName) { + dbName = dbStrName; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/TestDBConfiguration.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/TestDBConfiguration.java new file mode 100644 index 0000000000..633041fdd2 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/TestDBConfiguration.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2014, 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.common; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "DBType") +public class TestDBConfiguration { + + private String connectionUrl; + private String driverClass; + private String userName; + private String pwd; + + @Override public String toString() { + return "TestDBConfiguration{" + + "connectionUrl='" + connectionUrl + '\'' + + ", driverClass='" + driverClass + '\'' + + ", userName='" + userName + '\'' + + ", pwd='" + pwd + '\'' + + ", dbType='" + dbType + '\'' + + '}'; + } + + private String dbType; + + @XmlElement(name = "connectionurl", nillable = false) + public String getConnectionUrl() { + return connectionUrl; + } + + public void setConnectionUrl(String connectionUrl) { + this.connectionUrl = connectionUrl; + } + + @XmlElement(name = "driverclass", nillable = false) + public String getDriverClass() { + return driverClass; + } + + public void setDriverClass(String driverClass) { + this.driverClass = driverClass; + } + + @XmlElement(name = "userName", nillable = false) + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + @XmlElement(name = "pwd", nillable = false) + public String getPwd() { + return pwd; + } + + public void setPwd(String pwd) { + this.pwd = pwd; + } + + @XmlAttribute(name = "typeName") + public String getDbType() { + return dbType; + } + + public void setDbType(String dbType) { + this.dbType = dbType; + } + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/TestDBConfigurations.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/TestDBConfigurations.java new file mode 100644 index 0000000000..629b8106a1 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/TestDBConfigurations.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014, 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.common; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement(name = "DeviceMgtTestDBConfigurations") +public class TestDBConfigurations { + + private List dbTypesList; + + @XmlElement(name = "DBType") + public List getDbTypesList() { + return dbTypesList; + } + + public void setDbTypesList(List dbTypesList) { + this.dbTypesList = dbTypesList; + } + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/FeatureCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/FeatureCreator.java new file mode 100644 index 0000000000..ea06c80c87 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/FeatureCreator.java @@ -0,0 +1,115 @@ +/* +* 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.util; + +import org.wso2.carbon.policy.mgt.common.Feature; + +import java.util.ArrayList; +import java.util.List; + +public class FeatureCreator { + + public static List getFeatureList() { + + Feature feature1 = new Feature(); + feature1.setName("Camera"); + feature1.setCode("C001"); + feature1.setDescription("Camera"); + feature1.setRuleValue("permit_override"); + + + Feature feature2 = new Feature(); + feature2.setName("LOCK"); + feature2.setCode("L001"); + feature2.setDescription("Lock the phone"); + feature2.setRuleValue("deny_override"); + + + Feature feature3 = new Feature(); + feature3.setName("WIFI"); + feature3.setCode("W001"); + feature3.setDescription("Wifi configuration for the device"); + feature3.setRuleValue("all_available"); + + Feature feature4 = new Feature(); + feature4.setName("RING"); + feature4.setCode("R001"); + feature4.setDescription("Ring the mobile"); + feature4.setRuleValue("first_applicable"); + + Feature feature5 = new Feature(); + feature5.setName("LDAP"); + feature5.setCode("L002"); + feature5.setDescription("LDAP Configurations"); + feature5.setRuleValue("all_available"); + + + Feature feature6 = new Feature(); + feature6.setName("VPN"); + feature6.setCode("V001"); + feature6.setDescription("VPN config for accessing the company network from out side"); + feature6.setRuleValue("all_available"); + + + Feature feature7 = new Feature(); + feature7.setName("PASSWORD"); + feature7.setCode("P001"); + feature7.setDescription("Setting the password for the mobile"); + feature7.setRuleValue("first_applicable"); + + Feature feature8 = new Feature(); + feature8.setName("WIPE"); + feature8.setCode("W002"); + feature8.setDescription("Wiping the company profile created to access the company secure data"); + feature8.setRuleValue("permit_override"); + + Feature feature9 = new Feature(); + feature9.setName("ENCRYPTION"); + feature9.setCode("E001"); + feature9.setDescription("Adding the encryption for the phone and SD card."); + feature9.setRuleValue("permit_override"); + + Feature feature10 = new Feature(); + feature10.setName("APP"); + feature10.setCode("A001"); + feature10.setDescription("Installing an application to the phone"); + feature10.setRuleValue("permit_override"); + + Feature feature11 = new Feature(); + feature11.setName("EMAIL"); + feature11.setCode("E002"); + feature11.setDescription("Email configurations of the phone."); + feature11.setRuleValue("all_applicable"); + + List featureList = new ArrayList(); + featureList.add(feature1); + featureList.add(feature2); + featureList.add(feature3); + featureList.add(feature4); + featureList.add(feature5); + featureList.add(feature6); + featureList.add(feature7); + featureList.add(feature8); + featureList.add(feature9); + featureList.add(feature10); + featureList.add(feature11); + + return featureList; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/log4j.properties b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/log4j.properties new file mode 100644 index 0000000000..7da6d6c9e1 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/log4j.properties @@ -0,0 +1,32 @@ +# +# Copyright 2009 WSO2, Inc. (http://wso2.com) +# +# Licensed 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. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=DEBUG, STD_OUT + +# Redirect log messages to console +log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender +log4j.appender.STD_OUT.Target=System.out +log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout +log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql new file mode 100644 index 0000000000..0fd55c652d --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -0,0 +1,213 @@ + +-- ----------------------------------------------------- +-- Table `DM_DEVICE_TYPE` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` ( + `ID` INT(11) NOT NULL , + `NAME` VARCHAR(300) NULL DEFAULT NULL , + PRIMARY KEY (`ID`) ) + +; + + +-- ----------------------------------------------------- +-- Table `DM_DEVICE` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `DM_DEVICE` ( + `ID` VARCHAR(20) NOT NULL , + `DESCRIPTION` TEXT NULL DEFAULT NULL , + `NAME` VARCHAR(100) NULL DEFAULT NULL , + `DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL , + `DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL , + `OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL , + `STATUS` VARCHAR(15) NULL DEFAULT NULL , + `DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL , + `DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL , + `OWNER` VARCHAR(45) NULL DEFAULT NULL , + `TENANT_ID` INT(11) NULL DEFAULT '0' , + PRIMARY KEY (`ID`) , + CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2` + FOREIGN KEY (`DEVICE_TYPE_ID` ) + REFERENCES `DM_DEVICE_TYPE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) + +; + + +-- ----------------------------------------------------- +-- Table `DM_PROFILE` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `DM_PROFILE` ( + `ID` INT NOT NULL AUTO_INCREMENT , + `PROFILE_NAME` VARCHAR(45) NOT NULL , + `TENANT_ID` INT NOT NULL , + `DEVICE_TYPE_ID` INT NOT NULL , + `CREATED_TIME` DATETIME NOT NULL , + `UPDATED_TIME` DATETIME NOT NULL , + PRIMARY KEY (`ID`) , + CONSTRAINT `DM_PROFILE_DEVICE_TYPE` + FOREIGN KEY (`DEVICE_TYPE_ID` ) + REFERENCES `DM_DEVICE_TYPE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +; + + +-- ----------------------------------------------------- +-- Table `DM_POLICY` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `DM_POLICY` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `NAME` VARCHAR(45) NULL DEFAULT NULL , + `TENANT_ID` INT(11) NOT NULL , + `PROFILE_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + CONSTRAINT `FK_DM_PROFILE_DM_POLICY` + FOREIGN KEY (`PROFILE_ID` ) + REFERENCES `DM_PROFILE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) + +; + + +-- ----------------------------------------------------- +-- Table `DM_DEVICE_POLICY` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `DM_DEVICE_POLICY` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `DEVICE_ID` VARCHAR(20) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + CONSTRAINT `FK_POLICY_DEVICE_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DEVICE_DEVICE_POLICY` + FOREIGN KEY (`DEVICE_ID` ) + REFERENCES `DM_DEVICE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +; + + +-- ----------------------------------------------------- +-- Table `DM_DEVICE_TYPE_POLICY` +-- ----------------------------------------------------- + + +CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE_POLICY` ( + `ID` INT(11) NOT NULL , + `DEVICE_TYPE_ID` INT(11) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + CONSTRAINT `FK_DEVICE_TYPE_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` + FOREIGN KEY (`DEVICE_TYPE_ID` ) + REFERENCES `DM_DEVICE_TYPE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +; + + +-- ----------------------------------------------------- +-- Table `DM_FEATURES` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `DM_FEATURES` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `NAME` VARCHAR(256) NOT NULL , + `CODE` VARCHAR(45) NULL DEFAULT NULL , + `DESCRIPTION` TEXT NULL DEFAULT NULL , + `EVALUVATION_RULE` VARCHAR(60) NOT NULL , + PRIMARY KEY (`ID`) ); + +; + + +-- ----------------------------------------------------- +-- Table `DM_PROFILE_FEATURES` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `DM_PROFILE_FEATURES` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `PROFILE_ID` INT(11) NOT NULL , + `FEATURE_ID` INT(11) NOT NULL , + `CONTENT` BLOB NULL DEFAULT NULL , + PRIMARY KEY (`ID`) , + CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1` + FOREIGN KEY (`FEATURE_ID` ) + REFERENCES `DM_FEATURES` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES` + FOREIGN KEY (`PROFILE_ID` ) + REFERENCES `DM_PROFILE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +; + + +-- ----------------------------------------------------- +-- Table `DM_ROLE_POLICY` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( + `ID` INT(11) NOT NULL , + `ROLE_NAME` VARCHAR(45) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + CONSTRAINT `FK_ROLE_POLICY_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +; + + +-- ----------------------------------------------------- +-- Table `DM_LOCATION` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS DM_LOCATION ( + `LAT` VARCHAR(45) NOT NULL , + `LONG` VARCHAR(45) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + CONSTRAINT `FK_DM_POLICY_DM_LOCATION` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); +; + + +-- ----------------------------------------------------- +-- Table `DM_TIME` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS DM_TIME ( + `STARTING_TIME` DATETIME NOT NULL , + `ENDING_TIME` DATETIME NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + CONSTRAINT `FK_DM_POLICY_DM_TIME` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); +; + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql new file mode 100644 index 0000000000..554847059b --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql @@ -0,0 +1,247 @@ +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; + +DROP SCHEMA IF EXISTS `WSO2CDM` ; +CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ; +USE `WSO2CDM` ; + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE_TYPE` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ( + `ID` INT(11) NOT NULL , + `NAME` VARCHAR(300) NULL DEFAULT NULL , + PRIMARY KEY (`ID`) ) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` ( + `ID` VARCHAR(20) NOT NULL , + `DESCRIPTION` TEXT NULL DEFAULT NULL , + `NAME` VARCHAR(100) NULL DEFAULT NULL , + `DATE_OF_ENROLLMENT` BIGINT(20) NULL DEFAULT NULL , + `DATE_OF_LAST_UPDATE` BIGINT(20) NULL DEFAULT NULL , + `OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL , + `STATUS` VARCHAR(15) NULL DEFAULT NULL , + `DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL , + `DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL , + `OWNER` VARCHAR(45) NULL DEFAULT NULL , + `TENANT_ID` INT(11) NULL DEFAULT '0' , + PRIMARY KEY (`ID`) , + INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2` (`DEVICE_TYPE_ID` ASC) , + CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2` + FOREIGN KEY (`DEVICE_TYPE_ID` ) + REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_PROFILE` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE` ( + `ID` INT NOT NULL AUTO_INCREMENT , + `PROFILE_NAME` VARCHAR(45) NOT NULL , + `TENANT_ID` INT NOT NULL , + `DEVICE_TYPE_ID` INT NOT NULL , + `CREATED_TIME` DATETIME NOT NULL , + `UPDATED_TIME` DATETIME NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `DM_PROFILE_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) , + CONSTRAINT `DM_PROFILE_DEVICE_TYPE` + FOREIGN KEY (`DEVICE_TYPE_ID` ) + REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_POLICY` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `NAME` VARCHAR(45) NULL DEFAULT NULL , + `TENANT_ID` INT(11) NOT NULL , + `PROFILE_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC) , + CONSTRAINT `FK_DM_PROFILE_DM_POLICY` + FOREIGN KEY (`PROFILE_ID` ) + REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE_POLICY` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `DEVICE_ID` VARCHAR(20) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC) , + INDEX `FK_DEVICE_DEVICE_POLICY` (`DEVICE_ID` ASC) , + CONSTRAINT `FK_POLICY_DEVICE_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DEVICE_DEVICE_POLICY` + FOREIGN KEY (`DEVICE_ID` ) + REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` ( + `ID` INT(11) NOT NULL , + `DEVICE_TYPE_ID` INT(11) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_DEVICE_TYPE_POLICY` (`POLICY_ID` ASC) , + INDEX `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) , + CONSTRAINT `FK_DEVICE_TYPE_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` + FOREIGN KEY (`DEVICE_TYPE_ID` ) + REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_FEATURES` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_FEATURES` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `NAME` VARCHAR(256) NOT NULL , + `CODE` VARCHAR(45) NULL DEFAULT NULL , + `DESCRIPTION` TEXT NULL DEFAULT NULL , + `EVALUVATION_RULE` VARCHAR(60) NOT NULL , + PRIMARY KEY (`ID`) ) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_PROFILE_FEATURES` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT , + `PROFILE_ID` INT(11) NOT NULL , + `FEATURE_ID` INT(11) NOT NULL , + `CONTENT` BLOB NULL DEFAULT NULL , + PRIMARY KEY (`ID`) , + INDEX `fk_DM_POLICY_FEATURES_DM_FEATURES1` (`FEATURE_ID` ASC) , + INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC) , + CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1` + FOREIGN KEY (`FEATURE_ID` ) + REFERENCES `WSO2CDM`.`DM_FEATURES` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES` + FOREIGN KEY (`PROFILE_ID` ) + REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_ROLE_POLICY` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ( + `ID` INT(11) NOT NULL , + `ROLE_NAME` VARCHAR(45) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + PRIMARY KEY (`ID`) , + INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC) , + CONSTRAINT `FK_ROLE_POLICY_POLICY` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_LOCATION` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_LOCATION` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_LOCATION` ( + `LAT` VARCHAR(45) NOT NULL , + `LONG` VARCHAR(45) NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + INDEX `FK_DM_POLICY_DM_LOCATION` (`POLICY_ID` ASC) , + CONSTRAINT `FK_DM_POLICY_DM_LOCATION` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_TIME` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `WSO2CDM`.`DM_TIME` ; + +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_TIME` ( + `STARTING_TIME` DATETIME NOT NULL , + `ENDING_TIME` DATETIME NOT NULL , + `POLICY_ID` INT(11) NOT NULL , + INDEX `FK_DM_POLICY_DM_TIME` (`POLICY_ID` ASC) , + CONSTRAINT `FK_DM_POLICY_DM_TIME` + FOREIGN KEY (`POLICY_ID` ) + REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/testdbconfig.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/testdbconfig.xml new file mode 100644 index 0000000000..ee2d323f32 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/testdbconfig.xml @@ -0,0 +1,33 @@ + + + + + + jdbc:mysql://10.100.0.47:3306/WSO2CDM + com.mysql.jdbc.Driver + root + root + + + jdbc:h2:mem:cdm-test-db;DB_CLOSE_DELAY=-1 + org.h2.Driver + wso2carbon + wso2carbon + + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/testng.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/testng.xml new file mode 100644 index 0000000000..02107984d5 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/testng.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml index 8363e939da..f6fe137b9b 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml @@ -1,17 +1,16 @@ - + org.wso2.carbon.devicemgt policy-mgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.devicemgt org.wso2.carbon.simple.policy.decision.point - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT bundle WSO2 Carbon - Simple Policy Decision Point WSO2 Carbon - Simple Policy Decision Point diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index 8dc5b9f79b..7a9524a9ce 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -23,21 +23,21 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt policy-mgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT pom WSO2 Carbon - Policy Management Component http://wso2.org - org.wso2.carbon.policy.mgt.core org.wso2.carbon.policy.mgt.common + org.wso2.carbon.policy.mgt.core org.wso2.carbon.policy.information.point org.wso2.carbon.simple.policy.decision.point org.wso2.carbon.complex.policy.decision.point diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index 6570f92373..41b5933cf7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt device-mgt-feature - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.device.mgt.server.feature pom - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT WSO2 Carbon - Device Management Server Feature http://wso2.org This feature contains the core bundles required for Back-end Devvice Management functionality diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index c31d3adb67..7c34752dc0 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -22,14 +22,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt device-mgt-feature - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT pom WSO2 Carbon - Device Management Feature http://wso2.org diff --git a/features/etc/feature.properties b/features/etc/feature.properties new file mode 100644 index 0000000000..a84f4e33e9 --- /dev/null +++ b/features/etc/feature.properties @@ -0,0 +1,241 @@ +################################################################################ +# Copyright 2015 WSO2, Inc. (http://wso2.com) +# +# WSO2 Inc. Licensed 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. +################################################################################ + +providerName=WSO2 Inc. + +########################## license properties ################################## +licenseURL=http://www.apache.org/licenses/LICENSE-2.0 + +license=\ + Apache License\n\ + Version 2.0, January 2004\n\ + http://www.apache.org/licenses/\n\ +\n\ + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\ +\n\ + 1. Definitions.\n\ +\n\ + "License" shall mean the terms and conditions for use, reproduction,\n\ + and distribution as defined by Sections 1 through 9 of this document.\n\ +\n\ + "Licensor" shall mean the copyright owner or entity authorized by\n\ + the copyright owner that is granting the License.\n\ +\n\ + "Legal Entity" shall mean the union of the acting entity and all\n\ + other entities that control, are controlled by, or are under common\n\ + control with that entity. For the purposes of this definition,\n\ + "control" means (i) the power, direct or indirect, to cause the\n\ + direction or management of such entity, whether by contract or\n\ + otherwise, or (ii) ownership of fifty percent (50%) or more of the\n\ + outstanding shares, or (iii) beneficial ownership of such entity.\n\ +\n\ + "You" (or "Your") shall mean an individual or Legal Entity\n\ + exercising permissions granted by this License.\n\ +\n\ + "Source" form shall mean the preferred form for making modifications,\n\ + including but not limited to software source code, documentation\n\ + source, and configuration files.\n\ +\n\ + "Object" form shall mean any form resulting from mechanical\n\ + transformation or translation of a Source form, including but\n\ + not limited to compiled object code, generated documentation,\n\ + and conversions to other media types.\n\ +\n\ + "Work" shall mean the work of authorship, whether in Source or\n\ + Object form, made available under the License, as indicated by a\n\ + copyright notice that is included in or attached to the work\n\ + (an example is provided in the Appendix below).\n\ +\n\ + "Derivative Works" shall mean any work, whether in Source or Object\n\ + form, that is based on (or derived from) the Work and for which the\n\ + editorial revisions, annotations, elaborations, or other modifications\n\ + represent, as a whole, an original work of authorship. For the purposes\n\ + of this License, Derivative Works shall not include works that remain\n\ + separable from, or merely link (or bind by name) to the interfaces of,\n\ + the Work and Derivative Works thereof.\n\ +\n\ + "Contribution" shall mean any work of authorship, including\n\ + the original version of the Work and any modifications or additions\n\ + to that Work or Derivative Works thereof, that is intentionally\n\ + submitted to Licensor for inclusion in the Work by the copyright owner\n\ + or by an individual or Legal Entity authorized to submit on behalf of\n\ + the copyright owner. For the purposes of this definition, "submitted"\n\ + means any form of electronic, verbal, or written communication sent\n\ + to the Licensor or its representatives, including but not limited to\n\ + communication on electronic mailing lists, source code control systems,\n\ + and issue tracking systems that are managed by, or on behalf of, the\n\ + Licensor for the purpose of discussing and improving the Work, but\n\ + excluding communication that is conspicuously marked or otherwise\n\ + designated in writing by the copyright owner as "Not a Contribution."\n\ +\n\ + "Contributor" shall mean Licensor and any individual or Legal Entity\n\ + on behalf of whom a Contribution has been received by Licensor and\n\ + subsequently incorporated within the Work.\n\ +\n\ + 2. Grant of Copyright License. Subject to the terms and conditions of\n\ + this License, each Contributor hereby grants to You a perpetual,\n\ + worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n\ + copyright license to reproduce, prepare Derivative Works of,\n\ + publicly display, publicly perform, sublicense, and distribute the\n\ + Work and such Derivative Works in Source or Object form.\n\ +\n\ + 3. Grant of Patent License. Subject to the terms and conditions of\n\ + this License, each Contributor hereby grants to You a perpetual,\n\ + worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n\ + (except as stated in this section) patent license to make, have made,\n\ + use, offer to sell, sell, import, and otherwise transfer the Work,\n\ + where such license applies only to those patent claims licensable\n\ + by such Contributor that are necessarily infringed by their\n\ + Contribution(s) alone or by combination of their Contribution(s)\n\ + with the Work to which such Contribution(s) was submitted. If You\n\ + institute patent litigation against any entity (including a\n\ + cross-claim or counterclaim in a lawsuit) alleging that the Work\n\ + or a Contribution incorporated within the Work constitutes direct\n\ + or contributory patent infringement, then any patent licenses\n\ + granted to You under this License for that Work shall terminate\n\ + as of the date such litigation is filed.\n\ +\n\ + 4. Redistribution. You may reproduce and distribute copies of the\n\ + Work or Derivative Works thereof in any medium, with or without\n\ + modifications, and in Source or Object form, provided that You\n\ + meet the following conditions:\n\ +\n\ + (a) You must give any other recipients of the Work or\n\ + Derivative Works a copy of this License; and\n\ +\n\ + (b) You must cause any modified files to carry prominent notices\n\ + stating that You changed the files; and\n\ +\n\ + (c) You must retain, in the Source form of any Derivative Works\n\ + that You distribute, all copyright, patent, trademark, and\n\ + attribution notices from the Source form of the Work,\n\ + excluding those notices that do not pertain to any part of\n\ + the Derivative Works; and\n\ +\n\ + (d) If the Work includes a "NOTICE" text file as part of its\n\ + distribution, then any Derivative Works that You distribute must\n\ + include a readable copy of the attribution notices contained\n\ + within such NOTICE file, excluding those notices that do not\n\ + pertain to any part of the Derivative Works, in at least one\n\ + of the following places: within a NOTICE text file distributed\n\ + as part of the Derivative Works; within the Source form or\n\ + documentation, if provided along with the Derivative Works; or,\n\ + within a display generated by the Derivative Works, if and\n\ + wherever such third-party notices normally appear. The contents\n\ + of the NOTICE file are for informational purposes only and\n\ + do not modify the License. You may add Your own attribution\n\ + notices within Derivative Works that You distribute, alongside\n\ + or as an addendum to the NOTICE text from the Work, provided\n\ + that such additional attribution notices cannot be construed\n\ + as modifying the License.\n\ +\n\ + You may add Your own copyright statement to Your modifications and\n\ + may provide additional or different license terms and conditions\n\ + for use, reproduction, or distribution of Your modifications, or\n\ + for any such Derivative Works as a whole, provided Your use,\n\ + reproduction, and distribution of the Work otherwise complies with\n\ + the conditions stated in this License.\n\ +\n\ + 5. Submission of Contributions. Unless You explicitly state otherwise,\n\ + any Contribution intentionally submitted for inclusion in the Work\n\ + by You to the Licensor shall be under the terms and conditions of\n\ + this License, without any additional terms or conditions.\n\ + Notwithstanding the above, nothing herein shall supersede or modify\n\ + the terms of any separate license agreement you may have executed\n\ + with Licensor regarding such Contributions.\n\ +\n\ + 6. Trademarks. This License does not grant permission to use the trade\n\ + names, trademarks, service marks, or product names of the Licensor,\n\ + except as required for reasonable and customary use in describing the\n\ + origin of the Work and reproducing the content of the NOTICE file.\n\ +\n\ + 7. Disclaimer of Warranty. Unless required by applicable law or\n\ + agreed to in writing, Licensor provides the Work (and each\n\ + Contributor provides its Contributions) on an "AS IS" BASIS,\n\ + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n\ + implied, including, without limitation, any warranties or conditions\n\ + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n\ + PARTICULAR PURPOSE. You are solely responsible for determining the\n\ + appropriateness of using or redistributing the Work and assume any\n\ + risks associated with Your exercise of permissions under this License.\n\ +\n\ + 8. Limitation of Liability. In no event and under no legal theory,\n\ + whether in tort (including negligence), contract, or otherwise,\n\ + unless required by applicable law (such as deliberate and grossly\n\ + negligent acts) or agreed to in writing, shall any Contributor be\n\ + liable to You for damages, including any direct, indirect, special,\n\ + incidental, or consequential damages of any character arising as a\n\ + result of this License or out of the use or inability to use the\n\ + Work (including but not limited to damages for loss of goodwill,\n\ + work stoppage, computer failure or malfunction, or any and all\n\ + other commercial damages or losses), even if such Contributor\n\ + has been advised of the possibility of such damages.\n\ +\n\ + 9. Accepting Warranty or Additional Liability. While redistributing\n\ + the Work or Derivative Works thereof, You may choose to offer,\n\ + and charge a fee for, acceptance of support, warranty, indemnity,\n\ + or other liability obligations and/or rights consistent with this\n\ + License. However, in accepting such obligations, You may act only\n\ + on Your own behalf and on Your sole responsibility, not on behalf\n\ + of any other Contributor, and only if You agree to indemnify,\n\ + defend, and hold each Contributor harmless for any liability\n\ + incurred by, or claims asserted against, such Contributor by reason\n\ + of your accepting any such warranty or additional liability.\n\ +\n\ + END OF TERMS AND CONDITIONS\n\ +\n\ + APPENDIX: How to apply the Apache License to your work.\n\ +\n\ + To apply the Apache License to your work, attach the following\n\ + boilerplate notice, with the fields enclosed by brackets "[]"\n\ + replaced with your own identifying information. (Don't include\n\ + the brackets!) The text should be enclosed in the appropriate\n\ + comment syntax for the file format. We also recommend that a\n\ + file or class name and description of purpose be included on the\n\ + same "printed page" as the copyright notice for easier\n\ + identification within third-party archives.\n\ +\n\ + Copyright [yyyy] [name of copyright owner]\n\ +\n\ + Licensed under the Apache License, Version 2.0 (the "License");\n\ + you may not use this file except in compliance with the License.\n\ + You may obtain a copy of the License at\n\ +\n\ + http://www.apache.org/licenses/LICENSE-2.0\n\ +\n\ + Unless required by applicable law or agreed to in writing, software\n\ + distributed under the License is distributed on an "AS IS" BASIS,\n\ + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\ + See the License for the specific language governing permissions and\n\ + limitations under the License.\n + +######################### copyright properties ################################# +copyrightURL=TODO + +copyright=\ +Copyright (c) WSO2 Inc. (http://wso2.com)\n\ +\n\ +WSO2 Inc. Licensed under the Apache License, Version 2.0 (the "License");\n\ +you may not use this file except in compliance with the License.\n\ +You may obtain a copy of the License at\n\ +\n\ +http://www.apache.org/licenses/LICENSE-2.0\n\ +\n\ +Unless required by applicable law or agreed to in writing, software\n\ +distributed under the License is distributed on an "AS IS" BASIS,\n\ +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\ +See the License for the specific language governing permissions and\n\ +limitations under the License.\n diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index 903a0a5630..d09ae350bb 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -18,20 +18,19 @@ ~ under the License. --> - + org.wso2.carbon.devicemgt policy-mgt-feature - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../pom.xml 4.0.0 org.wso2.carbon.policy.mgt.server.feature pom - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT WSO2 Carbon - Policy Management Server Feature http://wso2.org This feature contains the core bundles required for Back-end Devvice Management functionality diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml index a672a70e89..9322cd5d50 100644 --- a/features/policy-mgt/pom.xml +++ b/features/policy-mgt/pom.xml @@ -23,14 +23,14 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT ../../pom.xml 4.0.0 org.wso2.carbon.devicemgt policy-mgt-feature - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT pom WSO2 Carbon - Policy Management Feature http://wso2.org diff --git a/pom.xml b/pom.xml index 98ea945241..60ae986f8e 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt pom - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT WSO2 Carbon - Device Management - Parent http://wso2.org WSO2 Connected Device Manager Components @@ -610,7 +610,7 @@ 4.3.0 - 0.9.1-SNAPSHOT + 0.9.2-SNAPSHOT