Search in sources :

Example 21 with User

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

the class NotificationServiceTest method testSendNotifications_loadUsersByRoles.

@Test
public void testSendNotifications_loadUsersByRoles() throws NotificationDeliveryFailedException {
    TestDataCreator.RDCF rdcf = creator.createRDCF();
    Region region = getRegionService().getByReferenceDto(rdcf.region);
    UserDto survSup = creator.createUser(rdcf, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    UserDto caseSup = creator.createUser(rdcf, "Case", "Sup", UserRole.CASE_SUPERVISOR);
    Mockito.when(userService.getAllByRegionsAndUserRoles(any(), any())).then(invocation -> {
        return getUserService().getAllByRegionsAndUserRoles((List<Region>) invocation.getArgument(0), (UserRole) invocation.getArgument(1), (UserRole) invocation.getArgument(2));
    });
    Mockito.doAnswer(invocation -> {
        Map<User, String> userMessages = (Map<User, String>) invocation.getArgument(0);
        assertThat(userMessages.size(), is(2));
        assertThat(userMessages.get(getUserService().getByReferenceDto(survSup.toReference())), is("Test message"));
        assertThat(userMessages.get(getUserService().getByReferenceDto(caseSup.toReference())), is("Test message"));
        return null;
    }).when(messagingService).sendEmail(any(), any(), any());
    notificationService.sendNotifications(NotificationType.CASE_LAB_RESULT_ARRIVED, Collections.singletonList(region), null, MessageSubject.LAB_RESULT_ARRIVED, "Test message");
    Mockito.verify(messagingService, Mockito.times(1)).sendEmail(any(), any(), any());
    Mockito.verify(messagingService, Mockito.times(1)).sendSms(any(), any(), any());
}
Also used : User(de.symeda.sormas.backend.user.User) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) Region(de.symeda.sormas.backend.infrastructure.region.Region) HashMap(java.util.HashMap) Map(java.util.Map) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 22 with User

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

the class DirectoryImmunizationService method createUserFilter.

private Predicate createUserFilter(DirectoryImmunizationQueryContext<DirectoryImmunization> qc) {
    final User currentUser = userService.getCurrentUser();
    final CriteriaBuilder cb = qc.getCriteriaBuilder();
    Predicate filter;
    if (!featureConfigurationFacade.isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
        filter = DirectoryImmunizationJurisdictionPredicateValidator.of(qc, currentUser).inJurisdictionOrOwned();
    } else {
        filter = CriteriaBuilderHelper.or(qc.getCriteriaBuilder(), qc.getCriteriaBuilder().equal(qc.getRoot().get(Immunization.REPORTING_USER), currentUser), PersonJurisdictionPredicateValidator.of(qc.getQuery(), qc.getCriteriaBuilder(), new PersonJoins<>(((DirectoryImmunizationJoins<DirectoryImmunization>) qc.getJoins()).getPerson()), currentUser, false).inJurisdictionOrOwned());
    }
    if (currentUser.getLimitedDisease() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(qc.getRoot().get(Contact.DISEASE), currentUser.getLimitedDisease()));
    }
    return filter;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DirectoryImmunization(de.symeda.sormas.backend.immunization.entity.DirectoryImmunization) User(de.symeda.sormas.backend.user.User) PersonJoins(de.symeda.sormas.backend.person.PersonJoins) Predicate(javax.persistence.criteria.Predicate)

Example 23 with User

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

the class ImmunizationFacadeEjb method restorePseudonymizedDto.

protected void restorePseudonymizedDto(ImmunizationDto dto, ImmunizationDto existingDto, Immunization entity, Pseudonymizer pseudonymizer) {
    if (existingDto != null) {
        final boolean inJurisdiction = service.inJurisdictionOrOwned(entity);
        final User currentUser = userService.getCurrentUser();
        pseudonymizer.restoreUser(entity.getReportingUser(), currentUser, dto, dto::setReportingUser);
        pseudonymizer.restorePseudonymizedValues(ImmunizationDto.class, dto, existingDto, inJurisdiction);
    }
}
Also used : User(de.symeda.sormas.backend.user.User)

Example 24 with User

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

the class AbstractInfrastructureFacadeEjb method doSave.

protected DTO doSave(DTO dtoToSave, boolean allowMerge, boolean includeArchived, boolean checkChangeDate, String duplicateErrorMessageProperty) {
    if (dtoToSave == null) {
        return null;
    }
    ADO existingEntity = service.getByUuid(dtoToSave.getUuid());
    final User currentUser = userService.getCurrentUser();
    if (currentUser != null) {
        if (existingEntity == null && !userService.hasRight(UserRight.INFRASTRUCTURE_CREATE)) {
            throw new UnsupportedOperationException("User " + currentUser.getUuid() + " is not allowed to create infrastructure data.");
        }
        if (existingEntity != null && !userService.hasRight(UserRight.INFRASTRUCTURE_EDIT)) {
            throw new UnsupportedOperationException("User " + currentUser.getUuid() + " is not allowed to edit infrastructure data.");
        }
    }
    if (existingEntity == null) {
        List<ADO> duplicates = findDuplicates(dtoToSave, includeArchived);
        if (!duplicates.isEmpty()) {
            if (allowMerge) {
                return mergeAndPersist(dtoToSave, duplicates, checkChangeDate);
            } else {
                throw new ValidationRuntimeException(I18nProperties.getValidationError(duplicateErrorMessageProperty));
            }
        }
    }
    return persistEntity(dtoToSave, existingEntity, checkChangeDate);
}
Also used : User(de.symeda.sormas.backend.user.User) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException)

Example 25 with User

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

the class ExportFacadeEjb method getExportConfigurations.

@Override
public List<ExportConfigurationDto> getExportConfigurations(ExportConfigurationCriteria criteria, boolean isPublic) {
    User user = userService.getCurrentUser();
    if (user == null) {
        return Collections.emptyList();
    }
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<ExportConfiguration> cq = cb.createQuery(ExportConfiguration.class);
    Root<ExportConfiguration> config = cq.from(ExportConfiguration.class);
    Predicate criteriaFilters = buildExportConfigurationCriteriaFilter(criteria, cb, config);
    Predicate filters;
    if (isPublic) {
        filters = CriteriaBuilderHelper.and(cb, criteriaFilters, cb.equal(config.get(ExportConfiguration.SHARED_TO_PUBLIC), true), cb.notEqual(config.get(ExportConfiguration.USER), user));
    } else {
        filters = CriteriaBuilderHelper.and(cb, criteriaFilters, cb.equal(config.get(ExportConfiguration.USER), user));
    }
    cq.where(filters);
    cq.orderBy(cb.desc(config.get(ExportConfiguration.CHANGE_DATE)));
    return em.createQuery(cq).getResultList().stream().map(ExportFacadeEjb::toExportConfigurationDto).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) User(de.symeda.sormas.backend.user.User) Predicate(javax.persistence.criteria.Predicate)

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