Search in sources :

Example 31 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.

@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", value = MULTIPLE_SAVE_RESOURCE_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void saveCompleteDataSetRegistration(@RequestBody CompleteDataSetRegistrationRequests completeDataSetRegistrationRequests, HttpServletResponse response) throws WebMessageException {
    List<CompleteDataSetRegistration> registrations = new ArrayList<>();
    for (CompleteDataSetRegistrationRequest completeDataSetRegistrationRequest : completeDataSetRegistrationRequests) {
        String ds = completeDataSetRegistrationRequest.getDs();
        DataSet dataSet = dataSetService.getDataSet(ds);
        if (dataSet == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
        }
        String pe = completeDataSetRegistrationRequest.getPe();
        Period period = PeriodType.getPeriodFromIsoString(pe);
        if (period == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
        }
        String ou = completeDataSetRegistrationRequest.getOu();
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
        if (organisationUnit == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
        }
        String cc = completeDataSetRegistrationRequest.getCc();
        String cp = completeDataSetRegistrationRequest.getCp();
        DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
        if (attributeOptionCombo == null) {
            return;
        }
        // ---------------------------------------------------------------------
        // Check locked status
        // ---------------------------------------------------------------------
        boolean multiOu = completeDataSetRegistrationRequest.isMultiOu();
        if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
            throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
        }
        // ---------------------------------------------------------------------
        // Register as completed data set
        // ---------------------------------------------------------------------
        String sb = completeDataSetRegistrationRequest.getSb();
        String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
        Date cd = completeDataSetRegistrationRequest.getCd();
        Date completionDate = (cd == null) ? new Date() : cd;
        Set<OrganisationUnit> orgUnits = new HashSet<>();
        orgUnits.add(organisationUnit);
        if (multiOu) {
            orgUnits.addAll(organisationUnit.getChildren());
        }
        addRegistrationsForOrgUnits(registrations, orgUnits, dataSet, period, attributeOptionCombo, storedBy, completionDate);
    }
    registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistrationRequest(org.hisp.dhis.datacompletion.CompleteDataSetRegistrationRequest) Date(java.util.Date) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) HashSet(java.util.HashSet) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class TrackedEntityInstanceAggregate method filterAttributes.

/**
 * Filter attributes based on queryParams, ownership and super user status
 */
private List<Attribute> filterAttributes(Collection<Attribute> attributes, Collection<String> programs, Set<TrackedEntityAttribute> trackedEntityTypeAttributes, Map<Program, Set<TrackedEntityAttribute>> teaByProgram, AggregateContext ctx) {
    List<Attribute> attributeList = new ArrayList<>();
    // Nothing to filter from, return empty
    if (attributes.isEmpty()) {
        return attributeList;
    }
    // Add all tet attributes. Conditionally filter out the ones marked for
    // skipSynchronization in case this is a dataSynchronization query
    Set<String> allowedAttributeUids = trackedEntityTypeAttributes.stream().filter(att -> (!ctx.getParams().isDataSynchronizationQuery() || !att.getSkipSynchronization())).map(BaseIdentifiableObject::getUid).collect(Collectors.toSet());
    for (Program program : teaByProgram.keySet()) {
        if (programs.contains(program.getUid()) || ctx.isSuperUser()) {
            allowedAttributeUids.addAll(teaByProgram.get(program).stream().filter(att -> (!ctx.getParams().isDataSynchronizationQuery() || !att.getSkipSynchronization())).map(BaseIdentifiableObject::getUid).collect(Collectors.toSet()));
        }
    }
    for (Attribute attributeValue : attributes) {
        if (allowedAttributeUids.contains(attributeValue.getAttribute())) {
            attributeList.add(attributeValue);
        }
    }
    return attributeList;
}
Also used : RequiredArgsConstructor(lombok.RequiredArgsConstructor) CompletableFuture(java.util.concurrent.CompletableFuture) Multimap(com.google.common.collect.Multimap) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) Relationship(org.hisp.dhis.dxf2.events.trackedentity.Relationship) Lists(com.google.common.collect.Lists) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) Map(java.util.Map) ProgramOwner(org.hisp.dhis.dxf2.events.trackedentity.ProgramOwner) User(org.hisp.dhis.user.User) ThreadPoolManager.getPool(org.hisp.dhis.dxf2.events.aggregates.ThreadPoolManager.getPool) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) TrackedEntityInstanceStore(org.hisp.dhis.dxf2.events.trackedentity.store.TrackedEntityInstanceStore) NonNull(lombok.NonNull) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) TrackedEntityInstanceQueryParams(org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams) Collection(java.util.Collection) TrackedEntityInstanceParams(org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams) Set(java.util.Set) Collectors(java.util.stream.Collectors) Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) AclStore(org.hisp.dhis.dxf2.events.trackedentity.store.AclStore) CacheProvider(org.hisp.dhis.cache.CacheProvider) List(java.util.List) CollectionUtils(org.hisp.dhis.commons.collection.CollectionUtils) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Cache(org.hisp.dhis.cache.Cache) PostConstruct(javax.annotation.PostConstruct) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Program(org.hisp.dhis.program.Program) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ArrayList(java.util.ArrayList)

