Search in sources :

Example 1 with EventQueryContext

use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.

the class ActionService method buildEventCriteriaFilter.

public Predicate buildEventCriteriaFilter(EventCriteria criteria, ActionQueryContext actionQueryContext) {
    CriteriaBuilder cb = actionQueryContext.getCriteriaBuilder();
    ActionJoins joins = (ActionJoins) actionQueryContext.getJoins();
    From<Action, Action> action = joins.getRoot();
    From<Action, Event> event = joins.getEvent(JoinType.INNER);
    Predicate filter = eventService.buildCriteriaFilter(criteria, new EventQueryContext(cb, actionQueryContext.getQuery(), event));
    if (criteria.getActionChangeDateFrom() != null && criteria.getActionChangeDateTo() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.between(action.get(Action.CHANGE_DATE), criteria.getActionChangeDateFrom(), criteria.getActionChangeDateTo()));
    } else if (criteria.getActionChangeDateFrom() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.greaterThanOrEqualTo(action.get(Action.CHANGE_DATE), criteria.getActionChangeDateFrom()));
    } else if (criteria.getActionChangeDateTo() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.lessThanOrEqualTo(action.get(Action.CHANGE_DATE), criteria.getActionChangeDateTo()));
    }
    if (criteria.getActionDateFrom() != null && criteria.getActionDateTo() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.between(action.get(Action.DATE), criteria.getActionDateFrom(), criteria.getActionDateTo()));
    } else if (criteria.getActionDateFrom() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.greaterThanOrEqualTo(action.get(Action.DATE), criteria.getActionDateFrom()));
    } else if (criteria.getActionDateTo() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.lessThanOrEqualTo(action.get(Action.DATE), criteria.getActionDateTo()));
    }
    if (criteria.getActionStatus() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(action.get(Action.ACTION_STATUS), criteria.getActionStatus()));
    }
    return filter;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Event(de.symeda.sormas.backend.event.Event) EventQueryContext(de.symeda.sormas.backend.event.EventQueryContext) Predicate(javax.persistence.criteria.Predicate)

Example 2 with EventQueryContext

use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.

the class TaskJurisdictionPredicateValidator method of.

public static TaskJurisdictionPredicateValidator of(TaskQueryContext qc, User user) {
    final List<PredicateJurisdictionValidator> associatedJurisdictionValidators = new ArrayList<>();
    final CriteriaBuilder cb = qc.getCriteriaBuilder();
    final TaskJoins joins = (TaskJoins) qc.getJoins();
    associatedJurisdictionValidators.add(CaseJurisdictionPredicateValidator.of(new CaseQueryContext(cb, qc.getQuery(), joins.getCaze()), user));
    associatedJurisdictionValidators.add(ContactJurisdictionPredicateValidator.of(new ContactQueryContext(cb, qc.getQuery(), joins.getContact()), user));
    associatedJurisdictionValidators.add(EventJurisdictionPredicateValidator.of(new EventQueryContext(cb, qc.getQuery(), joins.getEvent()), user));
    return new TaskJurisdictionPredicateValidator(cb, joins, user, associatedJurisdictionValidators);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) ArrayList(java.util.ArrayList) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) PredicateJurisdictionValidator(de.symeda.sormas.backend.util.PredicateJurisdictionValidator) EventQueryContext(de.symeda.sormas.backend.event.EventQueryContext)

Example 3 with EventQueryContext

use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.

the class TaskService method getJurisdictionSelections.

