Fixed bugs in policy

4.x.x
mharindu 10 years ago
parent 6586eb028c
commit 1ed6eec02f

@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.List;
import java.util.Map; import java.util.Map;
//TODO : //TODO :
@ -34,7 +33,7 @@ public class PIPDevice {
private DeviceType deviceType; private DeviceType deviceType;
private DeviceIdentifier deviceIdentifier; private DeviceIdentifier deviceIdentifier;
private String ownershipType; private String ownershipType;
private List<String> userIds; private String userId;
private String roles[]; private String roles[];
private String latitude; private String latitude;
private String longitude; private String longitude;
@ -67,12 +66,12 @@ public class PIPDevice {
this.ownershipType = ownershipType; this.ownershipType = ownershipType;
} }
public List<String> getUserIds() { public String getUserId() {
return userIds; return userId;
} }
public void setUserIds(List<String> userIds) { public void setUserId(String userId) {
this.userIds = userIds; this.userId = userId;
} }
public String[] getRoles() { public String[] getRoles() {

@ -19,18 +19,16 @@
package org.wso2.carbon.policy.mgt.common; package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.policy.mgt.common.Policy;
import java.util.List; import java.util.List;
public interface PolicyFilter { public interface PolicyFilter {
void filterRolesBasedPolicies(String roles[], List<Policy> policies); List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies);
void filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies); List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies);
void filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies); List<Policy> filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies);
void filterUserBasedPolicies(List<String> usernames, List<Policy> policies); List<Policy> filterUserBasedPolicies(String username, List<Policy> policies);
} }

@ -33,13 +33,14 @@ public class PolicyFilterImpl implements PolicyFilter {
private static final Log log = LogFactory.getLog(PolicyFilterImpl.class); private static final Log log = LogFactory.getLog(PolicyFilterImpl.class);
@Override @Override
public void filterRolesBasedPolicies(String roles[], List<Policy> policies) { public List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>(); List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) { for (Policy policy : policies) {
List<String> tempRoles = policy.getRoles(); List<String> tempRoles = policy.getRoles();
if (tempRoles.isEmpty()) { if (tempRoles.isEmpty()) {
temp.add(policy);
continue; continue;
} }
if (PolicyManagementConstants.ANY.equalsIgnoreCase(tempRoles.get(0))) { if (PolicyManagementConstants.ANY.equalsIgnoreCase(tempRoles.get(0))) {
@ -56,12 +57,11 @@ public class PolicyFilterImpl implements PolicyFilter {
} }
} }
} }
policies = temp; return temp;
} }
@Override @Override
public void filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies) { public List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>(); List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) { for (Policy policy : policies) {
@ -70,22 +70,22 @@ public class PolicyFilterImpl implements PolicyFilter {
temp.add(policy); temp.add(policy);
} }
} }
policies = temp; return temp;
} }
@Override @Override
public void filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies) { public List<Policy> filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>(); List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) { for (Policy policy : policies) {
if (deviceType.equalsIgnoreCase(policy.getProfile().getDeviceType().getName())) { if (deviceType.equalsIgnoreCase(policy.getProfile().getDeviceType().getName())) {
temp.add(policy); temp.add(policy);
} }
} }
policies = temp; return temp;
} }
@Override @Override
public void filterUserBasedPolicies(List<String> usernames, List<Policy> policies) { public List<Policy> filterUserBasedPolicies(String username, List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>(); List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) { for (Policy policy : policies) {
@ -95,13 +95,11 @@ public class PolicyFilterImpl implements PolicyFilter {
continue; continue;
} }
for (String user : users) { for (String user : users) {
if(usernames.contains(user)) { if(username.equalsIgnoreCase(user)) {
temp.add(policy); temp.add(policy);
} }
} }
} }
policies = temp; return temp;
} }
} }

@ -71,6 +71,7 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
pipDevice.setRoles(getRoleOfDevice(device)); pipDevice.setRoles(getRoleOfDevice(device));
pipDevice.setDeviceType(deviceType); pipDevice.setDeviceType(deviceType);
pipDevice.setDeviceIdentifier(deviceIdentifier); pipDevice.setDeviceIdentifier(deviceIdentifier);
pipDevice.setUserId(device.getOwner());
// TODO : Find a way to retrieve the timestamp and location (lat, long) of the device // TODO : Find a way to retrieve the timestamp and location (lat, long) of the device
// pipDevice.setLongitude(); // pipDevice.setLongitude();
@ -92,16 +93,16 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
PolicyFilter policyFilter = new PolicyFilterImpl(); PolicyFilter policyFilter = new PolicyFilterImpl();
if (pipDevice.getDeviceType() != null) { if (pipDevice.getDeviceType() != null) {
policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies); policies = policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies);
} }
if (!pipDevice.getOwnershipType().isEmpty()) { if (pipDevice.getOwnershipType() != null && !pipDevice.getOwnershipType().isEmpty()) {
policyFilter.filterOwnershipTypeBasedPolicies(pipDevice.getOwnershipType(), policies); policies = policyFilter.filterOwnershipTypeBasedPolicies(pipDevice.getOwnershipType(), policies);
} }
if (pipDevice.getRoles() != null) { if (pipDevice.getRoles() != null) {
policyFilter.filterRolesBasedPolicies(pipDevice.getRoles(), policies); policies = policyFilter.filterRolesBasedPolicies(pipDevice.getRoles(), policies);
} }
if(pipDevice.getUserIds()!=null) { if(pipDevice.getUserId() != null && !pipDevice.getUserId().isEmpty()) {
policyFilter.filterUserBasedPolicies(pipDevice.getUserIds(), policies); policies = policyFilter.filterUserBasedPolicies(pipDevice.getUserId(), policies);
} }
return policies; return policies;

Loading…
Cancel
Save