コード例 #1
0
 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);
     }
   }
 }
コード例 #2
0
 /**
  * Parses a rule template attribute
  *
  * @param element the attribute XML element
  * @param ruleTemplate the ruleTemplate to update
  * @return a parsed rule template attribute
  * @throws XmlException if the attribute does not exist
  */
 private RuleTemplateAttributeBo parseRuleTemplateAttribute(
     Element element, RuleTemplateBo ruleTemplate) throws XmlException {
   String attributeName = element.getChildText(NAME, RULE_TEMPLATE_NAMESPACE);
   String requiredValue = element.getChildText(REQUIRED, RULE_TEMPLATE_NAMESPACE);
   String activeValue = element.getChildText(ACTIVE, RULE_TEMPLATE_NAMESPACE);
   if (org.apache.commons.lang.StringUtils.isEmpty(attributeName)) {
     throw new XmlException("Attribute name must be non-empty");
   }
   boolean required = DEFAULT_ATTRIBUTE_REQUIRED;
   if (requiredValue != null) {
     required = Boolean.parseBoolean(requiredValue);
   }
   boolean active = DEFAULT_ATTRIBUTE_ACTIVE;
   if (activeValue != null) {
     active = Boolean.parseBoolean(activeValue);
   }
   RuleAttribute ruleAttribute =
       KEWServiceLocator.getRuleAttributeService().findByName(attributeName);
   if (ruleAttribute == null) {
     throw new XmlException("Could not locate rule attribute for name '" + attributeName + "'");
   }
   RuleTemplateAttributeBo templateAttribute = new RuleTemplateAttributeBo();
   templateAttribute.setRuleAttribute(ruleAttribute);
   templateAttribute.setRuleAttributeId(ruleAttribute.getId());
   templateAttribute.setRuleTemplate(ruleTemplate);
   templateAttribute.setRequired(Boolean.valueOf(required));
   templateAttribute.setActive(Boolean.valueOf(active));
   templateAttribute.setDisplayOrder(new Integer(templateAttributeCounter++));
   return templateAttribute;
 }
コード例 #3
0
 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);
   }
 }
コード例 #4
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);
      }
    }
  }