Search in sources :

Example 31 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class EffectiveMapping method createMultiDimSet.

public MultiDim createMultiDimSet(ColumnSet columnSet) {
    EnumType enumType = (EnumType) this.formula.getResultType();
    int numItems = enumType.getValues().size();
    int numCategories;
    if (model.getMissingIncluded()) {
        // If we are included cases with no values set, then consider it
        // a category on its own
        numCategories = numItems + 1;
    } else {
        numCategories = numItems;
    }
    String[] labels = new String[numCategories];
    BitSet[] bitSets = new BitSet[numCategories];
    List<EnumItem> values = enumType.getValues();
    for (int j = 0; j < numItems; j++) {
        BitSet bitSet = new BitSet();
        EnumItem enumItem = values.get(j);
        ColumnView columnView = columnSet.getColumnView(getColumnId(enumItem));
        assert columnView != null;
        assert columnView.getType() == ColumnType.BOOLEAN;
        for (int i = 0; i < columnView.numRows(); i++) {
            if (columnView.getBoolean(i) == ColumnView.TRUE) {
                bitSet.set(i, true);
            }
        }
        labels[j] = enumItem.getLabel();
        bitSets[j] = bitSet;
    }
    if (model.getMissingIncluded()) {
        labels[numCategories - 1] = getMissingLabel();
        bitSets[numCategories - 1] = computeMissingBitSet(columnSet.getNumRows(), numItems, bitSets);
    }
    return new MultiDim(this.index, labels, bitSets);
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) ColumnView(org.activityinfo.model.query.ColumnView) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 32 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class EffectiveMapping method getRequiredColumns.

public List<ColumnModel> getRequiredColumns() {
    if (multiValued) {
        List<ColumnModel> columns = new ArrayList<>();
        EnumType enumType = (EnumType) this.formula.getResultType();
        for (EnumItem enumItem : enumType.getValues()) {
            ColumnModel columnModel = new ColumnModel();
            columnModel.setId(getColumnId(enumItem));
            columnModel.setFormula(new CompoundExpr(this.formula.getRootNode(), new SymbolNode(enumItem.getId())));
            columns.add(columnModel);
        }
        return columns;
    }
    if (this.mapping != null && this.formula.isValid()) {
        ColumnModel columnModel = new ColumnModel();
        columnModel.setId(getColumnId());
        columnModel.setFormula(this.formula.getFormula());
        return Collections.singletonList(columnModel);
    }
    return Collections.emptyList();
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) SymbolNode(org.activityinfo.model.formula.SymbolNode) EnumType(org.activityinfo.model.type.enumerated.EnumType) ColumnModel(org.activityinfo.model.query.ColumnModel) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 33 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class EnumCheckboxWidget method editLabel.

private void editLabel(ResourceId id) {
    EnumItem enumItem = enumValueForId(id);
    String newLabel = Window.prompt(I18N.CONSTANTS.enterNameForOption(), enumItem.getLabel());
    if (!Strings.isNullOrEmpty(newLabel)) {
        enumItem.setLabel(newLabel);
        controlForId(id).setHTML(designLabel(newLabel));
    }
}
Also used : EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 34 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class PivotAdapter method findAttributeFilterNames.

/**
 * Maps attribute filter ids to their attribute group id and name.
 *
 * Attribute filters are _SERIALIZED_ as only the integer ids of the required attributes,
 * but they are actually applied by _NAME_ to all forms in the query.
 */
private void findAttributeFilterNames() {
    Set<Integer> attributeIds = filter.getRestrictions(DimensionType.Attribute);
    if (attributeIds.isEmpty()) {
        return;
    }
    for (FormTree formTree : formTrees.values()) {
        for (FormTree.Node node : formTree.getLeaves()) {
            if (node.isEnum()) {
                EnumType type = (EnumType) node.getType();
                for (EnumItem enumItem : type.getValues()) {
                    int attributeId = CuidAdapter.getLegacyIdFromCuid(enumItem.getId());
                    if (attributeIds.contains(attributeId)) {
                        attributeFilters.put(node.getField().getLabel(), enumItem.getLabel());
                        attributeIds.remove(attributeId);
                        if (attributeIds.isEmpty()) {
                            return;
                        }
                    }
                }
            }
        }
    }
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 35 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class MySqlUpdateTest method addNewAttributes.

@Test
public void addNewAttributes() {
    KeyGenerator generator = new KeyGenerator();
    int activityId = generator.generateInt();
    EnumType enumType = new EnumType(Cardinality.SINGLE, new EnumItem(EnumItem.generateId(), "A"), new EnumItem(EnumItem.generateId(), "B"));
    FormField selectField = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS)).setType(enumType).setLabel("Select");
    FormClass formClass = new FormClass(CuidAdapter.activityFormClass(activityId));
    formClass.setDatabaseId(1);
    formClass.setLabel("New Form");
    formClass.addElement(selectField);
    catalog.createOrUpdateFormSchema(formClass);
    System.out.println("Created activity " + activityId);
    // Now change the enum items
    EnumType updatedType = new EnumType(Cardinality.SINGLE, new EnumItem(EnumItem.generateId(), "C"), new EnumItem(EnumItem.generateId(), "D"));
    selectField.setType(updatedType);
    newRequest();
    catalog.createOrUpdateFormSchema(formClass);
    newRequest();
    // Now try to save a new instance with the value
    FieldValue valueC = new EnumValue(updatedType.getValues().get(0).getId());
    FormInstance newRecord = new FormInstance(CuidAdapter.generateSiteCuid(), formClass.getId());
    newRecord.set(selectField.getId(), new EnumValue(updatedType.getValues().get(0).getId()));
    newRecord.set(CuidAdapter.partnerField(activityId), CuidAdapter.partnerRef(1, 1));
    executeUpdate(newRecord);
    // Ensure that the select field has been saved
    FormRecord saved = catalog.getForm(formClass.getId()).get().get(newRecord.getId()).get();
    FormInstance savedInstance = FormInstance.toFormInstance(formClass, saved);
    assertThat(savedInstance.get(selectField.getId()), equalTo(valueC));
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) FormClass(org.activityinfo.model.form.FormClass) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) FieldValue(org.activityinfo.model.type.FieldValue) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormInstance(org.activityinfo.model.form.FormInstance) FormRecord(org.activityinfo.model.form.FormRecord) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) FormField(org.activityinfo.model.form.FormField) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Aggregations

EnumItem (org.activityinfo.model.type.enumerated.EnumItem)44 EnumType (org.activityinfo.model.type.enumerated.EnumType)30 FormField (org.activityinfo.model.form.FormField)11 FormClass (org.activityinfo.model.form.FormClass)9 ResourceId (org.activityinfo.model.resource.ResourceId)9 Test (org.junit.Test)7 QuantityType (org.activityinfo.model.type.number.QuantityType)6 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)5 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)2 SymbolNode (org.activityinfo.model.formula.SymbolNode)2 ColumnModel (org.activityinfo.model.query.ColumnModel)2 ColumnView (org.activityinfo.model.query.ColumnView)2 Cardinality (org.activityinfo.model.type.Cardinality)2 FieldValue (org.activityinfo.model.type.FieldValue)2 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 ActivityField (org.activityinfo.store.mysql.metadata.ActivityField)2 Optional (com.google.common.base.Optional)1