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);
}
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();
}
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));
}
}
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;
}
}
}
}
}
}
}
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));
}
Aggregations