From c129474b2f90bfe1087b9c62660fed02c0577eb3 Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Wed, 5 Jun 2024 14:27:13 -0400 Subject: [PATCH 1/5] #8796 fix display when no custom terms entered --- .../dataverse/DatasetVersionServiceBean.java | 17 +++++++++++++ .../iq/dataverse/TermsOfUseAndAccess.java | 24 +++++++++++++++++++ .../iq/dataverse/dataset/DatasetUtil.java | 18 ++++++++++++++ .../iq/dataverse/search/IndexServiceBean.java | 12 ++++++++++ src/main/java/propertyFiles/Bundle.properties | 2 ++ src/main/webapp/dataset-license-terms.xhtml | 4 ++-- .../search/IndexServiceBeanTest.java | 1 + 7 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java index ab23fa779d5..f99b3ee1b53 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionServiceBean.java @@ -315,6 +315,23 @@ private void msg(String s){ //logger.fine(s); } + public boolean isVersionDefaultCustomTerms(DatasetVersion datasetVersion) { + + if (datasetVersion.getId() != null) { + try { + TermsOfUseAndAccess toua = (TermsOfUseAndAccess) em.createNamedQuery("TermsOfUseAndAccess.findByDatasetVersionIdAndDefaultTerms") + .setParameter("id", datasetVersion.getId()).setParameter("defaultTerms", TermsOfUseAndAccess.DEFAULT_NOTERMS).getSingleResult(); + if (toua != null && datasetVersion.getTermsOfUseAndAccess().getLicense() == null) { + return true; + } + + } catch (NoResultException e) { + return false; + } + } + return false; + } + /** * Does the version identifier in the URL ask for a "DRAFT"? * diff --git a/src/main/java/edu/harvard/iq/dataverse/TermsOfUseAndAccess.java b/src/main/java/edu/harvard/iq/dataverse/TermsOfUseAndAccess.java index ee865770dbe..9e48c6c0165 100644 --- a/src/main/java/edu/harvard/iq/dataverse/TermsOfUseAndAccess.java +++ b/src/main/java/edu/harvard/iq/dataverse/TermsOfUseAndAccess.java @@ -17,6 +17,28 @@ import jakarta.persistence.Transient; import edu.harvard.iq.dataverse.license.License; +import jakarta.persistence.NamedQueries; +import jakarta.persistence.NamedQuery; + +@NamedQueries({ + // TermsOfUseAndAccess.findByDatasetVersionIdAndDefaultTerms + // is used to determine if the dataset terms were set by the multi license support update + // as part of the 5.10 release. + + @NamedQuery(name = "TermsOfUseAndAccess.findByDatasetVersionIdAndDefaultTerms", + query = "SELECT o FROM TermsOfUseAndAccess o, DatasetVersion dv WHERE " + + "dv.id =:id " + + "AND dv.termsOfUseAndAccess.id = o.id " + + "AND o.termsOfUse =:defaultTerms " + + "AND o.confidentialityDeclaration IS null " + + "AND o.specialPermissions IS null " + + "AND o.restrictions IS null " + + "AND o.citationRequirements IS null " + + "AND o.depositorRequirements IS null " + + "AND o.conditions IS null " + + "AND o.disclaimer IS null " + ) +}) /** * @@ -26,6 +48,8 @@ @Entity @ValidateTermsOfUseAndAccess public class TermsOfUseAndAccess implements Serializable { + + public static final String DEFAULT_NOTERMS = "This dataset is made available without information on how it can be used. You should communicate with the Contact(s) specified before use."; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java index 98bd26b51d6..060b8694e9c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java @@ -653,6 +653,15 @@ public static License getLicense(DatasetVersion dsv) { } public static String getLicenseName(DatasetVersion dsv) { + + DatasetVersionServiceBean datasetVersionService = CDI.current().select(DatasetVersionServiceBean.class).get(); + /* + Special case where there are default custom terms indicating that no actual choice has been made... + */ + if (datasetVersionService.isVersionDefaultCustomTerms(dsv)) { + return BundleUtil.getStringFromBundle("license.none.chosen"); + } + License license = DatasetUtil.getLicense(dsv); return getLocalizedLicenseName(license); } @@ -683,7 +692,16 @@ public static String getLicenseIcon(DatasetVersion dsv) { } public static String getLicenseDescription(DatasetVersion dsv) { + + DatasetVersionServiceBean datasetVersionService = CDI.current().select(DatasetVersionServiceBean.class).get(); + /* + Special case where there are default custom terms indicating that no actual choice has been made... + */ + if (datasetVersionService.isVersionDefaultCustomTerms(dsv)) { + return BundleUtil.getStringFromBundle("license.none.chosen.description"); + } License license = DatasetUtil.getLicense(dsv); + return license != null ? getLocalizedLicenseDetails(license,"DESCRIPTION") : BundleUtil.getStringFromBundle("license.custom.description"); } diff --git a/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java index e61b93a741f..cbe6c532a65 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java @@ -53,7 +53,9 @@ import jakarta.inject.Named; import jakarta.json.JsonObject; import jakarta.persistence.EntityManager; +import jakarta.persistence.NoResultException; import jakarta.persistence.PersistenceContext; +import jakarta.persistence.Query; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -96,6 +98,8 @@ public class IndexServiceBean { @EJB DatasetServiceBean datasetService; @EJB + DatasetVersionServiceBean datasetVersionService; + @EJB BuiltinUserServiceBean dataverseUserServiceBean; @EJB PermissionServiceBean permissionService; @@ -468,11 +472,13 @@ public void indexDvObject(DvObject objectIn) throws SolrServerException, IOExce public void indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) throws SolrServerException, IOException { doIndexDataset(dataset, doNormalSolrDocCleanUp); + System.out.print("indexed: " + dataset.getId()); updateLastIndexedTime(dataset.getId()); } private void doIndexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) throws SolrServerException, IOException { logger.fine("indexing dataset " + dataset.getId()); + System.out.print("indexing dataset " + dataset.getId()); /** * @todo should we use solrDocIdentifierDataset or * IndexableObject.IndexableTypes.DATASET.getName() + "_" ? @@ -1694,6 +1700,12 @@ private List getDataversePathsFromSegments(List dataversePathSeg private void addLicenseToSolrDoc(SolrInputDocument solrInputDocument, DatasetVersion datasetVersion) { if (datasetVersion != null && datasetVersion.getTermsOfUseAndAccess() != null) { + //test to see if the terms of use are the default set in 5.10 - if so and there's no license then don't add license to solr doc. + //fixes 10513 + if (datasetVersionService.isVersionDefaultCustomTerms(datasetVersion)){ + return; + } + String licenseName = "Custom Terms"; if(datasetVersion.getTermsOfUseAndAccess().getLicense() != null) { licenseName = datasetVersion.getTermsOfUseAndAccess().getLicense().getName(); diff --git a/src/main/java/propertyFiles/Bundle.properties b/src/main/java/propertyFiles/Bundle.properties index 0441853eee9..c32adb352a8 100644 --- a/src/main/java/propertyFiles/Bundle.properties +++ b/src/main/java/propertyFiles/Bundle.properties @@ -1445,6 +1445,8 @@ dataset.exportBtn.itemLabel.json=JSON dataset.exportBtn.itemLabel.oai_ore=OAI_ORE dataset.exportBtn.itemLabel.dataciteOpenAIRE=OpenAIRE dataset.exportBtn.itemLabel.html=DDI HTML Codebook +license.none.chosen=No license or custom terms chosen +license.none.chosen.description=No custom terms have been entered for this dataset license.custom=Custom Dataset Terms license.custom.description=Custom terms specific to this dataset metrics.title=Metrics diff --git a/src/main/webapp/dataset-license-terms.xhtml b/src/main/webapp/dataset-license-terms.xhtml index c54d94442ea..88bd75947cb 100644 --- a/src/main/webapp/dataset-license-terms.xhtml +++ b/src/main/webapp/dataset-license-terms.xhtml @@ -46,8 +46,8 @@

