Search in sources :

Example 1 with BrowsingSettingsDto

use of org.motechproject.mds.dto.BrowsingSettingsDto 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 BrowsingSettingsDto

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

the class Entity method updateBrowsingSettings.

protected void updateBrowsingSettings(AdvancedSettingsDto advancedSettings, boolean shouldSetUiChanged) {
    BrowsingSettingsDto dto = advancedSettings.getBrowsing();
    if (null == dto) {
        dto = new BrowsingSettingsDto();
    }
    for (Field field : getFields()) {
        Long fieldId = field.getId();
        boolean isDisplayed = dto.containsDisplayedField(fieldId) && !field.isNonDisplayable();
        boolean isFilterable = dto.containsFilterableField(fieldId);
        field.setUIDisplayable(isDisplayed);
        if ((field.isUIFilterable() != isFilterable) && shouldSetUiChanged) {
            field.setUIFilterable(isFilterable);
            field.setUiChanged(true);
        }
        if (isDisplayed) {
            long position = dto.indexOfDisplayedField(fieldId);
            field.setUIDisplayPosition(position);
        }
    }
}
Also used : BrowsingSettingsDto(org.motechproject.mds.dto.BrowsingSettingsDto)

Aggregations

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