Fix expunge issue when no tags present (#1671)

* Fix expunge issue when no tags present

* Add changelog

* Try to clean up POMs that are failing CI

* Rework dependencies

* Roll back change that did not work
This commit is contained in:
James Agnew 2020-01-15 14:47:22 +08:00 committed by GitHub
parent 0385c25aa3
commit 201ec34db4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 173 additions and 136 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 1671
title: When performing the $expunge operation in the JPA server, the operation sometimes failed if a
resource being expunged had historical versions that did not contain any tags. This has been corrected.

View File

@ -31,7 +31,7 @@ import java.util.List;
public interface IResourceHistoryTagDao extends JpaRepository<ResourceHistoryTag, Long> {
@Modifying
@Query("DELETE FROM ResourceHistoryTag t WHERE t.myId IN :pids")
void deleteByPid(@Param("pids") List<Long> thePids);
@Query("DELETE FROM ResourceHistoryTag t WHERE t.myResourceHistoryPid = :historyPid")
void deleteByPid(@Param("historyPid") Long theResourceHistoryTablePid);
}

View File

@ -37,5 +37,5 @@ public interface IResourceTagDao extends JpaRepository<ResourceTag, Long> {
Collection<ResourceTag> findByResourceIds(@Param("pids") Collection<Long> pids);
@Modifying
@Query("delete from ResourceTag t WHERE t.myResourceId = :resid")
void deleteByResourceId(@Param("resid") Long theResourcePid);}
@Query("delete from ResourceTag t WHERE t.myResourceId = :resId")
void deleteByResourceId(@Param("resId") Long theResourcePid);}

View File

@ -50,7 +50,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
class ResourceExpungeService implements IResourceExpungeService {
@ -151,7 +150,7 @@ class ResourceExpungeService implements IResourceExpungeService {
myResourceHistoryProvenanceTableDao.deleteByPid(version.getProvenance().getId());
}
myResourceHistoryTagDao.deleteByPid(version.getTags().stream().map(t->t.getId()).collect(Collectors.toList()));
myResourceHistoryTagDao.deleteByPid(version.getId());
myResourceHistoryTableDao.deleteByPid(version.getId());
theRemainingCount.decrementAndGet();

View File

@ -171,6 +171,34 @@ public class ExpungeR4Test extends BaseResourceProviderR4Test {
@Test
public void testExpungeAllVersionsDeletesRow() {
// Create then delete
Patient p = new Patient();
p.setId("TEST");
p.setActive(true);
p.addName().setFamily("FOO");
myPatientDao.update(p);
p.setActive(false);
myPatientDao.update(p);
myPatientDao.delete(new IdType("Patient/TEST"));
runInTransaction(() -> assertThat(myResourceTableDao.findAll(), not(empty())));
runInTransaction(() -> assertThat(myResourceHistoryTableDao.findAll(), not(empty())));
runInTransaction(() -> assertThat(myForcedIdDao.findAll(), not(empty())));
myPatientDao.expunge(new ExpungeOptions()
.setExpungeDeletedResources(true)
.setExpungeOldVersions(true), null);
runInTransaction(() -> assertThat(myResourceTableDao.findAll(), empty()));
runInTransaction(() -> assertThat(myResourceHistoryTableDao.findAll(), empty()));
runInTransaction(() -> assertThat(myForcedIdDao.findAll(), empty()));
}
@Test
public void testExpungeAllVersionsWithTagsDeletesRow() {
// Create then delete
Patient p = new Patient();
p.setId("TEST");
@ -178,6 +206,10 @@ public class ExpungeR4Test extends BaseResourceProviderR4Test {
p.setActive(true);
p.addName().setFamily("FOO");
myPatientDao.update(p).getId();
p.setActive(false);
myPatientDao.update(p);
myPatientDao.delete(new IdType("Patient/TEST"));
runInTransaction(() -> assertThat(myResourceTableDao.findAll(), not(empty())));

View File

@ -42,6 +42,9 @@ public class ResourceHistoryTag extends BaseTag implements Serializable {
@JoinColumn(name="RES_VER_PID", referencedColumnName="PID", nullable=false, foreignKey=@ForeignKey(name="FK_HISTORYTAG_HISTORY"))
private ResourceHistoryTable myResourceHistory;
@Column(name="RES_VER_PID", insertable = false, updatable = false, nullable = false)
private Long myResourceHistoryPid;
@Column(name = "RES_TYPE", length = ResourceTable.RESTYPE_LEN, nullable=false)
private String myResourceType;

View File

@ -113,7 +113,6 @@
</dependency>
</dependencies>
<!--
<dependencyManagement>
<dependencies>
<dependency>
@ -126,7 +125,6 @@
</dependency>
</dependencies>
</dependencyManagement>
-->
<build>
<plugins>