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

Commit 905d610

Browse files
author
sowerstl
committed
Add Biblio Link to API Output; (DOECODE-788)
1 parent 55222ba commit 905d610

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
*/
3+
package gov.osti.entity;
4+
5+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
7+
import java.io.Serializable;
8+
import java.util.Objects;
9+
10+
/**
11+
* A Link for Biblio, for SEO usage.
12+
*
13+
* @author sowerst
14+
*/
15+
@JsonIgnoreProperties ( ignoreUnknown = true )
16+
public class BiblioLink implements Serializable {
17+
private static final long serialVersionUID = 1L;
18+
19+
@JacksonXmlProperty(isAttribute = true)
20+
private String rel;
21+
@JacksonXmlProperty(isAttribute = true)
22+
private String href;
23+
24+
public BiblioLink() {
25+
26+
}
27+
28+
public BiblioLink(String rel, String href) {
29+
this.setRel(rel);
30+
this.setHref(href);
31+
}
32+
33+
/**
34+
* @return the rel
35+
*/
36+
public String getRel() {
37+
return rel;
38+
}
39+
40+
/**
41+
* @param rel the rel to set
42+
*/
43+
public void setRel(String rel) {
44+
this.rel = rel;
45+
}
46+
47+
/**
48+
* @return the href
49+
*/
50+
public String getHref() {
51+
return href;
52+
}
53+
54+
/**
55+
* @param href the value to set
56+
*/
57+
public void setHref(String href) {
58+
this.href = href;
59+
}
60+
61+
@Override
62+
public boolean equals(Object o) {
63+
if (o instanceof BiblioLink ) {
64+
return (((BiblioLink)o).getRel().equals(getRel()) && ((BiblioLink)o).getHref().equals(getHref()));
65+
}
66+
67+
return false;
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
int hash = 7;
73+
hash = 83 * hash + Objects.hashCode(this.rel);
74+
hash = 83 * hash + Objects.hashCode(this.href);
75+
return hash;
76+
}
77+
78+
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import java.io.Reader;
1515
import java.util.List;
1616

17+
import gov.osti.entity.BiblioLink;
18+
import gov.osti.listeners.DoeServletContextListener;
19+
import java.util.ArrayList;
20+
1721
import javax.persistence.Entity;
1822
import javax.persistence.GeneratedValue;
1923
import javax.persistence.GenerationType;
@@ -64,6 +68,9 @@ public class DOECodeMetadata implements Serializable {
6468
private static final long serialVersionUID = -909574677603914304L;
6569
private static final Logger log = LoggerFactory.getLogger(DOECodeMetadata.class.getName());
6670

71+
// get the SITE URL base for applications
72+
private static String SITE_URL = DoeServletContextListener.getConfigurationProperty("site.url");
73+
6774
/**
6875
* Record states/work flow:
6976
* Saved - stored to the database without validation
@@ -235,6 +242,10 @@ public String label() {
235242
// determine whether or not the RELEASE DATE was changed
236243
private transient boolean hasSetReleaseDate=false;
237244

245+
@JacksonXmlElementWrapper (localName = "links")
246+
@JacksonXmlProperty (localName = "link")
247+
private transient List<BiblioLink> links;
248+
238249
// Jackson object mapper
239250
private static final ObjectMapper mapper = new ObjectMapper()
240251
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
@@ -277,7 +288,7 @@ public Long getCodeId() {
277288
}
278289

279290
public void setCodeId(Long codeId) {
280-
this.codeId = codeId;
291+
this.codeId = codeId;
281292
}
282293

283294
@Column (name="SITE_OWNERSHIP_CODE")
@@ -803,6 +814,16 @@ public boolean hasSetReleaseDate() {
803814
return hasSetReleaseDate;
804815
}
805816

817+
public List<BiblioLink> getLinks() {
818+
String biblioLink = SITE_URL + "/biblio/" + this.codeId;
819+
820+
this.links = new ArrayList<>();
821+
BiblioLink citationLink = new BiblioLink("citation", biblioLink);
822+
this.links.add(citationLink);
823+
824+
return this.links;
825+
}
826+
806827
/**
807828
* Obtain the SOFTWARE TYPE: one of Type.S (scientific) or Type.B (Business)
808829
*

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ A full JSON example is [provided below](#json_example).
403403
| date_of_issuance | The date the software project was made available or submitted. |
404404
| software_title | The software title. |
405405
| software_type | The type of software, either "S" for Scientific, or "B" for Business related. |
406+
| links | (Array) Read-only set of URL links for the record. Only "citation" link is currently provided. |
406407
407408
### <a name="persons_fields"></a>Developers and Contributors
408409
Developers and Contributors are one-to-many Objects within a software project's metadata information.
@@ -571,7 +572,10 @@ metadata fields.
571572
"country_of_origin": "United States",
572573
"keywords": "doecode",
573574
"license":["Apache License 2.0"],
574-
"release_date":"2017-08-23"
575+
"release_date":"2017-08-23",
576+
"links": [
577+
{"rel": "citation",
578+
"href": "https://www.osti.gov/doecode/biblio/2651"}]
575579
}
576580
```
577581

src/main/java/gov/osti/services/Search.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ Content-Type: application/json
122122
"licenses": [
123123
"MIT License",
124124
"Mozilla Public License 2.0"
125+
],
126+
"links": [
127+
{
128+
"rel": "citation",
129+
"href": "https://dev.osti.gov/doecode/biblio/12345"
130+
}
125131
]
126132
}
127133
]
@@ -197,6 +203,12 @@ Content-Type: application/json
197203
"licenses": [
198204
"MIT License",
199205
"Mozilla Public License 2.0"
206+
],
207+
"links": [
208+
{
209+
"rel": "citation",
210+
"href": "https://dev.osti.gov/doecode/biblio/12345"
211+
}
200212
]
201213
}
202214
]

0 commit comments

Comments
 (0)