Search in sources :

Example 16 with Event

use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.

the class AbstractEventService method updateEvents.

// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
@Override
public ImportSummaries updateEvents(List<Event> events, boolean singleValue) {
    ImportSummaries importSummaries = new ImportSummaries();
    int counter = 0;
    User user = currentUserService.getCurrentUser();
    for (Event event : events) {
        importSummaries.addImportSummary(updateEvent(event, user, singleValue, null));
        if (counter % FLUSH_FREQUENCY == 0) {
            clearSession();
        }
        counter++;
    }
    return importSummaries;
}
Also used : User(org.hisp.dhis.user.User) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries)

Example 17 with Event

use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.

the class AbstractEventService method getFromUrl.

@Override
public EventSearchParams getFromUrl(String program, String programStage, ProgramStatus programStatus, Boolean followUp, String orgUnit, OrganisationUnitSelectionMode orgUnitSelectionMode, String trackedEntityInstance, Date startDate, Date endDate, Date dueDateStart, Date dueDateEnd, Date lastUpdatedStartDate, Date lastUpdatedEndDate, EventStatus status, DataElementCategoryOptionCombo attributeOptionCombo, IdSchemes idSchemes, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, List<Order> orders, List<String> gridOrders, boolean includeAttributes, Set<String> events, Set<String> filters, Set<String> dataElements, boolean includeDeleted) {
    UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
    EventSearchParams params = new EventSearchParams();
    Program pr = programService.getProgram(program);
    if (StringUtils.isNotEmpty(program) && pr == null) {
        throw new IllegalQueryException("Program is specified but does not exist: " + program);
    }
    ProgramStage ps = programStageService.getProgramStage(programStage);
    if (StringUtils.isNotEmpty(programStage) && ps == null) {
        throw new IllegalQueryException("Program stage is specified but does not exist: " + programStage);
    }
    OrganisationUnit ou = organisationUnitService.getOrganisationUnit(orgUnit);
    if (StringUtils.isNotEmpty(orgUnit) && ou == null) {
        throw new IllegalQueryException("Org unit is specified but does not exist: " + orgUnit);
    }
    if (ou != null && !organisationUnitService.isInUserHierarchy(ou)) {
        if (!userCredentials.isSuper() && !userCredentials.isAuthorized("F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS")) {
            throw new IllegalQueryException("User has no access to organisation unit: " + ou.getUid());
        }
    }
    if (pr != null && !userCredentials.isSuper() && !userCredentials.canAccessProgram(pr)) {
        throw new IllegalQueryException("User has no access to program: " + pr.getUid());
    }
    TrackedEntityInstance tei = entityInstanceService.getTrackedEntityInstance(trackedEntityInstance);
    if (StringUtils.isNotEmpty(trackedEntityInstance) && tei == null) {
        throw new IllegalQueryException("Tracked entity instance is specified but does not exist: " + trackedEntityInstance);
    }
    if (events != null && filters != null) {
        throw new IllegalQueryException("Event UIDs and filters can not be specified at the same time");
    }
    if (events == null) {
        events = new HashSet<>();
    }
    if (filters != null) {
        if (StringUtils.isNotEmpty(programStage) && ps == null) {
            throw new IllegalQueryException("ProgramStage needs to be specified for event filtering to work");
        }
        for (String filter : filters) {
            QueryItem item = getQueryItem(filter);
            params.getFilters().add(item);
        }
    }
    if (dataElements != null) {
        for (String de : dataElements) {
            QueryItem dataElement = getQueryItem(de);
            params.getDataElements().add(dataElement);
        }
    }
    params.setProgram(pr);
    params.setProgramStage(ps);
    params.setOrgUnit(ou);
    params.setTrackedEntityInstance(tei);
    params.setProgramStatus(programStatus);
    params.setFollowUp(followUp);
    params.setOrgUnitSelectionMode(orgUnitSelectionMode);
    params.setStartDate(startDate);
    params.setEndDate(endDate);
    params.setDueDateStart(dueDateStart);
    params.setDueDateEnd(dueDateEnd);
    params.setLastUpdatedStartDate(lastUpdatedStartDate);
    params.setLastUpdatedEndDate(lastUpdatedEndDate);
    params.setEventStatus(status);
    params.setCategoryOptionCombo(attributeOptionCombo);
    params.setIdSchemes(idSchemes);
    params.setPage(page);
    params.setPageSize(pageSize);
    params.setTotalPages(totalPages);
    params.setSkipPaging(skipPaging);
    params.setIncludeAttributes(includeAttributes);
    params.setOrders(orders);
    params.setGridOrders(gridOrders);
    params.setEvents(events);
    params.setIncludeDeleted(includeDeleted);
    return params;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) QueryItem(org.hisp.dhis.common.QueryItem) Program(org.hisp.dhis.program.Program) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) UserCredentials(org.hisp.dhis.user.UserCredentials) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 18 with Event

use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.

the class AbstractEventService method addEvents.

// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@Override
public ImportSummaries addEvents(List<Event> events, ImportOptions importOptions) {
    ImportSummaries importSummaries = new ImportSummaries();
    int counter = 0;
    User user = currentUserService.getCurrentUser();
    for (Event event : events) {
        importSummaries.addImportSummary(addEvent(event, user, importOptions));
        if (counter % FLUSH_FREQUENCY == 0) {
            clearSession();
        }
        counter++;
    }
    return importSummaries;
}
Also used : User(org.hisp.dhis.user.User) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries)

Example 19 with Event

use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.

the class AbstractEnrollmentService method handleEvents.

// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
private ImportSummaries handleEvents(Enrollment enrollment, ProgramInstance programInstance, ImportOptions importOptions) {
    List<Event> create = new ArrayList<>();
    List<Event> update = new ArrayList<>();
    for (Event event : enrollment.getEvents()) {
        event.setEnrollment(enrollment.getEnrollment());
        event.setProgram(programInstance.getProgram().getUid());
        if (!programStageInstanceService.programStageInstanceExists(event.getEvent())) {
            create.add(event);
        } else {
            update.add(event);
        }
    }
    ImportSummaries importSummaries = new ImportSummaries();
    importSummaries.addImportSummaries(eventService.addEvents(create, importOptions));
    importSummaries.addImportSummaries(eventService.updateEvents(update, false));
    return importSummaries;
}
Also used : ArrayList(java.util.ArrayList) Event(org.hisp.dhis.dxf2.events.event.Event) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries)

Example 20 with Event

use of org.hisp.dhis.dxf2.events.event.Event in project dhis2-core by dhis2.

the class EventController method getEvent.

@RequestMapping(value = "/{uid}", method = RequestMethod.GET)
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public Event getEvent(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request) throws Exception {
    Event event = eventService.getEvent(uid);
    if (event == null) {
        throw new WebMessageException(WebMessageUtils.notFound("Event not found for ID " + uid));
    }
    event.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + uid);
    return event;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Event(org.hisp.dhis.dxf2.events.event.Event) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Event (org.hisp.dhis.dxf2.events.event.Event)30 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)24 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 DhisSpringTest (org.hisp.dhis.DhisSpringTest)12 Test (org.junit.Test)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 InputStream (java.io.InputStream)9 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)9 EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)9 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)9 Date (java.util.Date)8 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)7 Events (org.hisp.dhis.dxf2.events.event.Events)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 IOException (java.io.IOException)5 DataElement (org.hisp.dhis.dataelement.DataElement)5 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)5 Program (org.hisp.dhis.program.Program)5 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)5