2828import net .sourceforge .seqware .common .metadata .Metadata ;
2929import net .sourceforge .seqware .common .metadata .MetadataDB ;
3030import net .sourceforge .seqware .common .metadata .MetadataFactory ;
31+ import net .sourceforge .seqware .common .model .ParentAccessionModel ;
3132import net .sourceforge .seqware .common .model .Processing ;
3233import net .sourceforge .seqware .common .module .FileMetadata ;
3334import net .sourceforge .seqware .common .module .ReturnValue ;
4344import org .apache .commons .io .FileUtils ;
4445
4546// FIXME: auto-adding to rc.data, support "," delimited
46- // FIXME: When adding STDOUT/STDERR to metadb, we should add a timestamp or something else to make it easier to merge. Right now, it is hard to tell which stdout message corresponds to which step in stderr
47+ // FIXME: When adding STDOUT/STDERR to metadb, we should add a timestamp or something else to make it easier to merge. Right now, it is hard to tell which stdout message corresponds to which step in stderr
4748// FIXME: is parent accession comma separated?
4849
4950/*
5051 * Run each method for the requested module object. Based on return value, either continue or exit:
5152 * Return values > 0 are errors that will cause the runner to exit.
5253 * Return of 0 implies success and the runner will continue, assuming all is well.
53- * Return of -1 implies the method was not implemented for that Module, AND IS NOT AN ERROR!!! By default the runner will continue on with steps as if it succeeded!
54+ * Return of -1 implies the method was not implemented for that Module, AND IS NOT AN ERROR!!! By default the runner will continue on with steps as if it succeeded!
5455 */
5556//Create a main() function here, which will be compiled in, to parse input and run all steps
5657/**
5758 * <p>
5859 * Runner class.
5960 * </p>
60- *
61+ *
6162 * @author boconnor
6263 * @version $Id: $Id
6364 */
@@ -185,7 +186,7 @@ public Runner() {
185186 * <p>
186187 * getSyntax.
187188 * </p>
188- *
189+ *
189190 * @param parser
190191 * a {@link joptsimple.OptionParser} object.
191192 * @param errorMessage
@@ -211,19 +212,20 @@ public static void getSyntax(OptionParser parser, String errorMessage) {
211212 System .exit (-1 );
212213 }
213214
214- private void writeProcessingAccessionToFile (File file , boolean append ) {
215+ private void writeStringToFile (File file , boolean append , String output ) {
215216 int maxTries = (Integer ) options .valueOf ("metadata-tries-number" );
216- for (int i = 0 ; i < maxTries ; i ++) {
217+ for (int i = 0 ; i <= maxTries ; i ++) {
218+ Log .fatal ("On try " + i + " of " + maxTries );
217219 // Break on success
218- if (LockingFileTools .lockAndWrite (file , processingAccession + System . getProperty ( "line.separator" ) , append )) {
220+ if (LockingFileTools .lockAndWrite (file , output , append )) {
219221 break ;
220222 } // Sleep if going to try again
221223 else if (i < maxTries ) {
222224 ProcessTools .sleep ((Integer ) options .valueOf ("metadata-tries-delay" ));
223225 } // Return error if failed on last try
224- else {
226+ if ( maxTries == i ) {
225227 ReturnValue retval = new ReturnValue ();
226- retval .printAndAppendtoStderr ("Could not write to processingAccession File for metadata" );
228+ retval .printAndAppendtoStderr ("Could not write to " + file . getAbsolutePath () + " for metadata" );
227229 retval .setExitStatus (ReturnValue .METADATAINVALIDIDCHAIN );
228230 meta .update_processing_event (processingID , retval );
229231 meta .update_processing_status (processingID , ProcessingStatus .failed );
@@ -236,7 +238,7 @@ else if (i < maxTries) {
236238 * <p>
237239 * printAndAppendtoStderr.
238240 * </p>
239- *
241+ *
240242 * @param buffer
241243 * a {@link java.lang.String} object.
242244 */
@@ -249,7 +251,7 @@ public void printAndAppendtoStderr(String buffer) {
249251 * <p>
250252 * printAndAppendtoStdout.
251253 * </p>
252- *
254+ *
253255 * @param buffer
254256 * a {@link java.lang.String} object.
255257 */
@@ -266,7 +268,7 @@ public void printAndAppendtoStdout(String buffer) {
266268 * <p>
267269 * evaluateReturn.
268270 * </p>
269- *
271+ *
270272 * @param app
271273 * a {@link net.sourceforge.seqware.pipeline.module.Module} object.
272274 * @param methodName
@@ -370,7 +372,7 @@ public void evaluateReturn(Module app, String methodName) {
370372
371373 /**
372374 * FIXME: this needs to be migrated to something that is ZIP64 aware. Try using the unzip feature of FileTools.java
373- *
375+ *
374376 * @param zipFile
375377 * a {@link java.lang.String} object.
376378 * @throws java.util.zip.ZipException
@@ -438,7 +440,7 @@ public static void unzipPkg(String zipFile) throws ZipException, IOException {
438440 * <p>
439441 * main.
440442 * </p>
441- *
443+ *
442444 * @param args
443445 * an array of {@link java.lang.String} objects.
444446 */
@@ -642,24 +644,7 @@ private void preProcessMetadata() {
642644
643645 try {
644646 if ((file .exists () || file .createNewFile ()) && file .canWrite ()) {
645- int maxTries = (Integer ) options .valueOf ("metadata-tries-number" );
646- for (int i = 0 ; i < maxTries ; i ++) {
647- // Break on success
648- if (LockingFileTools .lockAndAppend (file , workflowRunAccession + System .getProperty ("line.separator" ))) {
649- break ;
650- } // Sleep if going to try again
651- else if (i < maxTries ) {
652- ProcessTools .sleep ((Integer ) options .valueOf ("metadata-tries-delay" ));
653- } // Return error if failed on last try
654- else {
655- ReturnValue retval = new ReturnValue ();
656- retval .printAndAppendtoStderr ("Could not write to processingID File for metadata" );
657- retval .setExitStatus (ReturnValue .METADATAINVALIDIDCHAIN );
658- meta .update_processing_event (workflowRunAccession , retval );
659- meta .update_processing_status (workflowRunAccession , ProcessingStatus .failed );
660- System .exit (retval .getExitStatus ());
661- }
662- }
647+ this .writeStringToFile (file , true , workflowRunAccession + System .getProperty ("line.separator" ));
663648 } else {
664649 Log .error ("Could not create processingAccession File for metadata" );
665650 System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
@@ -719,16 +704,29 @@ else if (i < maxTries) {
719704 BufferedReader r ;
720705 String line ;
721706 r = new BufferedReader (new FileReader (file ));
722-
707+ boolean accessionFound = false ;
708+ // seqware-2023, we need to ensure that there is at least one accession found
723709 while ((line = r .readLine ()) != null ) {
724710 try {
725- parentAccessions .add (Integer .parseInt (line ));
711+ int parseInt = Integer .parseInt (line );
712+ parentAccessions .add (parseInt );
713+ int [] accessions = new int [] { parseInt };
714+ List <ParentAccessionModel > viaParentAccessions = meta .getViaParentAccessions (accessions );
715+ if (viaParentAccessions == null ) {
716+ Log .error ("Invalid accession found when parsing parent accession file '" + line + "'" );
717+ System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
718+ }
719+ accessionFound = true ;
726720 } catch (NumberFormatException ex ) {
727721 Log .error ("Non number found when parsing parent accession file '" + line + "'" );
728722 System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
729723 }
730724 }
731725 r .close ();
726+ if (!accessionFound ) {
727+ Log .error ("No number found when parsing parent accession file '" + file + "'" );
728+ System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
729+ }
732730 } catch (Exception e ) {
733731 Log .error ("Could not open parent accession file for metadata-parent-accession-file: " + e .getMessage ());
734732 System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
@@ -880,35 +878,18 @@ private void postProcessMetadata() {
880878 // Try to write to each processingIDFile until success or timeout
881879 for (File file : processingIDFiles ) {
882880 Log .debug ("Writing out accession to " + file .toString ());
883- int maxTries = (Integer ) options .valueOf ("metadata-tries-number" );
884- for (int i = 0 ; i < maxTries ; i ++) {
885- // Break on success
886- if (LockingFileTools .lockAndAppend (file , processingID + System .getProperty ("line.separator" ))) {
887- break ;
888- } // Sleep if going to try again
889- else if (i < maxTries ) {
890- ProcessTools .sleep ((Integer ) options .valueOf ("metadata-tries-delay" ));
891- } // Return error if failed on last try
892- else {
893- ReturnValue retval = new ReturnValue ();
894- retval .printAndAppendtoStderr ("Could not write to processingID File for metadata" );
895- retval .setExitStatus (ReturnValue .METADATAINVALIDIDCHAIN );
896- meta .update_processing_event (processingID , retval );
897- meta .update_processing_status (processingID , ProcessingStatus .failed );
898- System .exit (retval .getExitStatus ());
899- }
900- }
881+ this .writeStringToFile (file , true , processingID + System .getProperty ("line.separator" ));
901882 }
902883 Log .debug ("Completed processingIDFiles" );
903884
904885 // Try to write to each processingAccessionFile until success or timeout
905886 for (File file : processingAccessionFiles ) {
906887 Log .debug ("Writing out to " + file .toString ());
907- writeProcessingAccessionToFile (file , true );
888+ writeStringToFile (file , true , processingAccession + System . getProperty ( "line.separator" ) );
908889 }
909890 Log .debug ("Completed processingAccessionFiles" );
910891 if (processingAccessionFileCheck != null ) {
911- writeProcessingAccessionToFile (processingAccessionFileCheck , false );
892+ writeStringToFile (processingAccessionFileCheck , true , processingAccession + System . getProperty ( "line.separator" ) );
912893 }
913894 Log .debug ("Completed processingAccessionFileCheck" );
914895 meta .update_processing_status (processingID , ProcessingStatus .success );
@@ -972,7 +953,7 @@ private void invokeModuleMethods() {
972953 * <p>
973954 * run.
974955 * </p>
975- *
956+ *
976957 * @param args
977958 * an array of {@link java.lang.String} objects.
978959 */
0 commit comments