mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Refactored policy
This commit is contained in:
commit
ffaccbe371
@ -349,18 +349,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
PolicyOperation policyOperation;
|
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;
|
||||||
|
|||||||
@ -277,11 +277,7 @@ 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);
|
||||||
if (ois.readObject() instanceof PolicyOperation){
|
operation = (ProfileOperation) ois.readObject();
|
||||||
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"));
|
||||||
|
|||||||
@ -38,6 +38,8 @@ public interface PolicyAdministratorPoint {
|
|||||||
|
|
||||||
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
|
boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException;
|
||||||
|
|
||||||
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||||
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
|
|||||||
@ -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.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
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.core.operation.mgt.PolicyOperation;
|
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;
|
||||||
@ -93,27 +94,23 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
|
|||||||
getEffectivePolicy(deviceIdentifier);
|
getEffectivePolicy(deviceIdentifier);
|
||||||
|
|
||||||
if (policy != null) {
|
if (policy != null) {
|
||||||
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
||||||
|
deviceIdentifiers.add(deviceIdentifier);
|
||||||
|
|
||||||
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
|
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
|
||||||
|
|
||||||
ProfileOperation policyOperation = new ProfileOperation();
|
|
||||||
|
|
||||||
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
|
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
|
||||||
for (ProfileFeature feature : effectiveFeatures) {
|
for (ProfileFeature feature : effectiveFeatures) {
|
||||||
ProfileOperation operation = new ProfileOperation();
|
ProfileOperation operation = new ProfileOperation();
|
||||||
|
|
||||||
operation.setCode(feature.getFeatureCode());
|
operation.setCode(feature.getFeatureCode());
|
||||||
|
operation.setEnabled(true);
|
||||||
|
operation.setStatus(Operation.Status.PENDING);
|
||||||
|
operation.setType(Operation.Type.PROFILE);
|
||||||
operation.setPayLoad(feature.getContent());
|
operation.setPayLoad(feature.getContent());
|
||||||
profileOperationList.add(operation);
|
|
||||||
}
|
|
||||||
policyOperation.setPayLoad(profileOperationList);
|
|
||||||
policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);
|
|
||||||
|
|
||||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
|
||||||
deviceIdentifiers.add(deviceIdentifier);
|
|
||||||
|
|
||||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService().
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService().
|
||||||
addOperation(policyOperation, deviceIdentifiers);
|
addOperation(operation, deviceIdentifiers);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -140,25 +137,23 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
|
|||||||
List<ProfileFeature> effectiveFeatures = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
|
List<ProfileFeature> effectiveFeatures = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
|
||||||
getEffectiveFeatures(deviceIdentifier);
|
getEffectiveFeatures(deviceIdentifier);
|
||||||
|
|
||||||
if (!effectiveFeatures.isEmpty()) {
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
||||||
ProfileOperation profileOperation = new ProfileOperation();
|
deviceIdentifiers.add(deviceIdentifier);
|
||||||
|
|
||||||
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
|
List<ProfileOperation> profileOperationList = new ArrayList<ProfileOperation>();
|
||||||
|
|
||||||
|
if (!effectiveFeatures.isEmpty()) {
|
||||||
for (ProfileFeature feature : effectiveFeatures) {
|
for (ProfileFeature feature : effectiveFeatures) {
|
||||||
ProfileOperation operation = new ProfileOperation();
|
ProfileOperation operation = new ProfileOperation();
|
||||||
|
|
||||||
operation.setCode(feature.getFeatureCode());
|
operation.setCode(feature.getFeatureCode());
|
||||||
operation.setPayLoad(feature.getContent());
|
operation.setPayLoad(feature.getContent());
|
||||||
|
operation.setStatus(Operation.Status.PENDING);
|
||||||
|
operation.setType(Operation.Type.PROFILE);
|
||||||
|
operation.setEnabled(true);
|
||||||
profileOperationList.add(operation);
|
profileOperationList.add(operation);
|
||||||
}
|
|
||||||
profileOperation.setPayLoad(profileOperationList);
|
|
||||||
profileOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);
|
|
||||||
|
|
||||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
|
|
||||||
deviceIdentifiers.add(deviceIdentifier);
|
|
||||||
|
|
||||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService().
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService().
|
||||||
addOperation(profileOperation, deviceIdentifiers);
|
addOperation(operation, deviceIdentifiers);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,31 +145,28 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
@Override
|
@Override
|
||||||
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException {
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
/* Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "UPDATE DM_POLICY SET PRIORITY = ? WHERE ID = ?";
|
String query = "UPDATE DM_POLICY SET PRIORITY = ? WHERE ID = ?";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setString(1, policy.getPolicyName());
|
|
||||||
stmt.setInt(2, policy.getTenantId());
|
for (Policy policy : policies) {
|
||||||
stmt.setInt(3, policy.getProfile().getProfileId());
|
stmt.setInt(1, policy.getPriorityId());
|
||||||
stmt.setInt(4, policy.getPriorityId());
|
stmt.setInt(2, policy.getId());
|
||||||
stmt.setString(5, policy.getCompliance());
|
stmt.addBatch();
|
||||||
stmt.setInt(6, policy.getId());
|
}
|
||||||
stmt.executeUpdate();
|
stmt.executeBatch();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while updating policy (" + policy.getPolicyName() + ") in database.";
|
String msg = "Error occurred while updating policy priorities in database.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new PolicyManagerDAOException(msg, e);
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return policy;*/
|
return true;
|
||||||
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
@ -1146,7 +1143,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Policy (" + policyId+ ") delete from database.");
|
log.debug("Policy (" + policyId + ") delete from database.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@ -63,6 +63,11 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
return policyManager.updatePolicy(policy);
|
return policyManager.updatePolicy(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
||||||
|
return policyManager.updatePolicyPriorities(policies);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
||||||
return policyManager.deletePolicy(policy);
|
return policyManager.deletePolicy(policy);
|
||||||
@ -203,4 +208,5 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
public int getPolicyCount() throws PolicyManagementException {
|
public int getPolicyCount() throws PolicyManagementException {
|
||||||
return policyManager.getPolicyCount();
|
return policyManager.getPolicyCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,8 @@ public interface PolicyManager {
|
|||||||
|
|
||||||
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
|
boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException;
|
||||||
|
|
||||||
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|||||||
@ -210,6 +210,26 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
||||||
|
boolean bool;
|
||||||
|
try {
|
||||||
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
bool = policyDAO.updatePolicyPriorities(policies);
|
||||||
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
try {
|
||||||
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
|
} catch (PolicyManagerDAOException e1) {
|
||||||
|
log.warn("Error occurred while roll backing the transaction.");
|
||||||
|
}
|
||||||
|
String msg = "Error occurred while updating the policy priorities";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return bool;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
||||||
|
|
||||||
@ -249,7 +269,7 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
log.warn("Error occurred while roll backing the transaction.");
|
log.warn("Error occurred while roll backing the transaction.");
|
||||||
}
|
}
|
||||||
String msg = "Error occurred while deleting the policy ("
|
String msg = "Error occurred while deleting the policy ("
|
||||||
+ policyId +")";
|
+ policyId + ")";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new PolicyManagementException(msg, e);
|
throw new PolicyManagementException(msg, e);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user