|
|
@ -195,33 +195,70 @@ public class PolicyManagerUtil {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void setCorrectiveActions(List<ProfileFeature> features,
|
|
|
|
private static void setCorrectiveActions(List<ProfileFeature> features,
|
|
|
|
PolicyOperation policyOperation, Policy policy) throws PolicyTransformException {
|
|
|
|
PolicyOperation policyOperation, Policy policy)
|
|
|
|
List<ProfileFeature> effectiveFeatures = new ArrayList<>(features);
|
|
|
|
throws PolicyTransformException {
|
|
|
|
|
|
|
|
ProfileOperation correctiveOperations = new ProfileOperation();
|
|
|
|
|
|
|
|
correctiveOperations.setCode(PolicyManagementConstants.CORRECTIVE_POLICY_LIST);
|
|
|
|
for (ProfileFeature effectiveFeature : features) {
|
|
|
|
for (ProfileFeature effectiveFeature : features) {
|
|
|
|
if (effectiveFeature.getCorrectiveActions() != null) {
|
|
|
|
if (effectiveFeature.getCorrectiveActions() != null) {
|
|
|
|
for (CorrectiveAction correctiveAction : effectiveFeature.getCorrectiveActions()) {
|
|
|
|
for (CorrectiveAction correctiveAction : effectiveFeature.getCorrectiveActions()) {
|
|
|
|
if (PolicyManagementConstants.POLICY_CORRECTIVE_ACTION_TYPE
|
|
|
|
if (PolicyManagementConstants.POLICY_CORRECTIVE_ACTION_TYPE
|
|
|
|
.equalsIgnoreCase(correctiveAction.getActionType())) {
|
|
|
|
.equalsIgnoreCase(correctiveAction.getActionType())) {
|
|
|
|
|
|
|
|
|
|
|
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
|
|
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Policy correctivePolicy = pap.getPolicy(correctiveAction.getPolicyId());
|
|
|
|
Policy correctivePolicy = pap.getPolicy(correctiveAction.getPolicyId());
|
|
|
|
if (correctivePolicy == null || !PolicyManagementConstants.CORRECTIVE_POLICY_TYPE
|
|
|
|
if (correctivePolicy == null || !PolicyManagementConstants
|
|
|
|
.equalsIgnoreCase(correctivePolicy.getPolicyType() )) {
|
|
|
|
.CORRECTIVE_POLICY_TYPE.equalsIgnoreCase(correctivePolicy
|
|
|
|
String msg = "No corrective policy was found for the policy " + policy.getPolicyName() +
|
|
|
|
.getPolicyType())) {
|
|
|
|
" and policy ID " + policy.getId();
|
|
|
|
String msg = "No corrective policy was found for the policy " +
|
|
|
|
|
|
|
|
policy.getPolicyName() + " and policy ID " + policy.getId();
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new PolicyTransformException(msg);
|
|
|
|
throw new PolicyTransformException(msg);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
List<ProfileOperation> correctiveProfileOperations = createProfileOperations(
|
|
|
|
createCorrectiveProfileOperations(correctivePolicy, correctiveOperations);
|
|
|
|
correctivePolicy.getProfile().getProfileFeaturesList());
|
|
|
|
policyOperation.getProfileOperations().add(correctiveOperations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (PolicyManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while retrieving corrective policy for policy " +
|
|
|
|
|
|
|
|
policy.getPolicyName() + " and policy ID " + policy.getId();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new PolicyTransformException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*for (CorrectiveAction correctiveAction : effectiveFeature.getCorrectiveActions()) {
|
|
|
|
|
|
|
|
if (PolicyManagementConstants.POLICY_CORRECTIVE_ACTION_TYPE
|
|
|
|
|
|
|
|
.equalsIgnoreCase(correctiveAction.getActionType())) {
|
|
|
|
|
|
|
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Policy correctivePolicy = pap.getPolicy(correctiveAction.getPolicyId());
|
|
|
|
|
|
|
|
if (correctivePolicy == null || !PolicyManagementConstants
|
|
|
|
|
|
|
|
.CORRECTIVE_POLICY_TYPE.equalsIgnoreCase(correctivePolicy
|
|
|
|
|
|
|
|
.getPolicyType() )) {
|
|
|
|
|
|
|
|
String msg = "No corrective policy was found for the policy " +
|
|
|
|
|
|
|
|
policy.getPolicyName() + " and policy ID " + policy.getId();
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new PolicyTransformException(msg);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
*//*List<ProfileOperation> correctiveProfileOperations =
|
|
|
|
|
|
|
|
createProfileOperations();*//*
|
|
|
|
|
|
|
|
createCorrectiveProfileOperations(correctivePolicy.getProfile()
|
|
|
|
|
|
|
|
.getProfileFeaturesList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProfileFeature correctivePolicyFeature = new ProfileFeature();
|
|
|
|
ProfileFeature correctivePolicyFeature = new ProfileFeature();
|
|
|
|
correctivePolicyFeature.setProfileId(correctivePolicy.getProfileId());
|
|
|
|
correctivePolicyFeature.setProfileId(correctivePolicy.getProfileId());
|
|
|
|
correctivePolicyFeature.setContent(new Gson().toJson(correctiveProfileOperations));
|
|
|
|
correctivePolicyFeature.setContent(new Gson()
|
|
|
|
correctivePolicyFeature.setDeviceType(correctivePolicy.getProfile().getDeviceType());
|
|
|
|
.toJson(correctiveProfileOperations));
|
|
|
|
|
|
|
|
correctivePolicyFeature.setDeviceType(correctivePolicy
|
|
|
|
|
|
|
|
.getProfile().getDeviceType());
|
|
|
|
correctivePolicyFeature.setFeatureCode(
|
|
|
|
correctivePolicyFeature.setFeatureCode(
|
|
|
|
PolicyManagementConstants.CORRECTIVE_POLICY_FEATURE_CODE);
|
|
|
|
PolicyManagementConstants.CORRECTIVE_POLICY_FEATURE_CODE);
|
|
|
|
correctivePolicyFeature.setId(correctivePolicy.getId());
|
|
|
|
correctivePolicyFeature.setId(correctivePolicy.getId());
|
|
|
|
List<ProfileOperation> profileOperations = policyOperation.getProfileOperations();
|
|
|
|
|
|
|
|
effectiveFeatures.add(correctivePolicyFeature);
|
|
|
|
effectiveFeatures.add(correctivePolicyFeature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (PolicyManagementException e) {
|
|
|
|
} catch (PolicyManagementException e) {
|
|
|
@ -230,13 +267,37 @@ public class PolicyManagerUtil {
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new PolicyTransformException(msg, e);
|
|
|
|
throw new PolicyTransformException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Currently only supported POLICY corrective action type so the break is added. This should be
|
|
|
|
// Currently only supported POLICY corrective action type so the break
|
|
|
|
// removed when we start supporting other corrective action types
|
|
|
|
// is added. This should be removed when we start supporting other
|
|
|
|
|
|
|
|
// corrective action types
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void createCorrectiveProfileOperations(Policy correctivePolicy,
|
|
|
|
|
|
|
|
ProfileOperation correctiveOperationList) {
|
|
|
|
|
|
|
|
ProfileOperation profileOperation = new ProfileOperation();
|
|
|
|
|
|
|
|
profileOperation.setId(correctivePolicy.getId());
|
|
|
|
|
|
|
|
profileOperation.setCode(PolicyManagementConstants.CORRECTIVE_POLICY_FEATURE_CODE);
|
|
|
|
|
|
|
|
profileOperation.setEnabled(true);
|
|
|
|
|
|
|
|
profileOperation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.PENDING);
|
|
|
|
|
|
|
|
profileOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE);
|
|
|
|
|
|
|
|
String correctivePayload =(String) correctiveOperationList.getPayLoad();
|
|
|
|
|
|
|
|
if (correctivePayload == null) {
|
|
|
|
|
|
|
|
correctivePayload = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<ProfileOperation> profileOperations = createProfileOperations(correctivePolicy
|
|
|
|
|
|
|
|
.getProfile().getProfileFeaturesList());
|
|
|
|
|
|
|
|
String payload = new Gson().toJson(profileOperations);
|
|
|
|
|
|
|
|
correctiveOperationList.setPayLoad(correctivePayload.concat(payload));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -249,6 +310,9 @@ public class PolicyManagerUtil {
|
|
|
|
profileOperation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.PENDING);
|
|
|
|
profileOperation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.PENDING);
|
|
|
|
profileOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE);
|
|
|
|
profileOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE);
|
|
|
|
profileOperation.setPayLoad(feature.getContent());
|
|
|
|
profileOperation.setPayLoad(feature.getContent());
|
|
|
|
|
|
|
|
for (CorrectiveAction correctiveAction : feature.getCorrectiveActions()) {
|
|
|
|
|
|
|
|
profileOperation.getCorrectiveActionIds().add(correctiveAction.getPolicyId());
|
|
|
|
|
|
|
|
}
|
|
|
|
profileOperations.add(profileOperation);
|
|
|
|
profileOperations.add(profileOperation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return profileOperations;
|
|
|
|
return profileOperations;
|
|
|
|