Search in sources :

Example 26 with User

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

the class VisitFacadeEjb method getVisitsExportList.

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public List<VisitExportDto> getVisitsExportList(VisitCriteria visitCriteria, Collection<String> selectedRows, VisitExportType exportType, int first, int max, ExportConfigurationDto exportConfiguration) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<VisitExportDto> cq = cb.createQuery(VisitExportDto.class);
    final Root<Visit> visitRoot = cq.from(Visit.class);
    final Join<Visit, Symptoms> symptomsJoin = visitRoot.join(Visit.SYMPTOMS, JoinType.LEFT);
    final Join<Visit, Person> personJoin = visitRoot.join(Visit.PERSON, JoinType.LEFT);
    final Join<Visit, User> userJoin = visitRoot.join(Visit.VISIT_USER, JoinType.LEFT);
    final Join<Visit, Case> caseJoin = visitRoot.join(Visit.CAZE, JoinType.LEFT);
    final Join<Visit, Contact> contactJoin = visitRoot.join(Visit.CONTACTS, JoinType.LEFT);
    cq.multiselect(visitRoot.get(Visit.ID), visitRoot.get(Visit.UUID), personJoin.get(Person.ID), personJoin.get(Person.FIRST_NAME), personJoin.get(Person.LAST_NAME), symptomsJoin.get(Symptoms.ID), userJoin.get(User.ID), visitRoot.get(Visit.DISEASE), visitRoot.get(Visit.VISIT_DATE_TIME), visitRoot.get(Visit.VISIT_STATUS), visitRoot.get(Visit.VISIT_REMARKS), visitRoot.get(Visit.REPORT_LAT), visitRoot.get(Visit.REPORT_LON), visitRoot.get(Visit.ORIGIN), personJoin.get(Person.UUID), jurisdictionSelector(cq, cb, caseJoin, contactJoin));
    Predicate filter = visitService.buildCriteriaFilter(visitCriteria, cb, visitRoot);
    filter = CriteriaBuilderHelper.andInValues(selectedRows, filter, cb, visitRoot.get(Visit.UUID));
    if (filter != null) {
        cq.where(filter);
    }
    cq.orderBy(cb.desc(visitRoot.get(Visit.VISIT_DATE_TIME)), cb.desc(visitRoot.get(Case.ID)));
    List<VisitExportDto> resultList = QueryHelper.getResultList(em, cq, first, max);
    if (!resultList.isEmpty()) {
        Map<Long, Symptoms> symptoms = null;
        if (exportConfiguration == null || exportConfiguration.getProperties().contains(CaseDataDto.SYMPTOMS)) {
            List<Symptoms> symptomsList = null;
            CriteriaQuery<Symptoms> symptomsCq = cb.createQuery(Symptoms.class);
            Root<Symptoms> symptomsRoot = symptomsCq.from(Symptoms.class);
            Expression<String> symptomsIdsExpr = symptomsRoot.get(Symptoms.ID);
            symptomsCq.where(symptomsIdsExpr.in(resultList.stream().map(VisitExportDto::getSymptomsId).collect(Collectors.toList())));
            symptomsList = em.createQuery(symptomsCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList();
            symptoms = symptomsList.stream().collect(Collectors.toMap(Symptoms::getId, Function.identity()));
        }
        if (resultList.size() > 0) {
            Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight);
            for (VisitExportDto exportDto : resultList) {
                boolean inJurisdiction = exportDto.getInJurisdiction();
                pseudonymizer.pseudonymizeDto(VisitExportDto.class, exportDto, inJurisdiction, v -> {
                    if (v.getSymptoms() != null) {
                        pseudonymizer.pseudonymizeDto(SymptomsDto.class, v.getSymptoms(), inJurisdiction, null);
                    }
                });
                if (symptoms != null) {
                    Optional.ofNullable(symptoms.get(exportDto.getSymptomsId())).ifPresent(symptom -> exportDto.setSymptoms(SymptomsFacadeEjb.toDto(symptom)));
                }
            }
        }
    }
    return resultList;
}
Also used : User(de.symeda.sormas.backend.user.User) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) VisitExportDto(de.symeda.sormas.api.visit.VisitExportDto) Contact(de.symeda.sormas.backend.contact.Contact) Person(de.symeda.sormas.backend.person.Person) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 27 with User

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

the class VaccinationFacadeEjb method restorePseudonymizedDto.

private void restorePseudonymizedDto(VaccinationDto dto, VaccinationDto existingDto, Vaccination vaccination, Pseudonymizer pseudonymizer) {
    if (existingDto != null) {
        final boolean inJurisdiction = immunizationService.inJurisdictionOrOwned(vaccination.getImmunization());
        final User currentUser = userService.getCurrentUser();
        pseudonymizer.restoreUser(vaccination.getReportingUser(), currentUser, dto, dto::setReportingUser);
        pseudonymizer.restorePseudonymizedValues(VaccinationDto.class, dto, existingDto, inJurisdiction);
    }
}
Also used : User(de.symeda.sormas.backend.user.User)

Example 28 with User

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

the class MockDataGenerator method createUser.

