44import static org .folio .okapi .common .HttpResponse .responseJson ;
55import static org .folio .okapi .common .HttpResponse .responseText ;
66
7- import io .vertx .core .Vertx ;
87import io .vertx .core .json .JsonObject ;
9- import io .vertx .ext .web .RoutingContext ;
8+ import org .folio .harvesteradmin .service .AdminRequest ;
9+
1010import java .text .SimpleDateFormat ;
1111import java .util .Date ;
1212import java .util .TimeZone ;
@@ -27,8 +27,8 @@ public class JobLauncher extends LegacyHarvesterStorage {
2727 /**
2828 * Constructor.
2929 */
30- public JobLauncher (Vertx vertx , String tenant ) {
31- super (vertx , tenant );
30+ public JobLauncher (AdminRequest adminRequest ) {
31+ super (adminRequest . vertx (), adminRequest . tenant () );
3232
3333 dateFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
3434 dateFormat .setTimeZone (TimeZone .getTimeZone ("UTC" ));
@@ -37,45 +37,45 @@ public JobLauncher(Vertx vertx, String tenant) {
3737 /**
3838 * Starts a harvest job.
3939 */
40- public void startJob (RoutingContext routingContext ) {
40+ public void startJob (AdminRequest adminRequest ) {
4141
42- String harvestableId = routingContext . request (). getParam ("id" );
42+ String harvestableId = adminRequest . pathParam ("id" );
4343 getConfigRecordById (HARVESTER_HARVESTABLES_PATH , harvestableId ).onComplete (lookUp -> {
4444 if (lookUp .succeeded ()) {
4545 if (lookUp .result ().wasNotFound ()) {
46- responseText (routingContext , NOT_FOUND ).end (
46+ responseText (adminRequest . routingContext () , NOT_FOUND ).end (
4747 "Did not find a harvest configuration with ID " + harvestableId
4848 + ". No job started." );
4949 } else if (lookUp .result ().wasOK () && lookUp .result ().jsonObject ()
5050 .getString ("currentStatus" ).equals ("RUNNING" )) {
51- responseText (routingContext , BAD_REQUEST ).end (
51+ responseText (adminRequest . routingContext () , BAD_REQUEST ).end (
5252 "A job with this configuration is already running " + lookUp .result ().jsonObject ()
5353 .getString ("name" ));
5454 } else if (lookUp .result ().wasOK ()) {
5555 JsonObject harvestConfig = lookUp .result ().jsonObject ().copy ();
5656 harvestConfig .put (PROP_HARVEST_IMMEDIATELY , TRUE );
5757 harvestConfig .put (PROP_LAST_UPDATED , dateFormat .format (new Date ()));
58- putConfigRecord (routingContext , HARVESTER_HARVESTABLES_PATH , harvestConfig ,
58+ putConfigRecord (adminRequest , HARVESTER_HARVESTABLES_PATH , harvestConfig ,
5959 harvestableId ).onComplete (putResponse -> {
6060 if (putResponse .succeeded ()) {
6161 JsonObject responseOk = new JsonObject ();
6262 responseOk .put (PROP_HARVESTABLE_ID , harvestableId );
6363 responseOk .put (PROP_NAME , harvestConfig .getString ("name" ));
6464 responseOk .put (PROP_INITIATED , harvestConfig .getString (PROP_LAST_UPDATED ));
65- responseJson (routingContext , OK ).end (responseOk .encodePrettily ());
65+ responseJson (adminRequest . routingContext () , OK ).end (responseOk .encodePrettily ());
6666 } else {
67- responseText (routingContext , INTERNAL_SERVER_ERROR ).end (
67+ responseText (adminRequest . routingContext () , INTERNAL_SERVER_ERROR ).end (
6868 "An error occurred when trying to start job " + harvestableId + ": "
6969 + putResponse .cause ().getMessage ());
7070 }
7171 });
7272 } else {
73- responseText (routingContext , lookUp .result ().statusCode ()).end (
73+ responseText (adminRequest . routingContext () , lookUp .result ().statusCode ()).end (
7474 "A problem occurred when looking for the job to start:" + lookUp .result ()
7575 .errorMessage ());
7676 }
7777 } else {
78- responseText (routingContext , INTERNAL_SERVER_ERROR ).end (
78+ responseText (adminRequest . routingContext () , INTERNAL_SERVER_ERROR ).end (
7979 "Could not look up harvest configuration. Job not started." );
8080 }
8181 });
@@ -84,43 +84,43 @@ public void startJob(RoutingContext routingContext) {
8484 /**
8585 * Stops a harvest job.
8686 */
87- public void stopJob (RoutingContext routingContext ) {
88- String harvestableId = routingContext . request (). getParam ("id" );
87+ public void stopJob (AdminRequest adminRequest ) {
88+ String harvestableId = adminRequest . pathParam ("id" );
8989 getConfigRecordById (HARVESTER_HARVESTABLES_PATH , harvestableId ).onComplete (lookUp -> {
9090 if (lookUp .succeeded ()) {
9191 if (lookUp .result ().wasNotFound ()) {
92- responseText (routingContext , NOT_FOUND ).end (
92+ responseText (adminRequest . routingContext () , NOT_FOUND ).end (
9393 "Did not find a harvest configuration with ID " + harvestableId
9494 + ". No job stopped." );
9595 } else if (lookUp .result ().wasOK () && !lookUp .result ().jsonObject ()
9696 .getString ("currentStatus" ).equals ("RUNNING" )) {
97- responseText (routingContext , BAD_REQUEST ).end (
97+ responseText (adminRequest . routingContext () , BAD_REQUEST ).end (
9898 "This configuration has no running job, cannot stop it. " + lookUp .result ()
9999 .jsonObject ().getString ("name" ));
100100 } else if (lookUp .result ().wasOK ()) {
101101 JsonObject harvestConfig = lookUp .result ().jsonObject ().copy ();
102102 harvestConfig .put (PROP_LAST_UPDATED , dateFormat .format (new Date ()));
103- putConfigRecord (routingContext , HARVESTER_HARVESTABLES_PATH , harvestConfig ,
103+ putConfigRecord (adminRequest , HARVESTER_HARVESTABLES_PATH , harvestConfig ,
104104 harvestableId ).onComplete (putResponse -> {
105105 if (putResponse .succeeded ()) {
106106 JsonObject responseOk = new JsonObject ();
107107 responseOk .put (PROP_HARVESTABLE_ID , harvestableId );
108108 responseOk .put (PROP_NAME , harvestConfig .getString ("name" ));
109109 responseOk .put (PROP_INITIATED , harvestConfig .getString (PROP_LAST_UPDATED ));
110- responseJson (routingContext , OK ).end (responseOk .encodePrettily ());
110+ responseJson (adminRequest . routingContext () , OK ).end (responseOk .encodePrettily ());
111111 } else {
112- responseText (routingContext , INTERNAL_SERVER_ERROR ).end (
112+ responseText (adminRequest . routingContext () , INTERNAL_SERVER_ERROR ).end (
113113 "An error occurred when trying to stop job using " + harvestableId + ": "
114114 + putResponse .cause ().getMessage ());
115115 }
116116 });
117117 } else {
118- responseText (routingContext , lookUp .result ().statusCode ()).end (
118+ responseText (adminRequest . routingContext () , lookUp .result ().statusCode ()).end (
119119 "A problem occurred when looking for the job to stop:" + lookUp .result ()
120120 .errorMessage ());
121121 }
122122 } else {
123- responseText (routingContext , INTERNAL_SERVER_ERROR ).end (
123+ responseText (adminRequest . routingContext () , INTERNAL_SERVER_ERROR ).end (
124124 "Could not look up harvest configuration. No job stopped." );
125125 }
126126 });
0 commit comments