From f0e19168ebedf708e3e0e0df1876b57ca378af88 Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Mon, 25 Nov 2024 15:33:28 -0500 Subject: [PATCH 1/6] #11044 refresh facet array --- .../iq/dataverse/DataverseFacetServiceBean.java | 14 ++++++++++---- .../impl/AbstractWriteDataverseCommand.java | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java index 5c77989f6d6..67dc183ba66 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java @@ -4,6 +4,8 @@ import java.util.List; import jakarta.ejb.EJB; import jakarta.ejb.Stateless; +import jakarta.ejb.TransactionAttribute; +import jakarta.ejb.TransactionAttributeType; import jakarta.inject.Named; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; @@ -42,23 +44,27 @@ public void delete(DataverseFacet dataverseFacet) { cache.invalidate(); } + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void deleteFacetsFor( Dataverse d ) { em.createNamedQuery("DataverseFacet.removeByOwnerId") .setParameter("ownerId", d.getId()) .executeUpdate(); cache.invalidate(d.getId()); - + } - public DataverseFacet create(int displayOrder, DatasetFieldType fieldType, Dataverse ownerDv) { + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) + public DataverseFacet create(int displayOrder, DatasetFieldType fieldType, Dataverse ownerDv) { DataverseFacet dataverseFacet = new DataverseFacet(); dataverseFacet.setDisplayOrder(displayOrder); dataverseFacet.setDatasetFieldType(fieldType); dataverseFacet.setDataverse(ownerDv); - - ownerDv.getDataverseFacets().add(dataverseFacet); + em.persist(dataverseFacet); + ownerDv.getDataverseFacets().add(dataverseFacet); + em.merge(ownerDv); + cache.invalidate(ownerDv.getId()); return dataverseFacet; } diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java index 40c2abf5d21..ede07ba5ab7 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java @@ -56,7 +56,8 @@ public Dataverse execute(CommandContext ctxt) throws CommandException { if (facets != null) { ctxt.facets().deleteFacetsFor(dataverse); - + dataverse.setDataverseFacets(new ArrayList<>()); + if (!facets.isEmpty()) { dataverse.setFacetRoot(true); } From 51e1ad7b2c0bd79cf84d58147285831755b01ff1 Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Tue, 26 Nov 2024 13:09:49 -0500 Subject: [PATCH 2/6] #11044 reset input levels prior to update --- .../engine/command/impl/AbstractWriteDataverseCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java index ede07ba5ab7..0b3d1da0f6d 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java @@ -73,6 +73,7 @@ public Dataverse execute(CommandContext ctxt) throws CommandException { dataverse.addInputLevelsMetadataBlocksIfNotPresent(inputLevels); } ctxt.fieldTypeInputLevels().deleteFacetsFor(dataverse); + dataverse.setDataverseFieldTypeInputLevels(new ArrayList<>()); for (DataverseFieldTypeInputLevel inputLevel : inputLevels) { inputLevel.setDataverse(dataverse); ctxt.fieldTypeInputLevels().create(inputLevel); From 8fd500dc9328f5e21472e0140f4b4a11befc91b4 Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Tue, 26 Nov 2024 13:35:44 -0500 Subject: [PATCH 3/6] #11044 reset after merge conflict --- .../engine/command/impl/AbstractWriteDataverseCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java index 91f3a5b823c..2a8bb18a942 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java @@ -93,6 +93,7 @@ private void processInputLevels(CommandContext ctxt) { dataverse.addInputLevelsMetadataBlocksIfNotPresent(inputLevels); } ctxt.fieldTypeInputLevels().deleteFacetsFor(dataverse); + dataverse.setDataverseFieldTypeInputLevels(new ArrayList<>()); inputLevels.forEach(inputLevel -> { inputLevel.setDataverse(dataverse); ctxt.fieldTypeInputLevels().create(inputLevel); From 232804619656e2637888c9ac4602bb1003eda69b Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Tue, 26 Nov 2024 14:42:19 -0500 Subject: [PATCH 4/6] #11044 code cleanup --- .../dataverse/DataverseFacetServiceBean.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java index 67dc183ba66..aa750e96bc9 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java @@ -4,8 +4,6 @@ import java.util.List; import jakarta.ejb.EJB; import jakarta.ejb.Stateless; -import jakarta.ejb.TransactionAttribute; -import jakarta.ejb.TransactionAttributeType; import jakarta.inject.Named; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; @@ -44,26 +42,23 @@ public void delete(DataverseFacet dataverseFacet) { cache.invalidate(); } - @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) - public void deleteFacetsFor( Dataverse d ) { - em.createNamedQuery("DataverseFacet.removeByOwnerId") - .setParameter("ownerId", d.getId()) - .executeUpdate(); + public void deleteFacetsFor(Dataverse d) { + em.createNamedQuery("DataverseFacet.removeByOwnerId") + .setParameter("ownerId", d.getId()) + .executeUpdate(); cache.invalidate(d.getId()); - } - - @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) - public DataverseFacet create(int displayOrder, DatasetFieldType fieldType, Dataverse ownerDv) { + } + + public DataverseFacet create(int displayOrder, DatasetFieldType fieldType, Dataverse ownerDv) { DataverseFacet dataverseFacet = new DataverseFacet(); - + dataverseFacet.setDisplayOrder(displayOrder); dataverseFacet.setDatasetFieldType(fieldType); dataverseFacet.setDataverse(ownerDv); - + em.persist(dataverseFacet); ownerDv.getDataverseFacets().add(dataverseFacet); - em.merge(ownerDv); cache.invalidate(ownerDv.getId()); return dataverseFacet; } From ea97785bc0a49ff762b2a37d97ef3980a4c6ab94 Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Tue, 26 Nov 2024 14:48:04 -0500 Subject: [PATCH 5/6] #11044 more cleanup --- .../edu/harvard/iq/dataverse/DataverseFacetServiceBean.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java index aa750e96bc9..804f1fe2943 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java @@ -49,7 +49,7 @@ public void deleteFacetsFor(Dataverse d) { cache.invalidate(d.getId()); } - + public DataverseFacet create(int displayOrder, DatasetFieldType fieldType, Dataverse ownerDv) { DataverseFacet dataverseFacet = new DataverseFacet(); From ca95ad8d0b260060c7e7ed435767bd134cbf3907 Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Tue, 3 Dec 2024 15:24:04 -0500 Subject: [PATCH 6/6] #11044 fix failing tests --- .../edu/harvard/iq/dataverse/DataverseFacetServiceBean.java | 4 ++-- .../engine/command/impl/AbstractWriteDataverseCommand.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java index 804f1fe2943..56f522fa816 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DataverseFacetServiceBean.java @@ -56,9 +56,9 @@ public DataverseFacet create(int displayOrder, DatasetFieldType fieldType, Datav dataverseFacet.setDisplayOrder(displayOrder); dataverseFacet.setDatasetFieldType(fieldType); dataverseFacet.setDataverse(ownerDv); - - em.persist(dataverseFacet); ownerDv.getDataverseFacets().add(dataverseFacet); + em.persist(dataverseFacet); + cache.invalidate(ownerDv.getId()); return dataverseFacet; } diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java index 2a8bb18a942..91f3a5b823c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractWriteDataverseCommand.java @@ -93,7 +93,6 @@ private void processInputLevels(CommandContext ctxt) { dataverse.addInputLevelsMetadataBlocksIfNotPresent(inputLevels); } ctxt.fieldTypeInputLevels().deleteFacetsFor(dataverse); - dataverse.setDataverseFieldTypeInputLevels(new ArrayList<>()); inputLevels.forEach(inputLevel -> { inputLevel.setDataverse(dataverse); ctxt.fieldTypeInputLevels().create(inputLevel);