ref #4311 fix collectorTitleCache handling in Team an in person2Team
authorAndreas Müller <a.mueller@bgbm.org>
Mon, 28 Jun 2021 13:45:58 +0000 (15:45 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Mon, 28 Jun 2021 13:45:58 +0000 (15:45 +0200)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/Team.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/AgentServiceImpl.java
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/AgentServiceImplTest.java

index 06b2ea4dcd7c87c0e824414ccf9a505c58d0bad6..dfd19e15b050204819c13f617a857a405c00b0ba 100644 (file)
@@ -361,11 +361,16 @@ public class Team extends TeamOrPersonBase<Team> {
     //#4311
     @Override
     public String getCollectorTitleCache() {
-        if (protectedCollectorTitleCache){
+        if (protectedCollectorTitleCache == PROTECTED){
             return this.collectorTitleCache;
+        }
+        if (collectorTitleCache == null){
+            this.collectorTitleCache = getCacheStrategy().getCollectorTitleCache(this);
         }else{
-            return super.getCollectorTitleCache();
+            //as long as team members do not inform the team about changes the cache must be created new each time
+            collectorTitleCache = getCacheStrategy().getCollectorTitleCache(this);
         }
+        return collectorTitleCache;
     }
 
        /**
index 1bfe4edc1ff1adfd73ae8ca1568f0e69e433acdc..a4dda456bb2c618df729a41e6ade40bf9c40be66 100644 (file)
@@ -235,6 +235,9 @@ public class AgentServiceImpl
         if (StringUtils.isNotBlank(person.getNomenclaturalTitle())){
             team.setNomenclaturalTitleCache(person.getNomenclaturalTitle(), true);  //sets the protected flag always to true, this is necessary as long as person does not have a nomenclatural title cache; maybe setting the protected title itself is not necessary but does no harm
         }
+        if (StringUtils.isNotBlank(person.getCollectorTitle())){
+            team.setCollectorTitleCache(person.getCollectorTitle(), true);  //sets the protected flag always to true, this is necessary as long as person does not have a collector title cache; maybe setting the protected title itself is not necessary but does no harm
+        }
 
         if (! genericDao.isMergeable(team, person, strategy)){
                        throw new MergeException("Person can not be transformed into team.");
index 3319a6a79ca3ec45288943887b62bc1f8ccda40a..9f464ac2ebc9380480c409ff2d896ba59395f91e 100644 (file)
@@ -122,6 +122,7 @@ public class AgentServiceImplTest extends CdmTransactionalIntegrationTest{
         Assert.assertEquals("If person was completely empty we don't expect the title cache to be taken from person.nomenclaturalTitle", TeamDefaultCacheStrategy.EMPTY_TEAM, team.getTitleCache());
         Assert.assertFalse("If person was completely empty we don't expect the title cache to be protected", team.isProtectedTitleCache());
         Assert.assertEquals("If person was completely empty we expect nom. title to be the empty team constant", TeamDefaultCacheStrategy.EMPTY_TEAM, team.getNomenclaturalTitleCache());
+        Assert.assertEquals("If person was completely empty we expect collector title to be the empty team constant", TeamDefaultCacheStrategy.EMPTY_TEAM, team.getCollectorTitleCache());
 
         try{
             service.convertPerson2Team(person2.getUuid());