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

Commit a0b94aa

Browse files
committed
v1.2:
adding java bean validations to various character fields for length checks prior to database persistence modified ApprovedMetadata to MetadataSnapshot, and repurposed it to track various workflow states by CODE ID (Submitted, Approved, and Announced) Signed-off-by: Neal Ensor <[email protected]>
1 parent 456ce78 commit a0b94aa

File tree

8 files changed

+214
-20
lines changed

8 files changed

+214
-20
lines changed

pom.xml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,31 @@
179179
<type>jar</type>
180180
</dependency>
181181

182+
<!-- javax bean validation reference spec -->
183+
<dependency>
184+
<groupId>javax.validation</groupId>
185+
<artifactId>validation-api</artifactId>
186+
<version>2.0.0.Final</version>
187+
</dependency>
188+
189+
<!-- Java Bean validation libraries from Hibernate -->
190+
<dependency>
191+
<groupId>org.hibernate.validator</groupId>
192+
<artifactId>hibernate-validator</artifactId>
193+
<version>6.0.2.Final</version>
194+
</dependency>
195+
<dependency>
196+
<groupId>org.hibernate.validator</groupId>
197+
<artifactId>hibernate-validator-annotation-processor</artifactId>
198+
<version>6.0.2.Final</version>
199+
</dependency>
182200

183-
<dependency>
201+
<!-- apache shiro authentication layer -->
202+
<dependency>
184203
<groupId>org.apache.shiro</groupId>
185204
<artifactId>shiro-core</artifactId>
186205
<version>1.3.2</version>
187-
</dependency>
206+
</dependency>
188207

189208
<dependency>
190209
<groupId>org.apache.shiro</groupId>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.persistence.GenerationType;
99
import javax.persistence.Id;
1010
import javax.persistence.MappedSuperclass;
11+
import javax.validation.constraints.Size;
1112
import org.apache.commons.lang3.StringUtils;
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
@@ -45,20 +46,23 @@ public void setAgentId(Long id) {
4546
this.agentId = id;
4647
}
4748

