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