use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.
the class FieldRecordTest method shouldHandleSingleSelectComboBoxes.
@Test
public void shouldHandleSingleSelectComboBoxes() {
FieldDto fieldDto = FieldTestHelper.fieldDto(1L, "name", List.class.getName(), "disp", "[one, two]");
fieldDto.setSettings(asList(new SettingDto(COMBOBOX_VALUES, asList("one", "two", "three"), null, null)));
FieldRecord fieldRecord = new FieldRecord(fieldDto);
fieldRecord.setValue("[two]");
assertEquals("two", fieldRecord.getValue());
fieldRecord.setValue("test");
assertEquals("test", fieldRecord.getValue());
// test with enum
fieldRecord.setValue(TestEnum.TWO);
assertEquals("TWO", fieldRecord.getValue());
fieldRecord.setValue(asList(TestEnum.ONE));
assertEquals("ONE", fieldRecord.getValue());
fieldRecord.setValue(null);
assertNull(fieldRecord.getValue());
}
use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.
the class HistoryRecordComparator method compare.
@Override
public int compare(HistoryRecord one, HistoryRecord two) {
FieldRecord fieldFromOne = findFieldByName(one, compareField);
FieldRecord fieldFromTwo = findFieldByName(two, compareField);
int ret;
try {
DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy hh:mm aaa", Locale.ENGLISH);
Date dateOne = dateFormat.parse(fieldFromOne.getValue().toString());
Date dateTwo = dateFormat.parse(fieldFromTwo.getValue().toString());
ret = dateOne.compareTo(dateTwo);
} catch (ParseException e) {
ret = 0;
}
return (sortAscending) ? ret : -ret;
}
use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.
the class InstanceController method decodeBlobFiles.
private EntityRecord decodeBlobFiles(EntityRecord record) {
for (FieldRecord field : record.getFields()) {
if (TypeDto.BLOB.getTypeClass().equals(field.getType().getTypeClass())) {
byte[] content = field.getValue() != null ? field.getValue().toString().getBytes() : ArrayUtils.EMPTY_BYTE_ARRAY;
field.setValue(decodeBase64(content));
}
}
return record;
}
use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.
the class InstanceController method getInstanceValueAsRelatedField.
/**
* Retrieves instance and builds field value from it. Used when user adds related instances
* in Data Browser UI.
*
* @param entityId the id of entity which has related field
* @param fieldId the id of related field
* @param instanceId the id of instance which will be related to given field
* @return instance value as related field
*/
@RequestMapping(value = "/instances/{entityId}/field/{fieldId}/instance/{instanceId}", method = RequestMethod.GET)
@ResponseBody
public FieldRecord getInstanceValueAsRelatedField(@PathVariable Long entityId, @PathVariable Long fieldId, @PathVariable Long instanceId) {
FieldRecord record = instanceService.getInstanceValueAsRelatedField(entityId, fieldId, instanceId);
processFieldForUI(record);
return record;
}
use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.
the class InstanceServiceTest method shouldReturnNewInstances.
@Test
public void shouldReturnNewInstances() {
mockSampleFields();
mockEntity();
EntityRecord record = instanceService.newInstance(ENTITY_ID);
assertNotNull(record);
assertEquals(Long.valueOf(ENTITY_ID), record.getEntitySchemaId());
assertNull(record.getId());
List<FieldRecord> fieldRecords = record.getFields();
assertCommonFieldRecordFields(fieldRecords);
assertEquals(asList("Default", 7, null, null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
}
Aggregations