@@ -1027,18 +1027,13 @@ private Response doSubmit(String json, InputStream file, FormDataContentDisposit
10271027 }
10281028
10291029 // if there's a FILE associated here, store it
1030- String fileName = null ;
1031- String base64 = null ;
10321030 if ( null !=file && null !=fileInfo ) {
10331031 // re-attach metadata to transaction in order to store the filename
10341032 md = em .find (DOECodeMetadata .class , md .getCodeId ());
10351033
10361034 try {
1037- fileName = writeFile (file , md .getCodeId (), fileInfo .getFileName ());
1035+ String fileName = writeFile (file , md .getCodeId (), fileInfo .getFileName ());
10381036 md .setFileName (fileName );
1039-
1040- // convert to base64 for GitLab
1041- base64 = convertBase64 (new FileInputStream (fileName ));
10421037 } catch ( IOException e ) {
10431038 log .error ("File Upload Failed: " + e .getMessage ());
10441039 return ErrorResponse
@@ -1050,7 +1045,7 @@ private Response doSubmit(String json, InputStream file, FormDataContentDisposit
10501045 // create OSTI Hosted project, as needed
10511046 try {
10521047 // process local GitLab, if needed
1053- processOSTIGitLab (md , fileName , base64 );
1048+ processOSTIGitLab (md );
10541049 } catch ( Exception e ) {
10551050 log .error ("OSTI GitLab failure: " + e .getMessage ());
10561051 return ErrorResponse
@@ -1167,18 +1162,13 @@ private Response doAnnounce(String json, InputStream file, FormDataContentDispos
11671162 store (em , md , user );
11681163
11691164 // if there's a FILE associated here, store it
1170- String fileName = null ;
1171- String base64 = null ;
11721165 if ( null !=file && null !=fileInfo ) {
11731166 // re-attach metadata to transaction in order to store the filename
11741167 md = em .find (DOECodeMetadata .class , md .getCodeId ());
11751168
11761169 try {
1177- fileName = writeFile (file , md .getCodeId (), fileInfo .getFileName ());
1170+ String fileName = writeFile (file , md .getCodeId (), fileInfo .getFileName ());
11781171 md .setFileName (fileName );
1179-
1180- // convert to base64 for GitLab
1181- base64 = convertBase64 (new FileInputStream (fileName ));
11821172 } catch ( IOException e ) {
11831173 log .error ("File Upload Failed: " + e .getMessage ());
11841174 return ErrorResponse
@@ -1190,7 +1180,7 @@ private Response doAnnounce(String json, InputStream file, FormDataContentDispos
11901180 // create OSTI Hosted project, as needed
11911181 try {
11921182 // process local GitLab, if needed
1193- processOSTIGitLab (md , fileName , base64 );
1183+ processOSTIGitLab (md );
11941184 } catch ( Exception e ) {
11951185 log .error ("OSTI GitLab failure: " + e .getMessage ());
11961186 return ErrorResponse
@@ -1920,19 +1910,29 @@ private static void sendPOCNotification(DOECodeMetadata md) {
19201910 *
19211911 * @param md the METADATA to process GitLab for
19221912 */
1923- private static void processOSTIGitLab (DOECodeMetadata md , String filePath , String base64Content ) throws Exception {
1913+ private static void processOSTIGitLab (DOECodeMetadata md ) throws Exception {
19241914 // only process OSTI Hosted type
19251915 if (!DOECodeMetadata .Accessibility .CO .equals (md .getAccessibility ()))
19261916 return ;
19271917
1928- if (filePath == null )
1929- throw new Exception ("File Name required for OSTI Hosted project!" );
1918+ String fileName = md .getFileName ();
1919+
1920+ // sometimes getFileName returns a full path (this should be addressed overall, but temp fix here for now)
1921+ fileName = fileName .substring (fileName .lastIndexOf (File .separator )+1 );
1922+
1923+ String codeId = String .valueOf (md .getCodeId ());
1924+ java .nio .file .Path uploadedFile = Paths .get (FILE_UPLOADS , String .valueOf (codeId ), fileName );
1925+
1926+ // if no file was uploaded, fail
1927+ if (!Files .exists (uploadedFile ))
1928+ throw new Exception ("File not found in Uploads directory! [" + uploadedFile .toString () + "]" );
1929+
1930+ // convert to base64 for GitLab
1931+ String base64Content = convertBase64 (new FileInputStream (uploadedFile .toString ()));
19301932
19311933 if (base64Content == null )
19321934 throw new Exception ("Base 64 Content required for OSTI Hosted project!" );
19331935
1934- String fileName = new File (filePath ).getName ();
1935-
19361936 String projectName = "dc-" + md .getCodeId ();
19371937 String hostedFolder = "hosted_files" ;
19381938
0 commit comments