Search in sources :

Example 16 with TypeDto

use of org.motechproject.mds.dto.TypeDto in project motech by motech.

the class TypeMatcherTest method matchTypes.

private void matchTypes(String term, int matchedCount, int noMatchedCount) {
    TypeMatcher matcher = new TypeMatcher(term, messageSource);
    int falseCout = 0;
    int trueCount = 0;
    for (TypeDto entity : TYPES) {
        if (matcher.evaluate(entity)) {
            ++trueCount;
        } else {
            ++falseCout;
        }
    }
    assertEquals("The number of matched types is incorrect", matchedCount, trueCount);
    assertEquals("The number of no matched types is incorrect", noMatchedCount, falseCout);
}
Also used : TypeDto(org.motechproject.mds.dto.TypeDto)

Example 17 with TypeDto

use of org.motechproject.mds.dto.TypeDto in project motech by motech.

the class LookupProcessor method setUseGenericParam.

private void setUseGenericParam(EntityDto entity, Class<?> methodParameterType, LookupFieldDto lookupField) {
    FieldDto field = findEntityFieldByName(entity.getClassName(), lookupField.getName());
    TypeDto fieldType = field.getType();
    EntityDto relatedEntity = null;
    if (fieldType.isRelationship()) {
        relatedEntity = findEntityByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
        field = findEntityFieldByName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue(), lookupField.getRelatedName());
    }
    if (fieldType.isCombobox()) {
        ComboboxHolder holder = new ComboboxHolder(relatedEntity == null ? entity : relatedEntity, field);
        boolean isCollection = holder.isCollection();
        boolean isCollectionParam = Collection.class.isAssignableFrom(methodParameterType);
        lookupField.setUseGenericParam(isCollection && !isCollectionParam);
    }
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) TypeDto(org.motechproject.mds.dto.TypeDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 18 with TypeDto

use of org.motechproject.mds.dto.TypeDto 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());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) TypeDto(org.motechproject.mds.dto.TypeDto) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 19 with TypeDto

use of org.motechproject.mds.dto.TypeDto 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);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Field(org.motechproject.mds.domain.Field) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) TypeDto(org.motechproject.mds.dto.TypeDto) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 20 with TypeDto

use of org.motechproject.mds.dto.TypeDto in project motech by motech.

the class TypeServiceImplContextIT method testFindType.

private void testFindType(Class<?> request, Class<?> expected) {
    TypeDto type = typeService.findType(request);
    assertNotNull(type);
    assertEquals(expected.getName(), type.getTypeClass());
}
Also used : TypeDto(org.motechproject.mds.dto.TypeDto)

Aggregations

TypeDto (org.motechproject.mds.dto.TypeDto)30 FieldDto (org.motechproject.mds.dto.FieldDto)17 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)9 EntityDto (org.motechproject.mds.dto.EntityDto)7 MetadataDto (org.motechproject.mds.dto.MetadataDto)7 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)6 CtClass (javassist.CtClass)3 FieldValidationDto (org.motechproject.mds.dto.FieldValidationDto)3 LookupDto (org.motechproject.mds.dto.LookupDto)3 IOException (java.io.IOException)2 AccessibleObject (java.lang.reflect.AccessibleObject)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 CannotCompileException (javassist.CannotCompileException)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ClassData (org.motechproject.mds.domain.ClassData)2 Field (org.motechproject.mds.domain.Field)2