use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityValidator method validateEntityComboboxesValues.
private void validateEntityComboboxesValues(EntityDraft draft) {
Entity parent = draft.getParentEntity();
List<Field> oldComboboxFields = draft.getParentEntity().getStringComboboxFields();
List<Field> comboboxFields = draft.getStringComboboxFields();
for (Field field : substract(oldComboboxFields, comboboxFields)) {
String tableName;
String fieldName;
if (!field.isMultiSelectCombobox()) {
fieldName = field.getName();
tableName = ClassTableName.getTableName(parent);
} else {
fieldName = "ELEMENT";
tableName = ClassTableName.getTableName(parent) + "_" + field.getName().toUpperCase();
}
List<?> values = executeSQLQuery(prepareSelectDistincQuery(tableName, fieldName));
validateUserSuppliedValuesUsageForField(values, draft.getField(field.getName()));
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class AllEntityDrafts method setProperties.
public void setProperties(EntityDraft draft, Entity entity, String username) {
draft.setParentEntity(entity);
draft.setParentVersion(entity.getEntityVersion());
draft.setDraftOwnerUsername(username);
draft.setLastModificationDate(DateUtil.nowUTC());
draft.setName(entity.getName());
draft.setClassName(entity.getClassName());
draft.setNamespace(entity.getNamespace());
draft.setModule(entity.getModule());
draft.setSecurityMode(entity.getSecurityMode());
draft.setSecurityMembers(new HashSet<>(entity.getSecurityMembers()));
draft.setReadOnlySecurityMode(entity.getReadOnlySecurityMode());
draft.setReadOnlySecurityMembers(new HashSet<>(entity.getReadOnlySecurityMembers()));
draft.getFields().clear();
for (Field field : entity.getFields()) {
draft.addField(field.copy());
}
draft.getLookups().clear();
for (Lookup lookup : entity.getLookups()) {
Lookup newLookup = lookup.copy(draft.getFields());
draft.addLookup(newLookup);
}
if (entity.getRestOptions() != null) {
RestOptions restOptions = entity.getRestOptions().copy();
restOptions.setEntity(draft);
draft.setRestOptions(restOptions);
}
if (entity.getTracking() != null) {
Tracking tracking = entity.getTracking().copy();
tracking.setEntity(draft);
draft.setTracking(tracking);
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImplTest method shouldAddNewField.
@Test
public void shouldAddNewField() {
// given
long entityId = 1L;
EntityDto dto = new EntityDto(entityId, CLASS_NAME);
TypeDto type = TypeDto.INTEGER;
Type integerType = new Type(Integer.class);
FieldBasicDto basic = new FieldBasicDto();
basic.setDisplayName("pi");
basic.setName("pi");
basic.setRequired(true);
basic.setDefaultValue("3.14");
basic.setTooltip("Sets the value of the PI number");
basic.setPlaceholder("3.14");
FieldDto fieldDto = new FieldDto();
fieldDto.setEntityId(dto.getId());
fieldDto.setType(type);
fieldDto.setBasic(basic);
// when
doReturn(entity).when(allEntities).retrieveById(dto.getId());
doReturn(entityId).when(entity).getId();
doReturn(integerType).when(allTypes).retrieveByClassName(type.getTypeClass());
entityService.addFields(dto, asList(fieldDto));
// then
verify(allEntities).retrieveById(dto.getId());
verify(entity).addField(fieldCaptor.capture());
Field field = fieldCaptor.getValue();
assertEquals(basic.getName(), field.getName());
assertEquals(basic.getDisplayName(), field.getDisplayName());
assertEquals(basic.isRequired(), field.isRequired());
assertEquals(basic.getDefaultValue(), field.getDefaultValue());
assertEquals(basic.getTooltip(), field.getTooltip());
assertEquals(basic.getPlaceholder(), field.getPlaceholder());
assertEquals(fieldDto.getType().getTypeClass(), field.getType().getTypeClass().getName());
assertEquals(fieldDto.getEntityId(), field.getEntity().getId());
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImplTest method shouldSetUIFilterableOnlyToCorrectFields.
@Test
public void shouldSetUIFilterableOnlyToCorrectFields() {
// given
Field filterableField = mock(Field.class);
Field nonFilterableField = mock(Field.class);
// #1 when
doReturn("filterableField").when(filterableField).getName();
doReturn("nonFilterableField").when(nonFilterableField).getName();
doReturn(1L).when(entityDto).getId();
doReturn(entity).when(allEntities).retrieveById(1L);
doReturn(asList(filterableField, nonFilterableField)).when(entity).getFields();
entityService.addFilterableFields(entityDto, asList("filterableField"));
// #1 then
verify(allEntities).retrieveById(1L);
verify(entity).getFields();
verify(filterableField).setUIFilterable(true);
verify(nonFilterableField).setUIFilterable(false);
// #2 when
entityService.addFilterableFields(entityDto, asList("nonFilterableField"));
// #2 then
verify(allEntities, times(2)).retrieveById(1L);
verify(entity, times(2)).getFields();
verify(filterableField).setUIFilterable(false);
verify(nonFilterableField).setUIFilterable(true);
// #3 when
entityService.addFilterableFields(entityDto, asList("filterableField", "nonFilterableField"));
// #3 then
verify(allEntities, times(3)).retrieveById(1L);
verify(entity, times(3)).getFields();
verify(filterableField, times(2)).setUIFilterable(true);
verify(nonFilterableField, times(2)).setUIFilterable(true);
// #4 when
entityService.addFilterableFields(entityDto, new ArrayList<String>());
// #4 then
verify(allEntities, times(4)).retrieveById(1L);
verify(entity, times(4)).getFields();
verify(filterableField, times(2)).setUIFilterable(false);
verify(nonFilterableField, times(2)).setUIFilterable(false);
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImplTest method shouldUpdateExistingField.
@Test
public void shouldUpdateExistingField() {
// given
long entityId = 1L;
EntityDto dto = new EntityDto(entityId, CLASS_NAME);
TypeDto type = TypeDto.INTEGER;
Field field = mock(Field.class);
FieldBasicDto basic = new FieldBasicDto();
basic.setDisplayName("pi");
basic.setName("pi");
basic.setRequired(true);
basic.setDefaultValue("3.14");
basic.setTooltip("Sets the value of the PI number");
basic.setPlaceholder("3.14");
FieldDto fieldDto = new FieldDto();
fieldDto.setEntityId(dto.getId());
fieldDto.setType(type);
fieldDto.setBasic(basic);
// when
doReturn(entity).when(allEntities).retrieveById(dto.getId());
doReturn(entityId).when(entity).getId();
doReturn(field).when(entity).getField(basic.getName());
entityService.addFields(dto, asList(fieldDto));
// then
verify(allEntities).retrieveById(dto.getId());
verify(entity).getField(basic.getName());
verify(entity, never()).addField(any(Field.class));
verify(field).update(fieldDto);
}
Aggregations