Search in sources :

Example 1 with UserCriteria

use of de.symeda.sormas.api.user.UserCriteria in project SORMAS-Project by hzi-braunschweig.

the class UserGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<UserDto, UserCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getUserFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> {
        return (int) FacadeProvider.getUserFacade().count(query.getFilter().orElse(null));
    });
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) UserCriteria(de.symeda.sormas.api.user.UserCriteria) UserDto(de.symeda.sormas.api.user.UserDto)

Example 2 with UserCriteria

use of de.symeda.sormas.api.user.UserCriteria in project SORMAS-Project by hzi-braunschweig.

the class UserFacadeEjbTest method testGetIndexList.

/**
 * Testing with some users that might not be selected DISTINCT because of 1:n relations.
 */
@Test
public void testGetIndexList() {
    // 1 region, 2 districts
    RDCF rdcf = creator.createRDCF();
    Region region = getBean(RegionService.class).getByUuid(rdcf.region.getUuid());
    creator.createDistrict("district 2", region);
    // user with a 2 districts region, 2 user roles
    creator.createUser(rdcf, "my", "User", CASE_OFFICER, CONTACT_OFFICER);
    // some other users to be filtered out
    creator.createUser(rdcf, "Some", "User", SURVEILLANCE_SUPERVISOR, CONTACT_SUPERVISOR);
    creator.createUser(rdcf, "Other", "User", SURVEILLANCE_OFFICER, DISTRICT_OBSERVER);
    List<UserDto> result;
    // 1. Check that query works without filter: All 3 distinct users are found (+ admin by default)
    result = getUserFacade().getIndexList(new UserCriteria(), 0, 100, null);
    assertThat(result, hasSize(4));
    assertThat(result.stream().map(EntityDto::getUuid).collect(Collectors.toSet()), hasSize(4));
    // 2. Check that only the expected user is found
    result = getUserFacade().getIndexList(new UserCriteria().freeText("myUser"), 0, 100, null);
    assertThat(result, hasSize(1));
    assertThat(result.get(0).getUserName(), equalTo("myUser"));
}
Also used : EntityDto(de.symeda.sormas.api.EntityDto) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) UserCriteria(de.symeda.sormas.api.user.UserCriteria) UserDto(de.symeda.sormas.api.user.UserDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with UserCriteria

use of de.symeda.sormas.api.user.UserCriteria in project SORMAS-Project by hzi-braunschweig.

the class UserSyncHandler method startSync.

public void startSync(Consumer<StreamResource> errorReportConsumer, UI currentUI) {
    long totalCount = FacadeProvider.getUserFacade().count(new UserCriteria());
    UserSyncProgressLayout progressLayout = new UserSyncProgressLayout(totalCount, currentUI, this::cancelImport);
    userSyncCallback = progressLayout::updateProgress;
    Window window = VaadinUiUtil.createPopupWindow();
    window.setCaption(I18nProperties.getString(Strings.headingSyncUsers));
    window.setWidth(800, Sizeable.Unit.PIXELS);
    window.setContent(progressLayout);
    window.setClosable(false);
    currentUI.addWindow(window);
    Thread importThread = new Thread(() -> {
        try {
            currentUI.setPollInterval(300);
            ImportResultStatus importResult = runUserSync();
            // Display a window presenting the import result
            currentUI.access(() -> {
                window.setClosable(true);
                progressLayout.makeClosable(window::close);
                if (importResult == ImportResultStatus.COMPLETED) {
                    progressLayout.displaySuccessIcon();
                    progressLayout.setInfoLabelText(I18nProperties.getString(Strings.messageUserSyncSuccessful));
                } else if (importResult == ImportResultStatus.COMPLETED_WITH_ERRORS) {
                    progressLayout.displayWarningIcon();
                    progressLayout.setInfoLabelText(I18nProperties.getString(Strings.messageUserSyncPartiallySuccessful));
                } else if (importResult == ImportResultStatus.CANCELED) {
                    progressLayout.displaySuccessIcon();
                    progressLayout.setInfoLabelText(I18nProperties.getString(Strings.messageUserSyncCanceled));
                } else {
                    progressLayout.displayWarningIcon();
                    progressLayout.setInfoLabelText(I18nProperties.getString(Strings.messageUserSyncCanceledErrors));
                }
                window.addCloseListener(e -> {
                    if (importResult == ImportResultStatus.COMPLETED_WITH_ERRORS || importResult == ImportResultStatus.CANCELED_WITH_ERRORS) {
                        StreamResource streamResource = createErrorReportStreamResource();
                        errorReportConsumer.accept(streamResource);
                    }
                });
                currentUI.setPollInterval(-1);
            });
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            currentUI.access(() -> {
                window.setClosable(true);
                progressLayout.makeClosable(window::close);
                progressLayout.displayErrorIcon();
                progressLayout.setInfoLabelText(I18nProperties.getString(Strings.messageUserSyncFailedFull));
                currentUI.setPollInterval(-1);
            });
        }
    });
    importThread.start();
}
Also used : Window(com.vaadin.ui.Window) StreamResource(com.vaadin.server.StreamResource) UserCriteria(de.symeda.sormas.api.user.UserCriteria) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) IOException(java.io.IOException)

Aggregations

UserCriteria (de.symeda.sormas.api.user.UserCriteria)3 UserDto (de.symeda.sormas.api.user.UserDto)2 StreamResource (com.vaadin.server.StreamResource)1 Window (com.vaadin.ui.Window)1 EntityDto (de.symeda.sormas.api.EntityDto)1 SortProperty (de.symeda.sormas.api.utils.SortProperty)1 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)1 Region (de.symeda.sormas.backend.infrastructure.region.Region)1 RegionService (de.symeda.sormas.backend.infrastructure.region.RegionService)1 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)1 IOException (java.io.IOException)1 Test (org.junit.Test)1