use of org.motechproject.mds.dto.FieldBasicDto in project motech by motech.
the class FieldTestHelper method fieldInfo.
public static FieldInfo fieldInfo(String name, Class typeClass, boolean required, boolean restExposed, boolean autoGenerated) {
FieldInfo field = new FieldInfo();
FieldDto fieldDto = new FieldDto();
fieldDto.setBasic(new FieldBasicDto());
fieldDto.getBasic().setName(name);
fieldDto.getBasic().setDisplayName(name + " disp");
fieldDto.getBasic().setRequired(required);
TypeDto type = new TypeDto();
type.setTypeClass(typeClass.getName());
fieldDto.setType(type);
field.setRestExposed(restExposed);
if (autoGenerated) {
fieldDto.addMetadata(new MetadataDto(Constants.Util.AUTO_GENERATED, Constants.Util.TRUE));
}
field.setField(fieldDto);
field.getTypeInfo().setType(typeClass.getName());
return field;
}
use of org.motechproject.mds.dto.FieldBasicDto in project motech by motech.
the class FieldTestHelper method fieldDto.
public static FieldDto fieldDto(Long id, String name, String className, String displayName, Object defValue) {
FieldDto fieldDto = new FieldDto();
fieldDto.setType(new TypeDto(className, "", "", className));
fieldDto.setBasic(new FieldBasicDto(displayName, name));
fieldDto.getBasic().setDefaultValue(defValue);
fieldDto.setId(id);
return fieldDto;
}
use of org.motechproject.mds.dto.FieldBasicDto in project motech by motech.
the class EntityServiceImpl method addField.
private void addField(Entity entity, FieldDto fieldDto) {
FieldBasicDto basic = fieldDto.getBasic();
String typeClass = fieldDto.getType().getTypeClass();
Type type = allTypes.retrieveByClassName(typeClass);
Field field = new Field(entity, basic.getName(), basic.getDisplayName(), basic.isRequired(), basic.isUnique(), fieldDto.isReadOnly(), fieldDto.isNonEditable(), fieldDto.isNonDisplayable(), (String) basic.getDefaultValue(), basic.getTooltip(), basic.getPlaceholder(), null);
field.setType(type);
if (type.hasSettings()) {
for (TypeSetting setting : type.getSettings()) {
SettingDto settingDto = fieldDto.getSetting(setting.getName());
FieldSetting fieldSetting = new FieldSetting(field, setting);
if (null != settingDto) {
fieldSetting.setValue(settingDto.getValueAsString());
}
field.addSetting(fieldSetting);
}
}
if (type.hasValidation()) {
for (TypeValidation validation : type.getValidations()) {
FieldValidation fieldValidation = new FieldValidation(field, validation);
FieldValidationDto validationDto = fieldDto.getValidation();
if (null != validationDto) {
ValidationCriterionDto criterion = validationDto.getCriterion(validation.getDisplayName());
if (null != criterion) {
fieldValidation.setValue(criterion.valueAsString());
fieldValidation.setEnabled(criterion.isEnabled());
}
}
field.addValidation(fieldValidation);
}
}
for (MetadataDto metadata : fieldDto.getMetadata()) {
field.addMetadata(new FieldMetadata(metadata));
}
entity.addField(field);
}
use of org.motechproject.mds.dto.FieldBasicDto in project motech by motech.
the class RestIgnoreProcessorTest method mockEntityFields.
private List<FieldDto> mockEntityFields() {
List<FieldDto> fields = new ArrayList<>();
List<String> fieldNames = new ArrayList<>(Arrays.asList(Constants.Util.GENERATED_FIELD_NAMES));
fieldNames.addAll(Arrays.asList("anotherInt", "anotherString", "restIgnoredBoolean"));
long i = 0;
for (String fieldName : fieldNames) {
long fieldId = i++;
FieldDto fieldDto = mock(FieldDto.class);
FieldBasicDto fieldBasicDto = mock(FieldBasicDto.class);
when(fieldDto.getId()).thenReturn(fieldId);
when(fieldDto.getBasic()).thenReturn(fieldBasicDto);
when(fieldBasicDto.getName()).thenReturn(fieldName);
fields.add(fieldDto);
}
return fields;
}
use of org.motechproject.mds.dto.FieldBasicDto in project motech by motech.
the class EntityMetadataBuilderTest method shouldMarkEudeFieldsAsUnique.
@Test
public void shouldMarkEudeFieldsAsUnique() {
when(entity.getName()).thenReturn(ENTITY_NAME);
when(jdoMetadata.newPackageMetadata(anyString())).thenReturn(packageMetadata);
when(packageMetadata.newClassMetadata(anyString())).thenReturn(classMetadata);
FieldDto eudeField = mock(FieldDto.class);
FieldBasicDto eudeBasic = mock(FieldBasicDto.class);
when(eudeField.getBasic()).thenReturn(eudeBasic);
when(eudeBasic.getName()).thenReturn("uniqueField");
when(eudeField.isReadOnly()).thenReturn(false);
when(eudeBasic.isUnique()).thenReturn(true);
when(eudeField.getType()).thenReturn(TypeDto.STRING);
FieldDto ddeField = mock(FieldDto.class);
FieldBasicDto ddeBasic = mock(FieldBasicDto.class);
when(ddeField.getBasic()).thenReturn(ddeBasic);
when(ddeBasic.getName()).thenReturn("uniqueField2");
when(ddeField.isReadOnly()).thenReturn(true);
when(ddeBasic.isUnique()).thenReturn(true);
when(ddeField.getType()).thenReturn(TypeDto.STRING);
when(schemaHolder.getFields(entity)).thenReturn(asList(ddeField, eudeField));
FieldMetadata fmdEude = mock(FieldMetadata.class);
when(fmdEude.getName()).thenReturn("uniqueField");
when(classMetadata.newFieldMetadata("uniqueField")).thenReturn(fmdEude);
FieldMetadata fmdDde = mock(FieldMetadata.class);
when(fmdDde.getName()).thenReturn("uniqueField2");
when(classMetadata.newFieldMetadata("uniqueField2")).thenReturn(fmdDde);
UniqueMetadata umd = mock(UniqueMetadata.class);
when(fmdEude.newUniqueMetadata()).thenReturn(umd);
entityMetadataBuilder.addEntityMetadata(jdoMetadata, entity, Sample.class, schemaHolder);
verify(fmdDde, never()).newUniqueMetadata();
verify(fmdDde, never()).setUnique(anyBoolean());
verify(fmdEude).newUniqueMetadata();
verify(umd).setName("unq_Sample_uniqueField");
}
Aggregations