Search in sources :

Example 1 with User

use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjb method getIndexDetailedList.

@Override
public List<ContactIndexDetailedDto> getIndexDetailedList(ContactCriteria contactCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    CriteriaQuery<ContactIndexDetailedDto> query = listCriteriaBuilder.buildIndexDetailedCriteria(contactCriteria, sortProperties);
    List<ContactIndexDetailedDto> dtos = QueryHelper.getResultList(em, query, first, max);
    // Load event count and latest events info per contact
    Map<String, List<ContactEventSummaryDetails>> eventSummaries = eventService.getEventSummaryDetailsByContacts(dtos.stream().map(ContactIndexDetailedDto::getUuid).collect(Collectors.toList())).stream().collect(Collectors.groupingBy(ContactEventSummaryDetails::getContactUuid, Collectors.toList()));
    for (ContactIndexDetailedDto contact : dtos) {
        List<ContactEventSummaryDetails> contactEvents = eventSummaries.getOrDefault(contact.getUuid(), Collections.emptyList());
        contact.setEventCount((long) contactEvents.size());
        contactEvents.stream().max(Comparator.comparing(ContactEventSummaryDetails::getEventDate)).ifPresent(eventSummary -> {
            contact.setLatestEventId(eventSummary.getEventUuid());
            contact.setLatestEventTitle(eventSummary.getEventTitle());
        });
    }
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    User currentUser = userService.getCurrentUser();
    pseudonymizer.pseudonymizeDtoCollection(ContactIndexDetailedDto.class, dtos, c -> c.getInJurisdiction(), (c, isInJurisdiction) -> {
        pseudonymizer.pseudonymizeUser(userService.getByUuid(c.getReportingUser().getUuid()), currentUser, c::setReportingUser);
        if (c.getCaze() != null) {
            pseudonymizer.pseudonymizeDto(CaseReferenceDto.class, c.getCaze(), c.getCaseInJurisdiction(), null);
        }
    });
    return dtos;
}
Also used : Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) User(de.symeda.sormas.backend.user.User) ContactLogic(de.symeda.sormas.api.contact.ContactLogic) ContactEventSummaryDetails(de.symeda.sormas.backend.event.ContactEventSummaryDetails) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto)

Example 2 with User

use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class StartupShutdownService method createAndPersistDefaultUser.

private User createAndPersistDefaultUser(UserRole userRole, String firstName, String lastName, DataHelper.Pair<String, String> usernameAndPassword, Consumer<User> userModificator) {
    User user = MockDataGenerator.createUser(userRole, firstName, lastName, usernameAndPassword.getElement1());
    user.setUserName(usernameAndPassword.getElement0());
    userModificator.accept(user);
    userService.persist(user);
    userUpdateEvent.fire(new UserUpdateEvent(user));
    return user;
}
Also used : UserUpdateEvent(de.symeda.sormas.backend.user.event.UserUpdateEvent) User(de.symeda.sormas.backend.user.User)

Example 3 with User

use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class StartupShutdownService method syncUsers.

/**
 * Synchronizes all active users with the external Authentication Provider if User Sync at startup is enabled and supported.
 *
 * @see AuthProvider#isUserSyncSupported()
 * @see AuthProvider#isUserSyncAtStartupEnabled()
 */
private void syncUsers() {
    AuthProvider authProvider = AuthProvider.getProvider(configFacade);
    if (!authProvider.isUserSyncSupported()) {
        logger.info("Active Authentication Provider {} doesn't support user sync", authProvider.getName());
        return;
    }
    if (!authProvider.isUserSyncAtStartupEnabled()) {
        logger.info("User sync at startup is disabled. Enable this in SORMAS properties if the active Authentication Provider supports it");
        return;
    }
    List<User> users = userService.getAllActive();
    for (User user : users) {
        syncUser(user);
    }
    logger.info("User synchronization finalized");
}
Also used : User(de.symeda.sormas.backend.user.User) AuthProvider(de.symeda.sormas.api.AuthProvider)

Example 4 with User

use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class StartupShutdownService method createOrUpdateDefaultUser.

private void createOrUpdateDefaultUser(Set<UserRole> userRoles, String username, String password, String firstName, String lastName) {
    if (StringUtils.isAnyBlank(username, password)) {
        logger.debug("Invalid user details. Will not create/update default user");
        return;
    }
    User existingUser = userService.getByUserName(username);
    if (existingUser == null) {
        if (!DataHelper.isNullOrEmpty(password)) {
            User newUser = MockDataGenerator.createUser(userRoles, firstName, lastName, password);
            newUser.setUserName(username);
            userService.persist(newUser);
            userUpdateEvent.fire(new UserUpdateEvent(newUser));
        }
    } else if (!DataHelper.equal(existingUser.getPassword(), PasswordHelper.encodePassword(password, existingUser.getSeed()))) {
        existingUser.setSeed(PasswordHelper.createPass(16));
        existingUser.setPassword(PasswordHelper.encodePassword(password, existingUser.getSeed()));
        userService.persist(existingUser);
        passwordResetEvent.fire(new PasswordResetEvent(existingUser));
    }
}
Also used : UserUpdateEvent(de.symeda.sormas.backend.user.event.UserUpdateEvent) User(de.symeda.sormas.backend.user.User) PasswordResetEvent(de.symeda.sormas.backend.user.event.PasswordResetEvent)

Example 5 with User

use of de.symeda.sormas.backend.user.User in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjb method getDeathsBetween.

@Override
public List<PersonDto> getDeathsBetween(Date fromDate, Date toDate, DistrictReferenceDto districtRef, Disease disease) {
    final User user = userService.getCurrentUser();
    if (user == null) {
        return Collections.emptyList();
    }
    final District district = districtService.getByReferenceDto(districtRef);
    return toPseudonymizedDtos(personService.getDeathsBetween(fromDate, toDate, district, disease, user));
}
Also used : User(de.symeda.sormas.backend.user.User) District(de.symeda.sormas.backend.infrastructure.district.District)

Aggregations

User (de.symeda.sormas.backend.user.User)138 Predicate (javax.persistence.criteria.Predicate)61 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)51 List (java.util.List)48 Region (de.symeda.sormas.backend.infrastructure.region.Region)43 Collections (java.util.Collections)42 ArrayList (java.util.ArrayList)40 DataHelper (de.symeda.sormas.api.utils.DataHelper)38 Date (java.util.Date)38 Stateless (javax.ejb.Stateless)38 EJB (javax.ejb.EJB)37 LocalBean (javax.ejb.LocalBean)37 District (de.symeda.sormas.backend.infrastructure.district.District)36 Collectors (java.util.stream.Collectors)36 UserRole (de.symeda.sormas.api.user.UserRole)34 UserService (de.symeda.sormas.backend.user.UserService)33 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)33 Case (de.symeda.sormas.backend.caze.Case)32 Root (javax.persistence.criteria.Root)32 Disease (de.symeda.sormas.api.Disease)31