5951d7c83bad9d74b0496bf01118e403b77971e9
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / command / HttpCallCommand.java
1 package org.onap.vid.job.command;
2
3 import com.google.common.collect.ImmutableMap;
4 import org.onap.vid.job.Job;
5 import org.onap.vid.job.JobCommand;
6 import org.onap.vid.job.NextCommand;
7 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
8 import org.springframework.context.annotation.Scope;
9 import org.springframework.stereotype.Component;
10
11 import javax.ws.rs.client.ClientBuilder;
12 import javax.ws.rs.client.Entity;
13 import javax.ws.rs.core.Response;
14 import java.util.Map;
15 import java.util.UUID;
16
17
18 @Component
19 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
20 public class HttpCallCommand implements JobCommand {
21     private String url;
22     private UUID uuid;
23
24     public HttpCallCommand() {
25     }
26
27     public HttpCallCommand(String url, UUID uuid) {
28         init(url, uuid);
29     }
30
31     @Override
32     public NextCommand call() {
33         final Response response = ClientBuilder.newClient().target(url).request().post(Entity.text(uuid.toString()));
34         return new NextCommand(Job.JobStatus.COMPLETED);
35     }
36
37     @Override
38     public HttpCallCommand init(UUID jobUuid, Map<String, Object> data) {
39         return init((String) data.get("url"), jobUuid);
40     }
41
42     private HttpCallCommand init(String url, UUID jobUuid) {
43         this.url = url;
44         this.uuid = jobUuid;
45         return this;
46     }
47
48     @Override
49     public Map<String, Object> getData() {
50         return ImmutableMap.of("url", url);
51     }
52 }