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

Commit c319840

Browse files
author
sowerstl
committed
Add processOSTIGitLab logic to Announce; (DOECODE-424)
1 parent 1ed28e4 commit c319840

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,13 +1168,25 @@ private Response doAnnounce(String json, InputStream file, FormDataContentDispos
11681168
store(em, md, user);
11691169

11701170
// if there's a FILE associated here, store it
1171+
String fileName = null;
1172+
String base64 = null;
11711173
if ( null!=file && null!=fileInfo ) {
11721174
// re-attach metadata to transaction in order to store the filename
11731175
md = em.find(DOECodeMetadata.class, md.getCodeId());
11741176

11751177
try {
1176-
String fileName = writeFile(file, md.getCodeId(), fileInfo.getFileName());
1178+
// can only read InputStream once, so copy in order to reset for base64 conversion
1179+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
1180+
org.apache.commons.io.IOUtils.copy(file, baos);
1181+
byte[] bytes = baos.toByteArray();
1182+
1183+
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
1184+
fileName = writeFile(bais, md.getCodeId(), fileInfo.getFileName());
11771185
md.setFileName(fileName);
1186+
1187+
// convert to base64 for GitLab
1188+
bais.reset();
1189+
base64 = convertBase64(bais);
11781190
} catch ( IOException e ) {
11791191
log.error ("File Upload Failed: " + e.getMessage());
11801192
return ErrorResponse
@@ -1183,6 +1195,17 @@ private Response doAnnounce(String json, InputStream file, FormDataContentDispos
11831195
}
11841196
}
11851197

1198+
// create OSTI Hosted project, as needed
1199+
try {
1200+
// process local GitLab, if needed
1201+
processOSTIGitLab(md, fileName, base64);
1202+
} catch ( Exception e ) {
1203+
log.error("OSTI GitLab failure: " + e.getMessage());
1204+
return ErrorResponse
1205+
.internalServerError("Unable to create OSTI Hosted project.")
1206+
.build();
1207+
}
1208+
11861209
// check validations
11871210
List<String> errors = validateAnnounce(md);
11881211
if ( !errors.isEmpty() ) {

0 commit comments

Comments
 (0)