Skip to content

Commit a018fdb

Browse files
committed
fix tests, fully enforce no license and terms in TofU&A
1 parent 9a34fe1 commit a018fdb

3 files changed

Lines changed: 97 additions & 18 deletions

File tree

src/main/java/edu/harvard/iq/dataverse/TermsOfUseAndAccess.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ public String getTermsOfUse() {
161161

162162
public void setTermsOfUse(String termsOfUse) {
163163
this.termsOfUse = termsOfUse;
164+
if (termsOfUse != null) {
165+
this.license = null;
166+
}
164167
}
165168

166169
public String getTermsOfAccess() {
@@ -177,6 +180,9 @@ public String getConfidentialityDeclaration() {
177180

178181
public void setConfidentialityDeclaration(String confidentialityDeclaration) {
179182
this.confidentialityDeclaration = confidentialityDeclaration;
183+
if (confidentialityDeclaration != null) {
184+
this.license = null;
185+
}
180186
}
181187

182188
public String getSpecialPermissions() {
@@ -185,6 +191,9 @@ public String getSpecialPermissions() {
185191

186192
public void setSpecialPermissions(String specialPermissions) {
187193
this.specialPermissions = specialPermissions;
194+
if (specialPermissions != null) {
195+
this.license = null;
196+
}
188197
}
189198

190199
public String getRestrictions() {
@@ -193,6 +202,9 @@ public String getRestrictions() {
193202

194203
public void setRestrictions(String restrictions) {
195204
this.restrictions = restrictions;
205+
if (restrictions != null) {
206+
this.license = null;
207+
}
196208
}
197209

198210
public String getCitationRequirements() {
@@ -201,6 +213,9 @@ public String getCitationRequirements() {
201213

202214
public void setCitationRequirements(String citationRequirements) {
203215
this.citationRequirements = citationRequirements;
216+
if (citationRequirements != null) {
217+
this.license = null;
218+
}
204219
}
205220

206221
public String getDepositorRequirements() {
@@ -209,6 +224,9 @@ public String getDepositorRequirements() {
209224

210225
public void setDepositorRequirements(String depositorRequirements) {
211226
this.depositorRequirements = depositorRequirements;
227+
if (depositorRequirements != null) {
228+
this.license = null;
229+
}
212230
}
213231

214232
public String getConditions() {
@@ -217,6 +235,9 @@ public String getConditions() {
217235

218236
public void setConditions(String conditions) {
219237
this.conditions = conditions;
238+
if (conditions != null) {
239+
this.license = null;
240+
}
220241
}
221242

222243
public String getDisclaimer() {
@@ -225,6 +246,9 @@ public String getDisclaimer() {
225246

226247
public void setDisclaimer(String disclaimer) {
227248
this.disclaimer = disclaimer;
249+
if (disclaimer != null) {
250+
this.license = null;
251+
}
228252
}
229253

230254
public String getDataAccessPlace() {

src/main/java/edu/harvard/iq/dataverse/util/json/JsonParser.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -491,24 +491,6 @@ public DatasetVersion parseDatasetVersion(JsonObject obj, DatasetVersion dsv) th
491491
}
492492
}
493493

494-
//test to see if license exists in dataset type
495-
//if not set it to null -
496-
//only test if Dataset has a type and if it has custom available licenses
497-
if (dsv.getDataset() != null) {
498-
DatasetType dst = dsv.getDataset().getDatasetType();
499-
if (dst != null && dst.getLicenses() != null && !dst.getLicenses().isEmpty() && license != null) {
500-
boolean invalidLicense = true;
501-
for (License testLicense : dst.getLicenses()) {
502-
if (testLicense.equals(license)) {
503-
invalidLicense = false;
504-
}
505-
}
506-
if (invalidLicense) {
507-
license = null;
508-
}
509-
}
510-
}
511-
512494
terms.setTermsOfUse(obj.getString("termsOfUse", null));
513495
terms.setConfidentialityDeclaration(obj.getString("confidentialityDeclaration", null));
514496
terms.setSpecialPermissions(obj.getString("specialPermissions", null));
@@ -547,6 +529,25 @@ public DatasetVersion parseDatasetVersion(JsonObject obj, DatasetVersion dsv) th
547529
terms.setFileAccessRequest(obj.getBoolean("fileAccessRequest", false));
548530
dsv.setTermsOfUseAndAccess(terms);
549531
terms.setDatasetVersion(dsv);
532+
533+
//test to see if license exists in dataset type
534+
//if not set it to null -
535+
//only test if Dataset has a type and if it has custom available licenses
536+
if (dsv.getDataset() != null) {
537+
DatasetType dst = dsv.getDataset().getDatasetType();
538+
if (dst != null && dst.getLicenses() != null && !dst.getLicenses().isEmpty() && license != null) {
539+
boolean invalidLicense = true;
540+
for (License testLicense : dst.getLicenses()) {
541+
if (testLicense.equals(license)) {
542+
invalidLicense = false;
543+
}
544+
}
545+
if (invalidLicense) {
546+
license = null;
547+
}
548+
}
549+
}
550+
550551
JsonObject metadataBlocks = obj.getJsonObject("metadataBlocks");
551552
if (metadataBlocks == null){
552553
throw new JsonParseException(BundleUtil.getStringFromBundle("jsonparser.error.metadatablocks.not.found"));
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package edu.harvard.iq.dataverse;
2+
3+
import org.junit.jupiter.api.Test;
4+
import edu.harvard.iq.dataverse.license.License;
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
public class TermsOfUseAndAccessTest {
8+
9+
@Test
10+
public void testLicenseAndTermsMutualExclusivity() {
11+
License license = new License();
12+
license.setName("CC0");
13+
14+
TermsOfUseAndAccess terms = new TermsOfUseAndAccess();
15+
16+
// 1. Setting license should clear terms
17+
terms.setTermsOfUse("Some terms");
18+
assertEquals("Some terms", terms.getTermsOfUse());
19+
assertNull(terms.getLicense());
20+
21+
terms.setLicense(license);
22+
assertNull(terms.getTermsOfUse());
23+
assertEquals(license, terms.getLicense());
24+
25+
// 2. Setting terms should clear license
26+
terms.setTermsOfUse("New terms");
27+
assertNull(terms.getLicense());
28+
assertEquals("New terms", terms.getTermsOfUse());
29+
30+
// 3. Test other fields clear license too
31+
terms.setLicense(license);
32+
terms.setConfidentialityDeclaration("Confidential");
33+
assertNull(terms.getLicense());
34+
assertEquals("Confidential", terms.getConfidentialityDeclaration());
35+
}
36+
37+
@Test
38+
public void testCopyTermsOfUseAndAccess() {
39+
License license = new License();
40+
license.setName("CC0");
41+
42+
TermsOfUseAndAccess terms = new TermsOfUseAndAccess();
43+
terms.setLicense(license);
44+
45+
TermsOfUseAndAccess copy = terms.copyTermsOfUseAndAccess();
46+
assertEquals(license, copy.getLicense());
47+
assertNull(copy.getTermsOfUse());
48+
49+
terms.setTermsOfUse("Some terms");
50+
TermsOfUseAndAccess copy2 = terms.copyTermsOfUseAndAccess();
51+
assertNull(copy2.getLicense());
52+
assertEquals("Some terms", copy2.getTermsOfUse());
53+
}
54+
}

0 commit comments

Comments
 (0)