public List<Selection<?>> getJurisdictionSelections(TaskQueryContext qc) {
    CriteriaBuilder cb = qc.getCriteriaBuilder();
    TaskJoins joins = (TaskJoins) qc.getJoins();
    ContactJoins<Task> contactJoins = new ContactJoins<>(joins.getContact());
    return Arrays.asList(JurisdictionHelper.booleanSelector(cb, inJurisdictionOrOwned(qc)), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getCaze()), caseService.inJurisdictionOrOwned(new CaseQueryContext(cb, qc.getQuery(), joins.getCaze())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getContact()), contactService.inJurisdictionOrOwned(new ContactQueryContext<>(cb, qc.getQuery(), joins.getContact())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getContact()), cb.isNotNull(contactJoins.getCaze()), caseService.inJurisdictionOrOwned(new CaseQueryContext(cb, qc.getQuery(), contactJoins.getCaze())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getEvent()), eventService.inJurisdictionOrOwned(new EventQueryContext<>(cb, qc.getQuery(), joins.getEvent())))), JurisdictionHelper.booleanSelector(cb, cb.and(cb.isNotNull(joins.getTravelEntry()), travelEntryService.inJurisdictionOrOwned(new TravelEntryQueryContext(cb, qc.getQuery(), joins.getTravelEntry())))));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ContactJoins(de.symeda.sormas.backend.contact.ContactJoins) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) TravelEntryQueryContext(de.symeda.sormas.backend.travelentry.TravelEntryQueryContext) EventQueryContext(de.symeda.sormas.backend.event.EventQueryContext)

Example 4 with EventQueryContext

use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.

the class DashboardService method getEventCountByStatus.

public Map<EventStatus, Long> getEventCountByStatus(DashboardCriteria dashboardCriteria) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    Root<Event> event = cq.from(Event.class);
    EventQueryContext eventQueryContext = new EventQueryContext(cb, cq, event);
    cq.multiselect(event.get(Event.EVENT_STATUS), cb.count(event));
    cq.groupBy(event.get(Event.EVENT_STATUS));
    Predicate filter = eventService.createDefaultFilter(cb, event);
    filter = CriteriaBuilderHelper.and(cb, filter, buildEventCriteriaFilter(dashboardCriteria, eventQueryContext));
    filter = CriteriaBuilderHelper.and(cb, filter, eventService.createUserFilter(cb, cq, event));
    if (filter != null)
        cq.where(filter);
    List<Object[]> results = em.createQuery(cq).getResultList();
    return results.stream().collect(Collectors.toMap(e -> (EventStatus) e[0], e -> (Long) e[1]));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EventService(de.symeda.sormas.backend.event.EventService) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) DashboardEventDto(de.symeda.sormas.api.dashboard.DashboardEventDto) EventJoins(de.symeda.sormas.utils.EventJoins) StringUtils(org.apache.commons.lang3.StringUtils) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) From(javax.persistence.criteria.From) DashboardCaseDto(de.symeda.sormas.api.dashboard.DashboardCaseDto) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CaseService(de.symeda.sormas.backend.caze.CaseService) Person(de.symeda.sormas.backend.person.Person) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Collectors(java.util.stream.Collectors) List(java.util.List) User(de.symeda.sormas.backend.user.User) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) Order(javax.persistence.criteria.Order) Location(de.symeda.sormas.backend.location.Location) Community(de.symeda.sormas.backend.infrastructure.community.Community) CaseUserFilterCriteria(de.symeda.sormas.backend.caze.CaseUserFilterCriteria) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) DateHelper(de.symeda.sormas.api.utils.DateHelper) HashMap(java.util.HashMap) EventStatus(de.symeda.sormas.api.event.EventStatus) EventQueryContext(de.symeda.sormas.backend.event.EventQueryContext) ArrayList(java.util.ArrayList) Case(de.symeda.sormas.backend.caze.Case) DashboardCriteria(de.symeda.sormas.api.dashboard.DashboardCriteria) LocalBean(javax.ejb.LocalBean) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) CaseJoins(de.symeda.sormas.utils.CaseJoins) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Event(de.symeda.sormas.backend.event.Event) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Disease(de.symeda.sormas.api.Disease) Collections(java.util.Collections) EventStatus(de.symeda.sormas.api.event.EventStatus) Event(de.symeda.sormas.backend.event.Event) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) EventQueryContext(de.symeda.sormas.backend.event.EventQueryContext) Predicate(javax.persistence.criteria.Predicate)

