From 75705262f984bab8b873d263876b63548505871b Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Fri, 3 Jun 2022 09:45:15 -0400 Subject: [PATCH] #165 ensure ordering of MDBs with Citation first --- .../harvard/iq/dataverse/DatasetVersionUI.java | 16 +++++++++------- .../edu/harvard/iq/dataverse/MetadataBlock.java | 10 +++++++++- .../command/impl/MoveDataverseCommandTest.java | 2 ++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionUI.java b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionUI.java index b20cf0debaa..d09457c86bf 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionUI.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionUI.java @@ -18,6 +18,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; +import static java.util.stream.Collectors.toList; import javax.ejb.EJB; import javax.faces.view.ViewScoped; import javax.inject.Named; @@ -39,22 +41,22 @@ public class DatasetVersionUI implements Serializable { public DatasetVersionUI() { } - private Map> metadataBlocksForView = new HashMap<>(); - private Map> metadataBlocksForEdit = new HashMap<>(); + private TreeMap> metadataBlocksForView = new TreeMap<>(); + private TreeMap> metadataBlocksForEdit = new TreeMap<>(); - public Map> getMetadataBlocksForView() { + public TreeMap> getMetadataBlocksForView() { return metadataBlocksForView; } - public void setMetadataBlocksForView(Map> metadataBlocksForView) { + public void setMetadataBlocksForView(TreeMap> metadataBlocksForView) { this.metadataBlocksForView = metadataBlocksForView; } - public Map> getMetadataBlocksForEdit() { + public TreeMap> getMetadataBlocksForEdit() { return metadataBlocksForEdit; } - public void setMetadataBlocksForEdit(Map> metadataBlocksForEdit) { + public void setMetadataBlocksForEdit(TreeMap> metadataBlocksForEdit) { this.metadataBlocksForEdit = metadataBlocksForEdit; } @@ -417,7 +419,7 @@ public void setMetadataValueBlocks(DatasetVersion datasetVersion) { actualMDB.add(mdbTest); } } - } + } for (MetadataBlock mdb : actualMDB) { mdb.setEmpty(true); diff --git a/src/main/java/edu/harvard/iq/dataverse/MetadataBlock.java b/src/main/java/edu/harvard/iq/dataverse/MetadataBlock.java index 039915c7201..844c0ec5be7 100644 --- a/src/main/java/edu/harvard/iq/dataverse/MetadataBlock.java +++ b/src/main/java/edu/harvard/iq/dataverse/MetadataBlock.java @@ -35,7 +35,7 @@ @NamedQuery( name="MetadataBlock.findByName", query = "SELECT mdb FROM MetadataBlock mdb WHERE mdb.name=:name") }) @Entity -public class MetadataBlock implements Serializable { +public class MetadataBlock implements Serializable, Comparable { private static final long serialVersionUID = 1L; @@ -210,4 +210,12 @@ public String getLocaleDisplayName() return displayName; } } + + @Override + public int compareTo(Object arg0) { + //guaranteeing that citation will be shown first with custom blocks in order of creation + MetadataBlock other = (MetadataBlock) arg0; + Long t = "citation".equals(name) ? -1 : this.getId(); + return t.compareTo("citation".equals(other.name) ? -1 : other.getId()); + } } diff --git a/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/MoveDataverseCommandTest.java b/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/MoveDataverseCommandTest.java index e6f7a5ea34f..13b60f875d5 100644 --- a/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/MoveDataverseCommandTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/MoveDataverseCommandTest.java @@ -156,9 +156,11 @@ public void setUp() { mbA = new MetadataBlock(); mbA.setOwner(root); mbA.setId(1l); + mbA.setName("mbA"); mbB = new MetadataBlock(); mbB.setOwner(childE); mbB.setId(2l); + mbB.setName("mbB"); mbsE.add(mbB); mbsEE.add(mbA); mbsEE.add(mbB);