コード例 #1
0
  /**
   * This overridden updates an existing Rule in the Repository
   *
   * @see
   *     org.kuali.rice.krms.impl.repository.RuleBoService#updateRule(org.kuali.rice.krms.api.repository.rule.RuleDefinition)
   */
  @Override
  public void updateRule(RuleDefinition rule) {
    if (rule == null) {
      throw new IllegalArgumentException("rule is null");
    }

    // must already exist to be able to update
    final String ruleIdKey = rule.getId();
    final RuleBo existing = businessObjectService.findBySinglePrimaryKey(RuleBo.class, ruleIdKey);
    if (existing == null) {
      throw new IllegalStateException("the rule does not exist: " + rule);
    }
    final RuleDefinition toUpdate;
    if (!existing.getId().equals(rule.getId())) {
      // if passed in id does not match existing id, correct it
      final RuleDefinition.Builder builder = RuleDefinition.Builder.create(rule);
      builder.setId(existing.getId());
      toUpdate = builder.build();
    } else {
      toUpdate = rule;
    }

    // copy all updateable fields to bo
    RuleBo boToUpdate = RuleBo.from(toUpdate);

    // delete any old, existing attributes
    Map<String, String> fields = new HashMap<String, String>(1);
    fields.put(PropertyNames.Rule.RULE_ID, toUpdate.getId());
    businessObjectService.deleteMatching(RuleAttributeBo.class, fields);

    // update the rule and create new attributes
    businessObjectService.save(boToUpdate);
  }
コード例 #2
0
 /**
  * This overridden creates a KRMS Rule in the repository
  *
  * @see
  *     org.kuali.rice.krms.impl.repository.RuleBoService#createRule(org.kuali.rice.krms.api.repository.rule.RuleDefinition)
  */
 @Override
 public RuleDefinition createRule(RuleDefinition rule) {
   if (rule == null) {
     throw new IllegalArgumentException("rule is null");
   }
   final String nameKey = rule.getName();
   final String namespaceKey = rule.getNamespace();
   final RuleDefinition existing = getRuleByNameAndNamespace(nameKey, namespaceKey);
   if (existing != null) {
     throw new IllegalStateException("the rule to create already exists: " + rule);
   }
   RuleBo ruleBo = RuleBo.from(rule);
   businessObjectService.save(ruleBo);
   return RuleBo.to(ruleBo);
 }