mharindu 10 years ago
commit 39ae880972

@ -0,0 +1,37 @@
/*
* 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.dto.operation.mgt;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
import java.util.List;
public class PolicyOperation extends Operation{
public List<ProfileOperation> getProfileOperations() {
return profileOperations;
}
public void setProfileOperations(List<ProfileOperation> profileOperations) {
this.profileOperations = profileOperations;
}
private List<ProfileOperation> profileOperations;
}

@ -26,6 +26,8 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 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.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.*;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; 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.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
@ -343,9 +345,22 @@ public class OperationManagerImpl implements OperationManager {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
.valueOf(status.toString())); .valueOf(status.toString()));
Operation operation; Operation operation = null;
PolicyOperation policyOperation;
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) { for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
if (dtoOperation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation){
policyOperation = (PolicyOperation)dtoOperation;
for(org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation
profileOperation:policyOperation.getProfileOperations()){
operation = OperationDAOUtil.convertOperation(profileOperation);
}
}else{
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
}
operations.add(operation); operations.add(operation);
} }
return operations; return operations;

@ -4,7 +4,7 @@
* WSO2 Inc. licenses this file to you under the Apache License, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. * in compliance with the License.
* You may obtain a copy of the License at * 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
* *
@ -15,17 +15,15 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.core.operation.mgt;
package org.wso2.carbon.policy.mgt.common;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.List; import java.util.List;
public class PolicyOperation extends ProfileOperation { public class PolicyOperation extends Operation {
private List<ProfileOperation> profileOperations;
public List<ProfileOperation> getProfileOperations() { public List<ProfileOperation> getProfileOperations() {
return profileOperations; return profileOperations;
@ -34,4 +32,7 @@ public class PolicyOperation extends ProfileOperation {
public void setProfileOperations(List<ProfileOperation> profileOperations) { public void setProfileOperations(List<ProfileOperation> profileOperations) {
this.profileOperations = profileOperations; this.profileOperations = profileOperations;
} }
private List<ProfileOperation> profileOperations;
} }

@ -22,6 +22,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; 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.OperationManagementDAOException;
@ -276,7 +277,11 @@ public class OperationDAOImpl implements OperationDAO {
operationDetails = rs.getBytes("OPERATION_DETAILS"); operationDetails = rs.getBytes("OPERATION_DETAILS");
bais = new ByteArrayInputStream(operationDetails); bais = new ByteArrayInputStream(operationDetails);
ois = new ObjectInputStream(bais); ois = new ObjectInputStream(bais);
operation = (ProfileOperation) ois.readObject(); if (ois.readObject() instanceof PolicyOperation){
operation = (PolicyOperation) ois.readObject();
}else{
operation = (PolicyOperation) ois.readObject();
}
} else { } else {
operation = new Operation(); operation = new Operation();
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl; import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;

@ -36,6 +36,8 @@ public interface PolicyDAO {
Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException; Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException;
boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException;
// Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException; // Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException;
// //
// Policy addTimesToPolicy(int startTime, int endTime, Policy policy) throws PolicyManagerDAOException; // Policy addTimesToPolicy(int startTime, int endTime, Policy policy) throws PolicyManagerDAOException;
@ -88,6 +90,8 @@ public interface PolicyDAO {
List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException; List<String> getPolicyAppliedRoles(int policyId) throws PolicyManagerDAOException;
List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException;
// PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException; // PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException;
// //
// PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException; // PolicyDates getDatesOfPolicy(Policy policy) throws PolicyManagerDAOException;

@ -142,6 +142,36 @@ public class PolicyDAOImpl implements PolicyDAO {
return policy; return policy;
} }
@Override
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException {
/* Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "UPDATE DM_POLICY SET PRIORITY = ? WHERE ID = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, policy.getPolicyName());
stmt.setInt(2, policy.getTenantId());
stmt.setInt(3, policy.getProfile().getProfileId());
stmt.setInt(4, policy.getPriorityId());
stmt.setString(5, policy.getCompliance());
stmt.setInt(6, policy.getId());
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating policy (" + policy.getPolicyName() + ") in database.";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
return policy;*/
return false;
}
// @Override // @Override
// public Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException { // public Policy addDatesToPolicy(Date startDate, Date endDate, Policy policy) throws PolicyManagerDAOException {
// //
@ -752,6 +782,36 @@ public class PolicyDAOImpl implements PolicyDAO {
} }
} }
@Override
public List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
List<String> users = new ArrayList<String>();
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_USER_POLICY WHERE POLICY_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policyId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
users.add(resultSet.getString("USERNAME"));
}
return users;
} catch (SQLException e) {
String msg = "Error occurred while getting the roles related to policies.";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection();
}
}
// public PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException { // public PolicyTimes getTimesOfPolicy(Policy policy) throws PolicyManagerDAOException {
// //

@ -88,7 +88,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
return policyManager.getPolicies(); return policyManager.getPolicies();
} }
@Override public Policy getPolicy(int policyId) throws PolicyManagementException { @Override
public Policy getPolicy(int policyId) throws PolicyManagementException {
return policyManager.getPolicy(policyId); return policyManager.getPolicy(policyId);
} }
@ -184,35 +185,18 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
@Override @Override
public Feature addFeature(Feature feature) throws FeatureManagementException { public Feature addFeature(Feature feature) throws FeatureManagementException {
try {
return featureManager.addFeature(feature); return featureManager.addFeature(feature);
} catch (FeatureManagementException e) {
String msg = "Error occurred while persisting the feature.";
log.error(msg, e);
throw new FeatureManagementException(msg, e);
}
} }
@Override @Override
public Feature updateFeature(Feature feature) throws FeatureManagementException { public Feature updateFeature(Feature feature) throws FeatureManagementException {
try {
return featureManager.updateFeature(feature); return featureManager.updateFeature(feature);
} catch (FeatureManagementException e) {
String msg = "Error occurred while persisting the feature.";
log.error(msg, e);
throw new FeatureManagementException(msg, e);
}
} }
@Override @Override
public boolean deleteFeature(int featureId) throws FeatureManagementException { public boolean deleteFeature(int featureId) throws FeatureManagementException {
try {
return featureManager.deleteFeature(featureId); return featureManager.deleteFeature(featureId);
} catch (FeatureManagementException e) {
String msg = "Error occurred while deleting the feature.";
log.error(msg, e);
throw new FeatureManagementException(msg, e);
}
} }
@Override @Override

