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