Search in sources :

Example 1 with FieldRecord

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());
}
Also used : List(java.util.List) Arrays.asList(java.util.Arrays.asList) SettingDto(org.motechproject.mds.dto.SettingDto) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 2 with FieldRecord

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;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with FieldRecord

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;
}
Also used : FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord)

Example 4 with FieldRecord

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;
}
Also used : FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with FieldRecord

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()));
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Test(org.junit.Test)

Aggregations

FieldRecord (org.motechproject.mds.web.domain.FieldRecord)24 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)16 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)15 Test (org.junit.Test)14 EntityDto (org.motechproject.mds.dto.EntityDto)7 FieldDto (org.motechproject.mds.dto.FieldDto)6 List (java.util.List)3 Matchers.anyString (org.mockito.Matchers.anyString)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 SettingDto (org.motechproject.mds.dto.SettingDto)2 ObjectNotFoundException (org.motechproject.mds.exception.object.ObjectNotFoundException)2 ObjectReadException (org.motechproject.mds.exception.object.ObjectReadException)2 MotechDataService (org.motechproject.mds.service.MotechDataService)2 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1