Search in sources :

Example 1 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class StrategyPreProcessor method preProcessEvents.

public void preProcessEvents(TrackerBundle bundle) {
    for (Event event : bundle.getEvents()) {
        TrackerImportStrategy importStrategy = bundle.getImportStrategy();
        ProgramStageInstance existingPsi = bundle.getPreheat().getEvent(TrackerIdScheme.UID, event.getEvent());
        if (importStrategy.isCreateAndUpdate()) {
            if (existingPsi == null) {
                bundle.setStrategy(event, TrackerImportStrategy.CREATE);
            } else {
                bundle.setStrategy(event, TrackerImportStrategy.UPDATE);
            }
        } else {
            bundle.setStrategy(event, importStrategy);
        }
    }
}
Also used : TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) Event(org.hisp.dhis.tracker.domain.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 2 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class StrategyPreProcessor method preProcessEnrollments.

public void preProcessEnrollments(TrackerBundle bundle) {
    for (Enrollment enrollment : bundle.getEnrollments()) {
        TrackerImportStrategy importStrategy = bundle.getImportStrategy();
        ProgramInstance existingPI = bundle.getPreheat().getEnrollment(TrackerIdScheme.UID, enrollment.getEnrollment());
        if (importStrategy.isCreateAndUpdate()) {
            if (existingPI == null) {
                bundle.setStrategy(enrollment, TrackerImportStrategy.CREATE);
            } else {
                bundle.setStrategy(enrollment, TrackerImportStrategy.UPDATE);
            }
        } else {
            bundle.setStrategy(enrollment, importStrategy);
        }
    }
}
Also used : TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Enrollment(org.hisp.dhis.tracker.domain.Enrollment)

Example 3 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class StrategyPreProcessor method preProcessTrackedEntities.

public void preProcessTrackedEntities(TrackerBundle bundle) {
    for (TrackedEntity tei : bundle.getTrackedEntities()) {
        TrackerImportStrategy importStrategy = bundle.getImportStrategy();
        TrackedEntityInstance existingTei = bundle.getPreheat().getTrackedEntity(TrackerIdScheme.UID, tei.getTrackedEntity());
        if (importStrategy.isCreateAndUpdate()) {
            if (existingTei == null) {
                bundle.setStrategy(tei, TrackerImportStrategy.CREATE);
            } else {
                bundle.setStrategy(tei, TrackerImportStrategy.UPDATE);
            }
        } else {
            bundle.setStrategy(tei, importStrategy);
        }
    }
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 4 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy strategy = context.getStrategy(event);
    TrackerBundle bundle = context.getBundle();
    User user = bundle.getUser();
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(event, EVENT_CANT_BE_NULL);
    checkNotNull(event.getOrgUnit(), ORGANISATION_UNIT_CANT_BE_NULL);
    OrganisationUnit organisationUnit = context.getOrganisationUnit(event.getOrgUnit());
    ProgramStage programStage = context.getProgramStage(event.getProgramStage());
    Program program = context.getProgram(event.getProgram());
    // has to be checked
    if (program.isWithoutRegistration() || strategy.isCreate() || strategy.isDelete()) {
        checkOrgUnitInCaptureScope(reporter, event, organisationUnit);
    }
    String teiUid = getTeiUidFromEvent(context, event, program);
    CategoryOptionCombo categoryOptionCombo = bundle.getPreheat().getCategoryOptionCombo(event.getAttributeOptionCombo());
    OrganisationUnit ownerOrgUnit = context.getOwnerOrganisationUnit(teiUid, program.getUid());
    // Check acting user is allowed to change existing/write event
    if (strategy.isUpdateOrDelete()) {
        ProgramStageInstance programStageInstance = context.getProgramStageInstance(event.getEvent());
        TrackedEntityInstance entityInstance = programStageInstance.getProgramInstance().getEntityInstance();
        validateUpdateAndDeleteEvent(reporter, event, programStageInstance, entityInstance == null ? null : entityInstance.getUid(), ownerOrgUnit);
    } else {
        validateCreateEvent(reporter, event, user, categoryOptionCombo, programStage, teiUid, organisationUnit, ownerOrgUnit, program, event.isCreatableInSearchScope());
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 5 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHook method validateTrackedEntity.

@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy strategy = context.getStrategy(trackedEntity);
    TrackerBundle bundle = context.getBundle();
    User user = bundle.getUser();
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(trackedEntity, TRACKED_ENTITY_CANT_BE_NULL);
    checkNotNull(trackedEntity.getOrgUnit(), ORGANISATION_UNIT_CANT_BE_NULL);
    // scope has to be checked
    if (strategy.isCreate() || strategy.isDelete()) {
        checkOrgUnitInCaptureScope(reporter, trackedEntity, context.getOrganisationUnit(trackedEntity.getOrgUnit()));
    } else // if its to update trackedEntity, search scope has to be checked
    {
        checkOrgUnitInSearchScope(reporter, trackedEntity, context.getOrganisationUnit(trackedEntity.getOrgUnit()));
    }
    if (strategy.isDelete()) {
        TrackedEntityInstance tei = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
        if (tei.getProgramInstances().stream().anyMatch(pi -> !pi.isDeleted()) && !user.isAuthorized(Authorities.F_TEI_CASCADE_DELETE.getAuthority())) {
            TrackerErrorReport error = TrackerErrorReport.builder().uid(trackedEntity.getUid()).trackerType(TrackerType.TRACKED_ENTITY).errorCode(E1100).addArg(user).addArg(tei).build(bundle);
            reporter.addError(error);
        }
    }
    TrackedEntityType trackedEntityType = context.getTrackedEntityType(trackedEntity.getTrackedEntityType());
    checkTeiTypeWriteAccess(reporter, trackedEntity.getUid(), trackedEntityType);
}
Also used : EVENT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.EVENT_CANT_BE_NULL) Authorities(org.hisp.dhis.security.Authorities) CategoryOption(org.hisp.dhis.category.CategoryOption) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) E1100(org.hisp.dhis.tracker.report.TrackerErrorCode.E1100) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Relationship(org.hisp.dhis.tracker.domain.Relationship) E1083(org.hisp.dhis.tracker.report.TrackerErrorCode.E1083) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) PROGRAM_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL) TRACKED_ENTITY_TYPE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.TRACKED_ENTITY_TYPE_CANT_BE_NULL) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TRACKED_ENTITY_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.TRACKED_ENTITY_CANT_BE_NULL) USER_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.USER_CANT_BE_NULL) ProgramInstance(org.hisp.dhis.program.ProgramInstance) PROGRAM_STAGE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_STAGE_CANT_BE_NULL) User(org.hisp.dhis.user.User) ORGANISATION_UNIT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.ORGANISATION_UNIT_CANT_BE_NULL) PROGRAM_INSTANCE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_INSTANCE_CANT_BE_NULL) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) NonNull(lombok.NonNull) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) ENROLLMENT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.ENROLLMENT_CANT_BE_NULL) EventStatus(org.hisp.dhis.event.EventStatus) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) E1103(org.hisp.dhis.tracker.report.TrackerErrorCode.E1103) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) AclService(org.hisp.dhis.security.acl.AclService) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackerDto(org.hisp.dhis.tracker.domain.TrackerDto) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) User(org.hisp.dhis.user.User) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Aggregations

TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)12 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)4 User (org.hisp.dhis.user.User)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Program (org.hisp.dhis.program.Program)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)3 TrackerErrorReport (org.hisp.dhis.tracker.report.TrackerErrorReport)3 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)2 Event (org.hisp.dhis.tracker.domain.Event)2 Relationship (org.hisp.dhis.tracker.domain.Relationship)2 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 NonNull (lombok.NonNull)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1