Search in sources :

Example 1 with ObjectDeletionRequestedEvent

use of org.hisp.dhis.common.ObjectDeletionRequestedEvent in project dhis2-core by dhis2.

the class SoftDeleteHibernateObjectStore method delete.

@Override
public void delete(SoftDeletableObject object) {
    publisher.publishEvent(new ObjectDeletionRequestedEvent(object));
    object.setDeleted(true);
    getSession().update(object);
}
Also used : ObjectDeletionRequestedEvent(org.hisp.dhis.common.ObjectDeletionRequestedEvent)

Example 2 with ObjectDeletionRequestedEvent

use of org.hisp.dhis.common.ObjectDeletionRequestedEvent in project dhis2-core by dhis2.

the class RelationshipDeletionHandlerTest method allowDeleteRelationshipTypeWithoutData.

@Test
void allowDeleteRelationshipTypeWithoutData() {
    when(relationshipService.getRelationshipsByRelationshipType(any())).thenReturn(emptyList());
    ObjectDeletionRequestedEvent event = new ObjectDeletionRequestedEvent(new RelationshipType());
    deletionManager.onDeletion(event);
    verify(relationshipService, atLeastOnce()).getRelationshipsByRelationshipType(any());
}
Also used : ObjectDeletionRequestedEvent(org.hisp.dhis.common.ObjectDeletionRequestedEvent) Test(org.junit.jupiter.api.Test)

Example 3 with ObjectDeletionRequestedEvent

use of org.hisp.dhis.common.ObjectDeletionRequestedEvent in project dhis2-core by dhis2.

the class RelationshipDeletionHandlerTest method allowDeleteRelationshipTypeWithData.

@Test
void allowDeleteRelationshipTypeWithData() {
    when(relationshipService.getRelationshipsByRelationshipType(any())).thenReturn(singletonList(new Relationship()));
    ObjectDeletionRequestedEvent event = new ObjectDeletionRequestedEvent(new RelationshipType());
    Exception ex = assertThrows(DeleteNotAllowedException.class, () -> deletionManager.onDeletion(event));
    assertEquals("Object could not be deleted because it is associated with another object: Relationship", ex.getMessage());
}
Also used : ObjectDeletionRequestedEvent(org.hisp.dhis.common.ObjectDeletionRequestedEvent) DeleteNotAllowedException(org.hisp.dhis.common.DeleteNotAllowedException) Test(org.junit.jupiter.api.Test)

Example 4 with ObjectDeletionRequestedEvent

use of org.hisp.dhis.common.ObjectDeletionRequestedEvent in project dhis2-core by dhis2.

the class RelationshipDeletionHandlerTest method deleteTrackedEntityInstance.

@Test
void deleteTrackedEntityInstance() {
    when(relationshipService.getRelationshipsByTrackedEntityInstance(any(), anyBoolean())).thenReturn(singletonList(new Relationship()));
    ObjectDeletionRequestedEvent event = new ObjectDeletionRequestedEvent(new TrackedEntityInstance());
    deletionManager.onDeletion(event);
    verify(relationshipService, atLeastOnce()).getRelationshipsByTrackedEntityInstance(any(), anyBoolean());
    verify(relationshipService, atLeastOnce()).deleteRelationship(any());
}
Also used : ObjectDeletionRequestedEvent(org.hisp.dhis.common.ObjectDeletionRequestedEvent) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 5 with ObjectDeletionRequestedEvent

use of org.hisp.dhis.common.ObjectDeletionRequestedEvent in project dhis2-core by dhis2.

the class HibernateCategoryOptionComboStore method deleteNoRollBack.

@Override
public void deleteNoRollBack(CategoryOptionCombo categoryOptionCombo) {
    ObjectDeletionRequestedEvent event = new ObjectDeletionRequestedEvent(categoryOptionCombo);
    event.setShouldRollBack(false);
    publisher.publishEvent(event);
    getSession().delete(categoryOptionCombo);
}
Also used : ObjectDeletionRequestedEvent(org.hisp.dhis.common.ObjectDeletionRequestedEvent)

Aggregations

ObjectDeletionRequestedEvent (org.hisp.dhis.common.ObjectDeletionRequestedEvent)6 Test (org.junit.jupiter.api.Test)3 DeleteNotAllowedException (org.hisp.dhis.common.DeleteNotAllowedException)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1