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;
}
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);
}
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));
}
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());
}
}
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;
}
Aggregations