@ -41,6 +41,8 @@ public class UrlController {
// TODO - Write the Assignment details to the database and then send it to the worker.
logger . info ( "Sending assignment_" + assignment . getAssignmentId ( ) + " to worker with ID: " + workerId ) ;
return ResponseEntity . status ( 200 ) . header ( "Content-Type" , "application/json" ) . body ( new AssignmentResponse ( assignment ) ) ;
}
@ -50,16 +52,20 @@ public class UrlController {
@GetMapping ( "test" )
public ResponseEntity < ? > getTestUrls ( @RequestParam String workerId , @RequestParam int tasksLimit ) {
List < Task > tasks = new ArrayList < > ( ) ;
new FileUtils ( ) ; // Find the input file.
try {
new FileUtils ( ) ; // Find the input file.
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) ) ;
return ResponseEntity . status ( 500 ) . body ( "The resource file for the requested tasks was not found." ) ;
}
List < Task > tasks = new ArrayList < > ( ) ;
HashMultimap < String , String > loadedIdUrlPairs ;
boolean isFirstRun = true ;
boolean tasksLimitReached = false ;
// Start loading urls.
while ( true )
{
while ( true ) {
loadedIdUrlPairs = FileUtils . getNextIdUrlPairBatchFromJson ( ) ; // Take urls from jsonFile.
if ( FileUtils . isFinishedLoading ( loadedIdUrlPairs . isEmpty ( ) , isFirstRun ) ) // Throws RuntimeException which is automatically passed on.
@ -81,14 +87,18 @@ public class UrlController {
} // end pairs-for-loop
if ( tasksLimitReached ) {
logger . debug ( "Done loading tasksLimit (" + tasksLimit + ") urls from the inputFile .") ;
logger . debug ( "Done loading urls from the inputFile as the tasksLimit (" + tasksLimit + ") was reached .") ;
break ;
}
} // end loading-while-loop
if ( FileUtils . inputScanner ! = null )
FileUtils . inputScanner . close ( ) ;
Assignment assignment = new Assignment ( ( + + assignmentId ) , tasks , workerId , new Date ( ) ) ;
logger . info ( "Sending assignment_" + assignment . getAssignmentId ( ) + " with " + tasks . size ( ) + " tasks (" + FileUtils . duplicateIdUrlEntries + " more tasks were discarded as duplicates), to worker with ID: " + workerId ) ;
return ResponseEntity . status ( 200 ) . header ( "Content-Type" , "application/json" ) . body ( new AssignmentResponse ( assignment ) ) ;
}