Ejemplo n.º 1
0
  /**
   * 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);
      }
    }
  }
 private void assertRuleTemplateExport(
     RuleTemplateBo oldRuleTemplate, RuleTemplateBo newRuleTemplate) {
   assertFalse(
       "Ids should be different.", oldRuleTemplate.getId().equals(newRuleTemplate.getId()));
   assertEquals(oldRuleTemplate.getDescription(), newRuleTemplate.getDescription());
   assertEquals(oldRuleTemplate.getName(), newRuleTemplate.getName());
   if (oldRuleTemplate.getDelegationTemplate() != null) {
     assertRuleTemplateExport(
         oldRuleTemplate.getDelegationTemplate(), newRuleTemplate.getDelegationTemplate());
   } else {
     assertNull(newRuleTemplate.getDelegationTemplate());
   }
   assertAttributes(
       oldRuleTemplate.getRuleTemplateAttributes(),
       newRuleTemplate.getRuleTemplateAttributes(),
       "attribute");
   assertAttributes(
       oldRuleTemplate.getActiveRuleTemplateAttributes(),
       newRuleTemplate.getActiveRuleTemplateAttributes(),
       "active attribute");
   assertOptions(
       oldRuleTemplate.getRuleTemplateOptions(), newRuleTemplate.getRuleTemplateOptions());
 }