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);
}
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"));
}
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();
}
Aggregations