private void assertAttributes( List oldAttributes, List newAttributes, String errorMessageAttributeLabel) { assertEquals(oldAttributes.size(), newAttributes.size()); for (Iterator iterator = oldAttributes.iterator(); iterator.hasNext(); ) { RuleTemplateAttributeBo oldAttribute = (RuleTemplateAttributeBo) iterator.next(); boolean foundAttribute = false; for (Iterator iterator2 = newAttributes.iterator(); iterator2.hasNext(); ) { RuleTemplateAttributeBo newAttribute = (RuleTemplateAttributeBo) iterator2.next(); if (oldAttribute .getRuleAttribute() .getName() .equals(newAttribute.getRuleAttribute().getName())) { assertEquals(oldAttribute.getRequired(), newAttribute.getRequired()); foundAttribute = true; } } assertTrue( "Could not locate " + errorMessageAttributeLabel + " with name '" + oldAttribute.getRuleAttribute().getName() + "' in new attributes list.", foundAttribute); } }
private void exportAttributes(Element parent, List ruleTemplateAttributes) { if (!ruleTemplateAttributes.isEmpty()) { Element attributesElement = renderer.renderElement(parent, ATTRIBUTES); for (Iterator iterator = ruleTemplateAttributes.iterator(); iterator.hasNext(); ) { RuleTemplateAttributeBo attribute = (RuleTemplateAttributeBo) iterator.next(); Element attributeElement = renderer.renderElement(attributesElement, ATTRIBUTE); renderer.renderTextElement(attributeElement, NAME, attribute.getRuleAttribute().getName()); renderer.renderBooleanElement(attributeElement, REQUIRED, attribute.getRequired(), false); } } }
/** * Updates the attributes set on the RuleTemplate * * @param ruleTemplateElement the XML ruleTemplate element * @param updatedRuleTemplate the RuleTemplate being updated * @throws XmlException if there was a problem parsing the rule template attributes */ protected void updateRuleTemplateAttributes( Element ruleTemplateElement, RuleTemplateBo updatedRuleTemplate) throws XmlException { // add any newly defined rule template attributes to the rule template, // update the active and required flags of any existing ones. // if this is an update of an existing rule template, related attribute objects will be present // in this rule template object, // otherwise none will be present (so they'll all be new) Element attributesElement = ruleTemplateElement.getChild(ATTRIBUTES, RULE_TEMPLATE_NAMESPACE); List<RuleTemplateAttributeBo> incomingAttributes = new ArrayList<RuleTemplateAttributeBo>(); if (attributesElement != null) { incomingAttributes.addAll( parseRuleTemplateAttributes(attributesElement, updatedRuleTemplate)); } // inactivate all current attributes for (RuleTemplateAttributeBo currentRuleTemplateAttribute : updatedRuleTemplate.getRuleTemplateAttributes()) { String ruleAttributeName = (currentRuleTemplateAttribute.getRuleAttribute() != null) ? currentRuleTemplateAttribute.getRuleAttribute().getName() : "(null)"; LOG.debug( "Inactivating rule template attribute with id " + currentRuleTemplateAttribute.getId() + " and rule attribute with name " + ruleAttributeName); currentRuleTemplateAttribute.setActive(Boolean.FALSE); } // NOTE: attributes are deactivated, not removed // add/update any new attributes for (RuleTemplateAttributeBo ruleTemplateAttribute : incomingAttributes) { RuleTemplateAttributeBo potentialExistingTemplateAttribute = updatedRuleTemplate.getRuleTemplateAttribute(ruleTemplateAttribute); if (potentialExistingTemplateAttribute != null) { // template attribute exists on rule template already; update the options potentialExistingTemplateAttribute.setActive(ruleTemplateAttribute.getActive()); potentialExistingTemplateAttribute.setRequired(ruleTemplateAttribute.getRequired()); } else { // template attribute does not yet exist on template so add it ruleTemplateAttribute.setRuleTemplate(updatedRuleTemplate); updatedRuleTemplate.getRuleTemplateAttributes().add(ruleTemplateAttribute); } } }