aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-requests-db/src
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-requests-db/src')
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java67
-rw-r--r--mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java35
2 files changed, 99 insertions, 3 deletions
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
index 9ab0f3b680..4d16d9c272 100644
--- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,6 +26,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import javax.annotation.PostConstruct;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
@@ -72,6 +74,9 @@ public class RequestsDbClient {
private static final String REQUEST_ID = "REQUEST_ID";
private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENV_ID";
private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID";
+ private static final String TAG = "TAG";
+ private static final String FLOW_EXECUTION_PATH = "flowExecutionPath";
+ private static final String BPMN_EXECUTION_DATA_TAG = "BPMNExecutionData";
@Value("${mso.adapters.requestDb.endpoint:#{null}}")
protected String endpoint;
@@ -95,6 +100,8 @@ public class RequestsDbClient {
private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId";
+ private String findOneByRequestId = "/infraActiveRequests/search/findOneByRequestId";
+
private String findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestIdURI =
"/findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId";
@@ -110,9 +117,13 @@ public class RequestsDbClient {
private static final String findBySoRequestIdAndGroupIdAndName =
"/requestProcessingData/search/findOneBySoRequestIdAndGroupingIdAndName";
+ private static final String findBySoRequestIdAndName = "/requestProcessingData/search/findOneBySoRequestIdAndName";
+
private static final String findBySoRequestIdOrderByGroupingIdDesc =
"/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc";
+ private static final String findByGroupingIdAndNameAndTag =
+ "/requestProcessingData/search/findByGroupingIdAndNameAndTag";
@Autowired
protected RestTemplate restTemplate;
@@ -136,6 +147,7 @@ public class RequestsDbClient {
+ findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestIdURI;
findAllByOperationalEnvIdAndRequestIdURI =
endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI;
+ findOneByRequestId = endpoint + findOneByRequestId;
}
private ClientFactory getClientFactory() {
@@ -342,7 +354,7 @@ public class RequestsDbClient {
public void updateRequestProcessingData(RequestProcessingData requestProcessingData) {
HttpHeaders headers = getHttpHeaders();
- URI uri = getUri(requestProcessingDataURI);
+ URI uri = getUri(requestProcessingDataURI + "/" + requestProcessingData.getId());
HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers);
restTemplate.put(uri, entity);
}
@@ -361,6 +373,41 @@ public class RequestsDbClient {
.queryParam(GROUPING_ID, groupingId).build().toString()));
}
+ public List<RequestProcessingData> getRequestProcessingDataByGroupingIdAndNameAndTag(String groupingId, String name,
+ String tag) {
+ Iterable<RequestProcessingData> requestProcessingDataListIt =
+ getClientFactory().create(RequestProcessingData.class)
+ .getAll(getUri(UriBuilder.fromUri(endpoint + findByGroupingIdAndNameAndTag)
+ .queryParam(GROUPING_ID, groupingId).queryParam(NAME, name).queryParam(TAG, tag).build()
+ .toString()));
+
+ List<RequestProcessingData> requestProcessingDataList =
+ StreamSupport.stream(requestProcessingDataListIt.spliterator(), false).collect(Collectors.toList());
+
+ return requestProcessingDataList;
+ }
+
+ public RequestProcessingData getRequestProcessingDataBySoRequestIdAndName(String soRequestId, String name) {
+ return getClientFactory().create(RequestProcessingData.class)
+ .get(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdAndName)
+ .queryParam(SO_REQUEST_ID, soRequestId).queryParam(NAME, name).build().toString()));
+ }
+
+
+ public void persistProcessingData(String flowExecutionPath, String requestId) {
+
+ HttpHeaders headers = getHttpHeaders();
+ URI uri = getUri(requestProcessingDataURI);
+ RequestProcessingData rpd = new RequestProcessingData();
+ rpd.setName(FLOW_EXECUTION_PATH);
+ rpd.setSoRequestId(requestId);
+ rpd.setValue(flowExecutionPath);
+ rpd.setTag(BPMN_EXECUTION_DATA_TAG);
+
+ HttpEntity<RequestProcessingData> entity = new HttpEntity<>(rpd, headers);
+ restTemplate.postForLocation(uri, entity);
+ }
+
private List<RequestProcessingData> getRequestProcessingData(URI uri) {
Iterable<RequestProcessingData> requestProcessingDataIterator =
getClientFactory().create(RequestProcessingData.class).getAll(uri);
@@ -370,6 +417,20 @@ public class RequestsDbClient {
return requestProcessingDataList;
}
+ public InfraActiveRequests findOneByRequestId(String requestId) {
+ try {
+ HttpEntity<?> entity = getHttpEntity();
+ return restTemplate.exchange(
+ getUri(UriBuilder.fromUri(findOneByRequestId).queryParam(REQUEST_ID, requestId).build().toString()),
+ HttpMethod.GET, entity, InfraActiveRequests.class).getBody();
+ } catch (HttpClientErrorException e) {
+ if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
+ return null;
+ }
+ throw e;
+ }
+ }
+
// From and To are defaulted to ignore start/endtime on query to database
public List<InfraActiveRequests> getRequest(final Map<String, String[]> filters) {
String url = UriBuilder.fromUri(getUri(getInfraActiveRequests)).queryParam("from", "0")
diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java
new file mode 100644
index 0000000000..fdbc04acb4
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java
@@ -0,0 +1,35 @@
+package org.onap.so.db.request.client;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.times;
+import java.net.URI;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.db.request.beans.RequestProcessingData;
+import org.springframework.http.HttpEntity;
+import org.springframework.web.client.RestTemplate;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class RequestDbClientTest {
+
+ @InjectMocks
+ protected RequestsDbClient requestsDbClient;
+
+ @Mock
+ protected RestTemplate restTemplate;
+
+ @Test
+ public void updateRequestProcessingDataTest() {
+ RequestProcessingData requestProcessingData = new RequestProcessingData();
+ requestProcessingData.setId(1);
+ URI uri = URI.create("/requestProcessingData/1");
+ requestsDbClient.updateRequestProcessingData(requestProcessingData);
+ Mockito.verify(restTemplate, times(1)).put(eq(uri), isA(HttpEntity.class));
+ }
+}