diff options
Diffstat (limited to 'common/src/main/java/org')
5 files changed, 42 insertions, 4 deletions
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java index 4f3816ad90..b3bfcc1648 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java @@ -30,6 +30,7 @@ public enum AAIObjectPlurals implements GraphInventoryObjectPlurals { CUSTOMER(AAINamespaceConstants.BUSINESS, "/customers"), GENERIC_VNF(AAINamespaceConstants.NETWORK, "/generic-vnfs"), + PORT_GROUP(AAIObjectType.VCE.uriTemplate(), "/port-groups"), PSERVER(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, "/pservers"), P_INTERFACE(AAIObjectType.PSERVER.uriTemplate(), "/p-interfaces"), L3_NETWORK(AAINamespaceConstants.NETWORK, "/l3-networks"), diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java index f003dc0628..0237f91833 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java @@ -45,9 +45,10 @@ import org.onap.aai.domain.yang.OwningEntity; import org.onap.aai.domain.yang.PInterface; import org.onap.aai.domain.yang.PhysicalLink; import org.onap.aai.domain.yang.Platform; +import org.onap.aai.domain.yang.PortGroup; import org.onap.aai.domain.yang.Project; import org.onap.aai.domain.yang.Pserver; -import org.onap.aai.domain.yang.RouteTableReferences; +import org.onap.aai.domain.yang.RouteTableReference; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.ServiceSubscription; import org.onap.aai.domain.yang.SpPartner; @@ -80,9 +81,10 @@ public enum AAIObjectType implements GraphInventoryObjectType { NETWORK_POLICY(AAINamespaceConstants.NETWORK, NetworkPolicy.class), NODES_QUERY("/search", "/nodes-query"), CUSTOM_QUERY("/query", ""), - ROUTE_TABLE_REFERENCE(AAINamespaceConstants.NETWORK, RouteTableReferences.class), + ROUTE_TABLE_REFERENCE(AAINamespaceConstants.NETWORK, RouteTableReference.class), DEFAULT_TENANT(AAINamespaceConstants.CLOUD_INFRASTRUCTURE + "/cloud-regions/cloud-region/" + Defaults.CLOUD_OWNER + "/AAIAIC25", "/tenants/tenant/{tenant-id}"), VCE(AAINamespaceConstants.NETWORK, Vce.class), + PORT_GROUP(AAIObjectType.VCE.uriTemplate(), PortGroup.class), VPN_BINDING(AAINamespaceConstants.NETWORK, VpnBinding.class), CONFIGURATION(AAINamespaceConstants.NETWORK, Configuration.class), PSERVER(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, Pserver.class), 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); + } + +} |