49+
@Size (max = 255, message = "First name is limited to 255 characters.")
4850
@Column (name = "FIRST_NAME")
4951
public String getFirstName() {
5052
return firstName;
5153
}
5254
public void setFirstName(String firstName) {
5355
this.firstName = firstName;
5456
}
57+
@Size (max = 255, message = "Last name is limited to 255 characters.")
5558
@Column (name = "LAST_NAME")
5659
public String getLastName() {
5760
return lastName;
5861
}
5962
public void setLastName(String lastName) {
6063
this.lastName = lastName;
6164
}
65+
@Size (max = 255, message = "Middle name is limited to 255 characters.")
6266
@Column (name = "MIDDLE_NAME")
6367
public String getMiddleName() {
6468
return middleName;
@@ -67,6 +71,7 @@ public void setMiddleName(String middleName) {
6771
this.middleName = middleName;
6872
}
6973

74+
@Size (max = 640, message = "Email is limited to 640 characters.")
7075
@Column (length = 640)
7176
public String getEmail() {
7277
return email;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import javax.persistence.PreUpdate;
3939
import javax.persistence.Temporal;
4040
import javax.persistence.TemporalType;
41+
import javax.validation.Valid;
42+
import javax.validation.constraints.Size;
4143
import javax.xml.bind.annotation.XmlRootElement;
4244
import org.slf4j.Logger;
4345
import org.slf4j.LoggerFactory;
@@ -63,10 +65,12 @@ public class DOECodeMetadata implements Serializable {
6365
* Saved - stored to the database without validation
6466
* Submitted - validated to business logic rules, and/or sent to OSTI
6567
* Approved - ready to be sent to SOLR/search services
68+
* Announced - sent to OSTI
6669
*/
6770
public enum Status {
6871
Saved,
6972
Submitted,
73+
Announced,
7074
Approved
7175
}
7276

@@ -270,6 +274,7 @@ public Boolean getOpenSource() {
270274
public void setOpenSource(Boolean openSource) {
271275
this.openSource = openSource;
272276
}
277+
@Size (max = 255, message = "Repository link is limited to 255 characters.")
273278
@Column (name="REPOSITORY_LINK")
274279
public String getRepositoryLink() {
275280
return repositoryLink;
@@ -306,6 +311,7 @@ public void setAccessLimitations(List<String> limitations) {
306311
*/
307312
@OneToMany (cascade = CascadeType.ALL, orphanRemoval = true)
308313
@JoinColumn (name="OWNER_ID", referencedColumnName = "CODE_ID")
314+
@Valid
309315
public List<Contributor> getContributors() {
310316
return this.contributors;
311317
}
@@ -316,6 +322,7 @@ public List<Contributor> getContributors() {
316322
*/
317323
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
318324
@JoinColumn (name ="OWNER_ID", referencedColumnName = "CODE_ID")
325+
@Valid
319326
public List<SponsoringOrganization> getSponsoringOrganizations() {
320327
return this.sponsoringOrganizations;
321328
}
@@ -326,6 +333,7 @@ public List<SponsoringOrganization> getSponsoringOrganizations() {
326333
*/
327334
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
328335
@JoinColumn (name = "OWNER_ID", referencedColumnName = "CODE_ID")
336+
@Valid
329337
public List<ContributingOrganization> getContributingOrganizations() {
330338
return this.contributingOrganizations;
331339
}
@@ -336,29 +344,34 @@ public List<ContributingOrganization> getContributingOrganizations() {
336344
*/
337345
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
338346
@JoinColumn (name="OWNER_ID", referencedColumnName = "CODE_ID")
347+
@Valid
339348
public List<ResearchOrganization> getResearchOrganizations() {
340349
return this.researchOrganizations;
341350
}
342351

352+
@Size (max = 1000, message = "Software title is limited to 1000 characters.")
343353
@Column (name = "SOFTWARE_TITLE", length = 1000)
344354
public String getSoftwareTitle() {
345355
return softwareTitle;
346356
}
347357
public void setSoftwareTitle(String softwareTitle) {
348358
this.softwareTitle = softwareTitle;
349359
}
360+
@Size (max = 255, message = "Acronym is limited to 255 characters.")
350361
public String getAcronym() {
351362
return acronym;
352363
}
353364
public void setAcronym(String acronym) {
354365
this.acronym = acronym;
355366
}
367+
@Size (max = 255, message = "DOI is limited to 255 characters.")
356368
public String getDoi() {
357369
return doi;
358370
}
359371
public void setDoi(String doi) {
360372
this.doi = doi;
361373
}
374+
@Size (max = 4000, message = "Description is limited to 4000 characters.")
362375
@Column (length = 4000, name = "description")
363376
public String getDescription() {
364377
return description;
@@ -380,20 +393,23 @@ public List<RelatedIdentifier> getRelatedIdentifiers() {
380393
return this.relatedIdentifiers;
381394
}
382395

396+
@Size (max = 255, message = "Country is limited to 255 characters.")
383397
@Column (name = "COUNTRY_OF_ORIGIN")
384398
public String getCountryOfOrigin() {
385399
return countryOfOrigin;
386400
}
387401
public void setCountryOfOrigin(String countryOfOrigin) {
388402
this.countryOfOrigin = countryOfOrigin;
389403
}
404+
@Size (max = 500, message = "Keywords are limited to 500 characters.")
390405
@Column (length = 500)
391406
public String getKeywords() {
392407
return keywords;
393408
}
394409
public void setKeywords(String keywords) {
395410
this.keywords = keywords;
396411
}
412+
@Size (max = 3000, message = "Disclaimers are limited to 3000 characters.")
397413
@Column (length = 3000)
398414
public String getDisclaimers() {
399415
return disclaimers;
@@ -415,6 +431,7 @@ public void setLicenses(List<String> licenses) {
415431
}
416432

417433

434+
@Size (max = 255, message = "Proprietary URL is limited to 255 characters.")
418435
@Column (name="PROPRIETARY_URL")
419436
public String getProprietaryUrl() {
420437
return proprietaryUrl;
@@ -430,6 +447,7 @@ public void setProprietaryUrl(String proprietaryUrl) {
430447
*/
431448
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
432449
@JoinColumn (name="OWNER_ID", referencedColumnName = "CODE_ID")
450+
@Valid
433451
public List<Developer> getDevelopers() {
434452
return developers;
435453
}
@@ -476,27 +494,31 @@ public void setDevelopers(List<Developer> devlist) {
476494
this.developers = devlist;
477495
}
478496

497+
@Size (max = 255, message = "Recipient name is limited to 255 characters.")
479498
@Column (name = "RECIPIENT_NAME")
480499
public String getRecipientName() {
481500
return recipientName;
482501
}
483502
public void setRecipientName(String recipientName) {
484503
this.recipientName = recipientName;
485504
}
505+
@Size (max = 255, message = "Recipient email is limited to 255 characters.")
486506
@Column (name="RECIPIENT_EMAIL")
487507
public String getRecipientEmail() {
488508
return recipientEmail;
489509
}
490510
public void setRecipientEmail(String recipientEmail) {
491511
this.recipientEmail = recipientEmail;
492512
}
513+
@Size (max = 255, message = "Recipient phone is limited to 255 characters.")
493514
@Column (name="RECIPIENT_PHONE")
494515
public String getRecipientPhone() {
495516
return recipientPhone;
496517
}
497518
public void setRecipientPhone(String recipientPhone) {
498519
this.recipientPhone = recipientPhone;
499520
}
521+
@Size (max = 255, message = "Recipient organization is limited to 255 characters.")
500522
@Column (name = "RECIPIENT_ORGANIZATION")
501523
public String getRecipientOrg() {
502524
return recipientOrg;
@@ -505,6 +527,7 @@ public void setRecipientOrg(String recipientOrg) {
505527
this.recipientOrg = recipientOrg;
506528
}
507529

530+
@Size (max = 255, message = "Accession number is limited to 255 characters.")
508531
@Column (name="SITE_ACCESSION_NUMBER")
509532
public String getSiteAccessionNumber() {
510533
return siteAccessionNumber;
@@ -513,6 +536,7 @@ public void setSiteAccessionNumber(String siteAccessionNumber) {
513536
this.siteAccessionNumber = siteAccessionNumber;
514537
}
515538

539+
@Size (max = 1500, message = "Other special requirements field is limited to 255 characters.")
516540
@Column (name="OTHER_SPECIAL_REQUIREMENTS", length = 1500)
517541
public String getOtherSpecialRequirements() {
518542
return otherSpecialRequirements;
@@ -559,6 +583,7 @@ public Date getReleaseDate() {
559583
return this.releaseDate;
560584
}
561585

586+
@Size (max = 255, message = "Landing page URL is limited to 255 characters.")
562587
@Column (name="LANDING_PAGE")
563588
public String getLandingPage() {
564589
return landingPage;

src/main/java/gov/osti/entity/ApprovedMetadata.java renamed to src/main/java/gov/osti/entity/MetadataSnapshot.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,45 @@
22
package gov.osti.entity;
33

44
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import gov.osti.entity.DOECodeMetadata.Status;
56
import java.io.Serializable;
67
import javax.persistence.Column;
78
import javax.persistence.Entity;
9+
import javax.persistence.EnumType;
10+
import javax.persistence.Enumerated;
811
import javax.persistence.Id;
12+
import javax.persistence.IdClass;
913
import javax.persistence.Lob;
1014
import javax.persistence.NamedQueries;
1115
import javax.persistence.NamedQuery;
1216
import javax.persistence.Table;
17+
import javax.persistence.UniqueConstraint;
1318

1419
/**
1520
* A storage cache Entity for Approved Metadata values.
1621
*
1722
1823
*/
1924
@Entity
20-
@Table (name = "approved_metadata")
25+
@IdClass (MetadataSnapshotKey.class)
26+
@Table (name = "metadata_snapshot",
27+
uniqueConstraints = {
28+
@UniqueConstraint (columnNames = {"code_id", "snapshot_status"})
29+
}
30+
)
2131
@JsonIgnoreProperties (ignoreUnknown = true)
2232
@NamedQueries ({
23-
@NamedQuery (name = "ApprovedMetadata.findByCodeId", query = "SELECT a FROM ApprovedMetadata a WHERE a.codeId=:codeId"),
24-
@NamedQuery (name = "ApprovedMetadata.findAll", query = "SELECT a FROM ApprovedMetadata a")
33+
@NamedQuery (name = "MetadataSnapshot.findByCodeIdAndStatus", query = "SELECT s FROM MetadataSnapshot s WHERE s.codeId=:codeId AND s.snapshotStatus=:status"),
34+
@NamedQuery (name = "MetadataSnapshot.findAllByStatus", query = "SELECT s FROM MetadataSnapshot s WHERE s.snapshotStatus=:status")
2535
})
26-
public class ApprovedMetadata implements Serializable {
36+
public class MetadataSnapshot implements Serializable {
2737
@Id
2838
@Column (name = "code_id")
2939
private Long codeId;
40+
@Id
41+
@Enumerated (EnumType.STRING)
42+
@Column (name = "snapshot_status")
43+
private Status snapshotStatus;
3044
@Lob
3145
@Column (name = "json")
3246
private String json;
@@ -62,4 +76,18 @@ public String getJson() {
6276
public void setJson(String json) {
6377
this.json = json;
6478
}
79+
80+
/**
81+
* @return the snapshotStatus
82+
*/
83+
public Status getSnapshotStatus() {
84+
return snapshotStatus;
85+
}
86+
87+
/**
88+
* @param snapshotStatus the snapshotStatus to set
89+
*/
90+
public void setSnapshotStatus(Status snapshotStatus) {
91+
this.snapshotStatus = snapshotStatus;
92+
}
6593
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
*/
3+
package gov.osti.entity;
4+
5+
import gov.osti.entity.DOECodeMetadata.Status;
6+
import java.io.Serializable;
7+
import java.util.Objects;
8+
9+
/**
10+
* Implement a primary composite key for the METADATA_SNAPSHOT Entity.
11+
*
12+
* @author ensornl
13+
*/
14+
public class MetadataSnapshotKey implements Serializable {
15+
private Long codeId;
16+
private Status snapshotStatus;
17+
18+
/**
19+
* @return the codeId
20+
*/
21+
public Long getCodeId() {
22+
return codeId;
23+
}
24+
25+
/**
26+
* @param codeId the codeId to set
27+
*/
28+
public void setCodeId(Long codeId) {
29+
this.codeId = codeId;
30+
}
31+
32+
/**
33+
* @return the snapshotStatus
34+
*/
35+
public Status getSnapshotStatus() {
36+
return snapshotStatus;
37+
}
38+
39+
/**
40+
* @param snapshotStatus the snapshotStatus to set
41+
*/
42+
public void setSnapshotStatus(Status snapshotStatus) {
43+
this.snapshotStatus = snapshotStatus;
44+
}
45+
46+
@Override
47+
public boolean equals(Object o) {
48+
if (o instanceof MetadataSnapshotKey ) {
49+
return ((MetadataSnapshotKey)o).getCodeId().equals(getCodeId()) &&
50+
((MetadataSnapshotKey)o).getSnapshotStatus().equals(getSnapshotStatus());
51+
}
52+
53+
return false;
54+
}
55+
56+
@Override
57+
public int hashCode() {
58+
int hash = 7;
59+
hash = 83 * hash + Objects.hashCode(this.codeId);
60+
hash = 83 * hash + Objects.hashCode(this.snapshotStatus);
61+
return hash;
62+
}
63+
}

0 commit comments

Comments
 (0)