Search in sources :

Example 1 with TrackerType

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

the class DefaultTrackerBundleService method commit.

@Override
@Transactional
public TrackerBundleReport commit(TrackerBundle bundle) {
    TrackerBundleReport bundleReport = new TrackerBundleReport();
    if (TrackerBundleMode.VALIDATE == bundle.getImportMode()) {
        return bundleReport;
    }
    Session session = sessionFactory.getCurrentSession();
    Map<TrackerType, TrackerTypeReport> report = bundleReport.getTypeReportMap();
    report.put(TrackerType.TRACKED_ENTITY, commitService.getTrackerPersister().persist(session, bundle));
    report.put(TrackerType.ENROLLMENT, commitService.getEnrollmentPersister().persist(session, bundle));
    report.put(TrackerType.EVENT, commitService.getEventPersister().persist(session, bundle));
    report.put(TrackerType.RELATIONSHIP, commitService.getRelationshipPersister().persist(session, bundle));
    return bundleReport;
}
Also used : TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport) Session(org.hibernate.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with TrackerType

use of org.hisp.dhis.tracker.TrackerType 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)

Example 3 with TrackerType

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

the class RelationshipsValidationHook method validateReferences.

private void validateReferences(ValidationErrorReporter reporter, Relationship relationship, RelationshipItem item) {
    TrackerType trackerType = relationshipItemValueType(item);
    Optional<String> itemUid = getUidFromRelationshipItem(item);
    itemUid.ifPresent(s -> reporter.addErrorIf(() -> reporter.isInvalid(trackerType, s), relationship, E4011, relationship.getRelationship(), trackerType.getName(), s));
}
Also used : TrackerType(org.hisp.dhis.tracker.TrackerType)

Example 4 with TrackerType

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

the class PreCheckDataRelationsValidationHook method validateRelationshipReference.

private void validateRelationshipReference(ValidationErrorReporter reporter, Relationship relationship, RelationshipItem item) {
    Optional<String> uid = getUidFromRelationshipItem(item);
    TrackerType trackerType = relationshipItemValueType(item);
    TrackerImportValidationContext ctx = reporter.getValidationContext();
    if (TRACKED_ENTITY.equals(trackerType)) {
        if (uid.isPresent() && !ValidationUtils.trackedEntityInstanceExist(ctx, uid.get())) {
            reporter.addError(relationship, E4012, trackerType.getName(), uid.get());
        }
    } else if (ENROLLMENT.equals(trackerType)) {
        if (uid.isPresent() && !ValidationUtils.enrollmentExist(ctx, uid.get())) {
            reporter.addError(relationship, E4012, trackerType.getName(), uid.get());
        }
    } else if (EVENT.equals(trackerType) && uid.isPresent() && !ValidationUtils.eventExist(ctx, uid.get())) {
        reporter.addError(relationship, E4012, trackerType.getName(), uid.get());
    }
}
Also used : TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

Example 5 with TrackerType

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

the class DefaultTrackerBundleService method delete.

@Override
@Transactional
public TrackerBundleReport delete(TrackerBundle bundle) {
    TrackerBundleReport bundleReport = new TrackerBundleReport();
    if (TrackerBundleMode.VALIDATE == bundle.getImportMode()) {
        return bundleReport;
    }
    Map<TrackerType, TrackerTypeReport> report = bundleReport.getTypeReportMap();
    report.put(TrackerType.RELATIONSHIP, deletionService.deleteRelationShips(bundle));
    report.put(TrackerType.EVENT, deletionService.deleteEvents(bundle));
    report.put(TrackerType.ENROLLMENT, deletionService.deleteEnrollments(bundle));
    report.put(TrackerType.TRACKED_ENTITY, deletionService.deleteTrackedEntityInstances(bundle));
    return bundleReport;
}
Also used : TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TrackerType (org.hisp.dhis.tracker.TrackerType)10 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 Test (org.junit.jupiter.api.Test)4 Mockito.mock (org.mockito.Mockito.mock)4 TrackerBundleReport (org.hisp.dhis.tracker.report.TrackerBundleReport)2 TrackerTypeReport (org.hisp.dhis.tracker.report.TrackerTypeReport)2 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 NonNull (lombok.NonNull)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Session (org.hibernate.Session)1 CategoryOption (org.hisp.dhis.category.CategoryOption)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 EventStatus (org.hisp.dhis.event.EventStatus)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 OrganisationUnitService (org.hisp.dhis.organisationunit.OrganisationUnitService)1 Program (org.hisp.dhis.program.Program)1