Search in sources :

Example 1 with UIDisplayFieldComparator

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

the class CsvImporterExporterTest method setUp.

@Before
public void setUp() {
    MotechClassPool.registerServiceInterface(ENTITY_CLASSNAME, DATA_SERVICE_CLASSNAME);
    when(bundleContext.getServiceReference(DATA_SERVICE_CLASSNAME)).thenReturn(serviceRef);
    when(bundleContext.getService(serviceRef)).thenReturn(motechDataService);
    when(motechDataService.getClassType()).thenReturn(Record2.class);
    MotechClassPool.registerServiceInterface(RELATED_CLASSNAME, RELATED_SERVICE_CLASSNAME);
    when(bundleContext.getServiceReference(RELATED_SERVICE_CLASSNAME)).thenReturn(relatedServiceRef);
    when(bundleContext.getService(relatedServiceRef)).thenReturn(relatedDataService);
    when(relatedDataService.getClassType()).thenReturn(RelatedClass.class);
    when(relatedDataService.findById(0L)).thenReturn(new RelatedClass(0L));
    when(relatedDataService.findById(1L)).thenReturn(new RelatedClass(1L));
    when(entityInfoReader.getEntityInfo(ENTITY_CLASSNAME)).thenReturn(entityInfo);
    when(entityInfoReader.getEntityInfo(ENTITY_ID)).thenReturn(entityInfo);
    when(entityInfo.getEntity()).thenReturn(entityDto);
    when(entityDto.getClassName()).thenReturn(ENTITY_CLASSNAME);
    when(entityDto.getName()).thenReturn(ENTITY_NAME);
    when(entityDto.getModule()).thenReturn(ENTITY_MODULE);
    when(entityDto.getNamespace()).thenReturn(ENTITY_NAMESPACE);
    when(csvExportCustomizer.columnOrderComparator(any(BrowsingSettingsDto.class))).thenReturn(new UIDisplayFieldComparator(new ArrayList<Number>()));
    when(csvExportCustomizer.exportDisplayName(any(FieldDto.class))).thenCallRealMethod();
    CsvTestHelper.mockRecord2Fields(entityInfo, advancedSettingsDto, browsingSettingsDto);
}
Also used : BrowsingSettingsDto(org.motechproject.mds.dto.BrowsingSettingsDto) ArrayList(java.util.ArrayList) RelatedClass(org.motechproject.mds.testutil.records.RelatedClass) UIDisplayFieldComparator(org.motechproject.mds.dto.UIDisplayFieldComparator) FieldDto(org.motechproject.mds.dto.FieldDto) Before(org.junit.Before)

Example 2 with UIDisplayFieldComparator

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

the class JarGeneratorServiceImpl method getFieldsInfo.

private List<FieldInfo> getFieldsInfo(EntityDto entity, List<FieldDto> fields, AdvancedSettingsDto advancedSettings) {
    List<FieldInfo> fieldsInfo = new ArrayList<>();
    Collections.sort(fields, new UIDisplayFieldComparator(advancedSettings.getBrowsing().getDisplayedFields()));
    for (FieldDto field : fields) {
        FieldInfo fieldInfo = new FieldInfo();
        fieldInfo.setField(field);
        boolean exposedByRest = advancedSettings.isFieldExposedByRest(field.getBasic().getName());
        fieldInfo.setRestExposed(exposedByRest);
        FieldInfo.TypeInfo typeInfo = fieldInfo.getTypeInfo();
        typeInfo.setType(field.getType().getTypeClass());
        typeInfo.setTaskType(ActionParameterTypeResolver.resolveType(entity, field));
        // combobox values
        typeInfo.setCombobox(field.getType().isCombobox());
        if (field.getType().isCombobox()) {
            ComboboxHolder cbHolder = new ComboboxHolder(entity, field);
            String[] items = cbHolder.getValues();
            if (ArrayUtils.isNotEmpty(items)) {
                typeInfo.setItems(Arrays.asList(items));
            }
            typeInfo.setAllowsMultipleSelection(cbHolder.isCollection());
            typeInfo.setAllowUserSupplied(cbHolder.isAllowUserSupplied());
        }
        fieldsInfo.add(fieldInfo);
    }
    return fieldsInfo;
}
Also used : ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) ArrayList(java.util.ArrayList) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) UIDisplayFieldComparator(org.motechproject.mds.dto.UIDisplayFieldComparator) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

ArrayList (java.util.ArrayList)2 FieldDto (org.motechproject.mds.dto.FieldDto)2 UIDisplayFieldComparator (org.motechproject.mds.dto.UIDisplayFieldComparator)2 Before (org.junit.Before)1 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)1 BrowsingSettingsDto (org.motechproject.mds.dto.BrowsingSettingsDto)1 FieldInfo (org.motechproject.mds.entityinfo.FieldInfo)1 RelatedClass (org.motechproject.mds.testutil.records.RelatedClass)1