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

Commit c848a6b

Browse files
author
sowerstl
committed
Fix so that Saved uploads are later Archived; (DOECODE-612)
1 parent bb76e7f commit c848a6b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,15 @@ private Response doSubmit(String json, InputStream file, FormDataContentDisposit
14411441

14421442
DOECodeMetadata md = DOECodeMetadata.parseJson(new StringReader(json));
14431443

1444+
Long currentCodeId = md.getCodeId();
1445+
boolean previouslySaved = false;
1446+
if (currentCodeId != null) {
1447+
DOECodeMetadata emd = em.find(DOECodeMetadata.class, currentCodeId);
1448+
1449+
if (emd != null)
1450+
previouslySaved = Status.Saved.equals(emd.getWorkflowStatus());
1451+
}
1452+
14441453
em.getTransaction().begin();
14451454

14461455
removeRiDups(md);
@@ -1507,6 +1516,20 @@ private Response doSubmit(String json, InputStream file, FormDataContentDisposit
15071516

15081517
// send this file upload along to archiver if configured
15091518
try {
1519+
// if no file/container, but previously Saved with a file/container, we need to attach to those streams and send to Archiver
1520+
if (previouslySaved) {
1521+
if (null==file && !StringUtils.isBlank(md.getFileName())) {
1522+
java.nio.file.Path destination = Paths.get(FILE_UPLOADS, String.valueOf(md.getCodeId()), md.getFileName());
1523+
fullFileName = destination.toString();
1524+
file = Files.newInputStream(destination);
1525+
}
1526+
if (null==container && !StringUtils.isBlank(md.getContainerName())) {
1527+
java.nio.file.Path destination = Paths.get(CONTAINER_UPLOADS, String.valueOf(md.getCodeId()), md.getContainerName());
1528+
fullContainerName = destination.toString();
1529+
container = Files.newInputStream(destination);
1530+
}
1531+
}
1532+
15101533
// if a FILE or CONTAINER was sent, create a File Object from it
15111534
File archiveFile = (null==file) ? null : new File(fullFileName);
15121535
File archiveContainer = (null==container) ? null : new File(fullContainerName);
@@ -1607,6 +1630,15 @@ private Response doAnnounce(String json, InputStream file, FormDataContentDispos
16071630

16081631
DOECodeMetadata md = DOECodeMetadata.parseJson(new StringReader(json));
16091632

1633+
Long currentCodeId = md.getCodeId();
1634+
boolean previouslySaved = false;
1635+
if (currentCodeId != null) {
1636+
DOECodeMetadata emd = em.find(DOECodeMetadata.class, currentCodeId);
1637+
1638+
if (emd != null)
1639+
previouslySaved = Status.Saved.equals(emd.getWorkflowStatus());
1640+
}
1641+
16101642
em.getTransaction().begin();
16111643

16121644
removeRiDups(md);
@@ -1681,6 +1713,20 @@ private Response doAnnounce(String json, InputStream file, FormDataContentDispos
16811713

16821714
// send this file upload along to archiver if configured
16831715
try {
1716+
// if no file/container, but previously Saved with a file/container, we need to attach to those streams and send to Archiver
1717+
if (previouslySaved) {
1718+
if (null==file && !StringUtils.isBlank(md.getFileName())) {
1719+
java.nio.file.Path destination = Paths.get(FILE_UPLOADS, String.valueOf(md.getCodeId()), md.getFileName());
1720+
fullFileName = destination.toString();
1721+
file = Files.newInputStream(destination);
1722+
}
1723+
if (null==container && !StringUtils.isBlank(md.getContainerName())) {
1724+
java.nio.file.Path destination = Paths.get(CONTAINER_UPLOADS, String.valueOf(md.getCodeId()), md.getContainerName());
1725+
fullContainerName = destination.toString();
1726+
container = Files.newInputStream(destination);
1727+
}
1728+
}
1729+
16841730
// if a FILE or CONTAINER was sent, create a File Object from it
16851731
File archiveFile = (null==file) ? null : new File(fullFileName);
16861732
File archiveContainer = (null==container) ? null : new File(fullContainerName);

0 commit comments

Comments
 (0)