Example 33 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EnrollmentRowCallbackHandler method getEnrollment.

private Enrollment getEnrollment(ResultSet rs) throws SQLException {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(rs.getString(getColumnName(UID)));
    MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY))).ifPresent(enrollment::setGeometry);
    enrollment.setTrackedEntityType(rs.getString(getColumnName(TEI_TYPE_UID)));
    enrollment.setTrackedEntityInstance(rs.getString(getColumnName(TEI_UID)));
    enrollment.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
    enrollment.setOrgUnitName(rs.getString(getColumnName(ORGUNIT_NAME)));
    enrollment.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
    enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(CREATED_BY), enrollment::setCreatedByUserInfo);
    enrollment.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
    enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), enrollment::setLastUpdatedByUserInfo);
    enrollment.setProgram(rs.getString(getColumnName(PROGRAM_UID)));
    enrollment.setStatus(EnrollmentStatus.fromStatusString(rs.getString(getColumnName(STATUS))));
    enrollment.setEnrollmentDate(rs.getTimestamp(getColumnName(ENROLLMENTDATE)));
    enrollment.setIncidentDate(rs.getTimestamp(getColumnName(INCIDENTDATE)));
    final boolean followup = rs.getBoolean(getColumnName(FOLLOWUP));
    enrollment.setFollowup(rs.wasNull() ? null : followup);
    enrollment.setCompletedDate(rs.getTimestamp(getColumnName(COMPLETED)));
    enrollment.setCompletedBy(rs.getString(getColumnName(COMPLETEDBY)));
    enrollment.setStoredBy(rs.getString(getColumnName(STOREDBY)));
    enrollment.setDeleted(rs.getBoolean(getColumnName(DELETED)));
    enrollment.setId(rs.getLong(getColumnName(ID)));
    return enrollment;
}
Also used : Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment)

Example 34 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class MetadataSyncPostProcessor method handleSyncNotificationsAndAbortStatus.

public boolean handleSyncNotificationsAndAbortStatus(MetadataSyncSummary metadataSyncSummary, MetadataRetryContext retryContext, MetadataVersion dataVersion) {
    ImportReport importReport = metadataSyncSummary.getImportReport();
    if (importReport == null) {
        handleImportFailedContext(null, retryContext, dataVersion);
        return true;
    }
    Status syncStatus = importReport.getStatus();
    log.info("Import completed. Import Status: " + syncStatus);
    if (Status.OK.equals(syncStatus) || (Status.WARNING.equals(syncStatus) && VersionType.BEST_EFFORT.equals(dataVersion.getType()))) {
        sendSuccessMailToAdmin(metadataSyncSummary);
        return false;
    }
    if (Status.ERROR.equals(syncStatus)) {
        handleImportFailedContext(metadataSyncSummary, retryContext, dataVersion);
        return true;
    }
    return false;
}
Also used : Status(org.hisp.dhis.feedback.Status) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport)

Example 35 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EnrollmentSecurityTest method testGetEnrollmentsInSearchScopeForUser.

/**
 * program = DATA READ orgUnit = Accessible in search scope status = SUCCESS
 */
@Test
void testGetEnrollmentsInSearchScopeForUser() {
    ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    programA.getSharing().setPublicAccess(AccessStringHelper.DATA_READ);
    manager.update(programA);
    User user = createUser("user1");
    user.setOrganisationUnits(Sets.newHashSet(organisationUnitB));
    user.setTeiSearchOrganisationUnits(Sets.newHashSet(organisationUnitA, organisationUnitB));
    user.setDataViewOrganisationUnits(Sets.newHashSet(organisationUnitB));
    injectSecurityContext(user);
    ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
    params.setProgram(programA);
    params.setOrganisationUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE);
    params.setUser(user);
    Enrollments enrollments = enrollmentService.getEnrollments(params);
    assertNotNull(enrollments);
    assertNotNull(enrollments.getEnrollments());
    assertEquals(1, enrollments.getEnrollments().size());
    assertEquals(importSummary.getReference(), enrollments.getEnrollments().get(0).getEnrollment());
}
Also used : User(org.hisp.dhis.user.User) Enrollments(org.hisp.dhis.dxf2.events.enrollment.Enrollments) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstanceQueryParams(org.hisp.dhis.program.ProgramInstanceQueryParams) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)28 User (org.hisp.dhis.user.User)20 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)16 Event (org.hisp.dhis.dxf2.events.event.Event)14 EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)6 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)6 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)5 Period (org.hisp.dhis.period.Period)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5