- - + +

diff --git a/src/test/java/edu/harvard/iq/dataverse/search/IndexServiceBeanTest.java b/src/test/java/edu/harvard/iq/dataverse/search/IndexServiceBeanTest.java index 92b06e5936f..c062f63e264 100644 --- a/src/test/java/edu/harvard/iq/dataverse/search/IndexServiceBeanTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/search/IndexServiceBeanTest.java @@ -51,6 +51,7 @@ public void setUp() { indexService.settingsService = Mockito.mock(SettingsServiceBean.class); indexService.dataverseService = Mockito.mock(DataverseServiceBean.class); indexService.datasetFieldService = Mockito.mock(DatasetFieldServiceBean.class); + indexService.datasetVersionService = Mockito.mock(DatasetVersionServiceBean.class); BrandingUtil.injectServices(indexService.dataverseService, indexService.settingsService); Mockito.when(indexService.dataverseService.findRootDataverse()).thenReturn(dataverse); From 7cb45960dfcad5b9e6f41c052769a174f2e8704a Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Wed, 5 Jun 2024 15:19:41 -0400 Subject: [PATCH 2/5] #8796 code cleanup --- .../edu/harvard/iq/dataverse/search/IndexServiceBean.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java index 02f04d38bd1..129e3f5af16 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java @@ -54,9 +54,7 @@ import jakarta.inject.Named; import jakarta.json.JsonObject; import jakarta.persistence.EntityManager; -import jakarta.persistence.NoResultException; import jakarta.persistence.PersistenceContext; -import jakarta.persistence.Query; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -476,13 +474,11 @@ public void indexDvObject(DvObject objectIn) throws SolrServerException, IOExce public void indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) throws SolrServerException, IOException { doIndexDataset(dataset, doNormalSolrDocCleanUp); - System.out.print("indexed: " + dataset.getId()); updateLastIndexedTime(dataset.getId()); } private void doIndexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) throws SolrServerException, IOException { logger.fine("indexing dataset " + dataset.getId()); - System.out.print("indexing dataset " + dataset.getId()); /** * @todo should we use solrDocIdentifierDataset or * IndexableObject.IndexableTypes.DATASET.getName() + "_" ? From 3d9592cdc20ae20c339fdd59f975cdfcfe09081c Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Wed, 5 Jun 2024 16:44:01 -0400 Subject: [PATCH 3/5] #8796 add release note --- doc/release-notes/8796-fix-license-display-indexing.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/release-notes/8796-fix-license-display-indexing.md diff --git a/doc/release-notes/8796-fix-license-display-indexing.md b/doc/release-notes/8796-fix-license-display-indexing.md new file mode 100644 index 00000000000..ebded088875 --- /dev/null +++ b/doc/release-notes/8796-fix-license-display-indexing.md @@ -0,0 +1 @@ +When datasets have neither a license nor custom terms of use the display will indicate this. Also, these datasets will no longer be indexed as having custom terms. From 584dad757bbb5b9e438466b50e2b6fefdfac8a2e Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Wed, 5 Jun 2024 16:58:45 -0400 Subject: [PATCH 4/5] #8796 fix popups --- src/main/webapp/datasetLicenseInfoFragment.xhtml | 2 +- src/main/webapp/guestbook-terms-popup-fragment.xhtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/datasetLicenseInfoFragment.xhtml b/src/main/webapp/datasetLicenseInfoFragment.xhtml index 257f6b3b12f..a1bd604aa6a 100644 --- a/src/main/webapp/datasetLicenseInfoFragment.xhtml +++ b/src/main/webapp/datasetLicenseInfoFragment.xhtml @@ -22,7 +22,7 @@ xmlns:jsf="http://xmlns.jcp.org/jsf"> target="_blank">#{DatasetUtil:getLicenseName(DatasetPage.workingVersion)} -

diff --git a/src/main/webapp/guestbook-terms-popup-fragment.xhtml b/src/main/webapp/guestbook-terms-popup-fragment.xhtml index 5948047d845..d53c4bf4709 100644 --- a/src/main/webapp/guestbook-terms-popup-fragment.xhtml +++ b/src/main/webapp/guestbook-terms-popup-fragment.xhtml @@ -48,7 +48,7 @@ - From 194b099902132d50b4ae961fbd427f2b69f05541 Mon Sep 17 00:00:00 2001 From: Leonid Andreev Date: Wed, 17 Jul 2024 12:33:17 -0400 Subject: [PATCH 5/5] an extra null check on TermsOfUse - this should fix #10513 for datasets harvested in oai_dc, and not break anything else... I think? #8796 --- .../edu/harvard/iq/dataverse/search/IndexServiceBean.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java index 78bc80a798d..c91eb0bfa7c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/IndexServiceBean.java @@ -1849,8 +1849,12 @@ private void addLicenseToSolrDoc(SolrInputDocument solrInputDocument, DatasetVer } String licenseName = "Custom Terms"; - if(datasetVersion.getTermsOfUseAndAccess().getLicense() != null) { + if (datasetVersion.getTermsOfUseAndAccess().getLicense() != null) { licenseName = datasetVersion.getTermsOfUseAndAccess().getLicense().getName(); + } else if (datasetVersion.getTermsOfUseAndAccess().getTermsOfUse() == null) { + // this fixes #10513 for datasets harvested in oai_dc - these + // have neither the license id, nor any actual custom terms + return; } solrInputDocument.addField(SearchFields.DATASET_LICENSE, licenseName); }