use of org.hisp.dhis.program.ProgramOwnershipHistory in project dhis2-core by dhis2.
the class DefaultTrackerOwnershipManager method transferOwnership.
// -------------------------------------------------------------------------
// Implementation
// -------------------------------------------------------------------------
@Override
@Transactional
public void transferOwnership(TrackedEntityInstance entityInstance, Program program, OrganisationUnit orgUnit, boolean skipAccessValidation, boolean createIfNotExists) {
if (entityInstance == null || program == null || orgUnit == null) {
return;
}
if (hasAccess(currentUserService.getCurrentUser(), entityInstance, program) || skipAccessValidation) {
TrackedEntityProgramOwner teProgramOwner = trackedEntityProgramOwnerService.getTrackedEntityProgramOwner(entityInstance.getId(), program.getId());
if (teProgramOwner != null) {
if (!teProgramOwner.getOrganisationUnit().equals(orgUnit)) {
ProgramOwnershipHistory programOwnershipHistory = new ProgramOwnershipHistory(program, entityInstance, teProgramOwner.getOrganisationUnit(), teProgramOwner.getLastUpdated(), teProgramOwner.getCreatedBy());
programOwnershipHistoryService.addProgramOwnershipHistory(programOwnershipHistory);
trackedEntityProgramOwnerService.updateTrackedEntityProgramOwner(entityInstance, program, orgUnit);
}
} else if (createIfNotExists) {
trackedEntityProgramOwnerService.createTrackedEntityProgramOwner(entityInstance, program, orgUnit);
}
ownerCache.invalidate(getOwnershipCacheKey(() -> entityInstance.getId(), program));
} else {
log.error("Unauthorized attempt to change ownership");
throw new AccessDeniedException("User does not have access to change ownership for the entity-program combination");
}
}
use of org.hisp.dhis.program.ProgramOwnershipHistory in project dhis2-core by dhis2.
the class DefaultTrackerOwnershipManager method assignOwnership.
@Override
@Transactional
public void assignOwnership(TrackedEntityInstance entityInstance, Program program, OrganisationUnit organisationUnit, boolean skipAccessValidation, boolean overwriteIfExists) {
if (entityInstance == null || program == null || organisationUnit == null) {
return;
}
if (hasAccess(currentUserService.getCurrentUser(), entityInstance, program) || skipAccessValidation) {
TrackedEntityProgramOwner teProgramOwner = trackedEntityProgramOwnerService.getTrackedEntityProgramOwner(entityInstance.getId(), program.getId());
if (teProgramOwner != null) {
if (overwriteIfExists && !teProgramOwner.getOrganisationUnit().equals(organisationUnit)) {
ProgramOwnershipHistory programOwnershipHistory = new ProgramOwnershipHistory(program, entityInstance, teProgramOwner.getOrganisationUnit(), teProgramOwner.getLastUpdated(), teProgramOwner.getCreatedBy());
programOwnershipHistoryService.addProgramOwnershipHistory(programOwnershipHistory);
trackedEntityProgramOwnerService.updateTrackedEntityProgramOwner(entityInstance, program, organisationUnit);
}
} else {
trackedEntityProgramOwnerService.createTrackedEntityProgramOwner(entityInstance, program, organisationUnit);
}
ownerCache.invalidate(getOwnershipCacheKey(() -> entityInstance.getId(), program));
} else {
log.error("Unauthorized attempt to assign ownership");
throw new AccessDeniedException("User does not have access to assign ownership for the entity-program combination");
}
}
Aggregations