Example 5 with EventQueryContext

use of de.symeda.sormas.backend.event.EventQueryContext in project SORMAS-Project by hzi-braunschweig.

the class DashboardService method getNewEvents.

public List<DashboardEventDto> getNewEvents(DashboardCriteria dashboardCriteria) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<DashboardEventDto> cq = cb.createQuery(DashboardEventDto.class);
    Root<Event> event = cq.from(Event.class);
    EventQueryContext eventQueryContext = new EventQueryContext(cb, cq, event);
    EventJoins<Event> eventJoins = (EventJoins<Event>) eventQueryContext.getJoins();
    Join<Event, Location> eventLocation = eventJoins.getLocation();
    Join<Location, District> eventDistrict = eventJoins.getDistrict();
    Predicate filter = eventService.createDefaultFilter(cb, event);
    filter = CriteriaBuilderHelper.and(cb, filter, buildEventCriteriaFilter(dashboardCriteria, eventQueryContext));
    filter = CriteriaBuilderHelper.and(cb, filter, eventService.createUserFilter(cb, cq, event));
    List<DashboardEventDto> result;
    if (filter != null) {
        cq.where(filter);
        cq.multiselect(event.get(Event.UUID), event.get(Event.EVENT_STATUS), event.get(Event.EVENT_INVESTIGATION_STATUS), event.get(Event.DISEASE), event.get(Event.DISEASE_DETAILS), event.get(Event.START_DATE), event.get(Event.REPORT_LAT), event.get(Event.REPORT_LON), eventLocation.get(Location.LATITUDE), eventLocation.get(Location.LONGITUDE), eventJoins.getReportingUser().get(User.UUID), eventJoins.getResponsibleUser().get(User.UUID), eventJoins.getRegion().get(Region.UUID), eventDistrict.get(District.NAME), eventDistrict.get(District.UUID), eventJoins.getCommunity().get(Community.UUID), JurisdictionHelper.booleanSelector(cb, eventService.inJurisdictionOrOwned(eventQueryContext)));
        result = em.createQuery(cq).getResultList();
    } else {
        result = Collections.emptyList();
    }
    return result;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EventQueryContext(de.symeda.sormas.backend.event.EventQueryContext) Predicate(javax.persistence.criteria.Predicate) Event(de.symeda.sormas.backend.event.Event) DashboardEventDto(de.symeda.sormas.api.dashboard.DashboardEventDto) EventJoins(de.symeda.sormas.utils.EventJoins) District(de.symeda.sormas.backend.infrastructure.district.District) Location(de.symeda.sormas.backend.location.Location)

Aggregations

EventQueryContext (de.symeda.sormas.backend.event.EventQueryContext)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 CaseQueryContext (de.symeda.sormas.backend.caze.CaseQueryContext)3 Event (de.symeda.sormas.backend.event.Event)3 Predicate (javax.persistence.criteria.Predicate)3 DashboardEventDto (de.symeda.sormas.api.dashboard.DashboardEventDto)2 ContactQueryContext (de.symeda.sormas.backend.contact.ContactQueryContext)2 District (de.symeda.sormas.backend.infrastructure.district.District)2 Location (de.symeda.sormas.backend.location.Location)2 EventJoins (de.symeda.sormas.utils.EventJoins)2 ArrayList (java.util.ArrayList)2 Disease (de.symeda.sormas.api.Disease)1 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)1 DashboardCaseDto (de.symeda.sormas.api.dashboard.DashboardCaseDto)1 DashboardCriteria (de.symeda.sormas.api.dashboard.DashboardCriteria)1 EventStatus (de.symeda.sormas.api.event.EventStatus)1 PresentCondition (de.symeda.sormas.api.person.PresentCondition)1 DateHelper (de.symeda.sormas.api.utils.DateHelper)1 Case (de.symeda.sormas.backend.caze.Case)1 CaseService (de.symeda.sormas.backend.caze.CaseService)1