summaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java')
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java80
1 files changed, 2 insertions, 78 deletions
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java
index a132e15d1f..00a213b264 100644
--- a/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java
+++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java
@@ -20,97 +20,21 @@
package org.onap.so.client.aai.entities.uri;
-import java.io.IOException;
import java.net.URI;
-import java.util.Arrays;
-import java.util.Map;
import java.util.Optional;
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.UriBuilder;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
-import org.onap.so.client.aai.entities.Results;
-import org.onap.so.client.graphinventory.Format;
-import org.onap.so.client.graphinventory.entities.uri.HttpAwareUri;
-import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
-import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
-import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class ServiceInstanceUri extends AAISimpleUri implements HttpAwareUri {
-
- private Optional<String> cachedValue = Optional.empty();
+public class ServiceInstanceUri extends HttpLookupUri {
protected ServiceInstanceUri(Object... values) {
super(AAIObjectType.SERVICE_INSTANCE, values);
}
protected ServiceInstanceUri(UriBuilder builder, Optional<String> cachedValue, Object... values) {
- super(AAIObjectType.SERVICE_INSTANCE, builder, values);
- this.cachedValue = cachedValue;
- }
- protected String getSerivceInstance(Object id) throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
- if (!this.getCachedValue().isPresent()) {
- AAIResourceUri serviceInstanceUri = AAIUriFactory.createNodesUri(AAIObjectType.SERVICE_INSTANCE, id).format(Format.PATHED);
- String resultJson;
- try {
- resultJson = this.getResourcesClient().get(serviceInstanceUri, NotFoundException.class).getJson();
- } catch (BadRequestException e) {
- throw new GraphInventoryUriNotFoundException("Service instance " + id + " not found at: " + serviceInstanceUri.build());
-
- }
- try {
- cachedValue = extractRelatedLink(resultJson);
- if (!cachedValue.isPresent()) {
- throw new GraphInventoryUriNotFoundException("Service instance " + id + " not found at: " + serviceInstanceUri.build());
- }
- } catch (IOException e) {
- throw new GraphInventoryPayloadException("could not map payload: " + resultJson, e);
- }
- }
- Optional<String> cachedValueOpt = this.getCachedValue();
- return cachedValueOpt.isPresent() ? cachedValueOpt.get() : "";
- }
-
- protected Optional<String> extractRelatedLink(String jsonString) throws IOException {
- Optional<String> result;
- ObjectMapper mapper = new ObjectMapper();
-
- Results<Map<String, String>> results = mapper.readValue(jsonString, new TypeReference<Results<Map<String, String>>>(){});
- if (results.getResult().size() == 1) {
- String uriString = results.getResult().get(0).get("resource-link");
- URI uri = UriBuilder.fromUri(uriString).build();
- String rawPath = uri.getRawPath();
- result = Optional.of(rawPath.replaceAll("/aai/v\\d+", ""));
- } else if (results.getResult().isEmpty()) {
- result = Optional.empty();
- } else {
- throw new IllegalStateException("more than one result returned");
- }
-
- return result;
- }
-
- protected Optional<String> getCachedValue() {
- return this.cachedValue;
- }
-
- @Override
- public URI build() {
- try {
- if (this.values.length == 1) {
- String uri = getSerivceInstance(this.values[0]);
- Map<String, String> map = getURIKeys(uri);
- return super.build(map.values().toArray(values));
- }
- } catch (GraphInventoryUriNotFoundException | GraphInventoryPayloadException e) {
- throw new GraphInventoryUriComputationException(e);
- }
- return super.build();
+ super(AAIObjectType.SERVICE_INSTANCE, builder, cachedValue, values);
}
@Override