@Test public void testEasyStuff() { CreatePolicyController controller = new CreatePolicyController(); PolicyRestAdapter adapter = new PolicyRestAdapter(); controller.prePopulateBaseConfigPolicyData(adapter, null); VariableDefinitionType var = new VariableDefinitionType(); PolicyType policy = new PolicyType(); policy.setDescription("i am a description. @CreatedBy: policy designer"); policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(var); adapter.setPolicyData(policy); adapter.setPolicyName("name"); controller.prePopulateBaseConfigPolicyData(adapter, entity); }
public void prePopulateBaseConfigPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { attributeList = new ArrayList<>(); if (! (policyAdapter.getPolicyData() instanceof PolicyType)) { return; } Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); policyAdapter.setConfigType(entity.getConfigurationData().getConfigType()); policyAdapter.setConfigBodyData(entity.getConfigurationData().getConfigBody()); String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf('_') + 1); policyAdapter.setPolicyName(policyNameValue); String description = ""; try { description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); } catch (Exception e) { policyLogger.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue, e); description = policy.getDescription(); } policyAdapter.setPolicyDescription(description); TargetType target = policy.getTarget(); if (target != null) { for (AnyOfType anyOf : target.getAnyOf()) { int index = 0; for (AllOfType allOf : anyOf.getAllOf()) { for (MatchType match : allOf.getMatch()) { String value = (String) match.getAttributeValue().getContent().get(0); String attributeId = match.getAttributeDesignator().getAttributeId(); policyAdapter.setupUsingAttribute(attributeId, value); if (index >= 7) { Map<String, String> attribute = new HashMap<>(); attribute.put("key", attributeId); attribute.put("value", value); attributeList.add(attribute); } index++; } } } policyAdapter.setAttributes(attributeList); } List<Object> ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); for (Object object : ruleList) { if (object instanceof RuleType) { policyAdapter.setRuleID(((RuleType) object).getRuleId()); } } }
CreatePolicyController extends RestrictedBaseController { public void prePopulateBaseConfigPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { attributeList = new ArrayList<>(); if (! (policyAdapter.getPolicyData() instanceof PolicyType)) { return; } Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); policyAdapter.setConfigType(entity.getConfigurationData().getConfigType()); policyAdapter.setConfigBodyData(entity.getConfigurationData().getConfigBody()); String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf('_') + 1); policyAdapter.setPolicyName(policyNameValue); String description = ""; try { description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); } catch (Exception e) { policyLogger.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue, e); description = policy.getDescription(); } policyAdapter.setPolicyDescription(description); TargetType target = policy.getTarget(); if (target != null) { for (AnyOfType anyOf : target.getAnyOf()) { int index = 0; for (AllOfType allOf : anyOf.getAllOf()) { for (MatchType match : allOf.getMatch()) { String value = (String) match.getAttributeValue().getContent().get(0); String attributeId = match.getAttributeDesignator().getAttributeId(); policyAdapter.setupUsingAttribute(attributeId, value); if (index >= 7) { Map<String, String> attribute = new HashMap<>(); attribute.put("key", attributeId); attribute.put("value", value); attributeList.add(attribute); } index++; } } } policyAdapter.setAttributes(attributeList); } List<Object> ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); for (Object object : ruleList) { if (object instanceof RuleType) { policyAdapter.setRuleID(((RuleType) object).getRuleId()); } } } }
CreatePolicyController extends RestrictedBaseController { public void prePopulateBaseConfigPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { attributeList = new ArrayList<>(); if (! (policyAdapter.getPolicyData() instanceof PolicyType)) { return; } Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); policyAdapter.setConfigType(entity.getConfigurationData().getConfigType()); policyAdapter.setConfigBodyData(entity.getConfigurationData().getConfigBody()); String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf('_') + 1); policyAdapter.setPolicyName(policyNameValue); String description = ""; try { description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); } catch (Exception e) { policyLogger.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue, e); description = policy.getDescription(); } policyAdapter.setPolicyDescription(description); TargetType target = policy.getTarget(); if (target != null) { for (AnyOfType anyOf : target.getAnyOf()) { int index = 0; for (AllOfType allOf : anyOf.getAllOf()) { for (MatchType match : allOf.getMatch()) { String value = (String) match.getAttributeValue().getContent().get(0); String attributeId = match.getAttributeDesignator().getAttributeId(); policyAdapter.setupUsingAttribute(attributeId, value); if (index >= 7) { Map<String, String> attribute = new HashMap<>(); attribute.put("key", attributeId); attribute.put("value", value); attributeList.add(attribute); } index++; } } } policyAdapter.setAttributes(attributeList); } List<Object> ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); for (Object object : ruleList) { if (object instanceof RuleType) { policyAdapter.setRuleID(((RuleType) object).getRuleId()); } } }  }
CreatePolicyController extends RestrictedBaseController { public void prePopulateBaseConfigPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { attributeList = new ArrayList<>(); if (! (policyAdapter.getPolicyData() instanceof PolicyType)) { return; } Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); policyAdapter.setConfigType(entity.getConfigurationData().getConfigType()); policyAdapter.setConfigBodyData(entity.getConfigurationData().getConfigBody()); String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf('_') + 1); policyAdapter.setPolicyName(policyNameValue); String description = ""; try { description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); } catch (Exception e) { policyLogger.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue, e); description = policy.getDescription(); } policyAdapter.setPolicyDescription(description); TargetType target = policy.getTarget(); if (target != null) { for (AnyOfType anyOf : target.getAnyOf()) { int index = 0; for (AllOfType allOf : anyOf.getAllOf()) { for (MatchType match : allOf.getMatch()) { String value = (String) match.getAttributeValue().getContent().get(0); String attributeId = match.getAttributeDesignator().getAttributeId(); policyAdapter.setupUsingAttribute(attributeId, value); if (index >= 7) { Map<String, String> attribute = new HashMap<>(); attribute.put("key", attributeId); attribute.put("value", value); attributeList.add(attribute); } index++; } } } policyAdapter.setAttributes(attributeList); } List<Object> ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); for (Object object : ruleList) { if (object instanceof RuleType) { policyAdapter.setRuleID(((RuleType) object).getRuleId()); } } }  void prePopulateBaseConfigPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity); }
CreatePolicyController extends RestrictedBaseController { public void prePopulateBaseConfigPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) { attributeList = new ArrayList<>(); if (! (policyAdapter.getPolicyData() instanceof PolicyType)) { return; } Object policyData = policyAdapter.getPolicyData(); PolicyType policy = (PolicyType) policyData; policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); policyAdapter.setConfigType(entity.getConfigurationData().getConfigType()); policyAdapter.setConfigBodyData(entity.getConfigurationData().getConfigBody()); String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf('_') + 1); policyAdapter.setPolicyName(policyNameValue); String description = ""; try { description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); } catch (Exception e) { policyLogger.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue, e); description = policy.getDescription(); } policyAdapter.setPolicyDescription(description); TargetType target = policy.getTarget(); if (target != null) { for (AnyOfType anyOf : target.getAnyOf()) { int index = 0; for (AllOfType allOf : anyOf.getAllOf()) { for (MatchType match : allOf.getMatch()) { String value = (String) match.getAttributeValue().getContent().get(0); String attributeId = match.getAttributeDesignator().getAttributeId(); policyAdapter.setupUsingAttribute(attributeId, value); if (index >= 7) { Map<String, String> attribute = new HashMap<>(); attribute.put("key", attributeId); attribute.put("value", value); attributeList.add(attribute); } index++; } } } policyAdapter.setAttributes(attributeList); } List<Object> ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); for (Object object : ruleList) { if (object instanceof RuleType) { policyAdapter.setRuleID(((RuleType) object).getRuleId()); } } }  void prePopulateBaseConfigPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity);  }