From c13b942f0edc683e8e56622b00d5fa06ecabc7db Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Thu, 12 Mar 2015 19:41:39 +0530 Subject: [PATCH 01/12] Adding the DAO layers for the policy administration, Test cases are added for H2 database type and MySql, This is having the initial cut of the policy and profile saving --- .../policy/evaluator/FeatureFilterImpl.java | 2 +- .../policy/evaluator/PolicyFilterImpl.java | 2 +- .../org.wso2.carbon.policy.mgt.common/pom.xml | 7 +- .../carbon/policy/mgt/common/Feature.java | 9 + .../mgt/common/FeatureManagerService.java | 2 +- .../wso2/carbon/policy/mgt/common/Policy.java | 27 +- .../common/PolicyAdministratorService.java | 12 +- .../carbon/policy/mgt/common/Profile.java | 91 ++++ .../mgt/common/impl/PolicyManagement.java | 15 +- .../src/main/resources/mysql.sql | 211 ++++++++ .../mgt/common/utils/PolicyCreator.java | 10 +- .../org.wso2.carbon.policy.mgt.core/pom.xml | 45 +- .../carbon/policy/mgt/core/dao/PolicyDAO.java | 25 + .../core/dao/PolicyManagementDAOFactory.java | 14 +- .../mgt/core/dao/impl/PolicyDAOImpl.java | 491 +++++++++++++++++- .../policy/mgt/core/PolicyDAOTestCase.java | 157 ++++++ .../carbon/policy/mgt/core/TestUtils.java | 56 ++ .../policy/mgt/core/common/DBTypes.java | 29 ++ .../mgt/core/common/TestDBConfiguration.java | 90 ++++ .../mgt/core/common/TestDBConfigurations.java | 39 ++ .../policy/mgt/core/util/FeatureCreator.java | 115 ++++ .../src/test/resources/log4j.properties | 32 ++ .../src/test/resources/sql/CreateH2TestDB.sql | 213 ++++++++ .../test/resources/sql/CreateMySqlTestDB.sql | 247 +++++++++ .../src/test/resources/testdbconfig.xml | 33 ++ .../src/test/resources/testng.xml | 31 ++ components/policy-mgt/pom.xml | 2 +- 27 files changed, 1965 insertions(+), 42 deletions(-) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Profile.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/resources/mysql.sql create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/TestUtils.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/DBTypes.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/TestDBConfiguration.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/common/TestDBConfigurations.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/util/FeatureCreator.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/log4j.properties create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/testdbconfig.xml create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/testng.xml 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.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index c90bdcccb7..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 @@ -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,6 +70,14 @@ public class Policy { this.priorityId = priorityId; } + public Profile getProfile() { + return profile; + } + + public void setProfile(Profile profile) { + this.profile = profile; + } + public String getPolicyName() { return policyName; } @@ -79,14 +86,6 @@ public class Policy { this.policyName = policyName; } - public List getFeaturesList() { - return featuresList; - } - - public void setFeaturesList(List featuresList) { - this.featuresList = featuresList; - } - public boolean isGeneric() { return generic; } @@ -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 5095cca991..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,7 +18,8 @@ ~ under the License. --> - + org.wso2.carbon.devicemgt policy-mgt @@ -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/pom.xml b/components/policy-mgt/pom.xml index c658229e18..7a9524a9ce 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -36,8 +36,8 @@ 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 From 4754da70be87f5a756e59ef32714355063bd6bed Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Mon, 16 Mar 2015 12:39:08 +0530 Subject: [PATCH 02/12] get all devices when the username is provided --- .../carbon/device/mgt/core/DeviceManager.java | 3 ++ .../device/mgt/core/DeviceManagerImpl.java | 17 ++++++++++ .../carbon/device/mgt/core/dao/DeviceDAO.java | 8 +++++ .../mgt/core/dao/impl/DeviceDAOImpl.java | 34 +++++++++++++++++++ .../carbon/device/mgt/core/dto/Device.java | 9 +++++ .../core/service/DeviceManagementService.java | 6 ++++ 6 files changed, 77 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java index 1f2c4df376..9dd432c870 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -55,4 +55,7 @@ public interface DeviceManager { public OperationManager getOperationManager(String type) throws DeviceManagementException; + public List getDeviceListOfUser(String username) + throws DeviceManagementException, DeviceManagementDAOException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java index 64ebbf0e46..f1232fb658 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java @@ -203,4 +203,21 @@ public class DeviceManagerImpl implements DeviceManager { public DeviceManagementRepository getPluginRepository() { return pluginRepository; } + + @Override + public List getDeviceListOfUser(String username) + throws DeviceManagementException, DeviceManagementDAOException { + List devicesList = this.deviceDAO.getDeviceListOfUser(username); + List devicesOfUser=new ArrayList(); + for(int x=0;x getDevices(Integer 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 54010a8554..f4a08f107f 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 @@ -24,6 +24,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; @@ -76,6 +77,39 @@ public class DeviceDAOImpl implements DeviceDAO { } } + @Override public List getDeviceListOfUser(String username) + throws DeviceManagementDAOException { + Connection conn = this.getConnection(); + PreparedStatement stmt = null; + List deviceList = new ArrayList(); + try { + stmt = conn.prepareStatement( + "SELECT DM_DEVICE_TYPE.ID, DM_DEVICE_TYPE.NAME, DM_DEVICE.ID, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION FROM DM_DEVICE, DM_DEVICE_TYPE WHERE DM_DEVICE.DEVICE_TYPE_ID =DM_DEVICE_TYPE.ID AND DM_DEVICE.OWNER =?"); + stmt.setString(1, username); + ResultSet results = stmt.executeQuery(); + + while (results.next()) { + Device device = new Device(); + DeviceType deviceType=new DeviceType(); + int id=results.getInt(results.getInt(1)); + deviceType.setId((long) id); + deviceType.setName(results.getString(2)); + device.setId(results.getInt(3)); + device.setDeviceType(deviceType); + device.setDeviceTypeId(results.getInt(4)); + device.setDeviceIdentificationId(results.getString(5)); + deviceList.add(device); + } + } catch (SQLException e) { + String msg = "Error occurred while fetching the list of devices belongs to " + username; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return deviceList; + } + @Override public void updateDevice(Device device) throws DeviceManagementDAOException { 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 fae390ac6b..f98c9fda86 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 @@ -34,6 +34,15 @@ public class Device implements Serializable { private String ownerShip; private int tenantId; private Integer deviceTypeId; + private DeviceType deviceType; + + public DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceType deviceType) { + this.deviceType = deviceType; + } public Integer 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/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index cb908edd7e..4245918736 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -22,6 +22,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.OperationManager; import org.wso2.carbon.device.mgt.core.DeviceManager; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import java.util.List; @@ -93,4 +94,9 @@ public class DeviceManagementService implements DeviceManager { getOperationManager(type); } + + @Override public List getDeviceListOfUser(String username) throws DeviceManagementException,DeviceManagementDAOException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().getDeviceListOfUser(username); + } + } From 8662eb36e44c17bf91756052a4f6c804a91c8b2a Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 17 Mar 2015 17:27:41 +0530 Subject: [PATCH 03/12] Adding operation manager related changes --- ...ManagerService.java => DeviceManager.java} | 13 +--- .../mgt/core/DeviceManagementService.java | 62 +++++++++++++++++ ... DeviceManagementServiceProviderImpl.java} | 66 ++++++++++++------ .../carbon/device/mgt/core/DeviceManager.java | 58 ---------------- .../mgt/GenericArtifactManagerFactory.java | 22 ++++++ .../core/operation/mgt/CommandOperation.java | 27 ++++++++ .../core/operation/mgt/ConfigOperation.java | 22 ++++++ .../mgt/core/operation/mgt}/Operation.java | 2 +- .../mgt}/OperationExecutionException.java | 2 +- .../mgt}/OperationManagementException.java | 2 +- .../core/operation/mgt}/OperationManager.java | 8 ++- .../operation/mgt/OperationManagerImpl.java | 69 +++++++++++++++++++ .../core/operation/mgt/SimpleOperation.java | 22 ++++++ .../core/operation/mgt/dao/OperationDAO.java | 22 ++++++ .../dao/OperationManagementDAOException.java | 23 +++++++ .../dao/OperationManagementDAOFactory.java | 22 ++++++ .../mgt/dao/OperationManagementDAOUtil.java | 22 ++++++ .../mgt/dao/OperationMappingDAO.java | 22 ++++++ .../mgt/dao/impl/AbstractOperationDAO.java | 22 ++++++ .../mgt/dao/impl/CommandOperationDAOImpl.java | 61 ++++++++++++++++ .../mgt/dao/impl/ConfigOperationDAOImpl.java | 22 ++++++ .../mgt/dao/impl/OperationMappingDAOImpl.java | 22 ++++++ .../mgt/dao/impl/SimpleOperationDAOImpl.java | 22 ++++++ ....java => DeviceManagementServiceImpl.java} | 27 +++----- .../mgt/core/DeviceManagementBaseTest.java | 22 ++++++ .../core/DeviceOperationManagementTests.java | 22 ++++++ ...gerService.java => TestDeviceManager.java} | 12 +--- .../src/test/resources/sql/h2.sql | 0 28 files changed, 595 insertions(+), 123 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/{DeviceManagerService.java => DeviceManager.java} (92%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementService.java rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/{DeviceManagerImpl.java => DeviceManagementServiceProviderImpl.java} (75%) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java rename components/device-mgt/{org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common => org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt}/Operation.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common => org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt}/OperationExecutionException.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common => org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt}/OperationManagementException.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common => org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt}/OperationManager.java (87%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOUtil.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/{DeviceManagementService.java => DeviceManagementServiceImpl.java} (83%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementBaseTest.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/{TestDeviceManagerService.java => TestDeviceManager.java} (86%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java similarity index 92% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java index 2002520ca1..808c39347c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java @@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.common.spi; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.OperationManager; import java.util.List; @@ -29,10 +28,10 @@ import java.util.List; * This represents the service provider interface that has to be implemented by any of new * device type plugin implementation intended to be managed through CDM. */ -public interface DeviceManagerService { +public interface DeviceManager { /** - * Method to retrieve the provider type that implements DeviceManagerService interface. + * Method to retrieve the provider type that implements DeviceManager interface. * * @return Returns provider type */ @@ -129,12 +128,4 @@ public interface DeviceManagerService { */ boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; - /** - * Method to retrieve the Operation manager implementation associated with a given plugin. - * - * @return An appropriate instance of the underlying operation management implementation - * @throws DeviceManagementException - */ - OperationManager getOperationManager() throws DeviceManagementException; - } 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 new file mode 100644 index 0000000000..bef3adf5d5 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementService.java @@ -0,0 +1,62 @@ +/* + * 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.device.mgt.core; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.core.config.license.License; +import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; + +import java.util.List; + +/** + * Proxy class for all Device Management related operations that take the corresponding plugin type in + * and resolve the appropriate plugin implementation + */ +public interface DeviceManagementService { + + boolean enrollDevice(Device device) throws DeviceManagementException; + + boolean modifyEnrollment(Device device) throws DeviceManagementException; + + boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; + + boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; + + boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException; + + boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException; + + List getAllDevices(String type) throws DeviceManagementException; + + Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; + + boolean updateDeviceInfo(Device device) throws DeviceManagementException; + + boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; + + OperationManager getOperationManager(String type) throws DeviceManagementException; + + License getLicense(String type) throws DeviceManagementException; + + boolean addLicense(String type, License license) throws DeviceManagementException; + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java similarity index 75% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 64ebbf0e46..0c21ccd7e4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -22,7 +22,11 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.OperationManager; +import org.wso2.carbon.device.mgt.core.config.license.License; +import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; @@ -32,24 +36,26 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.Status; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import java.util.ArrayList; import java.util.List; +import java.util.Locale; -public class DeviceManagerImpl implements DeviceManager { +public class DeviceManagementServiceProviderImpl implements DeviceManager { - private static Log log = LogFactory.getLog(DeviceManagerImpl.class); private DeviceDAO deviceDAO; private DeviceTypeDAO deviceTypeDAO; - private DeviceManagementConfig config; private DeviceManagementRepository pluginRepository; + private OperationManager operationManager; + private LicenseManager licenseManager; - public DeviceManagerImpl(DeviceManagementConfig config, - DeviceManagementRepository pluginRepository) { - this.config = config; + public DeviceManagementServiceProviderImpl(DeviceManagementRepository pluginRepository) { this.pluginRepository = pluginRepository; this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + this.operationManager = new OperationManagerImpl(); + this.licenseManager = new LicenseManagerImpl(); } @Override @@ -66,9 +72,8 @@ public class DeviceManagerImpl implements DeviceManager { deviceDto.setDeviceTypeId(deviceTypeId); this.getDeviceDAO().addDevice(deviceDto); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while enrolling the device '" + device.getId() + "'", - e); + throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + + "'", e); } return status; } @@ -81,9 +86,8 @@ public class DeviceManagerImpl implements DeviceManager { try { this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while modifying the device '" + device.getId() + "'", - e); + throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + + "'", e); } return status; } @@ -139,8 +143,8 @@ public class DeviceManagerImpl implements DeviceManager { devicesList.add(convertedDevice); } } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while obtaining the device for type '" + type + "'", e); + throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + + "'", e); } return devicesList; } @@ -165,9 +169,8 @@ public class DeviceManagerImpl implements DeviceManager { } } } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while obtaining the device for id '" + deviceId.getId() + "'", - e); + throw new DeviceManagementException("Error occurred while obtaining the device for id '" + + deviceId.getId() + "'", e); } return convertedDevice; } @@ -188,11 +191,31 @@ public class DeviceManagerImpl implements DeviceManager { } public OperationManager getOperationManager(String type) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); - return dms.getOperationManager(); + return operationManager; } - public DeviceDAO getDeviceDAO() { + @Override + public License getLicense(String type) throws DeviceManagementException { + try { + return licenseManager.getLicense(type, Locale.ENGLISH.getLanguage()); + } catch (LicenseManagementException e) { + throw new DeviceManagementException("Error occurred while retrieving license configured for " + + "device type '" + type + "'", e); + } + } + + @Override + public boolean addLicense(String type, License license) throws DeviceManagementException { + try { + return licenseManager.addLicense(type, license); + } catch (LicenseManagementException e) { + throw new DeviceManagementException("Error occurred while adding license for device type '" + + type + "'", e); + + } + } + + public DeviceDAO getDeviceDAO() { return deviceDAO; } @@ -203,4 +226,5 @@ public class DeviceManagerImpl implements DeviceManager { public DeviceManagementRepository getPluginRepository() { return pluginRepository; } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java deleted file mode 100644 index 1f2c4df376..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.device.mgt.core; - -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.OperationManager; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; - -import java.util.List; - -/** - * Proxy class for all Device Management related operations that take the corresponding plugin type in - * and resolve the appropriate plugin implementation - */ -public interface DeviceManager { - - public boolean enrollDevice(Device device) throws DeviceManagementException; - - public boolean modifyEnrollment(Device device) throws DeviceManagementException; - - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; - - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; - - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException; - - public boolean setActive(DeviceIdentifier deviceId, boolean status) - throws DeviceManagementException; - - public List getAllDevices(String type) throws DeviceManagementException; - - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; - - public boolean updateDeviceInfo(Device device) throws DeviceManagementException; - - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException; - - public OperationManager getOperationManager(String type) throws DeviceManagementException; - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java new file mode 100644 index 0000000000..8d07b6343c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.license.mgt; + +public class GenericArtifactManagerFactory { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java new file mode 100644 index 0000000000..37e65a8352 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java @@ -0,0 +1,27 @@ +/* + * 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.device.mgt.core.operation.mgt; + +import org.wso2.carbon.device.mgt.common.Operation; + +public class CommandOperation extends Operation { + + + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java new file mode 100644 index 0000000000..ec94611279 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt; + +public class ConfigOperation { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/Operation.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/Operation.java index 82f18f7068..a424180260 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/Operation.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.core.operation.mgt; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationExecutionException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationExecutionException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationExecutionException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationExecutionException.java index 1df7c95de4..94e870a440 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationExecutionException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationExecutionException.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.core.operation.mgt; public class OperationExecutionException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManagementException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementException.java index ceace67fd3..cdf8f79c93 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementException.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.core.operation.mgt; public class OperationManagementException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java similarity index 87% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java index b3a5b2a347..98b521c988 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java @@ -15,7 +15,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.common; +package org.wso2.carbon.device.mgt.core.operation.mgt; + +import org.wso2.carbon.device.mgt.common.*; import java.util.List; @@ -30,7 +32,7 @@ public interface OperationManager { * * @param operation Operation to be added * @param devices List of DeviceIdentifiers to execute the operation - * @throws OperationManagementException If some unusual behaviour is observed while adding the + * @throws org.wso2.carbon.device.mgt.common.OperationManagementException If some unusual behaviour is observed while adding the * operation */ public boolean addOperation(Operation operation, List devices) @@ -60,7 +62,7 @@ public interface OperationManager { * TODO: Move this into a separate FeatureManager * @param deviceType - Device type * @return a list of Feature objects. - * @throws FeatureManagementException + * @throws org.wso2.carbon.device.mgt.common.FeatureManagementException */ public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java new file mode 100644 index 0000000000..9d9923e0eb --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -0,0 +1,69 @@ +/* + * 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.device.mgt.core.operation.mgt; + +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; + +import java.util.List; + +public class OperationManagerImpl implements OperationManager { + + private OperationDAO commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); + private OperationDAO configOperationDAO = OperationManagementDAOFactory.getConfigOperationDAO(); + private OperationDAO simpleOperationDAO = OperationManagementDAOFactory.getSimpleOperationDAO(); + + @Override + public boolean addOperation(Operation operation, + List devices) throws OperationManagementException { + try { + return this.lookupOperationDAO(operation).addOperation(operation); + } catch (OperationManagementDAOException e) { + throw new OperationManagementException("Error occurred while adding operation", e); + } + } + + @Override + public List getOperations(DeviceIdentifier deviceId) throws OperationManagementException { + return null; + } + + @Override + public List getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException { + return null; + } + + @Override + public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException { + return null; + } + + private OperationDAO lookupOperationDAO(Operation operation) { + if (operation instanceof CommandOperation) { + return commandOperationDAO; + } else if (operation instanceof ConfigOperation) { + return configOperationDAO; + } else { + return simpleOperationDAO; + } + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java new file mode 100644 index 0000000000..2b967cd2a1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt; + +public class SimpleOperation { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java new file mode 100644 index 0000000000..0833f05981 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt.dao; + +public class OperationDAO { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOException.java new file mode 100644 index 0000000000..918259ebb1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOException.java @@ -0,0 +1,23 @@ +/* + * 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.device.mgt.core.operation.mgt.dao; + +public class OperationManagementDAOException extends Exception { + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java new file mode 100644 index 0000000000..b3d52caf3d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt.dao; + +public class OperationManagementDAOFactory { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOUtil.java new file mode 100644 index 0000000000..266c664d18 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOUtil.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt.dao; + +public class OperationManagementDAOUtil { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java new file mode 100644 index 0000000000..f4405a5813 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt.dao; + +public class OperationMappingDAO { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java new file mode 100644 index 0000000000..c89087fbef --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt.dao.impl; + +public class AbstractOperationDAO { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java new file mode 100644 index 0000000000..bfb95d7034 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -0,0 +1,61 @@ +/* + * 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.device.mgt.core.operation.mgt.dao.impl; + +import org.wso2.carbon.device.mgt.common.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; + +import javax.sql.DataSource; +import java.util.List; + +public class CommandOperationDAOImpl extends AbstractOperationDAO { + + public CommandOperationDAOImpl(DataSource dataSource) { + super(dataSource); + } + + @Override + public boolean addOperation(Operation operation) throws OperationManagementDAOException { + CommandOperation booleanOp = (CommandOperation) operation; + addOperationMetadata(); + return false; + } + + @Override + public boolean updateOperation(Operation operation) throws OperationManagementDAOException { + return false; + } + + @Override + public boolean deleteOperation(int id) throws OperationManagementDAOException { + return false; + } + + @Override + public Operation getOperation(int id) throws OperationManagementDAOException { + return null; + } + + @Override + public List getOperations() throws OperationManagementDAOException { + return null; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java new file mode 100644 index 0000000000..9a3a351138 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt.dao.impl; + +public class ConfigOperationDAOImpl { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java new file mode 100644 index 0000000000..c98367ca00 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt.dao.impl; + +public class OperationMappingDAOImpl { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java new file mode 100644 index 0000000000..107d08953d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core.operation.mgt.dao.impl; + +public class SimpleOperationDAOImpl { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java similarity index 83% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java index cb908edd7e..9b742f7054 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementServiceImpl.java @@ -20,13 +20,13 @@ package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.OperationManager; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.DeviceManager; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import java.util.List; -public class DeviceManagementService implements DeviceManager { +public class DeviceManagementServiceImpl implements DeviceManager { @Override public boolean enrollDevice(Device device) throws DeviceManagementException { @@ -40,8 +40,7 @@ public class DeviceManagementService implements DeviceManager { @Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager() - .disenrollDevice(deviceId); + return DeviceManagementDataHolder.getInstance().getDeviceManager().disenrollDevice(deviceId); } @Override @@ -55,10 +54,8 @@ public class DeviceManagementService implements DeviceManager { } @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) - throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager() - .setActive(deviceId, status); + public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().setActive(deviceId, status); } @Override @@ -69,10 +66,7 @@ public class DeviceManagementService implements DeviceManager { @Override public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - - Device device = - DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId); - return device; + return DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId); } @Override @@ -81,16 +75,13 @@ public class DeviceManagementService implements DeviceManager { } @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager() - .setOwnership(deviceId, ownershipType); + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().setOwnership(deviceId, ownershipType); } @Override public OperationManager getOperationManager(String type) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager(). - getOperationManager(type); + return DeviceManagementDataHolder.getInstance().getDeviceManager().getOperationManager(type); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementBaseTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementBaseTest.java new file mode 100644 index 0000000000..d2a329f503 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementBaseTest.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core; + +public class DeviceManagementBaseTest { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java new file mode 100644 index 0000000000..8fa8d1dca9 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.core; + +public class DeviceOperationManagementTests { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java similarity index 86% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagerService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java index 0870b10307..9e93d33c32 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java @@ -20,18 +20,17 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.OperationManager; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import java.util.List; -public class TestDeviceManagerService implements DeviceManagerService { +public class TestDeviceManager implements DeviceManager { public static final String DEVICE_TYPE_TEST = "Test"; @Override public String getProviderType() { - return TestDeviceManagerService.DEVICE_TYPE_TEST; + return TestDeviceManager.DEVICE_TYPE_TEST; } @Override @@ -84,9 +83,4 @@ public class TestDeviceManagerService implements DeviceManagerService { return false; } - @Override - public OperationManager getOperationManager() throws DeviceManagementException { - return null; - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql new file mode 100644 index 0000000000..e69de29bb2 From 31b931537f44963ce596d9b04141313696b6d384 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 17 Mar 2015 17:30:30 +0530 Subject: [PATCH 04/12] Adding operation and license management implementations --- .../device/mgt/common/DeviceIdentifier.java | 3 +- .../org.wso2.carbon.device.mgt.core/pom.xml | 9 +- .../mgt/core/DeviceManagementRepository.java | 22 +- .../mgt/core/DeviceManagementService.java | 27 +- .../DeviceManagementServiceProviderImpl.java | 374 +++++++++--------- .../carbon/device/mgt/core/dao/DeviceDAO.java | 20 +- .../core/dao/DeviceManagementDAOFactory.java | 1 + .../device/mgt/core/dao/DeviceTypeDAO.java | 6 +- .../mgt/core/dao/impl/DeviceDAOImpl.java | 313 ++++++++------- .../mgt/core/dao/impl/DeviceTypeDAOImpl.java | 95 ++--- .../carbon/device/mgt/core/dto/Device.java | 8 +- .../device/mgt/core/dto/DeviceType.java | 6 +- .../internal/DeviceManagementDataHolder.java | 12 +- .../DeviceManagementServiceComponent.java | 98 ++--- .../mgt/GenericArtifactManagerFactory.java | 74 +++- .../license/mgt/LicenseManagementService.java | 4 +- .../mgt/core/license/mgt/LicenseManager.java | 4 +- .../core/license/mgt/LicenseManagerImpl.java | 122 ++++-- .../core/operation/mgt/CommandOperation.java | 10 +- .../core/operation/mgt/ConfigOperation.java | 56 ++- .../core/operation/mgt/OperationManager.java | 5 +- .../operation/mgt/OperationManagerImpl.java | 41 +- .../core/operation/mgt/SimpleOperation.java | 4 +- .../core/operation/mgt/dao/OperationDAO.java | 17 +- .../dao/OperationManagementDAOException.java | 36 ++ .../dao/OperationManagementDAOFactory.java | 125 ++++++ .../mgt/dao/OperationManagementDAOUtil.java | 27 ++ .../mgt/dao/OperationMappingDAO.java | 11 +- .../mgt/dao/impl/AbstractOperationDAO.java | 50 ++- .../mgt/dao/impl/CommandOperationDAOImpl.java | 38 +- .../mgt/dao/impl/ConfigOperationDAOImpl.java | 39 +- .../mgt/dao/impl/OperationMappingDAOImpl.java | 48 ++- .../mgt/dao/impl/SimpleOperationDAOImpl.java | 33 +- .../service/DeviceManagementServiceImpl.java | 84 ++-- .../mgt/core/util/DeviceManagerUtil.java | 46 +-- .../mgt/core/DeviceManagementBaseTest.java | 48 +++ .../core/DeviceManagementRepositoryTests.java | 31 +- .../core/DeviceOperationManagementTests.java | 56 ++- .../core/dao/DeviceManagementDAOTests.java | 10 +- .../src/test/resources/sql/h2.sql | 58 +++ .../src/test/resources/testng.xml | 1 + pom.xml | 4 +- 42 files changed, 1446 insertions(+), 630 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index 8ac709519a..351fd1656b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -19,9 +19,8 @@ package org.wso2.carbon.device.mgt.common; public class DeviceIdentifier { - private String type; - private String id; + private String type; public String getType() { return type; 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 8babf3187b..3d7c7ed651 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 @@ -71,7 +71,10 @@ org.wso2.carbon.registry.core.exceptions, org.wso2.carbon.registry.core.service, org.wso2.carbon.registry.core.session, - org.w3c.dom + org.w3c.dom, + org.wso2.carbon.governance.api.exception, + org.wso2.carbon.governance.api.generic, + org.wso2.carbon.governance.api.generic.dataobjects !org.wso2.carbon.device.mgt.core.internal, @@ -152,6 +155,10 @@ org.wso2.carbon org.wso2.carbon.base + + org.wso2.carbon.governance + org.wso2.carbon.governance.api + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java index db8aaaeacb..048317a1e7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java @@ -20,7 +20,8 @@ package org.wso2.carbon.device.mgt.core; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.common.spi.DeviceManager; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.util.HashMap; @@ -28,35 +29,36 @@ import java.util.Map; public class DeviceManagementRepository { - private static final Log log = LogFactory.getLog(DeviceManagerUtil.class); - private Map providers; + private Map providers; public DeviceManagementRepository() { - providers = new HashMap(); + providers = new HashMap(); } - public void addDeviceManagementProvider(DeviceManagerService provider) { + public void addDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException { String deviceType = provider.getProviderType(); try { DeviceManagerUtil.registerDeviceType(deviceType); } catch (DeviceManagementException e) { - log.error("Exception occurred while registering the device type.", e); + throw new DeviceManagementException("Error occurred while adding device management provider '" + + deviceType + "'"); } providers.put(deviceType, provider); } - public void removeDeviceManagementProvider(DeviceManagerService provider) { + public void removeDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException { String deviceType = provider.getProviderType(); - try { DeviceManagerUtil.unregisterDeviceType(deviceType); } catch (DeviceManagementException e) { - log.error("Exception occurred while registering the device type.", e); + throw new DeviceManagementException("Error occurred while removing device management provider '" + + deviceType + "'", e); } providers.remove(deviceType); } - public DeviceManagerService getDeviceManagementProvider(String type) { + public DeviceManager getDeviceManagementProvider(String type) { return providers.get(type); } + } 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 bef3adf5d5..9521daf7e6 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 @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.core.config.license.License; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; @@ -31,32 +32,8 @@ import java.util.List; * Proxy class for all Device Management related operations that take the corresponding plugin type in * and resolve the appropriate plugin implementation */ -public interface DeviceManagementService { - - boolean enrollDevice(Device device) throws DeviceManagementException; - - boolean modifyEnrollment(Device device) throws DeviceManagementException; - - boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; - - boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; - - boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException; - - boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException; +public interface DeviceManagementService extends DeviceManager, LicenseManager, OperationManager { List getAllDevices(String type) throws DeviceManagementException; - Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; - - boolean updateDeviceInfo(Device device) throws DeviceManagementException; - - boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; - - OperationManager getOperationManager(String type) throws DeviceManagementException; - - License getLicense(String type) throws DeviceManagementException; - - boolean addLicense(String type, License license) throws DeviceManagementException; - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 0c21ccd7e4..c5421a6b6c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -17,18 +17,9 @@ */ package org.wso2.carbon.device.mgt.core; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.core.config.license.License; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; -import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; 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.DeviceManagementDAOFactory; @@ -36,195 +27,218 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.Status; +import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import java.util.ArrayList; import java.util.List; -import java.util.Locale; -public class DeviceManagementServiceProviderImpl implements DeviceManager { +public class DeviceManagementServiceProviderImpl implements DeviceManagementService { - private DeviceDAO deviceDAO; - private DeviceTypeDAO deviceTypeDAO; - private DeviceManagementRepository pluginRepository; + private DeviceDAO deviceDAO; + private DeviceTypeDAO deviceTypeDAO; + private DeviceManagementRepository pluginRepository; private OperationManager operationManager; private LicenseManager licenseManager; - public DeviceManagementServiceProviderImpl(DeviceManagementRepository pluginRepository) { - this.pluginRepository = pluginRepository; - this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); - this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + public DeviceManagementServiceProviderImpl(DeviceManagementRepository pluginRepository) { + this.pluginRepository = pluginRepository; + this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); + this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); this.operationManager = new OperationManagerImpl(); this.licenseManager = new LicenseManagerImpl(); - } - - @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(device.getType()); - boolean status = dms.enrollDevice(device); - try { - org.wso2.carbon.device.mgt.core.dto.Device deviceDto = - DeviceManagementDAOUtil.convertDevice(device); - Integer deviceTypeId = - this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); - deviceDto.setStatus(Status.ACTIVE); - deviceDto.setDeviceTypeId(deviceTypeId); - this.getDeviceDAO().addDevice(deviceDto); - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + - "'", e); - } - return status; - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(device.getType()); - boolean status = dms.modifyEnrollment(device); - try { - this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + - "'", e); - } - return status; - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.disenrollDevice(deviceId); - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.isEnrolled(deviceId); - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.isActive(deviceId); - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) - throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.setActive(deviceId, status); - } - - @Override - public List getAllDevices(String type) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); - List devicesList = new ArrayList(); - try { - Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type); - List devices = - this.getDeviceDAO().getDevices(deviceTypeId); - - for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) { - DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId()); - Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType); - DeviceIdentifier deviceIdentifier = - DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType); - Device dmsDevice = dms.getDevice(deviceIdentifier); - if (dmsDevice != null) { - convertedDevice.setProperties(dmsDevice.getProperties()); - convertedDevice.setFeatures(dmsDevice.getFeatures()); - } - devicesList.add(convertedDevice); - } - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + - "'", e); - } - return devicesList; - } - - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - Device convertedDevice = null; - try { - Integer deviceTypeId = - this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType()); - org.wso2.carbon.device.mgt.core.dto.Device device = - this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId()); - if (device != null) { - convertedDevice = DeviceManagementDAOUtil - .convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId)); - Device dmsDevice = dms.getDevice(deviceId); - if (dmsDevice != null) { - convertedDevice.setProperties(dmsDevice.getProperties()); - convertedDevice.setFeatures(dmsDevice.getFeatures()); - } - } - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for id '" + - deviceId.getId() + "'", e); - } - return convertedDevice; - } - - @Override - public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(device.getType()); - return dms.updateDeviceInfo(device); - } - - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - DeviceManagerService dms = - this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.setOwnership(deviceId, ownershipType); - } - - public OperationManager getOperationManager(String type) throws DeviceManagementException { - return operationManager; - } - - @Override - public License getLicense(String type) throws DeviceManagementException { - try { - return licenseManager.getLicense(type, Locale.ENGLISH.getLanguage()); - } catch (LicenseManagementException e) { - throw new DeviceManagementException("Error occurred while retrieving license configured for " + - "device type '" + type + "'", e); - } } @Override - public boolean addLicense(String type, License license) throws DeviceManagementException { - try { - return licenseManager.addLicense(type, license); - } catch (LicenseManagementException e) { - throw new DeviceManagementException("Error occurred while adding license for device type '" + - type + "'", e); + public String getProviderType() { + return null; + } + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + boolean status = dms.enrollDevice(device); + try { + org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device); + DeviceType deviceType = this.getDeviceTypeDAO().getDeviceType(device.getType()); + deviceDto.setStatus(Status.ACTIVE); + deviceDto.setDeviceTypeId(deviceType.getId()); + this.getDeviceDAO().addDevice(deviceDto); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while enrolling the device " + + "'" + device.getId() + "'", e); } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + boolean status = dms.modifyEnrollment(device); + try { + this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while modifying the device " + + "'" + device.getId() + "'", e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.disenrollDevice(deviceId); + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isEnrolled(deviceId); + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isActive(deviceId); + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.setActive(deviceId, status); + } + + @Override + public List getAllDevices() throws DeviceManagementException { + return null; + } + + @Override + public List getAllDevices(String type) throws DeviceManagementException { + DeviceManager dms = this.getPluginRepository().getDeviceManagementProvider(type); + List devicesList = new ArrayList(); + try { + DeviceType dt = this.getDeviceTypeDAO().getDeviceType(type); + List devices = + this.getDeviceDAO().getDevices(dt.getId()); + + for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) { + DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId()); + Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType); + DeviceIdentifier deviceIdentifier = + DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType); + Device dmsDevice = dms.getDevice(deviceIdentifier); + if (dmsDevice != null) { + convertedDevice.setProperties(dmsDevice.getProperties()); + convertedDevice.setFeatures(dmsDevice.getFeatures()); + } + devicesList.add(convertedDevice); + } + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while obtaining the device for type " + + "'" + type + "'", e); + } + return devicesList; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + Device convertedDevice = null; + try { + DeviceType deviceType = + this.getDeviceTypeDAO().getDeviceType(deviceId.getType()); + org.wso2.carbon.device.mgt.core.dto.Device device = + this.getDeviceDAO().getDevice(deviceId); + if (device != null) { + convertedDevice = DeviceManagementDAOUtil + .convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceType.getId())); + Device dmsDevice = dms.getDevice(deviceId); + if (dmsDevice != null) { + convertedDevice.setProperties(dmsDevice.getProperties()); + convertedDevice.setFeatures(dmsDevice.getFeatures()); + } + } + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while obtaining the device for id " + + "'" + deviceId.getId() + "'", e); + } + return convertedDevice; + } + + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + return dms.updateDeviceInfo(device); + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + DeviceManager dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.setOwnership(deviceId, ownershipType); + } + + public OperationManager getOperationManager(String type) throws DeviceManagementException { + return operationManager; + } + + @Override + public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { + return licenseManager.getLicense(deviceType, languageCode); + } + + @Override + public boolean addLicense(String type, License license) throws LicenseManagementException { + return licenseManager.addLicense(type, license); } public DeviceDAO getDeviceDAO() { - return deviceDAO; - } + return deviceDAO; + } - public DeviceTypeDAO getDeviceTypeDAO() { - return deviceTypeDAO; - } + public DeviceTypeDAO getDeviceTypeDAO() { + return deviceTypeDAO; + } - public DeviceManagementRepository getPluginRepository() { - return pluginRepository; - } + public DeviceManagementRepository getPluginRepository() { + return pluginRepository; + } + + @Override + public boolean addOperation(Operation operation, + List devices) throws OperationManagementException { + return operationManager.addOperation(operation, devices); + } + + @Override + public List getOperations(DeviceIdentifier deviceId) throws OperationManagementException { + return operationManager.getOperations(deviceId); + } + + @Override + public List getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException { + return operationManager.getPendingOperations(deviceId); + } + + @Override + public List getFeatures(String deviceType) throws FeatureManagementException { + return operationManager.getFeatures(deviceType); + } } 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 4e3a7f86ca..d4f07cf5d2 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 @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.dao; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dto.Device; import org.wso2.carbon.device.mgt.core.dto.Status; @@ -32,27 +33,22 @@ public interface DeviceDAO { void updateDevice(Device device) throws DeviceManagementDAOException; - void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException; + void updateDeviceStatus(int deviceId, Status status) throws DeviceManagementDAOException; - void deleteDevice(Long deviceId) throws DeviceManagementDAOException; + void deleteDevice(int deviceId) throws DeviceManagementDAOException; - Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException; + Device getDevice(int deviceId) throws DeviceManagementDAOException; - /** - * @param type - Device type. - * @param identifier - Device identifier. - * @return the Device object which matches given data - * @throws DeviceManagementDAOException - */ - Device getDeviceByDeviceIdentifier(Integer type, String identifier) - throws DeviceManagementDAOException; + Device getDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementDAOException; List getDevices() throws DeviceManagementDAOException; + List getDeviceIds(List devices) throws DeviceManagementDAOException; + /** * @param type - The device type id. * @return a list of devices based on the type id. * @throws DeviceManagementDAOException */ - List getDevices(Integer type) throws DeviceManagementDAOException; + List getDevices(int type) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java index df6ee073a7..10df0539a5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java @@ -90,4 +90,5 @@ public class DeviceManagementDAOFactory { public static DataSource getDataSource() { return dataSource; } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java index bed0d07ddd..b59781b876 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java @@ -33,10 +33,10 @@ public interface DeviceTypeDAO { List getDeviceTypes() throws DeviceManagementDAOException; - DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException; + DeviceType getDeviceType(int id) throws DeviceManagementDAOException; - Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException; + DeviceType getDeviceType(String name) throws DeviceManagementDAOException; - void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException; + void removeDeviceType(String type) 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 54010a8554..df80629a0f 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 @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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; @@ -37,164 +38,186 @@ import java.util.List; public class DeviceDAOImpl implements DeviceDAO { - private DataSource dataSource; - private static final Log log = LogFactory.getLog(DeviceDAOImpl.class); + private DataSource dataSource; + private static final Log log = LogFactory.getLog(DeviceDAOImpl.class); - public DeviceDAOImpl(DataSource dataSource) { - this.dataSource = dataSource; - } + public DeviceDAOImpl(DataSource dataSource) { + this.dataSource = dataSource; + } - @Override - public void addDevice(Device device) throws DeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String createDBQuery = - "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, " + - "OWNERSHIP, STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + @Override + public void addDevice(Device device) throws DeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String sql = + "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, " + + "OWNERSHIP, STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, device.getDescription()); + stmt.setString(2, device.getName()); + stmt.setLong(3, new Date().getTime()); + stmt.setLong(4, new Date().getTime()); + stmt.setString(5, device.getOwnerShip()); + stmt.setString(6, device.getStatus().toString()); + stmt.setInt(7, device.getDeviceTypeId()); + stmt.setString(8, device.getDeviceIdentificationId()); + stmt.setString(9, device.getOwnerId()); + stmt.setInt(10, device.getTenantId()); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while enrolling device " + + "'" + device.getName() + "'", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, device.getDescription()); - stmt.setString(2, device.getName()); - stmt.setLong(3, new Date().getTime()); - stmt.setLong(4, new Date().getTime()); - stmt.setString(5, device.getOwnerShip()); - stmt.setString(6, device.getStatus().toString()); - stmt.setInt(7, device.getDeviceTypeId()); - stmt.setString(8, device.getDeviceIdentificationId()); - stmt.setString(9, device.getOwnerId()); - stmt.setInt(10, device.getTenantId()); - stmt.executeUpdate(); - } catch (SQLException e) { - String msg = "Error occurred while enrolling device '" + device.getName() + "'"; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); - } finally { - DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - } + @Override + public void updateDevice(Device device) throws DeviceManagementDAOException { - @Override - public void updateDevice(Device device) throws DeviceManagementDAOException { + } - } + @Override + public void updateDeviceStatus(int deviceId, Status status) throws DeviceManagementDAOException { - @Override - public void updateDeviceStatus(Long deviceId, Status status) - throws DeviceManagementDAOException { + } - } + @Override + public void deleteDevice(int deviceId) throws DeviceManagementDAOException { - @Override - public void deleteDevice(Long deviceId) throws DeviceManagementDAOException { + } - } + @Override + public Device getDevice(int deviceId) throws DeviceManagementDAOException { + return null; + } - @Override - public Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException { - return null; - } + @Override + public Device getDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + Device device = null; + try { + conn = this.getConnection(); + String sql = + "SELECT d.ID, d.DESCRIPTION, d.NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, " + + "d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DEVICE_TYPE dt WHERE " + + "dt.NAME = ? AND d.DEVICE_IDENTIFICATION = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, deviceIdentifier.getType()); + stmt.setString(2, deviceIdentifier.getId()); - @Override - public Device getDeviceByDeviceIdentifier(Integer type, String identifier) - throws DeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - ResultSet resultSet = null; - Device device = null; - try { - conn = this.getConnection(); - String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " + - "DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " + - "DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " + - "WHERE DM_DEVICE.DEVICE_TYPE_ID=? AND " + - "DM_DEVICE.DEVICE_IDENTIFICATION=?"; - stmt = conn.prepareStatement(selectDBQueryForType); - stmt.setInt(1, type); - stmt.setString(2, identifier); - resultSet = stmt.executeQuery(); - while (resultSet.next()) { - device = new Device(); - device.setId(resultSet.getInt(1)); - device.setDescription(resultSet.getString(2)); - device.setName(resultSet.getString(3)); - device.setDateOfEnrollment(resultSet.getLong(4)); - device.setDateOfLastUpdate(resultSet.getLong(5)); - //TODO:- Ownership is not a enum in DeviceDAO - device.setOwnerShip(resultSet.getString(6)); - device.setStatus(Status.valueOf(resultSet.getString(7))); - device.setDeviceTypeId(resultSet.getInt(8)); - device.setDeviceIdentificationId(resultSet.getString(9)); - device.setOwnerId(resultSet.getString(10)); - device.setTenantId(resultSet.getInt(11)); - } - } catch (SQLException e) { - String msg = "Error occurred while listing devices for type '" + type + "'"; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); - } finally { - DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet); - } - return device; - } + rs = stmt.executeQuery(); + if (rs.next()) { + device = new Device(); + device.setId(rs.getInt("ID")); + device.setDescription(rs.getString("DESCRIPTION")); + device.setName(rs.getString("NAME")); + device.setDateOfEnrollment(rs.getLong("DATE_OF_ENROLLMENT")); + device.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE")); + //TODO:- Ownership is not a enum in DeviceDAO + device.setOwnerShip(rs.getString("OWNERSHIP")); + device.setStatus(Status.valueOf(rs.getString("STATUS"))); + device.setDeviceTypeId(rs.getInt("DEVICE_TYPE_ID")); + device.setDeviceIdentificationId(rs.getString("DEVICE_IDENTIFICATION")); + device.setOwnerId(rs.getString("OWNER")); + device.setTenantId(rs.getInt("TENANT_ID")); + } + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while listing devices for type " + + "'" + deviceIdentifier.getType() + "'", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, rs); + } + return device; + } - @Override - public List getDevices() throws DeviceManagementDAOException { - return null; - } + @Override + public List getDevices() throws DeviceManagementDAOException { + return null; + } - @Override - public List getDevices(Integer type) throws DeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - ResultSet resultSet = null; - List devicesList = null; - try { - conn = this.getConnection(); - String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " + - "DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " + - "DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " + - "WHERE DM_DEVICE.DEVICE_TYPE_ID=?"; - stmt = conn.prepareStatement(selectDBQueryForType); - stmt.setInt(1, type); - resultSet = stmt.executeQuery(); - devicesList = new ArrayList(); - while (resultSet.next()) { - Device device = new Device(); - device.setId(resultSet.getInt(1)); - device.setDescription(resultSet.getString(2)); - device.setName(resultSet.getString(3)); - device.setDateOfEnrollment(resultSet.getLong(4)); - device.setDateOfLastUpdate(resultSet.getLong(5)); - //TODO:- Ownership is not a enum in DeviceDAO - device.setOwnerShip(resultSet.getString(6)); - device.setStatus(Status.valueOf(resultSet.getString(7))); - device.setDeviceTypeId(resultSet.getInt(8)); - device.setDeviceIdentificationId(resultSet.getString(9)); - device.setOwnerId(resultSet.getString(10)); - device.setTenantId(resultSet.getInt(11)); - devicesList.add(device); - } - } catch (SQLException e) { - String msg = "Error occurred while listing devices for type '" + type + "'"; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); - } finally { - DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet); - } - return devicesList; - } + @Override + public List getDeviceIds(List devices) throws DeviceManagementDAOException { + List deviceIds = new ArrayList(); + try { + Connection conn = this.getConnection(); + String sql = "SELECT DISTINCT ID FROM DEVICE WHERE NAME IN (?) AND ID IN (?)"; + PreparedStatement stmt = conn.prepareStatement(sql); + //stmt.setArray(1, new java.sql.Date[0]); + stmt.setString(2, ""); + ResultSet rs = stmt.executeQuery(); + while (rs.next()) { + deviceIds.add(rs.getInt("ID")); + } + return deviceIds; + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while retrieving device ids", e); + } + } - private Connection getConnection() throws DeviceManagementDAOException { - try { - return dataSource.getConnection(); - } catch (SQLException e) { - throw new DeviceManagementDAOException( - "Error occurred while obtaining a connection from the device " + - "management metadata repository datasource", e); - } - } + private String getDeviceNameString(List devices) { + StringBuilder sb = new StringBuilder(); + for (DeviceIdentifier device : devices) { + sb.append(device.getId()); + } + return sb.toString(); + } + + @Override + public List getDevices(int type) throws DeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + List devicesList = null; + try { + conn = this.getConnection(); + String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " + + "DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " + + "DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " + + "WHERE DM_DEVICE.DEVICE_TYPE_ID = ?"; + stmt = conn.prepareStatement(selectDBQueryForType); + stmt.setInt(1, type); + resultSet = stmt.executeQuery(); + devicesList = new ArrayList(); + while (resultSet.next()) { + Device device = new Device(); + device.setId(resultSet.getInt(1)); + device.setDescription(resultSet.getString(2)); + device.setName(resultSet.getString(3)); + device.setDateOfEnrollment(resultSet.getLong(4)); + device.setDateOfLastUpdate(resultSet.getLong(5)); + //TODO:- Ownership is not a enum in DeviceDAO + device.setOwnerShip(resultSet.getString(6)); + device.setStatus(Status.valueOf(resultSet.getString(7))); + device.setDeviceTypeId(resultSet.getInt(8)); + device.setDeviceIdentificationId(resultSet.getString(9)); + device.setOwnerId(resultSet.getString(10)); + device.setTenantId(resultSet.getInt(11)); + devicesList.add(device); + } + } catch (SQLException e) { + String msg = "Error occurred while listing devices for type '" + type + "'"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + return devicesList; + } + + private Connection getConnection() throws DeviceManagementDAOException { + try { + return dataSource.getConnection(); + } catch (SQLException e) { + throw new DeviceManagementDAOException( + "Error occurred while obtaining a connection from the device " + + "management metadata repository datasource", e); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java index a7bf9d3802..caac62456f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java @@ -50,9 +50,8 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { stmt.setString(1, deviceType.getName()); stmt.execute(); } catch (SQLException e) { - String msg = "Error occurred while registering the device type '" + deviceType.getName() + "'"; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); + throw new DeviceManagementDAOException("Error occurred while registering the device type " + + "'" + deviceType.getName() + "'", e); } finally { DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); } @@ -65,85 +64,88 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { @Override public List getDeviceTypes() throws DeviceManagementDAOException { - Connection conn = this.getConnection(); + Connection conn = null; PreparedStatement stmt = null; - List deviceTypes = new ArrayList(); + ResultSet rs = null; + List deviceTypes = null; try { - stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE"); - ResultSet results = stmt.executeQuery(); + conn = this.getConnection(); + String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE"; + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); - while (results.next()) { + while (rs.next()) { + deviceTypes = new ArrayList(); DeviceType deviceType = new DeviceType(); - deviceType.setId(results.getLong("DEVICE_TYPE_ID")); - deviceType.setName(results.getString("DEVICE_TYPE")); + deviceType.setId(rs.getInt("DEVICE_TYPE_ID")); + deviceType.setName(rs.getString("DEVICE_TYPE")); deviceTypes.add(deviceType); } + return deviceTypes; } catch (SQLException e) { - String msg = "Error occurred while fetching the registered device types"; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); + throw new DeviceManagementDAOException("Error occurred while fetching the registered device types", e); } finally { - DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + DeviceManagementDAOUtil.cleanupResources(conn, stmt, rs); } - return deviceTypes; } @Override - public DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException { - Connection conn = this.getConnection(); + public DeviceType getDeviceType(int id) throws DeviceManagementDAOException { + Connection conn = null; PreparedStatement stmt = null; - DeviceType deviceType = null; + ResultSet rs = null; try { - stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID=?"); + conn = this.getConnection(); + String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID = ?"; + stmt = conn.prepareStatement(sql); stmt.setInt(1, id); - ResultSet results = stmt.executeQuery(); - while (results.next()) { + rs = stmt.executeQuery(); + DeviceType deviceType = null; + while (rs.next()) { deviceType = new DeviceType(); - deviceType.setId(results.getLong("DEVICE_TYPE_ID")); - deviceType.setName(results.getString("DEVICE_TYPE")); + deviceType.setId(rs.getInt("DEVICE_TYPE_ID")); + deviceType.setName(rs.getString("DEVICE_TYPE")); } + return deviceType; } catch (SQLException e) { - String msg = "Error occurred while fetching the registered device type"; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); + throw new DeviceManagementDAOException("Error occurred while fetching the registered device type", e); } finally { - DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + DeviceManagementDAOUtil.cleanupResources(conn, stmt, rs); } - return deviceType; } @Override - public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException { - - Connection conn = this.getConnection(); + public DeviceType getDeviceType(String type) throws DeviceManagementDAOException { + Connection conn = null; PreparedStatement stmt = null; - ResultSet resultSet = null; - Integer deviceTypeId = null; - + ResultSet rs = null; try { - String createDBQuery = "SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?"; - stmt = conn.prepareStatement(createDBQuery); + conn = this.getConnection(); + String sql = "SELECT ID From DM_DEVICE_TYPE WHERE NAME = ?"; + stmt = conn.prepareStatement(sql); stmt.setString(1, type); - resultSet = stmt.executeQuery(); + rs = stmt.executeQuery(); - while (resultSet.next()) { - deviceTypeId = resultSet.getInt(1); + int id = -1; + if (rs.next()) { + id = rs.getInt("ID"); } + DeviceType deviceType = new DeviceType(); + deviceType.setId(id); + deviceType.setName(type); + return deviceType; } catch (SQLException e) { - String msg = "Error occurred while fetch device type id for device type '" + type + "'"; - log.error(msg, e); - throw new DeviceManagementDAOException(msg, e); + throw new DeviceManagementDAOException("Error occurred while fetch device type id for device type " + + "'" + type + "'", e); } finally { - DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + DeviceManagementDAOUtil.cleanupResources(conn, stmt, rs); } - - return deviceTypeId; } @Override - public void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException { + public void removeDeviceType(String type) throws DeviceManagementDAOException { } @@ -157,4 +159,5 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { throw new DeviceManagementDAOException(msg, e); } } + } 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 fae390ac6b..87e4e477e6 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 @@ -23,7 +23,7 @@ import java.io.Serializable; public class Device implements Serializable { private static final long serialVersionUID = -8101106997837486245L; - private Integer id; + private int id; private String description; private String name; private Long dateOfEnrollment; @@ -33,13 +33,13 @@ public class Device implements Serializable { private String ownerId; private String ownerShip; private int tenantId; - private Integer deviceTypeId; + private int deviceTypeId; - public Integer getDeviceTypeId() { + public int getDeviceTypeId() { return deviceTypeId; } - public void setDeviceTypeId(Integer deviceTypeId) { + public void setDeviceTypeId(int deviceTypeId) { this.deviceTypeId = deviceTypeId; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java index cd23498202..85f1f948f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java @@ -23,14 +23,14 @@ import java.io.Serializable; public class DeviceType implements Serializable { private static final long serialVersionUID = 7927802716452548282L; - private Long id; + private int id; private String name; - public Long getId() { + public int getId() { return id; } - public void setId(Long id) { + public void setId(int id) { this.id = id; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 21c9379bae..7406993c3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -19,7 +19,7 @@ package org.wso2.carbon.device.mgt.core.internal; -import org.wso2.carbon.device.mgt.core.DeviceManager; +import org.wso2.carbon.device.mgt.core.DeviceManagementService; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; import org.wso2.carbon.registry.core.service.RegistryService; @@ -30,7 +30,7 @@ public class DeviceManagementDataHolder { private RealmService realmService; private TenantManager tenantManager; - private DeviceManager deviceManager; + private DeviceManagementService deviceManagerProvider; private LicenseManager licenseManager; private RegistryService registryService; private LicenseConfig licenseConfig; @@ -64,12 +64,12 @@ public class DeviceManagementDataHolder { return tenantManager; } - public DeviceManager getDeviceManager() { - return deviceManager; + public DeviceManagementService getDeviceManagementProvider() { + return deviceManagerProvider; } - public void setDeviceManager(DeviceManager deviceManager) { - this.deviceManager = deviceManager; + public void setDeviceManagementProvider(DeviceManagementService deviceManagerProvider) { + this.deviceManagerProvider = deviceManagerProvider; } public RegistryService getRegistryService() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 979323200e..ac3a7b832e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -22,11 +22,11 @@ import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; -import org.wso2.carbon.device.mgt.core.DeviceManager; -import org.wso2.carbon.device.mgt.core.DeviceManagerImpl; +import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; +import org.wso2.carbon.device.mgt.core.DeviceManagementService; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; @@ -38,7 +38,7 @@ import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementService; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; -import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; @@ -52,11 +52,11 @@ import org.wso2.carbon.user.core.service.RealmService; * bind="setRealmService" * unbind="unsetRealmService" * @scr.reference name="device.manager.service" - * interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagerService" + * interface="org.wso2.carbon.device.mgt.common.spi.DeviceManager" * cardinality="0..n" * policy="dynamic" - * bind="setDeviceManagerService" - * unbind="unsetDeviceManagerService" + * bind="setDeviceManager" + * unbind="unsetDeviceManager" * @scr.reference name="registry.service" * interface="org.wso2.carbon.registry.core.service.RegistryService" * cardinality="1..1" @@ -74,6 +74,7 @@ public class DeviceManagementServiceComponent { if (log.isDebugEnabled()) { log.debug("Initializing device management core bundle"); } + /* Initializing Device Management Configuration */ DeviceConfigurationManager.getInstance().initConfig(); DeviceManagementConfig config = @@ -82,8 +83,9 @@ public class DeviceManagementServiceComponent { DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig(); DeviceManagementDAOFactory.init(dsConfig); - DeviceManager deviceManager = new DeviceManagerImpl(config, this.getPluginRepository()); - DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager); + DeviceManagementService deviceManagementProvider = + new DeviceManagementServiceProviderImpl(this.getPluginRepository()); + DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider); LicenseConfigurationManager.getInstance().initConfig(); LicenseConfig licenseConfig = @@ -98,25 +100,17 @@ public class DeviceManagementServiceComponent { System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP); if (setupOption != null) { if (log.isDebugEnabled()) { - log.debug( - "-Dsetup is enabled. Device management repository schema initialization " + - "is about to begin"); + log.debug("-Dsetup is enabled. Device management repository schema initialization is about to " + + "begin"); } this.setupDeviceManagementSchema(dsConfig); - // this.setupDefaultLicenses(licenseConfig); + this.setupDefaultLicenses(licenseConfig); } - if (log.isDebugEnabled()) { - log.debug("Registering OSGi service DeviceManagementService"); - } - /* Registering Device Management service */ - BundleContext bundleContext = componentContext.getBundleContext(); - bundleContext.registerService(DeviceManagementService.class.getName(), - new DeviceManagementService(), null); - /* Registering License Management service */ - bundleContext.registerService(LicenseManagementService.class.getName(), - new LicenseManagementService(), null); - if (log.isDebugEnabled()) { + /* Registering declarative service instances exposed by DeviceManagementServiceComponent */ + this.registerServices(componentContext); + + if (log.isDebugEnabled()) { log.debug("Device management core bundle has been successfully initialized"); } } catch (Throwable e) { @@ -125,6 +119,16 @@ public class DeviceManagementServiceComponent { } } + private void registerServices(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("Registering OSGi service DeviceManagementServiceImpl"); + } + /* Registering Device Management Service */ + BundleContext bundleContext = componentContext.getBundleContext(); + bundleContext.registerService(DeviceManagementServiceImpl.class.getName(), + new DeviceManagementServiceImpl(), null); + } + private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException { DeviceManagementSchemaInitializer initializer = @@ -139,50 +143,54 @@ public class DeviceManagementServiceComponent { "database schema", e); } if (log.isDebugEnabled()) { - log.debug( - "Device management metadata repository schema has been successfully initialized"); + log.debug("Device management metadata repository schema has been successfully initialized"); } } private void setupDefaultLicenses(LicenseConfig licenseConfig) throws LicenseManagementException { - LicenseManager licenseManager = - DeviceManagementDataHolder.getInstance().getLicenseManager(); + LicenseManager licenseManager = DeviceManagementDataHolder.getInstance().getLicenseManager(); for (License license : licenseConfig.getLicenses()) { - License extLicense = - licenseManager.getLicense(license.getName(), license.getLanguage()); - if (extLicense != null) { - continue; + License extLicense = licenseManager.getLicense(license.getName(), license.getLanguage()); + if (extLicense == null) { + licenseManager.addLicense(license.getName(), license);; } - licenseManager.addLicense(license); } } /** * Sets Device Manager service. * - * @param deviceManagerService An instance of DeviceManagerService + * @param deviceManager An instance of DeviceManager */ - protected void setDeviceManagerService(DeviceManagerService deviceManagerService) { + protected void setDeviceManager(DeviceManager deviceManager) { if (log.isDebugEnabled()) { - log.debug("Setting Device Management Service Provider : '" + - deviceManagerService.getProviderType() + "'"); + log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'"); } - this.getPluginRepository().addDeviceManagementProvider(deviceManagerService); - } + try { + this.getPluginRepository().addDeviceManagementProvider(deviceManager); + } catch (DeviceManagementException e) { + log.error("Error occurred while adding device management provider '" + + deviceManager.getProviderType() + "'"); + } + } /** * Unsets Device Management service. * - * @param deviceManagerService An Instance of DeviceManagerService + * @param deviceManager An Instance of DeviceManager */ - protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) { + protected void unsetDeviceManager(DeviceManager deviceManager) { if (log.isDebugEnabled()) { - log.debug("Unsetting Device Management Service Provider : '" + - deviceManagerService.getProviderType() + "'"); + log.debug("Unsetting Device Management Service Provider : '" + deviceManager.getProviderType() + "'"); } - this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService); - } + try { + this.getPluginRepository().removeDeviceManagementProvider(deviceManager); + } catch (DeviceManagementException e) { + log.error("Error occurred while removing device management provider '" + + deviceManager.getProviderType() + "'"); + } + } /** * Sets Realm Service. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java index 8d07b6343c..f1fbbb617f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java @@ -1,22 +1,72 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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 + * 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. + * 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.device.mgt.core.license.mgt; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; +import org.wso2.carbon.governance.api.generic.GenericArtifactManager; +import org.wso2.carbon.registry.api.Registry; +import org.wso2.carbon.registry.core.exceptions.RegistryException; + +import java.util.HashMap; +import java.util.Map; + public class GenericArtifactManagerFactory { + + private static Map tenantArtifactManagers = + new HashMap(); + private static final Object lock = new Object(); + + public static GenericArtifactManager getTenantAwareGovernanceArtifactManager() throws + LicenseManagementException { + Registry registry; + int tenantId; + try { + tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + registry = + DeviceManagementDataHolder.getInstance().getRegistryService().getGovernanceSystemRegistry( + tenantId); + } catch (RegistryException e) { + throw new LicenseManagementException("Error occurred while initializing tenant system registry " + + "to be used to manipulate License artifacts", e); + } + + try { + GenericArtifactManager artifactManager; + synchronized (lock) { + artifactManager = + tenantArtifactManagers.get(tenantId); + if (artifactManager == null) { + /* Hack, to fix https://wso2.org/jira/browse/REGISTRY-2427 */ + //GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); + artifactManager = + new GenericArtifactManager((org.wso2.carbon.registry.core.Registry) registry, + DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY); + tenantArtifactManagers.put(tenantId, artifactManager); + } + } + return artifactManager; + } catch (RegistryException e) { + throw new LicenseManagementException("Error occurred while initializing GovernanceArtifactManager " + + "associated with tenant '" + CarbonContext.getThreadLocalCarbonContext().getTenantDomain() + "'"); + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementService.java index d6fe3df5da..92615e66d6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementService.java @@ -29,8 +29,8 @@ public class LicenseManagementService implements LicenseManager { } @Override - public void addLicense(License license) throws LicenseManagementException { - DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(license); + public boolean addLicense(String deviceType, License license) throws LicenseManagementException { + return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(deviceType, license); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManager.java index 18dfa06d01..df614f5fbb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManager.java @@ -22,8 +22,8 @@ import org.wso2.carbon.device.mgt.core.config.license.License; public interface LicenseManager { - License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException; + License getLicense(String deviceType, String languageCode) throws LicenseManagementException; - void addLicense(License license) throws LicenseManagementException; + boolean addLicense(String deviceType, License license) throws LicenseManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagerImpl.java index dca15462bc..42af35fcc9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagerImpl.java @@ -1,57 +1,111 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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 + * 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. + * 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.device.mgt.core.license.mgt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.core.DeviceManagerImpl; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; import org.wso2.carbon.device.mgt.core.config.license.License; -import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; -import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; +import org.wso2.carbon.governance.api.exception.GovernanceException; +import org.wso2.carbon.governance.api.generic.GenericArtifactFilter; +import org.wso2.carbon.governance.api.generic.GenericArtifactManager; +import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact; +import javax.xml.namespace.QName; import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Locale; public class LicenseManagerImpl implements LicenseManager { - private static Log log = LogFactory.getLog(DeviceManagerImpl.class); - private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); + private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class); + private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); - @Override - public License getLicense(final String deviceType, final String languageCode) - throws LicenseManagementException { - License deviceLicense = new License(); - LicenseConfig licenseConfig = DeviceManagementDataHolder.getInstance().getLicenseConfig(); - for (License license : licenseConfig.getLicenses()) { - if ((deviceType.equals(license.getName())) && - (languageCode.equals(license.getLanguage()))) { - deviceLicense = license; - break; - } - } - return deviceLicense; - } + @Override + public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException { + GenericArtifactManager artifactManager = + GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(); + try { + GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() { + @Override + public boolean matches(GenericArtifact artifact) throws GovernanceException { + String attributeNameVal = artifact.getAttribute( + DeviceManagementConstants.LicenseProperties.NAME); + String attributeLangVal = artifact.getAttribute( + DeviceManagementConstants.LicenseProperties.LANGUAGE); + return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.equals + (deviceType) && attributeLangVal.equals(languageCode)); + } + }); + if (artifacts == null || artifacts.length <= 0) { + return null; + } + return this.populateLicense(artifacts[0]); + } catch (GovernanceException e) { + throw new LicenseManagementException("Error occurred while retrieving license corresponding to " + + "device type '" + deviceType + "'"); + } catch (ParseException e) { + throw new LicenseManagementException("Error occurred while parsing the ToDate/FromDate date string " + + "of the license configured upon the device type '" + deviceType + "'"); + } + } - @Override - public void addLicense(License license) throws LicenseManagementException { + private License populateLicense(GenericArtifact artifact) throws GovernanceException, ParseException { + License license = new License(); + license.setName(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.NAME)); + license.setProvider(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER)); + license.setVersion(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VERSION)); + license.setLanguage(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE)); + license.setText(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.TEXT)); + license.setValidFrom(format.parse(artifact.getAttribute( + DeviceManagementConstants.LicenseProperties.VALID_FROM))); + license.setValidTo(format.parse(artifact.getAttribute( + DeviceManagementConstants.LicenseProperties.VALID_TO))); + return license; + } - } + @Override + public boolean addLicense(String deviceType, License license) throws LicenseManagementException { + GenericArtifactManager artifactManager = + GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager(); + try { + GenericArtifact artifact = + artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com", + DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY)); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.NAME, license.getName()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VERSION, license.getVersion()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER, license.getProvider()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE, license.getLanguage()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.TEXT, license.getText()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, + license.getValidTo().toString()); + artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM, + license.getValidFrom().toString()); + artifactManager.addGenericArtifact(artifact); + return true; + } catch (GovernanceException e) { + throw new LicenseManagementException("Error occurred while adding license for device type " + + deviceType + "'", e); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java index 37e65a8352..c135c41188 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java @@ -18,10 +18,18 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt; -import org.wso2.carbon.device.mgt.common.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; public class CommandOperation extends Operation { + private boolean enabled; + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java index ec94611279..2d25687779 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java @@ -18,5 +18,59 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt; -public class ConfigOperation { +import java.util.ArrayList; +import java.util.List; + +public class ConfigOperation extends Operation { + + private List properties; + + public ConfigOperation() { + properties = new ArrayList(); + } + + public List getConfigProperties() { + return properties; + } + + public void addConfigProperty(String name, Object value, Class type) { + properties.add(new Property(name, value, type)); + } + + public class Property { + private String name; + private Object value; + private Class type; + + public Property(String name, Object value, Class type) { + this.name = name; + this.value = value; + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public Class getType() { + return type; + } + + public void setType(Class type) { + this.type = type; + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java index 98b521c988..f7d9048de3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.List; @@ -32,7 +33,7 @@ public interface OperationManager { * * @param operation Operation to be added * @param devices List of DeviceIdentifiers to execute the operation - * @throws org.wso2.carbon.device.mgt.common.OperationManagementException If some unusual behaviour is observed while adding the + * @throws OperationManagementException If some unusual behaviour is observed while adding the * operation */ public boolean addOperation(Operation operation, List devices) @@ -64,6 +65,6 @@ public interface OperationManager { * @return a list of Feature objects. * @throws org.wso2.carbon.device.mgt.common.FeatureManagementException */ - public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException; + public List getFeatures(String deviceType) throws FeatureManagementException; } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 9d9923e0eb..13946eb07e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -18,25 +18,56 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO; import java.util.List; +/** + * This class implements all the functionalities exposed as part of the OperationManager. Any transaction initiated + * upon persisting information related to operation state, etc has to be managed, demarcated and terminated via the + * methods available in OperationManagementDAOFactory. + */ public class OperationManagerImpl implements OperationManager { - private OperationDAO commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); - private OperationDAO configOperationDAO = OperationManagementDAOFactory.getConfigOperationDAO(); - private OperationDAO simpleOperationDAO = OperationManagementDAOFactory.getSimpleOperationDAO(); + private static final Log log = LogFactory.getLog(OperationManagerImpl.class); + + private OperationDAO commandOperationDAO; + private OperationDAO configOperationDAO; + private OperationDAO simpleOperationDAO; + private OperationMappingDAO operationMappingDAO; + private DeviceDAO deviceDAO; + + public OperationManagerImpl() { + commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); + configOperationDAO = OperationManagementDAOFactory.getConfigOperationDAO(); + simpleOperationDAO = OperationManagementDAOFactory.getSimpleOperationDAO(); + operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO(); + deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); + } @Override public boolean addOperation(Operation operation, List devices) throws OperationManagementException { try { - return this.lookupOperationDAO(operation).addOperation(operation); + OperationManagementDAOFactory.beginTransaction(); + int operationId = this.lookupOperationDAO(operation).addOperation(operation); + operationMappingDAO.addOperationMapping(operationId, null); + OperationManagementDAOFactory.commitTransaction(); + return true; } catch (OperationManagementDAOException e) { + try { + OperationManagementDAOFactory.rollbackTransaction(); + } catch (OperationManagementDAOException e1) { + log.warn("Error occurred while roll-backing the transaction", e); + } throw new OperationManagementException("Error occurred while adding operation", e); } } @@ -52,7 +83,7 @@ public class OperationManagerImpl implements OperationManager { } @Override - public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException { + public List getFeatures(String deviceType) throws FeatureManagementException { return null; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java index 2b967cd2a1..b2a57eccab 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java @@ -18,5 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt; -public class SimpleOperation { +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; + +public class SimpleOperation extends Operation { } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index 0833f05981..00479d4908 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -18,5 +18,20 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; -public class OperationDAO { +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; + +import java.util.List; + +public interface OperationDAO { + + int addOperation(Operation operation) throws OperationManagementDAOException; + + int updateOperation(Operation operation) throws OperationManagementDAOException; + + int deleteOperation(int id) throws OperationManagementDAOException; + + Operation getOperation(int id) throws OperationManagementDAOException; + + List getOperations() throws OperationManagementDAOException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOException.java index 918259ebb1..e3e75f2afd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOException.java @@ -20,4 +20,40 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; public class OperationManagementDAOException extends Exception { + private static final long serialVersionUID = -3151279311929070299L; + + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public OperationManagementDAOException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public OperationManagementDAOException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public OperationManagementDAOException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public OperationManagementDAOException() { + super(); + } + + public OperationManagementDAOException(Throwable cause) { + super(cause); + } + + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java index b3d52caf3d..20c1aa2d80 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java @@ -18,5 +18,130 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.CommandOperationDAOImpl; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.ConfigOperationDAOImpl; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.OperationMappingDAOImpl; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.SimpleOperationDAOImpl; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Hashtable; +import java.util.List; + public class OperationManagementDAOFactory { + + private static DataSource dataSource; + private static final Log log = LogFactory.getLog(OperationManagementDAOFactory.class); + private static ThreadLocal currentConnection = new ThreadLocal(); + + public static OperationDAO getCommandOperationDAO() { + return new CommandOperationDAOImpl(dataSource); + } + + public static OperationDAO getConfigOperationDAO() { + return new ConfigOperationDAOImpl(dataSource); + } + + public static OperationDAO getSimpleOperationDAO() { + return new SimpleOperationDAOImpl(dataSource); + } + + public static OperationMappingDAO getOperationMappingDAO() { + return new OperationMappingDAOImpl(); + } + + public static void init(DataSource dtSource) { + dataSource = dtSource; + } + + public static void beginTransaction() throws OperationManagementDAOException { + try { + currentConnection.set(dataSource.getConnection()); + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while retrieving datasource connection", e); + } + } + + public static Connection getConnection() { + return currentConnection.get(); + } + + public static void commitTransaction() throws OperationManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.commit(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence commit " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while committing the transaction", e); + } + } + + public static void rollbackTransaction() throws OperationManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.rollback(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence rollback " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while rollbacking the transaction", e); + } + } + + /** + * Resolve data source from the data source definition + * + * @param config data source configuration + * @return data source resolved from the data source definition + */ + private static DataSource resolveDataSource(DataSourceConfig config) { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException( + "Device Management Repository data source configuration " + "is null and " + + "thus, is not initialized"); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = DeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = + DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } + + public static DataSource getDataSource() { + return dataSource; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOUtil.java index 266c664d18..bd0b5588c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOUtil.java @@ -18,5 +18,32 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + public class OperationManagementDAOUtil { + + private static final Log log = LogFactory.getLog(OperationManagementDAOUtil.class); + + public static void cleanupResources(Statement stmt, ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing the result set", e); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing the statement", e); + } + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java index f4405a5813..39873c306a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationMappingDAO.java @@ -18,5 +18,14 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; -public class OperationMappingDAO { +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; + +import java.util.List; + +public interface OperationMappingDAO { + + void addOperationMapping(int operationId, List deviceIds) throws OperationManagementDAOException; + + void removeOperationMapping(int operationId, List deviceIds) throws OperationManagementDAOException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java index c89087fbef..fa7e907f26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java @@ -18,5 +18,53 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -public class AbstractOperationDAO { +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.*; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Timestamp; +import java.util.Date; +import java.sql.SQLException; + +public abstract class AbstractOperationDAO implements OperationDAO { + + private DataSource dataSource; + + public AbstractOperationDAO(DataSource dataSource) { + this.dataSource = dataSource; + } + + public DataSource getDataSource() { + return dataSource; + } + + public int addOperation(Operation operation) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection connection = OperationManagementDAOFactory.getConnection(); + stmt = connection.prepareStatement( + "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS) VALUES (?, ?, ?, ?)"); + stmt.setString(1, operation.getType().toString()); + stmt.setTimestamp(2, new Timestamp(new Date().getTime())); + stmt.setTimestamp(3, null); + stmt.setBoolean(4, false); + stmt.executeUpdate(); + + rs = stmt.getGeneratedKeys(); + int id = -1; + if (rs.next()) { + id = rs.getInt(1); + } + return id; + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index bfb95d7034..ba3880daee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -18,11 +18,17 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -import org.wso2.carbon.device.mgt.common.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.List; public class CommandOperationDAOImpl extends AbstractOperationDAO { @@ -32,20 +38,34 @@ public class CommandOperationDAOImpl extends AbstractOperationDAO { } @Override - public boolean addOperation(Operation operation) throws OperationManagementDAOException { - CommandOperation booleanOp = (CommandOperation) operation; - addOperationMetadata(); - return false; + public int addOperation(Operation operation) throws OperationManagementDAOException { + int operationId = super.addOperation(operation); + CommandOperation commandOp = (CommandOperation) operation; + Connection conn = OperationManagementDAOFactory.getConnection(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = conn.prepareStatement("INSERT INTO DM_COMMAND_OPERATION(OPERATION_ID, ENABLED) VALUES(?, ?)"); + stmt.setInt(1, operationId); + stmt.setBoolean(2, commandOp.isEnabled()); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while adding command operation", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + return operationId; } @Override - public boolean updateOperation(Operation operation) throws OperationManagementDAOException { - return false; + public int updateOperation(Operation operation) throws OperationManagementDAOException { + return 0; } @Override - public boolean deleteOperation(int id) throws OperationManagementDAOException { - return false; + public int deleteOperation(int id) throws OperationManagementDAOException { + return 0; } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 9a3a351138..1cc87e76a9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -18,5 +18,42 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -public class ConfigOperationDAOImpl { +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; + +import javax.sql.DataSource; +import java.util.List; + +public class ConfigOperationDAOImpl extends AbstractOperationDAO { + + public ConfigOperationDAOImpl(DataSource dataSource) { + super(dataSource); + } + + @Override + public int addOperation(Operation operation) throws OperationManagementDAOException { + return 0; + } + + @Override + public int updateOperation(Operation operation) throws OperationManagementDAOException { + return 0; + } + + @Override + public int deleteOperation(int id) throws OperationManagementDAOException { + return 0; + } + + @Override + public Operation getOperation(int id) throws OperationManagementDAOException { + return null; + } + + @Override + public List getOperations() throws OperationManagementDAOException { + return null; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java index c98367ca00..ec05cc2129 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java @@ -18,5 +18,51 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -public class OperationMappingDAOImpl { +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.List; + +public class OperationMappingDAOImpl implements OperationMappingDAO { + + @Override + public void addOperationMapping(int operationId, List deviceIds) throws OperationManagementDAOException { + PreparedStatement stmt = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "INSERT INTO DEVICE_OPERATION_MAPPING(DEVICE_ID, OPERATION_ID) VALUES(?, ?)"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, 0); + stmt.setInt(2, operationId); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, null); + } + } + + @Override + public void removeOperationMapping(int operationId, + List deviceIds) throws OperationManagementDAOException { + PreparedStatement stmt = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "DELETE FROM DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, 0); + stmt.setInt(2, operationId); + stmt.executeUpdate(); + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, null); + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java index 107d08953d..43ba587889 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java @@ -18,5 +18,36 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -public class SimpleOperationDAOImpl { +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; + +import javax.sql.DataSource; +import java.util.List; + +public class SimpleOperationDAOImpl extends AbstractOperationDAO { + + public SimpleOperationDAOImpl(DataSource dataSource) { + super(dataSource); + } + + @Override + public int updateOperation(Operation operation) throws OperationManagementDAOException { + return 0; + } + + @Override + public int deleteOperation(int id) throws OperationManagementDAOException { + return 0; + } + + @Override + public Operation getOperation(int id) throws OperationManagementDAOException { + return null; + } + + @Override + public List getOperations() throws OperationManagementDAOException { + return null; + } + } 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 9b742f7054..ba6b9df2bd 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 @@ -17,71 +17,111 @@ */ package org.wso2.carbon.device.mgt.core.service; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; -import org.wso2.carbon.device.mgt.core.DeviceManager; +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.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import java.util.List; -public class DeviceManagementServiceImpl implements DeviceManager { +public class DeviceManagementServiceImpl implements DeviceManagementService { - @Override + @Override + public String getProviderType() { + return null; + } + + @Override public boolean enrollDevice(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().enrollDevice(device); } @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().modifyEnrollment(device); } @Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().disenrollDevice(deviceId); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().disenrollDevice(deviceId); } @Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().isEnrolled(deviceId); } @Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().isActive(deviceId); } @Override public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().setActive(deviceId, status); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().setActive(deviceId, status); } - @Override + @Override + public List getAllDevices() throws DeviceManagementException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override public List getAllDevices(String type) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getAllDevices(type); } @Override public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId); } @Override public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().updateDeviceInfo(device); } @Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().setOwnership(deviceId, ownershipType); + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().setOwnership(deviceId, + ownershipType); } - @Override - public OperationManager getOperationManager(String type) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().getOperationManager(type); - } + @Override + public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getLicense(deviceType, + languageCode); + } + + @Override + public boolean addLicense(String type, License license) throws LicenseManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addLicense(type, license); + } + + @Override + public boolean addOperation(Operation operation, + List devices) throws OperationManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, devices); + } + + @Override + public List getOperations(DeviceIdentifier deviceId) throws OperationManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperations(deviceId); + } + + @Override + public List getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getPendingOperations(deviceId); + } + + @Override + public List getFeaturesForDeviceType(String deviceType) throws FeatureManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeaturesForDeviceType( + deviceType); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index fd4a442164..110e46dacf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -50,11 +50,10 @@ public final class DeviceManagerUtil { DocumentBuilder docBuilder = factory.newDocumentBuilder(); return docBuilder.parse(file); } catch (Exception e) { - throw new DeviceManagementException( - "Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document : " + e.getMessage(), e); + throw new DeviceManagementException("Error occurred while parsing file, while converting " + + "to a org.w3c.dom.Document", e); } - } + } /** * Resolve data source from the data source definition. @@ -65,16 +64,13 @@ public final class DeviceManagerUtil { public static DataSource resolveDataSource(DataSourceConfig config) { DataSource dataSource = null; if (config == null) { - throw new RuntimeException( - "Device Management Repository data source configuration " + - "is null and thus, is not initialized"); + throw new RuntimeException("Device Management Repository data source configuration is null and thus, " + + "is not initialized"); } JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); if (jndiConfig != null) { if (log.isDebugEnabled()) { - log.debug( - "Initializing Device Management Repository data source using the JNDI " + - "Lookup Definition"); + log.debug("Initializing Device Management Repository data source using the JNDI Lookup Definition"); } List jndiPropertyList = jndiConfig.getJndiProperties(); @@ -83,11 +79,9 @@ public final class DeviceManagerUtil { for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { jndiProperties.put(prop.getName(), prop.getValue()); } - dataSource = DeviceManagementDAOUtil - .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); } else { - dataSource = - DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); } } return dataSource; @@ -103,7 +97,7 @@ public final class DeviceManagerUtil { boolean status; try { DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType); + DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType); if (deviceTypeId == null) { DeviceType dt = new DeviceType(); dt.setName(deviceType); @@ -111,14 +105,14 @@ public final class DeviceManagerUtil { } status = true; } catch (DeviceManagementDAOException e) { - String msg = "Error occurred while registering the device type " + deviceType; - throw new DeviceManagementException(msg, e); + throw new DeviceManagementException("Error occurred while registering the device type '" + + deviceType + "'", e); } return status; } /** - * Unregisters an existing device type from the device management metadata repository. + * Un-registers an existing device type from the device management metadata repository. * * @param deviceType device type * @return status of the operation @@ -126,25 +120,17 @@ public final class DeviceManagerUtil { public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException { try { DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType); + DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType); if (deviceTypeId == null) { DeviceType dt = new DeviceType(); dt.setName(deviceType); - deviceTypeDAO.removeDeviceType(dt); + deviceTypeDAO.removeDeviceType(deviceType); } return true; } catch (DeviceManagementDAOException e) { - String msg = "Error occurred while registering the device type " + deviceType; - throw new DeviceManagementException(msg, e); + throw new DeviceManagementException("Error occurred while registering the device type '" + + deviceType + "'", e); } } - public static Map convertPropertiesToMap(List properties) { - Map propertiesMap = new HashMap(); - for (Device.Property prop : properties) { - propertiesMap.put(prop.getName(), prop.getValue()); - } - return propertiesMap; - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementBaseTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementBaseTest.java index d2a329f503..e0e32265ec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementBaseTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementBaseTest.java @@ -18,5 +18,53 @@ */ package org.wso2.carbon.device.mgt.core; +import org.apache.tomcat.jdbc.pool.PoolProperties; +import org.testng.Assert; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + public class DeviceManagementBaseTest { + + private DataSource dataSource; + + public void init() { + this.initDataSource(); + try { + this.initDeviceManagementDatabaseSchema(); + } catch (SQLException e) { + Assert.fail("Error occurred while initializing database schema", e); + } + } + + private void initDeviceManagementDatabaseSchema() throws SQLException { + Connection conn = null; + Statement stmt = null; + try { + if (dataSource == null) { + Assert.fail("Device management datasource is not initialized peroperly"); + } + conn = dataSource.getConnection(); + stmt = conn.createStatement(); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/h2.sql'"); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + } + } + + private void initDataSource() { + PoolProperties properties = new PoolProperties(); + properties.setUrl("jdbc:h2:mem:MDM_DB;DB_CLOSE_DELAY=-1"); + properties.setDriverClassName("org.h2.Driver"); + properties.setUsername("wso2carbon"); + properties.setPassword("wso2carbon"); + this.dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties); + } + + protected DataSource getDataSource() { + return dataSource; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java index 79c19a0e0e..2b85365f2d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepositoryTests.java @@ -20,7 +20,8 @@ package org.wso2.carbon.device.mgt.core; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.spi.DeviceManager; public class DeviceManagementRepositoryTests { @@ -33,23 +34,27 @@ public class DeviceManagementRepositoryTests { @Test public void testAddDeviceManagementService() { - DeviceManagerService sourceProvider = new TestDeviceManagerService(); - this.getRepository().addDeviceManagementProvider(sourceProvider); - - DeviceManagerService targetProvider = - this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST); - + DeviceManager sourceProvider = new TestDeviceManager(); + try { + this.getRepository().addDeviceManagementProvider(sourceProvider); + } catch (DeviceManagementException e) { + Assert.fail("Unexpected error occurred while invoking addDeviceManagementProvider functionality", e); + } + DeviceManager targetProvider = + this.getRepository().getDeviceManagementProvider(TestDeviceManager.DEVICE_TYPE_TEST); Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType()); } @Test(dependsOnMethods = "testAddDeviceManagementService") public void testRemoveDeviceManagementService() { - DeviceManagerService sourceProvider = new TestDeviceManagerService(); - this.getRepository().removeDeviceManagementProvider(sourceProvider); - - DeviceManagerService targetProvider = - this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST); - + DeviceManager sourceProvider = new TestDeviceManager(); + try { + this.getRepository().removeDeviceManagementProvider(sourceProvider); + } catch (DeviceManagementException e) { + Assert.fail("Unexpected error occurred while invoking removeDeviceManagementProvider functionality", e); + } + DeviceManager targetProvider = + this.getRepository().getDeviceManagementProvider(TestDeviceManager.DEVICE_TYPE_TEST); Assert.assertNull(targetProvider); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java index 8fa8d1dca9..5038dc8acf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java @@ -18,5 +18,59 @@ */ package org.wso2.carbon.device.mgt.core; -public class DeviceOperationManagementTests { +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.operation.mgt.*; +import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; + +import java.util.ArrayList; +import java.util.List; + +public class DeviceOperationManagementTests extends DeviceManagementBaseTest { + + private OperationManager operationManager; + + @BeforeClass(alwaysRun = true) + public void init() { + super.init(); + this.initOperationManager(); + OperationManagementDAOFactory.init(this.getDataSource()); + } + + public void initOperationManager() { + this.operationManager = new OperationManagerImpl(); + } + + @Test + public void testAddOperation() throws Exception { + + CommandOperation op = new CommandOperation(); + op.setEnabled(true); + op.setType(Operation.Type.COMMAND); + + List deviceIds = new ArrayList(); + DeviceIdentifier deviceId = new DeviceIdentifier(); + deviceId.setId("Test"); + deviceId.setType("Android"); + deviceIds.add(deviceId); + + try { + operationManager.addOperation(op, deviceIds); + } catch (OperationManagementException e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + public void testGetOperations() { + try { + operationManager.getOperations(null); + } catch (OperationManagementException e) { + e.printStackTrace(); + } + } + + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java index 7ccc88d343..486859d61f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java @@ -114,17 +114,17 @@ public class DeviceManagementDAOTests { deviceType.setName("IOS"); deviceTypeMgtDAO.addDeviceType(deviceType); - Long id = null; + int id = -1; Connection conn = null; PreparedStatement stmt = null; - String sql = "SELECT ID, NAME from DM_DEVICE_TYPE DType where DType.NAME='IOS'"; + String sql = "SELECT dt.ID, dt.NAME FROM DM_DEVICE_TYPE dt where dt.NAME = 'IOS'"; try { conn = this.getDataSource().getConnection(); stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); if (rs.next()) { - id = rs.getLong("ID"); + id = rs.getInt("ID"); } } catch (SQLException e) { throw new DeviceManagementDAOException("error in fetch device type by name IOS", e); @@ -147,9 +147,9 @@ public class DeviceManagementDAOTests { device.setDeviceIdentificationId("111"); DeviceType deviceType = new DeviceType(); - deviceType.setId(Long.parseLong("1")); + deviceType.setId(Integer.parseInt("1")); - device.setDeviceTypeId(deviceType.getId().intValue()); + device.setDeviceTypeId(deviceType.getId()); device.setOwnerShip(OwnerShip.BYOD.toString()); device.setOwnerId("111"); device.setTenantId(-1234); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index e69de29bb2..c87c9fcf4e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -0,0 +1,58 @@ +CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( + ID INT auto_increment NOT NULL, + NAME VARCHAR(300) NULL DEFAULT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE ( + ID INTEGER auto_increment NOT NULL, + DESCRIPTION TEXT NULL DEFAULT NULL, + NAME VARCHAR(100) NULL DEFAULT NULL, + DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL, + DATE_OF_LAST_UPDATE BIGINT 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 INTEGER 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 +); + +CREATE TABLE IF NOT EXISTS DM_OPERATION ( + ID INTEGER AUTO_INCREMENT NOT NULL, + TYPE VARCHAR(50) NOT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, + STATUS VARCHAR(50) NULL, + PRIMARY KEY (ID) +) + +CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION ( + OPERATION_ID INTEGER NOT NULL, + PRIMARY KEY (OPERATION_ID), + CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES + DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +) + +CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( + OPERATION_ID INTEGER NOT NULL, + ENABLED INTEGER NOT NULL DEFAULT 0, + PRIMARY KEY (OPERATION_ID), + CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES + DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +) + +CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING ( + ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES + DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +) + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml index dbce1ebf52..998633e06b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml @@ -28,6 +28,7 @@ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5191ff4a60..98ea945241 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ org.wso2.carbon.base ${carbon.kernel.version} - + From 3fb61d9c8b724142e9583158b3178bc4df54db21 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 17 Mar 2015 17:40:49 +0530 Subject: [PATCH 05/12] Resolving more merge conflicts --- .../device/mgt/core/DeviceManagementServiceProviderImpl.java | 5 +++++ .../java/org/wso2/carbon/device/mgt/core/dto/Device.java | 4 ---- .../src/test/resources/testng.xml | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index c5421a6b6c..15e6502141 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -153,6 +153,11 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ return devicesList; } + @Override + public List getDeviceListOfUser(String username) throws DeviceManagementException { + return null; + } + @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManager dms = 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 2a898ce7b4..260f546311 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,10 +33,7 @@ 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() { @@ -46,7 +43,6 @@ public class Device implements Serializable { 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/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml index 998633e06b..797d214a0e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml @@ -28,7 +28,7 @@ - + \ No newline at end of file From d5127f687402e9fca737f7ef8f989a2770c65f15 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 17 Mar 2015 21:04:25 +0530 Subject: [PATCH 06/12] Code cleanup and fixing build failures --- .../internal/DeviceManagementServiceComponent.java | 2 +- .../mgt/core/operation/mgt/OperationManagerImpl.java | 2 +- .../mgt/dao/OperationManagementDAOFactory.java | 6 +++--- .../operation/mgt/dao/impl/AbstractOperationDAO.java | 10 ---------- .../mgt/dao/impl/CommandOperationDAOImpl.java | 4 ---- .../operation/mgt/dao/impl/ConfigOperationDAOImpl.java | 4 ---- .../operation/mgt/dao/impl/SimpleOperationDAOImpl.java | 4 ---- 7 files changed, 5 insertions(+), 27 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index ac3a7b832e..cee59d9d1d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -125,7 +125,7 @@ public class DeviceManagementServiceComponent { } /* Registering Device Management Service */ BundleContext bundleContext = componentContext.getBundleContext(); - bundleContext.registerService(DeviceManagementServiceImpl.class.getName(), + bundleContext.registerService(DeviceManagementService.class.getName(), new DeviceManagementServiceImpl(), null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 13946eb07e..b3ba04cffb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -66,7 +66,7 @@ public class OperationManagerImpl implements OperationManager { try { OperationManagementDAOFactory.rollbackTransaction(); } catch (OperationManagementDAOException e1) { - log.warn("Error occurred while roll-backing the transaction", e); + log.warn("Error occurred while roll-backing the transaction", e1); } throw new OperationManagementException("Error occurred while adding operation", e); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java index 20c1aa2d80..8600b00e96 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationManagementDAOFactory.java @@ -41,15 +41,15 @@ public class OperationManagementDAOFactory { private static ThreadLocal currentConnection = new ThreadLocal(); public static OperationDAO getCommandOperationDAO() { - return new CommandOperationDAOImpl(dataSource); + return new CommandOperationDAOImpl(); } public static OperationDAO getConfigOperationDAO() { - return new ConfigOperationDAOImpl(dataSource); + return new ConfigOperationDAOImpl(); } public static OperationDAO getSimpleOperationDAO() { - return new SimpleOperationDAOImpl(dataSource); + return new SimpleOperationDAOImpl(); } public static OperationMappingDAO getOperationMappingDAO() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java index fa7e907f26..2467a72c33 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java @@ -31,16 +31,6 @@ import java.sql.SQLException; public abstract class AbstractOperationDAO implements OperationDAO { - private DataSource dataSource; - - public AbstractOperationDAO(DataSource dataSource) { - this.dataSource = dataSource; - } - - public DataSource getDataSource() { - return dataSource; - } - public int addOperation(Operation operation) throws OperationManagementDAOException { PreparedStatement stmt = null; ResultSet rs = null; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index ba3880daee..80936c73db 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -33,10 +33,6 @@ import java.util.List; public class CommandOperationDAOImpl extends AbstractOperationDAO { - public CommandOperationDAOImpl(DataSource dataSource) { - super(dataSource); - } - @Override public int addOperation(Operation operation) throws OperationManagementDAOException { int operationId = super.addOperation(operation); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 1cc87e76a9..b2dac4ea69 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -27,10 +27,6 @@ import java.util.List; public class ConfigOperationDAOImpl extends AbstractOperationDAO { - public ConfigOperationDAOImpl(DataSource dataSource) { - super(dataSource); - } - @Override public int addOperation(Operation operation) throws OperationManagementDAOException { return 0; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java index 43ba587889..ab59e9c8f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java @@ -26,10 +26,6 @@ import java.util.List; public class SimpleOperationDAOImpl extends AbstractOperationDAO { - public SimpleOperationDAOImpl(DataSource dataSource) { - super(dataSource); - } - @Override public int updateOperation(Operation operation) throws OperationManagementDAOException { return 0; From 7056b01d18b381b6caca6685e0a328d029eb8adb Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 18 Mar 2015 10:25:38 +0530 Subject: [PATCH 07/12] Fixing more build issues --- .../device/mgt/core/DeviceManagementServiceProviderImpl.java | 1 + .../device/mgt/core/internal/DeviceManagementDataHolder.java | 2 +- .../mgt/core/internal/DeviceManagementServiceComponent.java | 2 +- .../device/mgt/core/{ => service}/DeviceManagementService.java | 2 +- .../device/mgt/core/service/DeviceManagementServiceImpl.java | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/{ => service}/DeviceManagementService.java (97%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index 15e6502141..d5df8311b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -34,6 +34,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import java.util.ArrayList; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 7406993c3b..2108aee649 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -19,7 +19,7 @@ package org.wso2.carbon.device.mgt.core.internal; -import org.wso2.carbon.device.mgt.core.DeviceManagementService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; import org.wso2.carbon.registry.core.service.RegistryService; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index cee59d9d1d..a93e88cced 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -26,7 +26,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; -import org.wso2.carbon.device.mgt.core.DeviceManagementService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; 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/service/DeviceManagementService.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index c94636fd46..5f752b4871 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/service/DeviceManagementService.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core; +package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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 e000083e2f..f3c90fd7ab 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 @@ -18,7 +18,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.service.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; From 5a253b286e5dea5ae2375ceed10df6df613e1e44 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Wed, 18 Mar 2015 12:08:25 +0530 Subject: [PATCH 08/12] Adding the policy management service and dao implementation, basic architecture is implemented here, only thing we have to do is to fill the method with relavant informations. PDP, PEP, PIP services are renamed. --- .../point/PolicyInformationServiceImpl.java | 9 +- ...PolicyInformationPointBundleActivator.java | 4 +- .../org.wso2.carbon.policy.mgt.common/pom.xml | 3 +- .../policy/mgt/common/PIPDeviceData.java | 79 ++++++++++++++++- ...ice.java => PolicyAdministratorPoint.java} | 36 ++++---- ...ervice.java => PolicyEvaluationPoint.java} | 12 +-- ...rvice.java => PolicyInformationPoint.java} | 14 +-- .../carbon/policy/mgt/common/Profile.java | 2 + .../mgt/common/impl/PolicyManagement.java | 88 ------------------- .../mgt/common/PolicyManagementTestCase.java | 54 ------------ .../org.wso2.carbon.policy.mgt.core/pom.xml | 3 +- .../carbon/policy/mgt/core/dao/PolicyDAO.java | 16 ++-- .../mgt/core/dao/impl/PolicyDAOImpl.java | 38 ++++++-- .../core/impl/PolicyInformationPointImpl.java | 67 ++++++++++++++ .../PolicyManagementServiceComponent.java | 13 ++- .../pom.xml | 4 + .../point/PolicyEvaluationException.java | 55 ++++++++++++ .../point/PolicyEvaluationServiceImpl.java | 9 +- .../decision/point/SimpleEvaluation.java | 31 +++++++ .../decision/point/SimpleEvaluationImpl.java | 47 ++++++++++ 20 files changed, 383 insertions(+), 201 deletions(-) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{PolicyAdministratorService.java => PolicyAdministratorPoint.java} (75%) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{PolicyEvaluationService.java => PolicyEvaluationPoint.java} (75%) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{PolicyInformationService.java => PolicyInformationPoint.java} (77%) delete mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java delete mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java index 5ce43efddf..2cdb6bcf9f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java @@ -18,17 +18,18 @@ package org.wso2.carbon.policy.information.point; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.PIPDeviceData; import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyInformationService; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; import java.util.List; -public class PolicyInformationServiceImpl implements PolicyInformationService{ +public class PolicyInformationServiceImpl implements PolicyInformationPoint { @Override - public void getDeviceData(PIPDeviceData pipDeviceData) { - + public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) { + return null; } @Override diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java index c25b2855db..b28a545dd6 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java @@ -24,7 +24,7 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.wso2.carbon.policy.information.point.PolicyInformationServiceImpl; -import org.wso2.carbon.policy.mgt.common.PolicyInformationService; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; public class PolicyInformationPointBundleActivator implements BundleActivator { @@ -38,7 +38,7 @@ public class PolicyInformationPointBundleActivator implements BundleActivator { log.debug("Activating Policy information Point bundle."); } - pipServiceRegRef = bundleContext.registerService(PolicyInformationService.class.getName(), + pipServiceRegRef = bundleContext.registerService(PolicyInformationPoint.class.getName(), new PolicyInformationServiceImpl(), null); if (log.isDebugEnabled()) { 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 bf119e445d..1685a5b72a 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 @@ -55,7 +55,8 @@ org.wso2.carbon.policy.mgt.common.internal org.apache.commons.logging, - org.wso2.carbon.device.mgt.core.* + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.device.mgt.core.dto.* org.wso2.carbon.policy.mgt.common.* diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java index caf5c81e2c..d234fa96b1 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java @@ -18,14 +18,18 @@ package org.wso2.carbon.policy.mgt.common; + +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; + import java.sql.Timestamp; import java.util.List; import java.util.Map; public class PIPDeviceData { - String deviceId; - String deviceType; + Device device; + DeviceType deviceType; String ownershipType; List userIds; List roles; @@ -36,4 +40,75 @@ public class PIPDeviceData { /*This will be used to record attributes to which would come from other PDPs*/ Map attributes; + public Device getDevice() { + return device; + } + + public void setDevice(Device device) { + this.device = device; + } + + public DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceType deviceType) { + this.deviceType = deviceType; + } + + public String getOwnershipType() { + return ownershipType; + } + + public void setOwnershipType(String ownershipType) { + this.ownershipType = ownershipType; + } + + public List getUserIds() { + return userIds; + } + + public void setUserIds(List userIds) { + this.userIds = userIds; + } + + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + public String getAltitude() { + return altitude; + } + + public void setAltitude(String altitude) { + this.altitude = altitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public Timestamp getTimestamp() { + return timestamp; + } + + public void setTimestamp(Timestamp timestamp) { + this.timestamp = timestamp; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } } 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/PolicyAdministratorPoint.java similarity index 75% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java index 4fb239d1fb..2174b64c12 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/PolicyAdministratorPoint.java @@ -22,7 +22,7 @@ package org.wso2.carbon.policy.mgt.common; * This interface defines the policy management which should be implemented by the plugins */ -public interface PolicyAdministratorService { +public interface PolicyAdministratorPoint { /** * This method adds a policy to the platform @@ -31,7 +31,10 @@ public interface PolicyAdministratorService { * @return primary key (generated key) */ - int addPolicy(Policy policy); + Policy addPolicy(Policy policy) throws PolicyManagementException; + + + Policy updatePolicy(Policy policy) throws PolicyManagementException; /** * This method adds a policy per device which should be implemented by the related plugins. @@ -42,17 +45,7 @@ public interface PolicyAdministratorService { * @return primary key (generated key) */ - int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; - - /** - * This method adds a policy to device type by the related device type plugins. - * - * @param deviceType - * @param policy - * @return primary key (generated key) - */ - - int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; + Policy addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; /** * This method adds the policy to specific role. @@ -61,7 +54,7 @@ public interface PolicyAdministratorService { * @param policy * @return primary key (generated key) */ - int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException; + Policy addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException; /** * This method returns the policy of whole platform @@ -119,7 +112,7 @@ public interface PolicyAdministratorService { * @return * @throws PolicyManagementException */ - boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException; + boolean isPolicyApplied(String deviceId, String deviceType) throws PolicyManagementException; /** @@ -135,7 +128,16 @@ public interface PolicyAdministratorService { * @param profile * @throws PolicyManagementException */ - void addProfile(Profile profile) throws PolicyManagementException; + Profile addProfile(Profile profile) throws PolicyManagementException; + + boolean deleteProfile(int profileId) throws PolicyManagementException; + + Profile updateProfile(Profile profile) throws PolicyManagementException; + + Feature addFeature(Feature feature) throws FeatureManagementException; + + Feature updateFeature(Feature feature) throws FeatureManagementException; + + void deleteFeature(int featureId) throws FeatureManagementException; - 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/PolicyEvaluationService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java similarity index 75% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java index b5082c578d..944e3aa620 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java @@ -19,26 +19,28 @@ package org.wso2.carbon.policy.mgt.common; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; + import java.util.List; /** * This is the interface which will be used to create plug-able policy decision points. */ -public interface PolicyEvaluationService { +public interface PolicyEvaluationPoint { /** * This method returns the effective policy from the list. - * @param pipDeviceData device information. + * @param deviceIdentifier device information. * @return returns the effective policy. */ - Policy getEffectivePolicy(PIPDeviceData pipDeviceData); + Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier); /** * This class will return the effective feature set from the list. - * @param pipDeviceData device information. + * @param deviceIdentifier device information. * @return returns the effective feature set. */ - List getEffectiveFeatures(PIPDeviceData pipDeviceData); + List getEffectiveFeatures(DeviceIdentifier deviceIdentifier); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java similarity index 77% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java index ea9509506a..0ba6f912ff 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationPoint.java @@ -19,26 +19,30 @@ package org.wso2.carbon.policy.mgt.common; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.dto.Device; + import java.util.List; /** * This will be used retrieve data database. This interface has to be implemented by PIP. PIP will be plug-able. */ -public interface PolicyInformationService { +public interface PolicyInformationPoint { /** * This method will return the data related Device, Some of the device data will provided in the initial pipDeviceData object such as * device id, device time and location, Other data such as roles, owned users and ownership type will be filled by this method. - * @param pipDeviceData device data. + * @param deviceIdentifier device data. + * @return PIPDeviceData */ - void getDeviceData(PIPDeviceData pipDeviceData); + PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; /** * This method will retrieve the policies related given device Data. * @param pipDeviceData * @return */ - List getRelatedPolicies(PIPDeviceData pipDeviceData); + List getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException; /** * This is will retrieve the features related to device type. This feature list will be used for dynamically @@ -46,5 +50,5 @@ public interface PolicyInformationService { * @param deviceType * @return */ - List getRelatedFeatures(String deviceType); + List getRelatedFeatures(String deviceType) throws FeatureManagementException; } 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 index e81dc42eb8..9df30554a0 100644 --- 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 @@ -18,6 +18,8 @@ package org.wso2.carbon.policy.mgt.common; + + import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.sql.Timestamp; 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 deleted file mode 100644 index 77ba5b6fe8..0000000000 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.common.impl; - -import org.wso2.carbon.policy.mgt.common.*; - -public class PolicyManagement implements PolicyAdministratorService { - @Override - public int addPolicy(Policy policy) { - return 0; - } - - @Override - public int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException { - return 0; - } - - @Override - public int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException { - return 0; - } - - @Override - public int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException { - return 0; - } - - @Override - public Policy getPolicy() { - return null; - } - - @Override - public Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException { - return null; - } - - @Override - public Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException { - return null; - } - - @Override - public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException { - return null; - } - - @Override - public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException { - return false; - } - - @Override - public boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException { - return false; - } - - @Override - 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/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java deleted file mode 100644 index 568c59684e..0000000000 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.wos2.carbon.policy.mgt.common; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.testng.Assert; -import org.testng.annotations.Test; -import org.wos2.carbon.policy.mgt.common.utils.PolicyCreator; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.policy.mgt.common.impl.PolicyManagement; - -public class PolicyManagementTestCase { - - private static final Log log = LogFactory.getLog(PolicyManagementTestCase.class); - - Policy policy = PolicyCreator.createPolicy(); - - private PolicyManagement policyManagement = new PolicyManagement(); - - @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device") - public void testAddPolicy() throws FeatureManagementException, PolicyManagementException { - Assert.assertEquals(policyManagement.addPolicyToDevice("1212-ESDD-12ER-7890", "MD", policy), 0); - } - - @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device type") - public void testAddPolicyToDeviceType() throws FeatureManagementException, PolicyManagementException { - Assert.assertEquals(policyManagement.addPolicyToDeviceType("MD", policy), 0); - } - - @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a user Role") - public void testAddPolicyToRole() throws FeatureManagementException, PolicyManagementException { - Assert.assertEquals(policyManagement.addPolicyToRole("Admin", policy), 0); - } - -} 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 0a08696f4e..9f4a752714 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 @@ -68,7 +68,8 @@ org.wso2.carbon.policy.mgt.common.*, org.wso2.carbon.user.core.*, org.wso2.carbon.utils.*, - org.wso2.carbon.device.mgt.core.* + org.wso2.carbon.device.mgt.core.*, + org.wso2.carbon.device.mgt.common.* !org.wso2.carbon.policy.mgt.core.internal, 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 9fd866f51f..0ed1d8e529 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 @@ -27,13 +27,15 @@ import java.util.List; public interface PolicyDAO { - int addPolicy(Policy policy) throws PolicyManagerDAOException; + Policy addPolicy(Policy policy) throws PolicyManagerDAOException; - int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException; + Policy addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException; - int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException; + Policy addPolicyToRole(String roleName, Policy policy) throws PolicyManagerDAOException; - void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException; + Policy addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException; + + Policy updatePolicy(Policy policy) throws PolicyManagerDAOException; Policy getPolicy() throws PolicyManagerDAOException; @@ -43,7 +45,9 @@ public interface PolicyDAO { void deletePolicy(Policy policy) throws PolicyManagerDAOException; - void addProfile(Profile profile) throws PolicyManagerDAOException; + Profile addProfile(Profile profile) throws PolicyManagerDAOException; + + Profile updateProfile(Profile profile) throws PolicyManagerDAOException; void deleteProfile(Profile profile) throws PolicyManagerDAOException; @@ -60,4 +64,6 @@ public interface PolicyDAO { void deleteFeaturesOfProfile(Profile profile) throws PolicyManagerDAOException; Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException; + + Feature updateFeature(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/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 e5afa35ec2..20b46af07c 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 @@ -42,13 +42,13 @@ public class PolicyDAOImpl implements PolicyDAO { @Override - public int addPolicy(Policy policy) throws PolicyManagerDAOException { + public Policy addPolicy(Policy policy) throws PolicyManagerDAOException { persistPolicy(policy); - return policy.getId(); + return policy; } @Override - public int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException { + public Policy addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException { // First persist the policy to the data base. persistPolicy(policy); @@ -73,12 +73,17 @@ public class PolicyDAOImpl implements PolicyDAO { PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); } - return policy.getId(); + return policy; } @Override - public int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException { + public Policy addPolicyToRole(String roleName, Policy policy) throws PolicyManagerDAOException { + return null; + } + + @Override + public Policy addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException { // First persist the policy to the data base. persistPolicy(policy); @@ -96,11 +101,11 @@ public class PolicyDAOImpl implements PolicyDAO { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } - return 0; + return policy; } @Override - public void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException { + public Policy updatePolicy(Policy policy) throws PolicyManagerDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -114,6 +119,8 @@ public class PolicyDAOImpl implements PolicyDAO { } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } + + return policy; } @Override @@ -219,7 +226,7 @@ public class PolicyDAOImpl implements PolicyDAO { int tenantId = -1234; try { conn = this.getConnection(); - String query = "IINSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID) VALUES (?, ?, ?)"; + String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS); stmt.setString(1, policy.getPolicyName()); @@ -276,7 +283,7 @@ public class PolicyDAOImpl implements PolicyDAO { } } - public void addProfile(Profile profile) throws PolicyManagerDAOException { + public Profile addProfile(Profile profile) throws PolicyManagerDAOException { Connection conn = null; PreparedStatement stmt = null; ResultSet generatedKeys = null; @@ -319,6 +326,13 @@ public class PolicyDAOImpl implements PolicyDAO { } finally { PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); } + + return profile; + } + + + public Profile updateProfile(Profile profile) throws PolicyManagerDAOException { + return profile; } @Override @@ -398,6 +412,12 @@ public class PolicyDAOImpl implements PolicyDAO { return feature; } + + @Override + public Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException { + return feature; + } + @Override public List getAllProfiles() throws PolicyManagerDAOException { Connection conn = null; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java new file mode 100644 index 0000000000..4bec7d6980 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.mgt.core.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl; +import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.policy.mgt.common.*; + +import java.util.List; + +public class PolicyInformationPointImpl implements PolicyInformationPoint { + + private static final Log log = LogFactory.getLog(PolicyInformationPointImpl.class); + DeviceDAOImpl deviceDAO; + + public PolicyInformationPointImpl() { + deviceDAO = new DeviceDAOImpl(DeviceManagementDAOFactory.getDataSource()); + } + + @Override + public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + PIPDeviceData pipDeviceData = new PIPDeviceData(); + Device device; + try { + device = deviceDAO.getDevice(deviceIdentifier); + pipDeviceData.setDevice(device); + + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred when retrieving the data related to device from the database."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + + return pipDeviceData; + } + + @Override + public List getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException { + return null; + } + + @Override + public List getRelatedFeatures(String deviceType) throws FeatureManagementException { + return null; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index 16255d95dc..f7fce484b1 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -21,11 +21,13 @@ package org.wso2.carbon.policy.mgt.core.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.policy.mgt.common.PolicyInformationService; +import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; +import org.wso2.carbon.policy.mgt.core.PolicyManager; import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager; import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig; import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; +import org.wso2.carbon.policy.mgt.core.service.PolicyManagementService; import org.wso2.carbon.user.core.service.RealmService; /** @@ -37,7 +39,7 @@ import org.wso2.carbon.user.core.service.RealmService; * bind="setRealmService" * unbind="unsetRealmService" * @scr.reference name="org.wso2.carbon.devicemgt.policy.information.point.default" - * interface="org.wso2.carbon.policy.mgt.common.PolicyInformationService" + * interface="org.wso2.carbon.policy.mgt.common.PolicyInformationPoint" * cardinality="1..1" * policy="dynamic" * bind="setPIPService" @@ -56,6 +58,9 @@ public class PolicyManagementServiceComponent { DataSourceConfig dsConfig = config.getPolicyManagementRepository().getDataSourceConfig(); PolicyManagementDAOFactory.init(dsConfig); + componentContext.getBundleContext().registerService( + PolicyManager.class.getName(), new PolicyManagementService(), null); + } catch (Throwable t) { String msg = "Error occurred while initializing the Policy management core."; log.error(msg, t); @@ -89,13 +94,13 @@ public class PolicyManagementServiceComponent { } - protected void setPIPService(PolicyInformationService policyInformationService) { + protected void setPIPService(PolicyInformationPoint policyInformationService) { if (log.isDebugEnabled()) { log.debug("Setting Policy Information Service"); } } - protected void unsetPIPService(PolicyInformationService policyInformationService) { + protected void unsetPIPService(PolicyInformationPoint policyInformationService) { if (log.isDebugEnabled()) { log.debug("Unsetting Policy Information Service"); } 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 f6fe137b9b..58a7644503 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 @@ -59,5 +59,9 @@ org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.common + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.core + diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java new file mode 100644 index 0000000000..f3dcdb6cd5 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java @@ -0,0 +1,55 @@ +/* +* 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.simple.policy.decision.point; + +public class PolicyEvaluationException extends Exception { + + private String policyErrorMessage; + + public String getPolicyErrorMessage() { + return policyErrorMessage; + } + + public void setPolicyErrorMessage(String policyErrorMessage) { + this.policyErrorMessage = policyErrorMessage; + } + + public PolicyEvaluationException(String message) { + super(message); + setPolicyErrorMessage(message); + } + + public PolicyEvaluationException(String message, Exception ex) { + super(message, ex); + setPolicyErrorMessage(message); + } + + public PolicyEvaluationException(String message, Throwable cause) { + super(message, cause); + setPolicyErrorMessage(message); + } + + public PolicyEvaluationException() { + super(); + } + + public PolicyEvaluationException(Throwable cause) { + super(cause); + } +} diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java index fbeb04c7a4..21e3888e80 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java @@ -18,21 +18,22 @@ package org.wso2.carbon.simple.policy.decision.point; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.PIPDeviceData; import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyEvaluationService; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import java.util.List; -public class PolicyEvaluationServiceImpl implements PolicyEvaluationService { +public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { @Override - public Policy getEffectivePolicy(PIPDeviceData pipDeviceData) { + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) { return null; } @Override - public List getEffectiveFeatures(PIPDeviceData pipDeviceData) { + public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) { return null; } } diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java new file mode 100644 index 0000000000..f1d076d0fd --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java @@ -0,0 +1,31 @@ +/* +* 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.simple.policy.decision.point; + +import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.Policy; + +public interface SimpleEvaluation { + + void sortPolicy(Policy policy) throws PolicyEvaluationException; + + Policy getEffectivePolicy(PIPDeviceData pipDeviceData) throws PolicyEvaluationException; + +} diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java new file mode 100644 index 0000000000..95f902a985 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java @@ -0,0 +1,47 @@ +/* +* 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.simple.policy.decision.point; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; + +public class SimpleEvaluationImpl implements SimpleEvaluation { + + private static final Log log = LogFactory.getLog(SimpleEvaluationImpl.class); + + PolicyDAOImpl policyDAO; + + + public SimpleEvaluationImpl() { + policyDAO = new PolicyDAOImpl(); + } + + @Override + public void sortPolicy(Policy policy) throws PolicyEvaluationException { + + } + + @Override + public Policy getEffectivePolicy(PIPDeviceData pipDeviceData) throws PolicyEvaluationException { + return null; + } +} From d7abfbc19b79b36cc03d8ae833c5aa2d61f830bd Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Wed, 18 Mar 2015 12:10:52 +0530 Subject: [PATCH 09/12] Adding the missed classes --- .../carbon/policy/mgt/core/PolicyManager.java | 50 +++++ .../policy/mgt/core/PolicyManagerImpl.java | 93 +++++++++ .../impl/PolicyAdministratorPointImpl.java | 196 ++++++++++++++++++ .../core/service/PolicyManagementService.java | 87 ++++++++ 4 files changed, 426 insertions(+) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java new file mode 100644 index 0000000000..4aa1a1b828 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManager.java @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + + +package org.wso2.carbon.policy.mgt.core; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.*; + +import java.util.List; + +public interface PolicyManager { + + Feature addFeature(Feature feature) throws FeatureManagementException; + + Feature updateFeature(Feature feature) throws FeatureManagementException; + + Profile addProfile(Profile profile) throws PolicyManagementException; + + Profile updateProfile(Profile profile) throws PolicyManagementException; + + Policy addPolicy(Policy policy) throws PolicyManagementException; + + Policy updatePolicy(Policy policy) throws PolicyManagementException; + + Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; + + Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException; + + List getPolicies(String deviceType) throws PolicyManagementException; + + List getFeatures() throws FeatureManagementException; + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java new file mode 100644 index 0000000000..7b86d252e3 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerImpl.java @@ -0,0 +1,93 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.mgt.core; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl; + +import java.util.List; + +public class PolicyManagerImpl implements PolicyManager { + + private static final Log log = LogFactory.getLog(PolicyManagerImpl.class); + + PolicyAdministratorPointImpl policyAdministratorPoint; + + public PolicyManagerImpl() { + policyAdministratorPoint = new PolicyAdministratorPointImpl(); + } + + @Override + public Feature addFeature(Feature feature) throws FeatureManagementException { + return policyAdministratorPoint.addFeature(feature); + } + + @Override + public Feature updateFeature(Feature feature) throws FeatureManagementException { + return policyAdministratorPoint.updateFeature(feature); + } + + @Override + public Profile addProfile(Profile profile) throws PolicyManagementException { + return policyAdministratorPoint.addProfile(profile); + } + + @Override + public Profile updateProfile(Profile profile) throws PolicyManagementException { + return policyAdministratorPoint.updateProfile(profile); + } + + @Override + public Policy addPolicy(Policy policy) throws PolicyManagementException { + return policyAdministratorPoint.addPolicy(policy); + } + + @Override + public Policy updatePolicy(Policy policy) throws PolicyManagementException { + return policyAdministratorPoint.updatePolicy(policy); + } + + @Override + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + return null; + } + + @Override + public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException { + return null; + } + + @Override + public List getPolicies(String deviceType) throws PolicyManagementException { + return null; + } + + @Override + public List getFeatures() throws FeatureManagementException { + return null; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java new file mode 100644 index 0000000000..3cb9ceaff1 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -0,0 +1,196 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.mgt.core.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; +import org.wso2.carbon.policy.mgt.common.PolicyManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; +import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; + +public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { + + private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class); + PolicyDAOImpl policyDAO; + + public PolicyAdministratorPointImpl() { + policyDAO = new PolicyDAOImpl(); + } + + @Override + public Policy addPolicy(Policy policy) throws PolicyManagementException { + try { + policy = policyDAO.addPolicy(policy); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + return policy; + } + + public Policy updatePolicy(Policy policy) throws PolicyManagementException { + try { + policy = policyDAO.updatePolicy(policy); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while updating the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + return policy; + } + + @Override + public Policy addPolicyToDevice(String deviceId, String deviceType, Policy policy) + throws FeatureManagementException, PolicyManagementException { + + try { + policy = policyDAO.addPolicy(deviceId, deviceType, policy); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + return policy; + } + + @Override + public Policy addPolicyToRole(String roleName, Policy policy) + throws FeatureManagementException, PolicyManagementException { + try { + policy = policyDAO.addPolicyToRole(roleName, policy); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + return policy; + } + + @Override + public Policy getPolicy() { + return null; + } + + @Override + public Policy getPolicyOfDevice(String deviceId, String deviceType) + throws FeatureManagementException, PolicyManagementException { + return null; + } + + @Override + public Policy getPolicyOfDeviceType(String deviceType) + throws FeatureManagementException, PolicyManagementException { + return null; + } + + @Override + public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException { + return null; + } + + @Override + public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException { + return false; + } + + @Override + public boolean isPolicyApplied(String deviceId, String deviceType) throws PolicyManagementException { + return false; + } + + @Override + public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException { + + } + + @Override + public Profile addProfile(Profile profile) throws PolicyManagementException { + try { + profile = policyDAO.addProfile(profile); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the policy."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + + return profile; + } + + @Override + public boolean deleteProfile(int profileId) throws PolicyManagementException { + return false; + } + + @Override + public Profile updateProfile(Profile profile) throws PolicyManagementException { + try { + profile = policyDAO.updateProfile(profile); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the profile."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + + return profile; + } + + @Override + public Feature addFeature(Feature feature) throws FeatureManagementException { + try { + feature = policyDAO.addFeature(feature); + } catch (FeatureManagementException e) { + String msg = "Error occurred while persisting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } + + return feature; + } + + @Override + public Feature updateFeature(Feature feature) throws FeatureManagementException { + try { + feature = policyDAO.updateFeature(feature); + } catch (PolicyManagerDAOException e) { + String msg = "Error occurred while persisting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } catch (FeatureManagementException e) { + String msg = "Error occurred while persisting the feature."; + log.error(msg, e); + throw new FeatureManagementException(msg, e); + } + return feature; + } + + @Override + public void deleteFeature(int featureId) throws FeatureManagementException { + + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java new file mode 100644 index 0000000000..4154c2bc84 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.mgt.core.service; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.*; +import org.wso2.carbon.policy.mgt.core.PolicyManager; +import org.wso2.carbon.policy.mgt.core.PolicyManagerImpl; + +import java.util.List; + +public class PolicyManagementService implements PolicyManager { + + + PolicyManager policyManager; + + public PolicyManagementService() { + policyManager = new PolicyManagerImpl(); + } + + @Override + public Feature addFeature(Feature feature) throws FeatureManagementException { + return policyManager.addFeature(feature); + } + + @Override + public Feature updateFeature(Feature feature) throws FeatureManagementException { + return policyManager.updateFeature(feature); + } + + @Override + public Profile addProfile(Profile profile) throws PolicyManagementException { + return policyManager.addProfile(profile); + } + + @Override + public Profile updateProfile(Profile profile) throws PolicyManagementException { + return policyManager.updateProfile(profile); + } + + @Override + public Policy addPolicy(Policy policy) throws PolicyManagementException { + return policyManager.addPolicy(policy); + } + + @Override + public Policy updatePolicy(Policy policy) throws PolicyManagementException { + return policyManager.updatePolicy(policy); + } + + @Override + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { + return policyManager.getEffectivePolicy(deviceIdentifier); + } + + @Override + public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException { + return policyManager.getEffectiveFeatures(deviceIdentifier); + } + + @Override + public List getPolicies(String deviceType) throws PolicyManagementException { + return policyManager.getPolicies(deviceType); + } + + @Override + public List getFeatures() throws FeatureManagementException { + return policyManager.getFeatures(); + } +} From 5bdbcaa0775cfd57872a2597cd8869af0500dc27 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Wed, 18 Mar 2015 14:00:21 +0530 Subject: [PATCH 10/12] Seperating the dao to Feature, profile, policy and adding the exeception for each ones --- .../policy/mgt/core/dao/FeatureDAO.java | 42 +++ .../core/dao/FeatureManagerDAOException.java | 56 ++++ .../carbon/policy/mgt/core/dao/PolicyDAO.java | 13 +- .../policy/mgt/core/dao/ProfileDAO.java | 38 +++ .../core/dao/ProfileManagerDAOException.java | 55 ++++ .../mgt/core/dao/impl/FeatureDAOImpl.java | 196 +++++++++++++ .../mgt/core/dao/impl/PolicyDAOImpl.java | 277 ------------------ .../mgt/core/dao/impl/ProfileDAOImpl.java | 195 ++++++++++++ .../impl/PolicyAdministratorPointImpl.java | 33 ++- .../policy/mgt/core/PolicyDAOTestCase.java | 6 +- .../point/PolicyEvaluationException.java | 16 +- 11 files changed, 622 insertions(+), 305 deletions(-) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureManagerDAOException.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileManagerDAOException.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java new file mode 100644 index 0000000000..1014756202 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureDAO.java @@ -0,0 +1,42 @@ +/* +* 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.dao; + +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.Profile; + +import java.util.List; + +public interface FeatureDAO { + + Feature addFeature(Feature feature) throws FeatureManagerDAOException; + + Feature updateFeature(Feature feature) throws FeatureManagerDAOException; + + List getAllFeatures() throws FeatureManagerDAOException; + + List getFeaturesForProfile(int ProfileId) throws FeatureManagerDAOException; + + void deleteFeature(int featureId) throws FeatureManagerDAOException; + + void deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException; + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureManagerDAOException.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureManagerDAOException.java new file mode 100644 index 0000000000..02ff4a00d6 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/FeatureManagerDAOException.java @@ -0,0 +1,56 @@ +/* +* 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.dao; + +public class FeatureManagerDAOException extends Exception { + + private String featureDAOErrorMessage; + + public String getFeatureDAOErrorMessage() { + return featureDAOErrorMessage; + } + + public void setFeatureDAOErrorMessage(String featureDAOErrorMessage) { + this.featureDAOErrorMessage = featureDAOErrorMessage; + } + + public FeatureManagerDAOException(String message) { + super(message); + setFeatureDAOErrorMessage(message); + } + + public FeatureManagerDAOException(String message, Exception ex) { + super(message, ex); + setFeatureDAOErrorMessage(message); + } + + public FeatureManagerDAOException(String message, Throwable cause) { + super(message, cause); + setFeatureDAOErrorMessage(message); + } + + public FeatureManagerDAOException() { + super(); + } + + public FeatureManagerDAOException(Throwable cause) { + super(cause); + } + +} 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 0ed1d8e529..8915e234ec 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 @@ -45,7 +45,13 @@ public interface PolicyDAO { void deletePolicy(Policy policy) throws PolicyManagerDAOException; - Profile addProfile(Profile profile) throws PolicyManagerDAOException; + + + + + + + /* Profile addProfile(Profile profile) throws PolicyManagerDAOException; Profile updateProfile(Profile profile) throws PolicyManagerDAOException; @@ -55,6 +61,9 @@ public interface PolicyDAO { List getProfilesOfDeviceType(String deviceType) throws PolicyManagerDAOException; + + + List getAllFeatures() throws PolicyManagerDAOException; List getFeaturesForProfile(int ProfileId) throws PolicyManagerDAOException; @@ -65,5 +74,5 @@ public interface PolicyDAO { Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException; - Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException; + Feature updateFeature(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/ProfileDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java new file mode 100644 index 0000000000..b35354d8ad --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileDAO.java @@ -0,0 +1,38 @@ +/* +* 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.dao; + +import org.wso2.carbon.policy.mgt.common.Profile; + +import java.util.List; + +public interface ProfileDAO { + + Profile addProfile(Profile profile) throws ProfileManagerDAOException; + + Profile updateProfile(Profile profile) throws ProfileManagerDAOException; + + void deleteProfile(Profile profile) throws ProfileManagerDAOException; + + List getAllProfiles() throws ProfileManagerDAOException; + + List getProfilesOfDeviceType(String deviceType) throws ProfileManagerDAOException; + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileManagerDAOException.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileManagerDAOException.java new file mode 100644 index 0000000000..ba859ed784 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/ProfileManagerDAOException.java @@ -0,0 +1,55 @@ +/* +* 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.dao; + +public class ProfileManagerDAOException extends Exception{ + + private String profileDAOErrorMessage; + + public String getProfileDAOErrorMessage() { + return profileDAOErrorMessage; + } + + public void setProfileDAOErrorMessage(String profileDAOErrorMessage) { + this.profileDAOErrorMessage = profileDAOErrorMessage; + } + + public ProfileManagerDAOException(String message) { + super(message); + setProfileDAOErrorMessage(message); + } + + public ProfileManagerDAOException(String message, Exception ex) { + super(message, ex); + setProfileDAOErrorMessage(message); + } + + public ProfileManagerDAOException(String message, Throwable cause) { + super(message, cause); + setProfileDAOErrorMessage(message); + } + + public ProfileManagerDAOException() { + super(); + } + + public ProfileManagerDAOException(Throwable cause) { + super(cause); + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java new file mode 100644 index 0000000000..42913cc7d6 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/FeatureDAOImpl.java @@ -0,0 +1,196 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.mgt.core.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.Profile; +import org.wso2.carbon.policy.mgt.core.dao.*; +import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; + +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 FeatureDAOImpl implements FeatureDAO { + + private static final Log log = LogFactory.getLog(FeatureDAOImpl.class); + + + @Override + public Feature addFeature(Feature feature) throws FeatureManagerDAOException { + 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 FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + return feature; + } + + + @Override + public Feature updateFeature(Feature feature) throws FeatureManagerDAOException { + return feature; + } + + @Override + public void deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException { + 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 FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } + + + @Override + public List getAllFeatures() throws FeatureManagerDAOException { + 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 FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + return featureList; + } + + @Override + public List getFeaturesForProfile(int profileId) throws FeatureManagerDAOException { + 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 FeatureManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + return featureList; + } + + @Override + public void deleteFeature(int featureId) throws FeatureManagerDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (SQLException e) { + + } + } + + private Connection getConnection() throws FeatureManagerDAOException { + try { + return PolicyManagementDAOFactory.getDataSource().getConnection(); + } catch (SQLException e) { + throw new FeatureManagerDAOException("Error occurred while obtaining a connection from the policy " + + "management metadata repository datasource", e); + } + } +} 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 20b46af07c..c28a5ca087 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 @@ -258,287 +258,10 @@ public class PolicyDAOImpl implements PolicyDAO { } - 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 Profile 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); - } - - return profile; - } - public Profile updateProfile(Profile profile) throws PolicyManagerDAOException { - return profile; - } - - @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 Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException { - 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) { - - } - } /** diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java new file mode 100644 index 0000000000..0c09c36eb9 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/ProfileDAOImpl.java @@ -0,0 +1,195 @@ +/* +* 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.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.Profile; +import org.wso2.carbon.policy.mgt.core.dao.*; +import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class ProfileDAOImpl implements ProfileDAO { + + private static final Log log = LogFactory.getLog(ProfileDAOImpl.class); + + + public Profile addProfile(Profile profile) throws ProfileManagerDAOException { + 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 ProfileManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys); + } + + return profile; + } + + + public Profile updateProfile(Profile profile) throws ProfileManagerDAOException { + return profile; + } + + @Override + public void deleteProfile(Profile profile) throws ProfileManagerDAOException { + + // First delete the features related to the profile + FeatureDAOImpl featureDAO = new FeatureDAOImpl(); + try { + featureDAO.deleteFeaturesOfProfile(profile); + } catch (FeatureManagerDAOException e) { + String msg = "Error occurred while deleting features."; + log.error(msg, e); + throw new ProfileManagerDAOException(msg, e); + } + + + 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 ProfileManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } + + private void persistFeatures(Profile profile) throws ProfileManagerDAOException { + 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 ProfileManagerDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(conn, stmt, null); + } + } + + + @Override + public List getAllProfiles() throws ProfileManagerDAOException { + 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 ProfileManagerDAOException { + + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet generatedKeys = null; + + try { + conn = this.getConnection(); + String query = ""; + stmt = conn.prepareStatement(query); + } catch (SQLException e) { + + } + + return null; + } + + + private Connection getConnection() throws ProfileManagerDAOException { + try { + return PolicyManagementDAOFactory.getDataSource().getConnection(); + } catch (SQLException e) { + throw new ProfileManagerDAOException("Error occurred while obtaining a connection from the policy " + + "management metadata repository datasource", e); + } + } + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index 3cb9ceaff1..c21bf86d69 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -26,16 +26,25 @@ import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.Profile; +import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; +import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException; +import org.wso2.carbon.policy.mgt.core.dao.impl.FeatureDAOImpl; import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; +import org.wso2.carbon.policy.mgt.core.dao.impl.ProfileDAOImpl; public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class); + PolicyDAOImpl policyDAO; + FeatureDAOImpl featureDAO; + ProfileDAOImpl profileDAO; public PolicyAdministratorPointImpl() { policyDAO = new PolicyDAOImpl(); + featureDAO = new FeatureDAOImpl(); + profileDAO = new ProfileDAOImpl(); } @Override @@ -128,8 +137,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public Profile addProfile(Profile profile) throws PolicyManagementException { try { - profile = policyDAO.addProfile(profile); - } catch (PolicyManagerDAOException e) { + profile = profileDAO.addProfile(profile); + } catch (ProfileManagerDAOException e) { String msg = "Error occurred while persisting the policy."; log.error(msg, e); throw new PolicyManagementException(msg, e); @@ -146,8 +155,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public Profile updateProfile(Profile profile) throws PolicyManagementException { try { - profile = policyDAO.updateProfile(profile); - } catch (PolicyManagerDAOException e) { + profile = profileDAO.updateProfile(profile); + } catch (ProfileManagerDAOException e) { String msg = "Error occurred while persisting the profile."; log.error(msg, e); throw new PolicyManagementException(msg, e); @@ -159,12 +168,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public Feature addFeature(Feature feature) throws FeatureManagementException { try { - feature = policyDAO.addFeature(feature); - } catch (FeatureManagementException e) { - String msg = "Error occurred while persisting the feature."; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } catch (PolicyManagerDAOException e) { + feature = featureDAO.addFeature(feature); + } catch (FeatureManagerDAOException e) { String msg = "Error occurred while persisting the feature."; log.error(msg, e); throw new FeatureManagementException(msg, e); @@ -176,12 +181,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public Feature updateFeature(Feature feature) throws FeatureManagementException { try { - feature = policyDAO.updateFeature(feature); - } catch (PolicyManagerDAOException e) { - String msg = "Error occurred while persisting the feature."; - log.error(msg, e); - throw new FeatureManagementException(msg, e); - } catch (FeatureManagementException e) { + feature = featureDAO.updateFeature(feature); + } catch (FeatureManagerDAOException e) { String msg = "Error occurred while persisting the feature."; log.error(msg, e); throw new FeatureManagementException(msg, e); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java index cddc3f834c..2c4d670cca 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyDAOTestCase.java @@ -31,8 +31,10 @@ 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.FeatureManagerDAOException; 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.FeatureDAOImpl; 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; @@ -144,9 +146,9 @@ public class PolicyDAOTestCase { } @Test - public void addFeatures() throws PolicyManagerDAOException, PolicyManagementException, FeatureManagementException { + public void addFeatures() throws FeatureManagerDAOException { - PolicyDAOImpl policyDAO = new PolicyDAOImpl(); + FeatureDAOImpl policyDAO = new FeatureDAOImpl(); List featureList = FeatureCreator.getFeatureList(); for (Feature feature : featureList) { policyDAO.addFeature(feature); diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java index f3dcdb6cd5..b779b6ab6c 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationException.java @@ -20,29 +20,29 @@ package org.wso2.carbon.simple.policy.decision.point; public class PolicyEvaluationException extends Exception { - private String policyErrorMessage; + private String policyEvaluationErrorMessage; - public String getPolicyErrorMessage() { - return policyErrorMessage; + public String getPolicyEvaluationErrorMessage() { + return policyEvaluationErrorMessage; } - public void setPolicyErrorMessage(String policyErrorMessage) { - this.policyErrorMessage = policyErrorMessage; + public void setPolicyEvaluationErrorMessage(String policyEvaluationErrorMessage) { + this.policyEvaluationErrorMessage = policyEvaluationErrorMessage; } public PolicyEvaluationException(String message) { super(message); - setPolicyErrorMessage(message); + setPolicyEvaluationErrorMessage(message); } public PolicyEvaluationException(String message, Exception ex) { super(message, ex); - setPolicyErrorMessage(message); + setPolicyEvaluationErrorMessage(message); } public PolicyEvaluationException(String message, Throwable cause) { super(message, cause); - setPolicyErrorMessage(message); + setPolicyEvaluationErrorMessage(message); } public PolicyEvaluationException() { From 3219a7cc41e6b9c79151ed059a980d35f3b08b32 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 18 Mar 2015 15:47:31 +0530 Subject: [PATCH 11/12] Restructuring source code to be able to make it more maintenable --- .../DeviceManagementServiceException.java | 57 ------------------- .../device/mgt/common/FeatureManager.java | 22 +++++++ .../mgt/common/license/mgt}/License.java | 2 +- .../mgt/LicenseManagementException.java | 2 +- .../common}/license/mgt/LicenseManager.java | 2 +- .../license/mgt/LicenseNotFoundException.java | 2 +- .../mgt/common}/operation/mgt/Operation.java | 2 +- .../mgt/OperationExecutionException.java | 2 +- .../mgt/OperationManagementException.java | 2 +- .../operation/mgt/OperationManager.java | 2 +- 10 files changed, 30 insertions(+), 65 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementServiceException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt}/License.java (97%) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/license/mgt/LicenseManagementException.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/license/mgt/LicenseManager.java (94%) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/license/mgt/LicenseNotFoundException.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/operation/mgt/Operation.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/operation/mgt/OperationExecutionException.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/operation/mgt/OperationManagementException.java (96%) rename components/device-mgt/{org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core => org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common}/operation/mgt/OperationManager.java (97%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementServiceException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementServiceException.java deleted file mode 100644 index 15520c16c7..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementServiceException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.device.mgt.common; - -public class DeviceManagementServiceException extends Exception { - - private static final long serialVersionUID = -8933146283800122640L; - private String errorMessage; - - public String getErrorMessage() { - return errorMessage; - } - - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - - public DeviceManagementServiceException(String msg, Exception nestedEx) { - super(msg, nestedEx); - setErrorMessage(msg); - } - - public DeviceManagementServiceException(String message, Throwable cause) { - super(message, cause); - setErrorMessage(message); - } - - public DeviceManagementServiceException(String msg) { - super(msg); - setErrorMessage(msg); - } - - public DeviceManagementServiceException() { - super(); - } - - public DeviceManagementServiceException(Throwable cause) { - super(cause); - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java new file mode 100644 index 0000000000..b10f0506fa --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java @@ -0,0 +1,22 @@ +/* + * 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.device.mgt.common; + +public interface FeatureManager { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/License.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/License.java index dc7a24135e..7044eb4916 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/License.java @@ -18,7 +18,7 @@ * */ -package org.wso2.carbon.device.mgt.core.config.license; +package org.wso2.carbon.device.mgt.common.license.mgt; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManagementException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManagementException.java index 7668f49682..8a0e462f39 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManagementException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.core.license.mgt; +package org.wso2.carbon.device.mgt.common.license.mgt; public class LicenseManagementException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManager.java similarity index 94% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManager.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManager.java index df614f5fbb..63df2aefba 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManager.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.core.license.mgt; +package org.wso2.carbon.device.mgt.common.license.mgt; import org.wso2.carbon.device.mgt.core.config.license.License; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseNotFoundException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseNotFoundException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseNotFoundException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseNotFoundException.java index c1c6ce9117..ee25364fcf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseNotFoundException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseNotFoundException.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.core.license.mgt; +package org.wso2.carbon.device.mgt.common.license.mgt; public class LicenseNotFoundException extends RuntimeException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/Operation.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index a424180260..0f3d46a473 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.core.operation.mgt; +package org.wso2.carbon.device.mgt.common.operation.mgt; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationExecutionException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationExecutionException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationExecutionException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationExecutionException.java index 94e870a440..422f689af3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationExecutionException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationExecutionException.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.operation.mgt; +package org.wso2.carbon.device.mgt.common.operation.mgt; public class OperationExecutionException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManagementException.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManagementException.java index cdf8f79c93..ec4d40b0a4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagementException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManagementException.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.operation.mgt; +package org.wso2.carbon.device.mgt.common.operation.mgt; public class OperationManagementException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index f7d9048de3..a045d10f5a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.mgt.core.operation.mgt; +package org.wso2.carbon.device.mgt.common.operation.mgt; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.core.dto.DeviceType; From 19fbc11642b70341d8bc90601829c580f1b0190f Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 18 Mar 2015 16:25:34 +0530 Subject: [PATCH 12/12] Restructuring the sources --- .../device/mgt/common/FeatureManager.java | 11 +++++++++++ .../mgt/common/license/mgt/LicenseManager.java | 2 -- .../common/operation/mgt/OperationManager.java | 1 - .../device/mgt/common/spi/DeviceManager.java | 12 +++++++++--- .../DeviceManagementServiceProviderImpl.java | 17 +++++++++++------ .../mgt/core/config/license/LicenseConfig.java | 2 ++ .../license/LicenseConfigurationManager.java | 2 +- .../internal/DeviceManagementDataHolder.java | 2 +- .../DeviceManagementServiceComponent.java | 7 +++---- .../mgt/GenericArtifactManagerFactory.java | 1 + .../license/mgt/LicenseManagementService.java | 4 +++- .../core/license/mgt/LicenseManagerImpl.java | 4 +++- .../core/operation/mgt/CommandOperation.java | 2 +- .../mgt/core/operation/mgt/ConfigOperation.java | 2 ++ .../operation/mgt/OperationManagerImpl.java | 3 +++ .../mgt/core/operation/mgt/SimpleOperation.java | 2 +- .../core/operation/mgt/dao/OperationDAO.java | 2 +- .../mgt/dao/impl/AbstractOperationDAO.java | 2 +- .../mgt/dao/impl/CommandOperationDAOImpl.java | 2 +- .../mgt/dao/impl/ConfigOperationDAOImpl.java | 2 +- .../mgt/dao/impl/SimpleOperationDAOImpl.java | 2 +- .../core/service/DeviceManagementService.java | 7 ++----- .../service/DeviceManagementServiceImpl.java | 15 +++++++++------ .../core/DeviceOperationManagementTests.java | 3 +++ .../device/mgt/core/TestDeviceManager.java | 6 ++++++ 25 files changed, 77 insertions(+), 38 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java index b10f0506fa..41f4211d41 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/FeatureManager.java @@ -18,5 +18,16 @@ */ package org.wso2.carbon.device.mgt.common; +import java.util.List; + public interface FeatureManager { + + boolean addFeature(Feature feature) throws DeviceManagementException; + + boolean getFeature(String name) throws DeviceManagementException; + + List getFeatures() throws DeviceManagementException; + + boolean removeFeature(String name) throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManager.java index 63df2aefba..6031de79ff 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/license/mgt/LicenseManager.java @@ -18,8 +18,6 @@ */ package org.wso2.carbon.device.mgt.common.license.mgt; -import org.wso2.carbon.device.mgt.core.config.license.License; - public interface LicenseManager { License getLicense(String deviceType, String languageCode) throws LicenseManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index a045d10f5a..3f134c69ad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -18,7 +18,6 @@ package org.wso2.carbon.device.mgt.common.operation.mgt; import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java index 808c39347c..ab42c1894d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManager.java @@ -18,9 +18,7 @@ package org.wso2.carbon.device.mgt.common.spi; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.*; import java.util.List; @@ -37,6 +35,13 @@ public interface DeviceManager { */ String getProviderType(); + /** + * Method to return feature manager implementation associated with a particular platform-specific plugin. + * + * @return Returns an instance of feature manager + */ + FeatureManager getFeatureManager(); + /** * Method to enrolling a particular device of type mobile, IoT, etc within CDM. * @@ -128,4 +133,5 @@ public interface DeviceManager { */ boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java index d5df8311b0..79b628349b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementServiceProviderImpl.java @@ -19,7 +19,7 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; -import org.wso2.carbon.device.mgt.core.config.license.License; +import org.wso2.carbon.device.mgt.common.license.mgt.License; 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.DeviceManagementDAOFactory; @@ -27,12 +27,12 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.Status; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; -import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagementException; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; @@ -60,6 +60,11 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ return null; } + @Override + public FeatureManager getFeatureManager() { + return null; + } + @Override public boolean enrollDevice(Device device) throws DeviceManagementException { DeviceManager dms = diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/LicenseConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/LicenseConfig.java index b378fa70c2..ba36bdd470 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/LicenseConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/LicenseConfig.java @@ -20,6 +20,8 @@ package org.wso2.carbon.device.mgt.core.config.license; +import org.wso2.carbon.device.mgt.common.license.mgt.License; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/LicenseConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/LicenseConfigurationManager.java index 43782e7518..824de24335 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/LicenseConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/LicenseConfigurationManager.java @@ -22,7 +22,7 @@ package org.wso2.carbon.device.mgt.core.config.license; import org.w3c.dom.Document; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.utils.CarbonUtils; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 2108aee649..a20c763baa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.core.internal; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.tenant.TenantManager; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index a93e88cced..4d79e58694 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -30,13 +30,12 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; -import org.wso2.carbon.device.mgt.core.config.license.License; +import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementService; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java index f1fbbb617f..85535f3f03 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/GenericArtifactManagerFactory.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.license.mgt; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.governance.api.generic.GenericArtifactManager; import org.wso2.carbon.registry.api.Registry; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementService.java index 92615e66d6..638a9dc881 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagementService.java @@ -18,7 +18,9 @@ */ package org.wso2.carbon.device.mgt.core.license.mgt; -import org.wso2.carbon.device.mgt.core.config.license.License; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; public class LicenseManagementService implements LicenseManager { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagerImpl.java index 42af35fcc9..e1ded0d3ee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/license/mgt/LicenseManagerImpl.java @@ -22,8 +22,10 @@ package org.wso2.carbon.device.mgt.core.license.mgt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; -import org.wso2.carbon.device.mgt.core.config.license.License; +import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.governance.api.exception.GovernanceException; import org.wso2.carbon.governance.api.generic.GenericArtifactFilter; import org.wso2.carbon.governance.api.generic.GenericArtifactManager; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java index c135c41188..a971ab9d79 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt; -import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; public class CommandOperation extends Operation { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java index 2d25687779..948902d1bf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java @@ -18,6 +18,8 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; + import java.util.ArrayList; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index b3ba04cffb..2dd3b844f7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -21,6 +21,9 @@ package org.wso2.carbon.device.mgt.core.operation.mgt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java index b2a57eccab..2f31c3107e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/SimpleOperation.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt; -import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; public class SimpleOperation extends Operation { } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index 00479d4908..e834c756f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; -import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java index 2467a72c33..de8ba47afa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/AbstractOperationDAO.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.*; import javax.sql.DataSource; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index 80936c73db..c892315d03 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index b2dac4ea69..2a7e71f424 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java index ab59e9c8f8..09f53bb3b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/SimpleOperationDAOImpl.java @@ -18,7 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; -import org.wso2.carbon.device.mgt.core.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import javax.sql.DataSource; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 5f752b4871..b024829c55 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -18,13 +18,10 @@ package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; -import org.wso2.carbon.device.mgt.core.config.license.License; -import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager; -import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManager; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import java.util.List; 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 f3c90fd7ab..c7b6937031 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 @@ -18,12 +18,10 @@ package org.wso2.carbon.device.mgt.core.service; import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.core.service.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; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import java.util.List; @@ -35,6 +33,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return null; } + @Override + public FeatureManager getFeatureManager() { + return null; + } + @Override public boolean enrollDevice(Device device) throws DeviceManagementException { return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().enrollDevice(device); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java index 5038dc8acf..6c29280d8f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/DeviceOperationManagementTests.java @@ -21,6 +21,9 @@ package org.wso2.carbon.device.mgt.core; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.core.dto.Device; import org.wso2.carbon.device.mgt.core.operation.mgt.*; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java index 9e93d33c32..4c44ee0c59 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManager.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import java.util.List; @@ -33,6 +34,11 @@ public class TestDeviceManager implements DeviceManager { return TestDeviceManager.DEVICE_TYPE_TEST; } + @Override + public FeatureManager getFeatureManager() { + return null; + } + @Override public boolean enrollDevice(Device device) throws DeviceManagementException { return false;