From 89a12a5660ffd490b3c195c3a5062ef7a9458cf7 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Tue, 12 May 2015 16:26:20 +0530 Subject: [PATCH] * Added xml annotations to Policy and Profile * Added methods to Policy Administrator Point --- .../org.wso2.carbon.policy.mgt.common/pom.xml | 3 ++- .../wso2/carbon/policy/mgt/common/Policy.java | 21 ++++++++++++++++++ .../mgt/common/PolicyAdministratorPoint.java | 4 ++++ .../carbon/policy/mgt/common/Profile.java | 12 +++++++--- .../impl/PolicyAdministratorPointImpl.java | 22 +++++++++++++++++++ .../policy/mgt/core/mgt/ProfileManager.java | 2 +- .../mgt/core/mgt/impl/ProfileManagerImpl.java | 2 +- 7 files changed, 60 insertions(+), 6 deletions(-) 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 6684c3f4a5..f63a2aafe6 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 @@ -56,7 +56,8 @@ org.apache.commons.logging, org.wso2.carbon.device.mgt.common.*, - org.wso2.carbon.device.mgt.core.dto.* + org.wso2.carbon.device.mgt.core.dto.*, + javax.xml.bind.*, 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/Policy.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java index 714bceecab..432b2fcedd 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 @@ -21,6 +21,8 @@ package org.wso2.carbon.policy.mgt.common; import org.wso2.carbon.device.mgt.core.dto.Device; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.sql.Date; import java.util.List; @@ -29,6 +31,7 @@ import java.util.Map; /** * This class will be the used to create policy object with relevant information for evaluating. */ +@XmlRootElement public class Policy implements Comparable, Serializable { private int id; // Identifier of the policy. @@ -63,6 +66,7 @@ public class Policy implements Comparable, Serializable { private Map attributes; + @XmlElement public int getId() { return id; } @@ -71,6 +75,7 @@ public class Policy implements Comparable, Serializable { this.id = id; } + @XmlElement public int getPriorityId() { return priorityId; } @@ -79,6 +84,7 @@ public class Policy implements Comparable, Serializable { this.priorityId = priorityId; } + @XmlElement public Profile getProfile() { return profile; } @@ -87,6 +93,7 @@ public class Policy implements Comparable, Serializable { this.profile = profile; } + @XmlElement public int getProfileId() { return profileId; } @@ -95,6 +102,7 @@ public class Policy implements Comparable, Serializable { this.profileId = profileId; } + @XmlElement public String getPolicyName() { return policyName; } @@ -103,6 +111,7 @@ public class Policy implements Comparable, Serializable { this.policyName = policyName; } + @XmlElement public boolean isGeneric() { return generic; } @@ -111,6 +120,7 @@ public class Policy implements Comparable, Serializable { this.generic = generic; } + @XmlElement public List getRoleList() { return roleList; } @@ -119,6 +129,7 @@ public class Policy implements Comparable, Serializable { this.roleList = roleList; } + @XmlElement public String getOwnershipType() { return ownershipType; } @@ -127,6 +138,7 @@ public class Policy implements Comparable, Serializable { this.ownershipType = ownershipType; } + @XmlElement public List getDeviceList() { return DeviceList; } @@ -135,6 +147,7 @@ public class Policy implements Comparable, Serializable { DeviceList = deviceList; } + @XmlElement public List getUsers() { return users; } @@ -143,6 +156,7 @@ public class Policy implements Comparable, Serializable { this.users = users; } + @XmlElement public int getStartTime() { return startTime; } @@ -151,6 +165,7 @@ public class Policy implements Comparable, Serializable { this.startTime = startTime; } + @XmlElement public int getEndTime() { return endTime; } @@ -159,6 +174,7 @@ public class Policy implements Comparable, Serializable { this.endTime = endTime; } + @XmlElement public Date getStartDate() { return startDate; } @@ -167,6 +183,7 @@ public class Policy implements Comparable, Serializable { this.startDate = startDate; } + @XmlElement public Date getEndDate() { return endDate; } @@ -175,6 +192,7 @@ public class Policy implements Comparable, Serializable { this.endDate = endDate; } + @XmlElement public String getLatitude() { return latitude; } @@ -183,6 +201,7 @@ public class Policy implements Comparable, Serializable { this.latitude = latitude; } + @XmlElement public String getLongitude() { return longitude; } @@ -191,6 +210,7 @@ public class Policy implements Comparable, Serializable { this.longitude = longitude; } + @XmlElement public Map getAttributes() { return attributes; } @@ -199,6 +219,7 @@ public class Policy implements Comparable, Serializable { this.attributes = attributes; } + @XmlElement public int getTenantId() { return tenantId; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java index da9ca06add..4d47880382 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorPoint.java @@ -131,6 +131,10 @@ public interface PolicyAdministratorPoint { Profile updateProfile(Profile profile) throws PolicyManagementException; + Profile getProfile(int profileId) throws PolicyManagementException; + + List getProfiles() throws PolicyManagementException; + Feature addFeature(Feature feature) throws FeatureManagementException; Feature updateFeature(Feature feature) 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 14e182036f..8c09357f0c 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 @@ -22,9 +22,11 @@ package org.wso2.carbon.policy.mgt.common; import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import java.sql.Timestamp; import java.util.List; - +@XmlRootElement public class Profile { private int profileId; @@ -43,7 +45,7 @@ public class Profile { public void setDeviceType(DeviceType deviceType) { this.deviceType = deviceType; } - + @XmlElement public int getTenantId() { return tenantId; } @@ -59,7 +61,7 @@ public class Profile { public void setFeaturesList(List featuresList) { this.featuresList = featuresList; }*/ - + @XmlElement public int getProfileId() { return profileId; } @@ -68,6 +70,7 @@ public class Profile { this.profileId = profileId; } + @XmlElement public String getProfileName() { return profileName; } @@ -76,6 +79,7 @@ public class Profile { this.profileName = profileName; } + @XmlElement public Timestamp getCreatedDate() { return createdDate; } @@ -84,6 +88,7 @@ public class Profile { this.createdDate = createdDate; } + @XmlElement public Timestamp getUpdatedDate() { return updatedDate; } @@ -92,6 +97,7 @@ public class Profile { this.updatedDate = updatedDate; } + @XmlElement public List getProfileFeaturesList() { return profileFeaturesList; } 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 f4dad99f00..c3f3bcfb10 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 @@ -145,6 +145,28 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { } } + @Override + public Profile getProfile(int profileId) throws PolicyManagementException { + try { + return profileManager.getProfile(profileId); + } catch (ProfileManagementException e) { + String msg = "Error occurred while retriving profile"; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + } + + @Override + public List getProfiles() throws PolicyManagementException { + try { + return profileManager.getAllProfiles(); + } catch (ProfileManagementException e) { + String msg = "Error occurred while obtaining list of profiles."; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + } + @Override public Feature addFeature(Feature feature) throws FeatureManagementException { try { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/ProfileManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/ProfileManager.java index 67757e546e..11d1ffd882 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/ProfileManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/ProfileManager.java @@ -32,7 +32,7 @@ public interface ProfileManager { boolean deleteProfile(Profile profile) throws ProfileManagementException; - Profile getProfiles(int profileId) throws ProfileManagementException; + Profile getProfile(int profileId) throws ProfileManagementException; List getAllProfiles() throws ProfileManagementException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImpl.java index de53ea3523..ac6b484815 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/ProfileManagerImpl.java @@ -178,7 +178,7 @@ public class ProfileManagerImpl implements ProfileManager { } @Override - public Profile getProfiles(int profileId) throws ProfileManagementException { + public Profile getProfile(int profileId) throws ProfileManagementException { Profile profile; List featureList; DeviceType deviceType;