Skip to content

Commit

Permalink
Merge pull request #10614 from IQSS/8796-fix-no-license-display-index
Browse files Browse the repository at this point in the history
8796 fix no license display and indexing
  • Loading branch information
landreev authored Jul 18, 2024
2 parents 93e7197 + 194b099 commit 4615f4f
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/release-notes/8796-fix-license-display-indexing.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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"?
*
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/TermsOfUseAndAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
)
})

/**
*
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class IndexServiceBean {
@EJB
DatasetServiceBean datasetService;
@EJB
DatasetVersionServiceBean datasetVersionService;
@EJB
BuiltinUserServiceBean dataverseUserServiceBean;
@EJB
PermissionServiceBean permissionService;
Expand Down Expand Up @@ -1840,9 +1842,19 @@ private List<String> getDataversePathsFromSegments(List<String> 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) {
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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/dataset-license-terms.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
</ui:fragment>
<ui:fragment rendered="#{empty editMode and empty termsOfUseAndAccess.license}">
<p>
<h:outputText value="#{bundle['license.custom'].concat(' ')}" escape="false"/>
<h:outputText value="#{bundle['file.dataFilesTab.terms.list.license.customterms.txt']}" escape="false"/>
<h:outputText value="#{DatasetUtil:getLicenseName(DatasetPage.workingVersion).concat(' ')}" escape="false"/>
<h:outputText rendered="#{!datasetVersionServiceBean.isVersionDefaultCustomTerms(DatasetPage.workingVersion)}" value="#{bundle['file.dataFilesTab.terms.list.license.customterms.txt']}" escape="false"/>
</p>
</ui:fragment>
<ui:fragment rendered="#{!empty editMode}">
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/datasetLicenseInfoFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ xmlns:jsf="http://xmlns.jcp.org/jsf">
target="_blank">#{DatasetUtil:getLicenseName(DatasetPage.workingVersion)}
</a>
<ui:fragment rendered="#{empty DatasetPage.workingVersion.termsOfUseAndAccess.license}">
<h:outputText value="#{bundle['file.dataFilesTab.terms.list.license.customterms.txt']}"
<h:outputText rendered="#{!datasetVersionServiceBean.isVersionDefaultCustomTerms(DatasetPage.workingVersion)}" value="#{bundle['file.dataFilesTab.terms.list.license.customterms.txt']}"
escape="false" />
</ui:fragment>
</p>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/guestbook-terms-popup-fragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</a>
<ui:fragment
rendered="#{empty workingVersion.termsOfUseAndAccess.license}">
<h:outputText
<h:outputText rendered="#{!datasetVersionServiceBean.isVersionDefaultCustomTerms(DatasetPage.workingVersion)}"
value="#{bundle['file.dataFilesTab.terms.list.license.customterms.txt']}"
escape="false" />
</ui:fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4615f4f

Please sign in to comment.