Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit fdd0c60

Browse files
author
Tim Sowers
committed
Validate license; (DOECODE-851)
1 parent cc7adc8 commit fdd0c60

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/main/java/gov/osti/entity/DOECodeMetadata.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.io.File;
1414
import java.io.Reader;
1515
import java.util.List;
16+
import java.util.Set;
17+
import java.util.HashSet;
1618

1719
import gov.osti.entity.BiblioLink;
1820
import gov.osti.listeners.DoeServletContextListener;
@@ -125,6 +127,13 @@ public enum License {
125127

126128
private final String label;
127129
private final String value;
130+
131+
private static final Set<String> values = new HashSet<String>(License.values().length);
132+
133+
static{
134+
for(License f: License.values())
135+
values.add(f.value());
136+
}
128137

129138
private License(String label, String value) {
130139
this.label =label;
@@ -138,6 +147,10 @@ public String value() {
138147
public String label() {
139148
return this.label;
140149
}
150+
151+
public static boolean contains(String value){
152+
return values.contains(value);
153+
}
141154
}
142155

143156
/**

src/main/java/gov/osti/services/Metadata.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import gov.osti.entity.MetadataSnapshot;
2929
import gov.osti.entity.DOECodeMetadata;
3030
import gov.osti.entity.DOECodeMetadata.Accessibility;
31+
import gov.osti.entity.DOECodeMetadata.License;
3132
import gov.osti.entity.DOECodeMetadata.Status;
3233
import gov.osti.entity.Developer;
3334
import gov.osti.entity.DoiReservation;
@@ -2394,6 +2395,12 @@ protected static List<String> validateSubmit(DOECodeMetadata m) {
23942395
reasons.add("A License is required.");
23952396
else if (hasLicense && m.getLicenses().contains(DOECodeMetadata.License.Other.value()) && StringUtils.isBlank(m.getProprietaryUrl()))
23962397
reasons.add("Proprietary License URL is required.");
2398+
if (hasLicense) {
2399+
for (String l : licenseList) {
2400+
if (!DOECodeMetadata.License.contains(l))
2401+
reasons.add("License not valid: [" + l +"]");
2402+
}
2403+
}
23972404
if (licenseContactRequired && !hasLicenseContactEmail)
23982405
reasons.add("A License Contact Email is required.");
23992406
if (null==m.getDevelopers() || m.getDevelopers().isEmpty())

0 commit comments

Comments
 (0)