public static User createUser(Set<UserRole> userRoles, String firstName, String lastName, String password) {
    User user = new User();
    user.setFirstName(firstName);
    user.setLastName(lastName);
    if (CollectionUtils.isNotEmpty(userRoles)) {
        user.setUserRoles(new HashSet<>(userRoles));
    }
    user.updateJurisdictionLevel();
    user.setUserName(UserHelper.getSuggestedUsername(user.getFirstName(), user.getLastName()));
    user.setSeed(PasswordHelper.createPass(16));
    user.setPassword(PasswordHelper.encodePassword(password, user.getSeed()));
    return user;
}
Also used : User(de.symeda.sormas.backend.user.User)

Example 29 with User

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

the class CampaignFormDataService method createUserFilter.

@Override
public Predicate createUserFilter(CriteriaBuilder cb, CriteriaQuery cq, From<?, CampaignFormData> campaignPath) {
    final User currentUser = getCurrentUser();
    if (currentUser == null) {
        return null;
    }
    Predicate filter = null;
    final JurisdictionLevel jurisdictionLevel = currentUser.getCalculatedJurisdictionLevel();
    if (jurisdictionLevel != JurisdictionLevel.NATION) {
        switch(jurisdictionLevel) {
            case REGION:
                final Region region = currentUser.getRegion();
                if (region != null) {
                    filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(campaignPath.get(CampaignFormData.REGION).get(Region.ID), region.getId()));
                }
                break;
            case DISTRICT:
                final District district = currentUser.getDistrict();
                if (district != null) {
                    filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(campaignPath.get(CampaignFormData.DISTRICT).get(District.ID), district.getId()));
                }
                break;
            case COMMUNITY:
                final Community community = currentUser.getCommunity();
                if (community != null) {
                    filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(campaignPath.get(CampaignFormData.COMMUNITY).get(Community.ID), community.getId()));
                }
                break;
            default:
                return null;
        }
    }
    return filter;
}
Also used : User(de.symeda.sormas.backend.user.User) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community) Predicate(javax.persistence.criteria.Predicate)

Example 30 with User

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

the class ActionService method getEventActionExportList.

public List<EventActionExportDto> getEventActionExportList(EventCriteria criteria, Integer first, Integer max) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<EventActionExportDto> cq = cb.createQuery(EventActionExportDto.class);
    Root<Action> action = cq.from(getElementClass());
    final ActionQueryContext actionQueryContext = new ActionQueryContext(cb, cq, action);
    ActionJoins actionJoins = (ActionJoins) actionQueryContext.getJoins();
    Join<Action, User> lastModifiedBy = actionJoins.getLastModifiedBy();
    Join<Action, User> creator = actionJoins.getCreator();
    Join<Action, Event> event = actionJoins.getEvent(JoinType.INNER);
    Join<Event, User> eventReportingUser = event.join(Event.REPORTING_USER, JoinType.LEFT);
    Join<Event, User> eventResponsibleUser = event.join(Event.RESPONSIBLE_USER, JoinType.LEFT);
    // Add filters
    Predicate filter = eventService.createUserFilter(cb, cq, event);
    if (criteria != null) {
        Predicate criteriaFilter = buildEventCriteriaFilter(criteria, actionQueryContext);
        filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
    }
    if (filter != null) {
        cq.where(filter);
    }
    cq.multiselect(event.get(Event.UUID), event.get(Event.EVENT_TITLE), event.get(Event.DISEASE), event.get(Event.DISEASE_VARIANT), event.get(Event.DISEASE_DETAILS), event.get(Event.EVENT_DESC), event.get(Event.EVENT_IDENTIFICATION_SOURCE), event.get(Event.START_DATE), event.get(Event.END_DATE), event.get(Event.EVOLUTION_DATE), event.get(Event.EVOLUTION_COMMENT), event.get(Event.EVENT_STATUS), event.get(Event.RISK_LEVEL), event.get(Event.EVENT_INVESTIGATION_STATUS), eventReportingUser.get(User.UUID), eventReportingUser.get(User.FIRST_NAME), eventReportingUser.get(User.LAST_NAME), eventResponsibleUser.get(User.UUID), eventResponsibleUser.get(User.FIRST_NAME), eventResponsibleUser.get(User.LAST_NAME), action.get(Action.ACTION_MEASURE), action.get(Action.TITLE), action.get(Action.CREATION_DATE), action.get(Action.CHANGE_DATE), action.get(Action.DATE), action.get(Action.ACTION_STATUS), action.get(Action.PRIORITY), lastModifiedBy.get(User.UUID), lastModifiedBy.get(User.FIRST_NAME), lastModifiedBy.get(User.LAST_NAME), creator.get(User.UUID), creator.get(User.FIRST_NAME), creator.get(User.LAST_NAME));
    cq.orderBy(cb.desc(event.get(Event.CHANGE_DATE)));
    return QueryHelper.getResultList(em, cq, first, max);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EventActionExportDto(de.symeda.sormas.api.event.EventActionExportDto) User(de.symeda.sormas.backend.user.User) Predicate(javax.persistence.criteria.Predicate) Event(de.symeda.sormas.backend.event.Event)

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