use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class SiteHistoryReader method parseChanges.
private Map<ResourceId, FieldValue> parseChanges(JsonValue jsonObject) {
Map<ResourceId, ResourceId> attributeToFieldMap = new HashMap<>();
for (ActivityField activityField : activity.getAttributeAndIndicatorFields()) {
if (activityField.getFormField().getType() instanceof EnumType) {
EnumType type = (EnumType) activityField.getFormField().getType();
for (EnumItem enumItem : type.getValues()) {
attributeToFieldMap.put(enumItem.getId(), activityField.getResourceId());
}
}
}
Map<ResourceId, FieldValue> valueMap = new HashMap<>();
Multimap<ResourceId, ResourceId> attributeValueMap = HashMultimap.create();
for (Map.Entry<String, JsonValue> jsonEntry : jsonObject.entrySet()) {
String fieldName = jsonEntry.getKey();
if (fieldName.equals("comments")) {
valueMap.put(fieldId(CuidAdapter.COMMENT_FIELD), NarrativeValue.valueOf(parseString(jsonEntry.getValue())));
} else if (fieldName.equals("date1")) {
valueMap.put(fieldId(CuidAdapter.START_DATE_FIELD), parseDate(jsonEntry.getValue()));
} else if (fieldName.equals("date2")) {
valueMap.put(fieldId(CuidAdapter.START_DATE_FIELD), parseDate(jsonEntry.getValue()));
} else if (fieldName.equals("partnerId")) {
valueMap.put(fieldId(CuidAdapter.PARTNER_FIELD), parseRef(jsonEntry.getValue(), activity.getPartnerFormClassId(), CuidAdapter.PARTNER_DOMAIN));
} else if (fieldName.equals("projectId")) {
valueMap.put(fieldId(CuidAdapter.PROJECT_FIELD), parseRef(jsonEntry.getValue(), activity.getProjectFormClassId(), CuidAdapter.PROJECT_DOMAIN));
} else if (fieldName.equals("locationId")) {
valueMap.put(fieldId(CuidAdapter.LOCATION_FIELD), parseRef(jsonEntry.getValue(), activity.getLocationFormClassId(), CuidAdapter.LOCATION_DOMAIN));
} else if (fieldName.startsWith("I")) {
int mIndex = fieldName.indexOf("M");
if (mIndex == -1) {
int indicatorId = Integer.parseInt(fieldName.substring(1));
ResourceId fieldId = CuidAdapter.indicatorField(indicatorId);
valueMap.put(fieldId, parseQuantity(jsonEntry.getValue()));
} else {
// old history
valueMap.put(ResourceId.valueOf(fieldName), parseQuantity(jsonEntry.getValue()));
}
} else if (fieldName.startsWith("ATTRIB")) {
if (parseBoolean(jsonEntry.getValue())) {
int attributeId = Integer.parseInt(fieldName.substring("ATTRIB".length()));
ResourceId attributeCuid = CuidAdapter.attributeId(attributeId);
ResourceId fieldId = attributeToFieldMap.get(attributeCuid);
if (fieldId != null) {
attributeValueMap.put(fieldId, attributeCuid);
}
}
}
}
for (ResourceId fieldId : attributeValueMap.keySet()) {
valueMap.put(fieldId, new EnumValue(attributeValueMap.get(fieldId)));
}
return valueMap;
}
use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class SideColumnBuilder method add.
public void add(ActivityField field, final CursorObserver<FieldValue> observer) {
ValueBuffer buffer = fieldMap.get(field.getId());
if (buffer == null) {
buffer = createBuffer(field.getFormField().getType(), observer);
fieldMap.put(field.getId(), buffer);
if (field.isAttributeGroup()) {
// Map each individual attribute id to this buffer so we don't need to query
// the attribute group from the database
EnumType enumType = (EnumType) field.getFormField().getType();
for (EnumItem enumItem : enumType.getValues()) {
int attributeId = CuidAdapter.getLegacyIdFromCuid(enumItem.getId());
attributeMap.put(attributeId, buffer);
}
}
}
buffer.add(observer);
}
use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class AttributeValueTableUpdater method update.
public void update(ResourceId fieldId, FieldValue value) {
Preconditions.checkArgument(fieldId.getDomain() == CuidAdapter.ATTRIBUTE_GROUP_FIELD_DOMAIN);
int attributeGroupId = CuidAdapter.getLegacyIdFromCuid(fieldId);
ActivityField field = activity.getAttributeGroupField(attributeGroupId);
EnumType enumType = (EnumType) field.getFormField().getType();
for (EnumItem enumItem : enumType.getValues()) {
attributesToClear.add(CuidAdapter.getLegacyIdFromCuid(enumItem.getId()));
}
add(value);
}
use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class MultiEnumFormat method getColumnModels.
@Override
public List<ColumnModel> getColumnModels() {
List<ColumnModel> columns = new ArrayList<>();
for (EnumItem enumItem : enumType.getValues()) {
ColumnModel model = new ColumnModel();
model.setId(getItemId(enumItem));
model.setFormula(new CompoundExpr(formula, new SymbolNode(enumItem.getId())));
columns.add(model);
}
return columns;
}
use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class XFormReader method enumItems.
private List<EnumItem> enumItems(SelectElement element) {
List<EnumItem> enumItems = Lists.newArrayList();
for (Item item : element.getItems()) {
EnumItem enumItem = new EnumItem(EnumItem.generateId(), item.getLabel());
enumItem.setCode(item.getValue());
enumItems.add(enumItem);
}
return enumItems;
}
Aggregations