Esempio n. 1
0
 @Override
 public String[] getPropertyNames(Object object) {
   List<String> result = new ArrayList<String>();
   if (object instanceof Entity) {
     EntityDefinition def = ((Entity) object).getDefinition();
     result.addAll(def.getChildDefinitionNames());
   }
   result.add(Path.NORMALIZED_PARENT_FUNCTION);
   return result.toArray(new String[result.size()]);
 }
Esempio n. 2
0
  protected Entity addItem(Entity parentEntity, Integer qtyValue, Double priceValue) {
    EntityDefinition rootEntityDefn = parentEntity.getDefinition();
    EntityDefinition itemDefn = (EntityDefinition) rootEntityDefn.getChildDefinition("item");
    Entity item = (Entity) itemDefn.createNode();

    if (qtyValue != null) {
      NodeDefinition qtyDefn = itemDefn.getChildDefinition("qty");
      IntegerAttribute qty = (IntegerAttribute) qtyDefn.createNode();
      qty.setValue(new IntegerValue(qtyValue, null));
      item.add(qty);
    }
    if (priceValue != null) {
      NumericAttributeDefinition priceDefn =
          (NumericAttributeDefinition) itemDefn.getChildDefinition("price");
      RealAttribute price = (RealAttribute) priceDefn.createNode();
      price.setValue(new RealValue(priceValue, null));
      item.add(price);
    }
    NumberAttributeDefinition totalDefn =
        (NumberAttributeDefinition) itemDefn.getChildDefinition("total");
    RealAttribute total = (RealAttribute) totalDefn.createNode();
    item.add(total);

    NumberAttributeDefinition discountDefn =
        (NumberAttributeDefinition) itemDefn.getChildDefinition("discount_percent");
    IntegerAttribute discount = (IntegerAttribute) discountDefn.createNode();
    item.add(discount);

    parentEntity.add(item);
    return item;
  }
Esempio n. 3
0
 /**
  * Writes empty nodes child of an entity if there is a node state specified.
  *
  * @param serializer
  * @param entity
  * @throws IOException
  */
 private void writeEmptyNodes(XmlSerializer serializer, Entity entity) throws IOException {
   EntityDefinition defn = entity.getDefinition();
   List<NodeDefinition> childDefns = defn.getChildDefinitions();
   for (NodeDefinition childDefn : childDefns) {
     String childName = childDefn.getName();
     if (entity.getCount(childName) == 0) {
       State childState = entity.getChildState(childName);
       int childStateInt = childState.intValue();
       if (childStateInt > 0) {
         serializer.startTag(null, childName);
         serializer.attribute(null, STATE_ATTRIBUTE, Integer.toString(childStateInt));
         serializer.endTag(null, childName);
       }
     }
   }
 }
Esempio n. 4
0
  /**
   * Creates a test survey in which there is a bill with a list of items. For each item there is a
   * price, a quantity and a total (calculated using the an expression or a constant).
   *
   * @return
   */
  private Survey createTestSurvey() {
    SurveyContext surveyContext = new TestSurveyContext();
    Survey survey = surveyContext.createSurvey();
    Schema schema = survey.getSchema();
    EntityDefinition root = schema.createEntityDefinition();
    root.setName("bill");
    schema.addRootEntityDefinition(root);
    EntityDefinition item = schema.createEntityDefinition();
    item.setName("item");
    root.addChildDefinition(item);
    NumberAttributeDefinition qty = schema.createNumberAttributeDefinition();
    qty.setType(Type.INTEGER);
    qty.setName("qty");
    item.addChildDefinition(qty);
    NumberAttributeDefinition price = schema.createNumberAttributeDefinition();
    price.setName("price");
    item.addChildDefinition(price);
    NumberAttributeDefinition total = schema.createNumberAttributeDefinition();
    total.setName("total");
    total.setCalculated(true);
    total.addAttributeDefault(
        new AttributeDefault("qty * (price - (price * discount_percent div 100))"));
    item.addChildDefinition(total);

    NumberAttributeDefinition discountPercent = schema.createNumberAttributeDefinition();
    discountPercent.setType(Type.INTEGER);
    discountPercent.setName("discount_percent");
    discountPercent.setCalculated(true);
    discountPercent.addAttributeDefault(new AttributeDefault("30", "qty > 50"));
    discountPercent.addAttributeDefault(new AttributeDefault("20", "qty > 20"));
    discountPercent.addAttributeDefault(new AttributeDefault("10", "qty > 10"));
    discountPercent.addAttributeDefault(new AttributeDefault("0", "true()"));
    item.addChildDefinition(discountPercent);

    return survey;
  }
Esempio n. 5
0
 private NodeDefinition getChildDefinition(Entity entity, String childName) {
   EntityDefinition entityDefn = entity.getDefinition();
   NodeDefinition childDefn = entityDefn.getChildDefinition(childName);
   return childDefn;
 }
Esempio n. 6
0
 public void setRootEntityDefinition(EntityDefinition rootEntityDefinition) {
   this.rootEntityDefinition = rootEntityDefinition;
   this.rootEntityDefinitionId =
       rootEntityDefinition == null ? null : rootEntityDefinition.getId();
 }