Example #1
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;
  }
  public Object evaluate(NodeDefinition context, NodeDefinition thisNode) {
    if (!(Schema.class.isAssignableFrom(context.getClass())
        || NodeDefinition.class.isAssignableFrom(context.getClass()))) {
      throw new IllegalArgumentException(
          "Unable to evaluate expression with context class " + context.getClass().getName());
    }
    JXPathContext jxPathContext = JXPathContext.newContext(CONTEXT, context);
    Variables variables = jxPathContext.getVariables();
    variables.declareVariable(AbstractExpression.THIS_VARIABLE_NAME, thisNode);

    String expr = Path.getNormalizedPath(expression);
    Object result = jxPathContext.getValue(expr);
    return result;
  }
Example #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);
       }
     }
   }
 }
 private void testNoResultsFound(CollectSurvey survey, NodeDefinition autoCompleteNodeDefn)
     throws Exception {
   List<String> result;
   result =
       persistedRecordIndexManager.search(
           SearchType.STARTS_WITH, survey, autoCompleteNodeDefn.getId(), 0, "GPS NOT LISTED", 10);
   assertNotNull(result);
   assertEquals(0, result.size());
 }
 private void testSingleResultMatching(CollectSurvey survey, NodeDefinition autoCompleteNodeDefn)
     throws Exception {
   List<String> result =
       persistedRecordIndexManager.search(
           SearchType.EQUAL, survey, autoCompleteNodeDefn.getId(), 0, "SXBLUEII-L", 10);
   assertNotNull(result);
   assertEquals(1, result.size());
   String value = result.iterator().next();
   assertEquals("SXBLUEII-L", value);
 }
 private void testLimitedMultipleResultsFound(
     CollectSurvey survey, NodeDefinition autoCompleteNodeDefn) throws Exception {
   List<String> result;
   result =
       persistedRecordIndexManager.search(
           SearchType.STARTS_WITH, survey, autoCompleteNodeDefn.getId(), 0, "GPS", 2);
   assertNotNull(result);
   assertEquals(2, result.size());
   assertArrayEquals(new String[] {"GPS MAP 60CSX", "GPS MAP 62 S"}, result.toArray());
 }
Example #7
0
 public void setElementNodes(int idx, List<Node<?>> nodes) {
   NodeDefinition defn = tupleDefinition.getElementDefinition(idx);
   Element element = defn.isMultiple() ? new Element(nodes) : new SingleElement(nodes);
   setElement(idx, element);
 }