blob: 372d7511fddee79b6e82dde25a5b967ea13dbe65 [file] [log] [blame]
Aharoni, Pavel (pa0916)8c70f072018-11-18 00:07:12 +02001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20package org.onap.osam.job.command;
21
22import com.google.common.collect.ImmutableMap;
23import org.onap.osam.job.dao.job.JobStatus;
24import org.onap.osam.job.IJobCommand;
25import org.onap.osam.job.NextCommand;
26import org.onap.osam.job.impl.JobSharedData;
27import org.springframework.beans.factory.config.ConfigurableBeanFactory;
28import org.springframework.context.annotation.Scope;
29import org.springframework.http.HttpEntity;
30import org.springframework.stereotype.Component;
31import org.springframework.web.client.RestTemplate;
32
33import java.util.Map;
34import java.util.UUID;
35
36
37@Component
38@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
39public class HttpCallCommand implements IJobCommand {
40 private String url;
41 private UUID uuid;
42
43 public HttpCallCommand() {
44 }
45
46 public HttpCallCommand(String url, UUID uuid) {
47 init(url, uuid);
48 }
49
50 @Override
51 public NextCommand call() {
52 RestTemplate restTemplate = new RestTemplate();
53 HttpEntity<String> request = new HttpEntity<>(new String(uuid.toString()));
54 String str = restTemplate.postForObject(url, request, String.class);
55 return new NextCommand(JobStatus.COMPLETED);
56 }
57
58 @Override
59 public HttpCallCommand init(JobSharedData sharedData, Map<String, Object> commandData) {
60 return init((String) commandData.get("url"), sharedData.getJobUuid());
61 }
62
63 private HttpCallCommand init(String url, UUID jobUuid) {
64 this.url = url;
65 this.uuid = jobUuid;
66 return this;
67 }
68
69 @Override
70 public Map<String, Object> getData() {
71 return ImmutableMap.of("url", url);
72 }
73}