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

Commit aed3818

Browse files
committed
version 1.2 initial commit
Adds new validation for SUBMIT and ANNOUNCE: new field SOFTWARE_TYPE, one of enumerations Type.B (BUSINESS) or Type.S (SCIENTIFIC). If BUSINESS type, at least one SPONSORING ORGANIZATION is also required. modified MetadataTest unit tests appropriately; also changed method names to be consistent with terminology already in place. Signed-off-by: Neal Ensor <[email protected]>
1 parent 84c2180 commit aed3818

File tree

4 files changed

+83
-12
lines changed

4 files changed

+83
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>gov.osti</groupId>
55
<artifactId>doecode</artifactId>
66
<packaging>war</packaging>
7-
<version>1.1</version>
7+
<version>1.2</version>
88
<name>DOE Code Web Application</name>
99
<url>http://maven.apache.org</url>
1010

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,33 @@ public String label() {
123123
}
124124
}
125125

126+
/**
127+
* Define the valid SOFTWARE TYPES.
128+
*/
129+
public enum Type {
130+
S ("Scientific"),
131+
B ("Business");
132+
133+
private final String label;
134+
135+
private Type(String label) {
136+
this.label = label;
137+
}
138+
139+
public String label() {
140+
return this.label;
141+
}
142+
}
143+
126144
// Attributes
127145
private Long codeId;
128146
private String siteOwnershipCode = null;
129147
private Boolean openSource = null;
130148
private String repositoryLink = null;
131149
private String landingPage = null;
132150
private Accessibility accessibility = null;
133-
151+
// the SOFTWARE TYPE
152+
private Type softwareType;
134153
// set of Access Limitations (Strings)
135154
@JacksonXmlElementWrapper (localName = "accessLimitations")
136155
@JacksonXmlProperty (localName = "accessLimitation")
@@ -666,4 +685,25 @@ void updatedAt() {
666685
public boolean hasSetReleaseDate() {
667686
return setReleaseDate;
668687
}
688+
689+
/**
690+
* Obtain the SOFTWARE TYPE: one of Type.S (scientific) or Type.B (Business)
691+
*
692+
* @return the type the SOFTWARE TYPE
693+
*/
694+
@Basic (optional = false)
695+
@Column (name = "SOFTWARE_TYPE", length = 1)
696+
@Enumerated (EnumType.STRING)
697+
public Type getSoftwareType() {
698+
return softwareType;
699+
}
700+
701+
/**
702+
* Set the SOFTWARE TYPE value.
703+
*
704+
* @param type the type to set
705+
*/
706+
public void setSoftwareType(Type type) {
707+
this.softwareType = type;
708+
}
669709
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,13 @@ else if (m.getLicenses().contains(DOECodeMetadata.License.Other.value()) && Stri
14791479
if (!Validation.isValidUrl(m.getLandingPage()))
14801480
reasons.add("A valid Landing Page URL is required for non-open source submissions.");
14811481
}
1482+
// SOFTWARE TYPE is REQUIRED; BUSINESS type requires SPONSORING ORGANIZATION
1483+
if (null==m.getSoftwareType())
1484+
reasons.add("Software type is required.");
1485+
else if (DOECodeMetadata.Type.B.equals(m.getSoftwareType()))
1486+
if (null==m.getSponsoringOrganizations() || m.getSponsoringOrganizations().isEmpty())
1487+
reasons.add("A sponsor is required for Business software.");
1488+
14821489
// if repository link is present, it needs to be valid too
14831490
if (StringUtils.isNotBlank(m.getRepositoryLink()) && !Validation.isValidRepositoryLink(m.getRepositoryLink()))
14841491
reasons.add("Repository URL is not a valid repository.");

src/test/java/gov/osti/services/MetadataTest.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import gov.osti.entity.DOECodeMetadata;
66
import gov.osti.entity.Developer;
7+
import gov.osti.entity.SponsoringOrganization;
78
import java.util.ArrayList;
89
import java.util.Arrays;
910
import java.util.List;
@@ -17,7 +18,8 @@
1718
import org.junit.Test;
1819

1920
/**
20-
*
21+
* Test various METADATA related functionality.
22+
*
2123
* @author ensornl
2224
*/
2325
public class MetadataTest {
@@ -42,10 +44,10 @@ public void tearDown() {
4244
}
4345

4446
/**
45-
* Test that PUBLISHED VALIDATIONS work.
47+
* Test that SUBMIT VALIDATIONS work.
4648
*/
4749
@Test
48-
public void testValidatePublished() {
50+
public void testValidateSubmit() {
4951
DOECodeMetadata m = new DOECodeMetadata();
5052

5153
// empty metadata should have numerous errors
@@ -59,7 +61,8 @@ public void testValidatePublished() {
5961
"Description is required.",
6062
"A License is required.",
6163
"At least one developer is required.",
62-
"A valid Landing Page URL is required for non-open source submissions."
64+
"A valid Landing Page URL is required for non-open source submissions.",
65+
"Software type is required."
6366
};
6467

6568
for ( String message : validations ) {
@@ -75,6 +78,7 @@ public void testValidatePublished() {
7578
assertFalse("Still requiring title?", reasons.contains("Software title is required."));
7679
assertFalse("Still requiring accessibility", reasons.contains("Missing Source Accessibility."));
7780
assertTrue ("Missing OS validation", reasons.contains("Repository URL is required for open source submissions."));
81+
assertTrue ("Missing software type validation", reasons.contains("Software type is required."));
7882

7983
// test developer issues
8084
Developer d = new Developer();
@@ -127,18 +131,37 @@ public void testValidatePublished() {
127131
m.setDevelopers(developers);
128132
m.setProprietaryUrl("http://mylicense.com/terms.html");
129133
m.setDescription("This is a testing description.");
134+
m.setSoftwareType(DOECodeMetadata.Type.S);
130135

131136
reasons = Metadata.validateSubmit(m);
132137

133138
assertTrue ("Should be no more errors: " + StringUtils.join(reasons, ", "), reasons.isEmpty());
134139

140+
// assert that the BUSINESS additional requirement is there
141+
m.setSoftwareType(DOECodeMetadata.Type.B);
142+
143+
reasons = Metadata.validateSubmit(m);
144+
145+
assertFalse("Missing business validation", reasons.isEmpty());
146+
assertTrue ("Reason is wrong", reasons.contains("A sponsor is required for Business software."));
147+
148+
// fix it
149+
SponsoringOrganization sponsor = new SponsoringOrganization();
150+
sponsor.setPrimaryAward("AWARD");
151+
sponsor.setOrganizationName("Testing Business Validation");
152+
153+
m.setSponsoringOrganizations(Arrays.asList(sponsor));
154+
155+
reasons = Metadata.validateSubmit(m);
156+
157+
assertTrue ("Still have errors:" + StringUtils.join(reasons, ", "), reasons.isEmpty());
135158
}
136159

137160
/**
138-
* Test some SUBMIT validations.
161+
* Test some ANNOUNCE validations.
139162
*/
140163
@Test
141-
public void testValidateSubmit() {
164+
public void testValidateAnnounce() {
142165
// test that published ones also apply here
143166
DOECodeMetadata m = new DOECodeMetadata();
144167

@@ -153,9 +176,10 @@ public void testValidateSubmit() {
153176
"Description is required.",
154177
"A License is required.",
155178
"At least one developer is required.",
156-
"A valid Landing Page URL is required for non-open source submissions."
179+
"A valid Landing Page URL is required for non-open source submissions.",
180+
"Software type is required."
157181
};
158-
String[] submit_validations = {
182+
String[] announce_validations = {
159183
"Release date is required.",
160184
"At least one sponsoring organization is required.",
161185
"At least one research organization is required.",
@@ -169,8 +193,8 @@ public void testValidateSubmit() {
169193
assertTrue ("Missing: " + message, reasons.contains(message));
170194
}
171195

172-
// also check submit only validations
173-
for ( String message : submit_validations ) {
196+
// also check announce only validations
197+
for ( String message : announce_validations ) {
174198
assertTrue ("Missing: " + message, reasons.contains(message));
175199
}
176200
}

0 commit comments

Comments
 (0)