Search in sources :

Example 6 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class InstanceServiceTest method shouldReturnEntityInstance.

@Test
public void shouldReturnEntityInstance() {
    mockDataService();
    mockSampleFields();
    mockEntity();
    when(motechDataService.retrieve("id", INSTANCE_ID)).thenReturn(new TestSample("Hello world", 99));
    EntityRecord record = instanceService.getEntityInstance(ENTITY_ID, INSTANCE_ID);
    assertNotNull(record);
    assertEquals(Long.valueOf(ENTITY_ID), record.getEntitySchemaId());
    assertEquals(Long.valueOf(INSTANCE_ID), record.getId());
    List<FieldRecord> fieldRecords = record.getFields();
    assertCommonFieldRecordFields(fieldRecords);
    assertEquals(asList("Hello world", 99, 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)

Example 7 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class InstanceServiceTest method shouldAcceptUserWithRegularAccessPermissionWhileReadingInstance.

@Test
public void shouldAcceptUserWithRegularAccessPermissionWhileReadingInstance() {
    EntityDto entityDto = new EntityDto();
    entityDto.setReadOnlySecurityMode(SecurityMode.NO_ACCESS);
    entityDto.setSecurityMode(SecurityMode.EVERYONE);
    entityDto.setClassName(TestSample.class.getName());
    EntityRecord entityRecord = new EntityRecord(ANOTHER_ENTITY_ID, null, new ArrayList<FieldRecord>());
    when(entityService.getEntity(ANOTHER_ENTITY_ID)).thenReturn(entityDto);
    mockDataService();
    instanceService.getEntityRecords(entityRecord.getId());
    verify(entityService).getEntityFieldsForUI(ANOTHER_ENTITY_ID);
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) EntityDto(org.motechproject.mds.dto.EntityDto) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Test(org.junit.Test)

Example 8 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class InstanceServiceTest method shouldNotAutoPopulateOwnerAndCreatorForNonEditableFields.

@Test
public void shouldNotAutoPopulateOwnerAndCreatorForNonEditableFields() {
    FieldDto ownerField = FieldTestHelper.fieldDto(1L, "owner", String.class.getName(), "String field", null);
    ownerField.setNonEditable(true);
    FieldDto creatorField = FieldTestHelper.fieldDto(1L, "creator", String.class.getName(), "String field", null);
    creatorField.setNonEditable(true);
    when(entityService.getEntityFieldsForUI(ENTITY_ID)).thenReturn(asList(ownerField, creatorField));
    mockEntity();
    setUpSecurityContext();
    EntityRecord record = instanceService.newInstance(ENTITY_ID);
    List<FieldRecord> fieldRecords = record.getFields();
    assertEquals(asList(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) Matchers.anyString(org.mockito.Matchers.anyString) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 9 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class InstanceServiceImpl method newInstance.

@Override
public EntityRecord newInstance(Long entityId) {
    validateCredentials(getEntity(entityId));
    List<FieldDto> fields = entityService.getEntityFieldsForUI(entityId);
    List<FieldRecord> fieldRecords = new ArrayList<>();
    for (FieldDto field : fields) {
        FieldRecord fieldRecord = new FieldRecord(field);
        fieldRecords.add(fieldRecord);
    }
    populateDefaultFields(fieldRecords);
    return new EntityRecord(null, entityId, fieldRecords);
}
Also used : EntityRecord(org.motechproject.mds.web.domain.EntityRecord) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) ArrayList(java.util.ArrayList) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 10 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class EntityRecordComparator method compare.

@Override
public int compare(EntityRecord one, EntityRecord two) {
    FieldRecord fieldFromOne = findFieldByName(one, compareField);
    FieldRecord fieldFromTwo = findFieldByName(two, compareField);
    int ret = fieldFromOne.getValue().toString().compareTo(fieldFromTwo.getValue().toString());
    return (sortAscending) ? ret : -ret;
}
Also used : FieldRecord(org.motechproject.mds.web.domain.FieldRecord)

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