8
8
import edu .harvard .iq .dataverse .harvest .client .HarvesterParams ;
9
9
import edu .harvard .iq .dataverse .harvest .client .HarvesterServiceBean ;
10
10
import edu .harvard .iq .dataverse .harvest .client .HarvestingClientDao ;
11
+ import edu .harvard .iq .dataverse .harvest .client .HarvestingClientsService ;
11
12
import edu .harvard .iq .dataverse .persistence .dataverse .Dataverse ;
12
13
import edu .harvard .iq .dataverse .persistence .harvest .HarvestingClient ;
13
14
import edu .harvard .iq .dataverse .persistence .user .AuthenticatedUser ;
14
15
import edu .harvard .iq .dataverse .util .json .JsonParseException ;
15
16
import io .vavr .control .Option ;
17
+ import io .vavr .control .Try ;
16
18
17
19
import javax .ejb .EJB ;
18
20
import javax .ejb .Stateless ;
19
21
import javax .json .Json ;
20
22
import javax .json .JsonArrayBuilder ;
21
23
import javax .json .JsonObject ;
22
24
import javax .json .JsonObjectBuilder ;
25
+ import javax .ws .rs .DELETE ;
23
26
import javax .ws .rs .GET ;
24
27
import javax .ws .rs .POST ;
25
28
import javax .ws .rs .PUT ;
29
32
import javax .ws .rs .core .Response ;
30
33
import java .io .IOException ;
31
34
import java .io .StringReader ;
32
- import java .util .ArrayList ;
33
35
import java .util .List ;
34
36
import java .util .logging .Logger ;
35
37
@@ -45,7 +47,9 @@ public class HarvestingClients extends AbstractApiBean {
45
47
@ EJB
46
48
HarvesterServiceBean harvesterService ;
47
49
@ EJB
48
- HarvestingClientDao harvestingClientService ;
50
+ HarvestingClientDao harvestingClientDao ;
51
+ @ EJB
52
+ HarvestingClientsService harvestingClientsService ;
49
53
50
54
private static final Logger logger = Logger .getLogger (HarvestingClients .class .getName ());
51
55
@@ -65,7 +69,7 @@ public Response harvestingClients(@QueryParam("key") String apiKey) throws Wrapp
65
69
66
70
List <HarvestingClient > harvestingClients ;
67
71
try {
68
- harvestingClients = harvestingClientService .getAllHarvestingClients ();
72
+ harvestingClients = harvestingClientDao .getAllHarvestingClients ();
69
73
} catch (Exception ex ) {
70
74
return error (Response .Status .INTERNAL_SERVER_ERROR , "Caught an exception looking up configured harvesting clients; " + ex .getMessage ());
71
75
}
@@ -89,7 +93,7 @@ public Response harvestingClient(@PathParam("nickName") String nickName, @QueryP
89
93
90
94
HarvestingClient harvestingClient ;
91
95
try {
92
- harvestingClient = harvestingClientService .findByNickname (nickName );
96
+ harvestingClient = harvestingClientDao .findByNickname (nickName );
93
97
} catch (Exception ex ) {
94
98
logger .warning ("Exception caught looking up harvesting client " + nickName + ": " + ex .getMessage ());
95
99
return error (Response .Status .BAD_REQUEST , "Internal error: failed to look up harvesting client " + nickName + "." );
@@ -129,10 +133,6 @@ public Response createHarvestingClient(String jsonBody, @PathParam("nickName") S
129
133
}
130
134
131
135
harvestingClient .setDataverse (ownerDataverse );
132
- if (ownerDataverse .getHarvestingClientConfigs () == null ) {
133
- ownerDataverse .setHarvestingClientConfigs (new ArrayList <>());
134
- }
135
- ownerDataverse .getHarvestingClientConfigs ().add (harvestingClient );
136
136
137
137
DataverseRequest req = createDataverseRequest (superuser );
138
138
HarvestingClient managedHarvestingClient = execCommand (new CreateHarvestingClientCommand (req , harvestingClient ));
@@ -148,6 +148,21 @@ public Response createHarvestingClient(String jsonBody, @PathParam("nickName") S
148
148
149
149
}
150
150
151
+ @ DELETE
152
+ @ ApiWriteOperation
153
+ @ Path ("{nickName}" )
154
+ public Response deleteHarvestingClient (@ PathParam ("nickName" ) String nickName , @ QueryParam ("key" ) String apiKey ) throws WrappedResponse {
155
+
156
+ findSuperuserOrDie ();
157
+
158
+ HarvestingClient harvestingClient = Try .of (() -> harvestingClientDao .findByNickname (nickName ))
159
+ .getOrElseThrow (() -> new WrappedResponse (notFound ("Harvesting client " + nickName + " not found." )));
160
+
161
+ harvestingClientDao .setDeleteInProgress (harvestingClient .getId ());
162
+ harvestingClientsService .deleteClient (harvestingClient );
163
+ return accepted ();
164
+ }
165
+
151
166
@ PUT
152
167
@ ApiWriteOperation
153
168
@ Path ("{nickName}" )
@@ -157,7 +172,7 @@ public Response modifyHarvestingClient(String jsonBody, @PathParam("nickName") S
157
172
158
173
HarvestingClient harvestingClient ;
159
174
try {
160
- harvestingClient = harvestingClientService .findByNickname (nickName );
175
+ harvestingClient = harvestingClientDao .findByNickname (nickName );
161
176
} catch (Exception ex ) {
162
177
// We don't care what happened; we'll just assume we couldn't find it.
163
178
harvestingClient = null ;
@@ -200,24 +215,25 @@ public Response modifyHarvestingClient(String jsonBody, @PathParam("nickName") S
200
215
@ POST
201
216
@ ApiWriteOperation
202
217
@ Path ("{nickName}/run" )
203
- public Response startHarvestingJob (@ PathParam ("nickName" ) String clientNickname , @ QueryParam ("key" ) String apiKey ) throws WrappedResponse {
218
+ public Response startHarvestingJob (String paramsJson , @ PathParam ("nickName" ) String clientNickname , @ QueryParam ("key" ) String apiKey ) throws WrappedResponse {
204
219
205
- AuthenticatedUser superuser = findSuperuserOrDie ();
220
+ AuthenticatedUser superuser = findSuperuserOrDie ();
206
221
207
222
try {
208
- HarvestingClient harvestingClient = harvestingClientService .findByNickname (clientNickname );
223
+ HarvestingClient harvestingClient = harvestingClientDao .findByNickname (clientNickname );
209
224
210
225
if (harvestingClient == null ) {
211
226
return error (Response .Status .NOT_FOUND , "No such dataverse: " + clientNickname );
212
227
}
213
228
214
229
DataverseRequest dataverseRequest = createDataverseRequest (superuser );
215
- harvesterService .doAsyncHarvest (dataverseRequest , harvestingClient , HarvesterParams .empty ());
230
+ HarvesterParams params = harvesterService .parseParams (harvestingClient , paramsJson );
231
+ harvesterService .doAsyncHarvest (dataverseRequest , harvestingClient , params );
216
232
217
233
} catch (Exception e ) {
218
234
return error (Response .Status .BAD_REQUEST , "Exception thrown when running harvesting client\" " + clientNickname + "\" via REST API; " + e .getMessage ());
219
235
}
220
- return this . accepted ();
236
+ return accepted ();
221
237
}
222
238
223
239
public static JsonObjectBuilder harvestingConfigAsJson (HarvestingClient harvestingConfig ) {
0 commit comments