summaryrefslogtreecommitdiffstats
path: root/common/src/main
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-01-22 11:48:03 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-01-22 11:48:16 -0500
commit147e9ee814448c8bbec4aa3aeac4b7118b7c1bc7 (patch)
treeb5b817e4a042430e862ba7611abbd6ee45e9df49 /common/src/main
parent5f72e4d0bb12e3291afac45a93d137b97006870f (diff)
validate number of uri keys
test was setting unnecessary keys on uri changed plural to singular AAI class added in validation for number of keys provided Change-Id: I86f61301aa5f2ea676678908bae1e88b86d7e570 Issue-ID: SO-1409 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'common/src/main')
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java14
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java14
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java11
3 files changed, 37 insertions, 2 deletions
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java
index 884f8c6ac4..324bb8abad 100644
--- a/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java
+++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java
@@ -22,7 +22,6 @@ 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;
@@ -38,6 +37,7 @@ 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 org.onap.so.client.graphinventory.exceptions.IncorrectNumberOfUriKeys;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -118,6 +118,18 @@ public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri
@Override
public abstract HttpLookupUri clone();
+ @Override
+ public void validateValuesSize(String template, Object... values) {
+ try {
+ super.validateValuesSize(template, values);
+ } catch (IncorrectNumberOfUriKeys e) {
+ if (values.length == 1) {
+ //Special case where we perform an http look up
+ } else {
+ throw e;
+ }
+ }
+ }
public AAIResourcesClient getResourcesClient() {
return new AAIResourcesClient();
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
index 2876f77d82..93de9139f9 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
@@ -24,11 +24,11 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import javax.ws.rs.core.UriBuilder;
@@ -39,6 +39,7 @@ import org.onap.so.client.graphinventory.GraphInventoryObjectPlurals;
import org.onap.so.client.graphinventory.GraphInventoryObjectType;
import org.onap.so.client.graphinventory.entities.uri.parsers.UriParser;
import org.onap.so.client.graphinventory.entities.uri.parsers.UriParserSpringImpl;
+import org.onap.so.client.graphinventory.exceptions.IncorrectNumberOfUriKeys;
import org.springframework.web.util.UriUtils;
public class SimpleUri implements GraphInventoryResourceUri, Serializable {
@@ -56,6 +57,7 @@ public class SimpleUri implements GraphInventoryResourceUri, Serializable {
this.pluralType = null;
this.internalURI = UriBuilder.fromPath(this.getTemplate(type));
this.values = values;
+ validateValuesSize(this.getTemplate(type), values);
}
protected SimpleUri(GraphInventoryObjectType type, URI uri) {
this.type = type;
@@ -86,12 +88,14 @@ public class SimpleUri implements GraphInventoryResourceUri, Serializable {
this.pluralType = type;
this.internalURI = UriBuilder.fromPath(this.getTemplate(type));
this.values = values;
+ validateValuesSize(this.getTemplate(type), values);
}
protected SimpleUri(GraphInventoryResourceUri parentUri, GraphInventoryObjectType childType, Object... childValues) {
this.type = childType;
this.pluralType = null;
this.internalURI = UriBuilder.fromUri(parentUri.build()).path(childType.partialUri());
this.values = childValues;
+ validateValuesSize(childType.partialUri(), values);
}
protected void setInternalURI(UriBuilder builder) {
@@ -232,6 +236,14 @@ public class SimpleUri implements GraphInventoryResourceUri, Serializable {
return this;
}
+ public void validateValuesSize(String template, Object... values) {
+ UriParser parser = new UriParserSpringImpl(template);
+ Set<String> variables = parser.getVariables();
+ if (variables.size() != values.length) {
+ throw new IncorrectNumberOfUriKeys(String.format("Expected %s variables: %s", variables.size(), variables));
+ }
+ }
+
protected String getTemplate(GraphInventoryObjectType type) {
return type.uriTemplate();
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java b/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java
new file mode 100644
index 0000000000..c94e561274
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java
@@ -0,0 +1,11 @@
+package org.onap.so.client.graphinventory.exceptions;
+
+public class IncorrectNumberOfUriKeys extends RuntimeException {
+
+ private static final long serialVersionUID = 2189285428827817518L;
+
+ public IncorrectNumberOfUriKeys(String message) {
+ super(message);
+ }
+
+}