Aharoni, Pavel (pa0916) | 8c70f07 | 2018-11-18 00:07:12 +0200 | [diff] [blame] | 1 | /*-
|
| 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 | */
|
| 20 | package org.onap.osam.job.command;
|
| 21 |
|
| 22 | import com.google.common.collect.ImmutableMap;
|
| 23 | import org.onap.osam.job.dao.job.JobStatus;
|
| 24 | import org.onap.osam.job.IJobCommand;
|
| 25 | import org.onap.osam.job.NextCommand;
|
| 26 | import org.onap.osam.job.impl.JobSharedData;
|
| 27 | import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
| 28 | import org.springframework.context.annotation.Scope;
|
| 29 | import org.springframework.http.HttpEntity;
|
| 30 | import org.springframework.stereotype.Component;
|
| 31 | import org.springframework.web.client.RestTemplate;
|
| 32 |
|
| 33 | import java.util.Map;
|
| 34 | import java.util.UUID;
|
| 35 |
|
| 36 |
|
| 37 | @Component
|
| 38 | @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
| 39 | public 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 | }
|