Skip to content

Commit

Permalink
chore: Remove deleteEnrollment [DHIS-17712] (#18171)
Browse files Browse the repository at this point in the history
* chore: Remove deleteEnrollment [DHIS-17712]

* chore: Use manager.delete [DHIS-17712]

* chore: Use store to delete enrollment [DHIS-17712]
  • Loading branch information
muilpp authored Jul 24, 2024
1 parent 4fc9178 commit 88777eb
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
*/
public interface EnrollmentService {

/**
* Soft deletes a {@link Enrollment}.
*
* @param enrollment the Enrollment to delete.
*/
void deleteEnrollment(Enrollment enrollment);

/** Get enrollments into a program. */
List<Enrollment> getEnrollments(Program program);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ public class DefaultEnrollmentService implements EnrollmentService {

private final IdentifiableObjectManager manager;

@Override
@Transactional
public void deleteEnrollment(Enrollment enrollment) {
enrollment.setStatus(EnrollmentStatus.CANCELLED);
enrollmentStore.update(enrollment);
enrollmentStore.delete(enrollment);
}

@Override
@Transactional(readOnly = true)
public List<Enrollment> getEnrollments(Program program) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public interface EnrollmentStore extends IdentifiableObjectStore<Enrollment> {
* names should occur before calling {@link #getEnrollments(EnrollmentQueryParams)}.
*/
Set<String> getOrderableFields();

void deleteEnrollment(Enrollment enrollment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.hisp.dhis.commons.util.SqlHelper;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Enrollment;
import org.hisp.dhis.program.EnrollmentStatus;
import org.hisp.dhis.security.acl.AclService;
import org.hisp.dhis.tracker.export.Order;
import org.hisp.dhis.tracker.export.Page;
Expand Down Expand Up @@ -305,4 +306,10 @@ protected Enrollment postProcessObject(Enrollment enrollment) {
public Set<String> getOrderableFields() {
return ORDERABLE_FIELDS;
}

@Override
public void deleteEnrollment(Enrollment enrollment) {
enrollment.setStatus(EnrollmentStatus.CANCELLED);
super.delete(enrollment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
@Service
@RequiredArgsConstructor
public class DefaultTrackerObjectsDeletionService implements TrackerObjectDeletionService {
private final org.hisp.dhis.program.EnrollmentService apiEnrollmentService;

private final TrackedEntityService teService;

private final IdentifiableObjectManager manager;
Expand Down Expand Up @@ -113,7 +111,8 @@ public TrackerTypeReport deleteEnrollments(List<String> enrollments) throws NotF
TrackedEntity te = enrollment.getTrackedEntity();
te.setLastUpdatedByUserInfo(userInfoSnapshot);

apiEnrollmentService.deleteEnrollment(enrollment);
manager.delete(enrollment);

teService.updateTrackedEntity(te);

typeReport.getStats().incDeleted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@
* @author Enrico Colasante
*/
class MaintenanceServiceTest extends PostgresIntegrationTestBase {
@Autowired private org.hisp.dhis.program.EnrollmentService apiEnrollmentService;

@Autowired private EnrollmentService enrollmentService;

@Autowired private ProgramMessageService programMessageService;
Expand Down Expand Up @@ -259,7 +257,8 @@ void testDeleteSoftDeletedEnrollmentWithAProgramMessage()
manager.save(enrollment);
programMessageService.saveProgramMessage(message);
assertNotNull(manager.get(Enrollment.class, enrollment.getUid()));
apiEnrollmentService.deleteEnrollment(enrollment);

manager.delete(enrollment);
assertNull(manager.get(Enrollment.class, enrollment.getUid()));
assertTrue(enrollmentExistsIncludingDeleted(enrollment));

Expand Down Expand Up @@ -338,7 +337,7 @@ void testDeleteSoftDeletedEnrollmentLinkedToATrackedEntityDataValueAudit()
trackedEntityDataValueChangeLog);
manager.save(enrollment);
assertNotNull(manager.get(Enrollment.class, enrollment.getUid()));
apiEnrollmentService.deleteEnrollment(enrollment);
manager.delete(enrollment);
assertNull(manager.get(Enrollment.class, enrollment.getUid()));
assertTrue(enrollmentExistsIncludingDeleted(enrollment));

Expand Down Expand Up @@ -410,7 +409,7 @@ void testDeleteSoftDeletedEnrollmentLinkedToARelationshipItem()
manager.save(r);
assertNotNull(manager.get(Enrollment.class, enrollment.getId()));
assertNotNull(getRelationship(r.getId()));
apiEnrollmentService.deleteEnrollment(enrollment);
manager.delete(enrollment);
assertNull(manager.get(Enrollment.class, enrollment.getId()));
manager.delete(r);
assertNull(getRelationship(r.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.trackedentity.TrackedEntityService;
import org.hisp.dhis.tracker.imports.bundle.persister.TrackerObjectDeletionService;
import org.hisp.dhis.tracker.export.enrollment.EnrollmentService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.sharing.Sharing;
import org.joda.time.DateTime;
Expand All @@ -72,11 +72,9 @@ class EnrollmentServiceTest extends PostgresIntegrationTestBase {
private static final String ENROLLMENT_D_UID = UID.of(CodeGenerator.generateUid()).getValue();
private static final String EVENT_UID = UID.of(CodeGenerator.generateUid()).getValue();

@Autowired private EnrollmentService apiEnrollmentService;
@Autowired private org.hisp.dhis.program.EnrollmentService apiEnrollmentService;

@Autowired private TrackerObjectDeletionService trackerObjectDeletionService;

@Autowired private org.hisp.dhis.tracker.export.enrollment.EnrollmentService enrollmentService;
@Autowired private EnrollmentService enrollmentService;

@Autowired private TrackedEntityService trackedEntityService;

Expand Down Expand Up @@ -197,21 +195,7 @@ void testAddEnrollment() {
}

@Test
void testDeleteEnrollment() {
manager.save(enrollmentA);
manager.save(enrollmentB);
assertNotNull(manager.get(Enrollment.class, enrollmentA.getUid()));
assertNotNull(manager.get(Enrollment.class, enrollmentB.getUid()));
apiEnrollmentService.deleteEnrollment(enrollmentA);
assertNull(manager.get(Enrollment.class, enrollmentA.getUid()));
assertNotNull(manager.get(Enrollment.class, enrollmentB.getUid()));
apiEnrollmentService.deleteEnrollment(enrollmentB);
assertNull(manager.get(Enrollment.class, enrollmentA.getUid()));
assertNull(manager.get(Enrollment.class, enrollmentB.getUid()));
}

@Test
void testSoftDeleteEnrollmentAndLinkedEvent() throws NotFoundException {
void testSoftDeleteEnrollmentAndLinkedEvent() {
manager.save(enrollmentA);
manager.save(eventA);
long eventIdA = eventA.getId();
Expand All @@ -220,7 +204,8 @@ void testSoftDeleteEnrollmentAndLinkedEvent() throws NotFoundException {
assertNotNull(manager.get(Enrollment.class, enrollmentA.getUid()));
assertNotNull(manager.get(Event.class, eventIdA));

trackerObjectDeletionService.deleteEnrollments(List.of(enrollmentA.getUid()));
manager.delete(enrollmentA);
manager.delete(eventA);

assertNull(manager.get(Enrollment.class, enrollmentA.getUid()));
assertNull(manager.get(Event.class, eventIdA));
Expand Down Expand Up @@ -312,7 +297,7 @@ void shouldNotDeleteNoteWhenDeletingEnrollment() throws ForbiddenException, NotF

assertNotNull(enrollmentService.getEnrollment(enrollmentA.getUid()));

apiEnrollmentService.deleteEnrollment(enrollmentA);
manager.delete(enrollmentA);

Assertions.assertThrows(
NotFoundException.class, () -> enrollmentService.getEnrollment(enrollmentA.getUid()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ void shouldIncludeDeletedEnrollmentAndEvents()
.collect(Collectors.toSet());
assertIsEmpty(deletedEvents);

enrollmentService.deleteEnrollment(enrollmentA);
manager.delete(enrollmentA);
manager.delete(eventA);

trackedEntities = trackedEntityService.getTrackedEntities(operationParams);
Expand Down

0 comments on commit 88777eb

Please sign in to comment.