@ -88,47 +88,19 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
@Override @Override
public List<Policy> getRelatedPolicies(PIPDevice pipDevice) throws PolicyManagementException { public List<Policy> getRelatedPolicies(PIPDevice pipDevice) throws PolicyManagementException {
// List<List<Policy>> policies = new ArrayList<List<Policy>>(); List<Policy> policies = policyManager.getPoliciesOfDeviceType(pipDevice.getDeviceType().getName());
List<Policy> policies = new ArrayList<Policy>();
try {
// Get the device type related policies
// policies.add(policyManager.getPoliciesOfDeviceType(pipDevice.getDeviceType().getName()));
// Commented out because these are already taken when device type based policies retrieved
// // Get the roles related policies
// for (String role : pipDevice.getRoles()) {
// policies.add(policyManager.getPoliciesOfRole(role));
// }
// // Get policy related to the device
// policies.add(policyManager.getPoliciesOfDevice(pipDevice.getDeviceIdentifier()));
policies = policyManager.getPoliciesOfDeviceType(pipDevice.getDeviceType().getName());
PolicyFilter policyFilter = new PolicyFilterImpl(); PolicyFilter policyFilter = new PolicyFilterImpl();
policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies); policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies);
policyFilter.filterOwnershipTypeBasedPolicies(pipDevice.getOwnershipType(), policies); policyFilter.filterOwnershipTypeBasedPolicies(pipDevice.getOwnershipType(), policies);
policyFilter.filterRolesBasedPolicies(pipDevice.getRoles(), policies); policyFilter.filterRolesBasedPolicies(pipDevice.getRoles(), policies);
return policies; return policies;
} catch (PolicyManagementException e) {
String msg = "Error occurred when retrieving related to given device " +
pipDevice.getDeviceIdentifier().getId() + " " + pipDevice.getDeviceIdentifier().getType() + ".";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
} }
@Override @Override
public List<Feature> getRelatedFeatures(String deviceType) throws FeatureManagementException { public List<Feature> getRelatedFeatures(String deviceType) throws FeatureManagementException {
try {
return featureManager.getAllFeatures(deviceType); return featureManager.getAllFeatures(deviceType);
} catch (FeatureManagementException e) {
String msg = "Error occurred when retrieving features related to device type.";
log.error(msg, e);
throw new FeatureManagementException(msg, e);
}
} }
private String[] getRoleOfDevice(Device device) throws PolicyManagementException { private String[] getRoleOfDevice(Device device) throws PolicyManagementException {

@ -468,6 +468,7 @@ public class PolicyManagerImpl implements PolicyManager {
} }
policy.setDevices(getPolicyAppliedDevicesIds(policy.getId())); policy.setDevices(getPolicyAppliedDevicesIds(policy.getId()));
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId())); policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId()));
policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId())); policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId()));
// policyDAO.getDatesOfPolicy(policy); // policyDAO.getDatesOfPolicy(policy);
// policyDAO.getTimesOfPolicy(policy); // policyDAO.getTimesOfPolicy(policy);

@ -263,6 +263,17 @@ public class PolicyDAOTestCase {
for (Policy policy : policyList) { for (Policy policy : policyList) {
log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName());
log.debug("Policy Ownership type :" + policy.getOwnershipType());
List<String> users = policy.getUsers();
for (String user : users) {
log.debug("User of the policy : " + user);
}
List<String> roles = policy.getRoles();
for (String role : roles) {
log.debug("User of the policy : " + role);
}
} }
} }
@ -276,6 +287,17 @@ public class PolicyDAOTestCase {
for (Policy policy : policyList) { for (Policy policy : policyList) {
log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName());
log.debug("Policy Ownership type :" + policy.getOwnershipType());
List<String> users = policy.getUsers();
for (String user : users) {
log.debug("User of the policy : " + user);
}
List<String> roles = policy.getRoles();
for (String role : roles) {
log.debug("User of the policy : " + role);
}
} }
} }
@ -290,6 +312,17 @@ public class PolicyDAOTestCase {
for (Policy policy : policyList) { for (Policy policy : policyList) {
log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName());
log.debug("Policy Ownership type :" + policy.getOwnershipType());
List<String> users = policy.getUsers();
for (String user : users) {
log.debug("User of the policy : " + user);
}
List<String> roles = policy.getRoles();
for (String role : roles) {
log.debug("User of the policy : " + role);
}
} }
} }
@ -303,6 +336,8 @@ public class PolicyDAOTestCase {
for (Policy policy : policyList) { for (Policy policy : policyList) {
log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName());
log.debug("Policy Ownership type :" + policy.getOwnershipType());
} }
} }
@ -324,6 +359,8 @@ public class PolicyDAOTestCase {
for (Policy policy : policyList) { for (Policy policy : policyList) {
log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName());
log.debug("Policy Ownership type :" + policy.getOwnershipType());
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList(); List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
for (ProfileFeature profileFeature : profileFeatures) { for (ProfileFeature profileFeature : profileFeatures) {

Loading…
Cancel
Save