private void extractLabels(CodeList codeList, Cursor crs, PersistedCodeListItem item) {
   Survey survey = codeList.getSurvey();
   item.removeAllLabels();
   List<String> languages = survey.getLanguages();
   String[] labelColumnNames = {
     OFC_CODE_LIST.LABEL1.getName(), OFC_CODE_LIST.LABEL2.getName(), OFC_CODE_LIST.LABEL3.getName()
   };
   for (int i = 0; i < languages.size(); i++) {
     String lang = languages.get(i);
     String label = crs.getString(crs.getColumnIndex(labelColumnNames[i]));
     item.setLabel(lang, label);
     if (i >= 3) break;
   }
 }
 private void extractDescriptions(CodeList codeList, Cursor crs, PersistedCodeListItem item) {
   Survey survey = codeList.getSurvey();
   item.removeAllDescriptions();
   List<String> languages = survey.getLanguages();
   String[] descrColumnNames = {
     OFC_CODE_LIST.DESCRIPTION1.getName(),
     OFC_CODE_LIST.DESCRIPTION2.getName(),
     OFC_CODE_LIST.DESCRIPTION3.getName()
   };
   for (int i = 0; i < languages.size(); i++) {
     String lang = languages.get(i);
     String label = crs.getString(crs.getColumnIndex(descrColumnNames[i]));
     item.setDescription(lang, label);
     if (i >= 3) break;
   }
 }
 // TODO hierarchical code lists as multiple tables
 private void createCodeListTables() throws DatabaseException {
   List<CodeList> lists = survey.getCodeLists();
   for (CodeList list : lists) {
     IdmCodeListTableBuilder tb = new IdmCodeListTableBuilder();
     tb.setList(list);
     tb.setTablePrefix(tablePrefix);
     tb.setTableSuffix(codeTableSuffix);
     Table table = tb.toTable();
     if (tables.contains(table)) {
       throw new DatabaseException(
           "Duplicate table name '" + table.getName() + "' for list " + list.getName());
     }
     tables.add(table);
   }
 }
Ejemplo 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;
  }
 public void setDatabase(IdmDatabase database) {
   this.database = database;
   this.survey = database.getSurvey();
   this.surveyUri = survey.getUri();
   this.schema = survey.getSchema();
 }
 private ModelVersion extractModelVersion(SurveyObject surveyObject, Integer versionId) {
   Survey survey = surveyObject.getSurvey();
   return ((versionId == null) || (versionId == 0)) ? null : survey.getVersionById(versionId);
 }