aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org/onap/so/client/graphinventory
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/org/onap/so/client/graphinventory')
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryClient.java18
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectBase.java9
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectPlurals.java5
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectType.java3
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java135
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java45
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryRelationships.java4
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryPluralResourceUri.java8
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryResourceUri.java39
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventorySingleResourceUri.java16
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java26
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java5
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleBaseUri.java237
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimplePluralUri.java77
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java239
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryMultipleItemsException.java13
16 files changed, 563 insertions, 316 deletions
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryClient.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryClient.java
index 98d48ec3a8..09efb5a48d 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryClient.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryClient.java
@@ -25,6 +25,7 @@ import org.onap.so.client.RestClient;
import org.onap.so.client.RestProperties;
import org.onap.so.client.RestPropertiesLoader;
import org.onap.so.client.graphinventory.entities.uri.GraphInventoryUri;
+import org.onap.so.client.graphinventory.entities.uri.HttpAwareUri;
public abstract class GraphInventoryClient {
@@ -36,9 +37,22 @@ public abstract class GraphInventoryClient {
this.props = props;
}
- protected abstract URI constructPath(GraphInventoryUri uri);
+ protected abstract URI constructPath(URI uri);
+
+ protected abstract RestClient createClient(URI uri);
+
+ public RestClient createClient(GraphInventoryUri uri) {
+ final URI result;
+ if (uri instanceof HttpAwareUri) {
+ result = ((HttpAwareUri) uri).locateAndBuild();
+ } else {
+ result = uri.build();
+ }
+
+ return createClient(result);
+
+ }
- public abstract RestClient createClient(GraphInventoryUri uri);
public <T extends RestProperties> T getRestProperties() {
if (props == null) {
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectBase.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectBase.java
new file mode 100644
index 0000000000..72de833884
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectBase.java
@@ -0,0 +1,9 @@
+package org.onap.so.client.graphinventory;
+
+public interface GraphInventoryObjectBase
+ extends GraphInventoryObjectName, GraphInventoryObjectUriTemplate, GraphInventoryObjectUriPartial {
+
+ public default boolean passThrough() {
+ return false;
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectPlurals.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectPlurals.java
index 42f4733e47..84604a76cf 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectPlurals.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectPlurals.java
@@ -20,7 +20,8 @@
package org.onap.so.client.graphinventory;
-public interface GraphInventoryObjectPlurals
- extends GraphInventoryObjectName, GraphInventoryObjectUriTemplate, GraphInventoryObjectUriPartial {
+public interface GraphInventoryObjectPlurals extends GraphInventoryObjectBase {
+
+ public GraphInventoryObjectType getType();
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectType.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectType.java
index c11a08e867..d09a83a644 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectType.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryObjectType.java
@@ -20,7 +20,6 @@
package org.onap.so.client.graphinventory;
-public interface GraphInventoryObjectType
- extends GraphInventoryObjectName, GraphInventoryObjectUriTemplate, GraphInventoryObjectUriPartial {
+public interface GraphInventoryObjectType extends GraphInventoryObjectBase {
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java
index c7cdb2ff58..f446e5ac4c 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryResourcesClient.java
@@ -21,6 +21,11 @@
package org.onap.so.client.graphinventory;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.ws.rs.NotFoundException;
@@ -32,9 +37,13 @@ import org.onap.so.client.RestClient;
import org.onap.so.client.RestProperties;
import org.onap.so.client.graphinventory.entities.GraphInventoryEdgeLabel;
import org.onap.so.client.graphinventory.entities.GraphInventoryResultWrapper;
+import org.onap.so.client.graphinventory.entities.uri.GraphInventoryPluralResourceUri;
import org.onap.so.client.graphinventory.entities.uri.GraphInventoryResourceUri;
+import org.onap.so.client.graphinventory.entities.uri.GraphInventorySingleResourceUri;
+import org.onap.so.client.graphinventory.entities.uri.HttpAwareUri;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryMultipleItemsException;
-public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInventoryResourceUri, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> {
+public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInventoryResourceUri<?, ?>, SingleUri extends GraphInventorySingleResourceUri<?, ?, ?, ?>, PluralUri extends GraphInventoryPluralResourceUri<?, ?>, EdgeLabel extends GraphInventoryEdgeLabel, Wrapper extends GraphInventoryResultWrapper, TransactionalClient, SingleTransactionClient> {
protected GraphInventoryClient client;
@@ -49,7 +58,7 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @param uri
* @return
*/
- public void create(Uri uri, Object obj) {
+ public void create(SingleUri uri, Object obj) {
RestClient giRC = client.createClient(uri);
giRC.put(obj);
}
@@ -60,7 +69,7 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @param uri
* @return
*/
- public void createEmpty(Uri uri) {
+ public void createEmpty(SingleUri uri) {
RestClient giRC = client.createClient(uri);
giRC.put("");
}
@@ -72,7 +81,7 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @return
*/
public boolean exists(Uri uri) {
- GraphInventoryResourceUri forceMinimal = uri.clone();
+ GraphInventoryResourceUri<?, ?> forceMinimal = (Uri) uri.clone();
forceMinimal.format(Format.COUNT);
forceMinimal.limit(1);
try {
@@ -91,8 +100,8 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @param uriB
* @return
*/
- public void connect(Uri uriA, Uri uriB) {
- GraphInventoryResourceUri uriAClone = uriA.clone();
+ public void connect(SingleUri uriA, SingleUri uriB) {
+ GraphInventorySingleResourceUri<?, ?, ?, ?> uriAClone = (SingleUri) uriA.clone();
RestClient giRC = client.createClient(uriAClone.relationshipAPI());
giRC.put(this.buildRelationship(uriB));
}
@@ -105,8 +114,8 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @param edge label
* @return
*/
- public void connect(Uri uriA, Uri uriB, EdgeLabel label) {
- GraphInventoryResourceUri uriAClone = uriA.clone();
+ public void connect(SingleUri uriA, SingleUri uriB, EdgeLabel label) {
+ GraphInventorySingleResourceUri<?, ?, ?, ?> uriAClone = (SingleUri) uriA.clone();
RestClient giRC = client.createClient(uriAClone.relationshipAPI());
giRC.put(this.buildRelationship(uriB, label));
}
@@ -118,8 +127,8 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @param uriB
* @return
*/
- public void disconnect(Uri uriA, Uri uriB) {
- GraphInventoryResourceUri uriAClone = uriA.clone();
+ public void disconnect(SingleUri uriA, SingleUri uriB) {
+ GraphInventorySingleResourceUri<?, ?, ?, ?> uriAClone = (SingleUri) uriA.clone();
RestClient giRC = client.createClient(uriAClone.relationshipAPI());
giRC.delete(this.buildRelationship(uriB));
}
@@ -130,8 +139,8 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @param uri
* @return
*/
- public void delete(Uri uri) {
- GraphInventoryResourceUri clone = uri.clone();
+ public void delete(SingleUri uri) {
+ GraphInventorySingleResourceUri<?, ?, ?, ?> clone = (SingleUri) uri.clone();
RestClient giRC = client.createClient(clone);
Map<String, Object> result = giRC.get(new GenericType<Map<String, Object>>() {}).orElseThrow(
() -> new NotFoundException(clone.build() + " does not exist in " + client.getGraphDBName()));
@@ -145,7 +154,7 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @param uri
* @return
*/
- public void update(Uri uri, Object obj) {
+ public void update(SingleUri uri, Object obj) {
RestClient giRC = client.createClient(uri);
giRC.patch(obj);
}
@@ -206,6 +215,88 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
}
}
+ public <T, R> Optional<R> getOne(Class<T> pluralClass, Class<R> resultClass, PluralUri uri) {
+ Optional<List<R>> result = unwrapPlural(pluralClass, resultClass, uri);
+
+ if (result.isPresent()) {
+ if (result.get().size() == 1) {
+ return Optional.of(result.get().get(0));
+ } else {
+ throw new GraphInventoryMultipleItemsException(result.get().size(), uri);
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ public <T, R> Optional<R> getFirst(Class<T> pluralClass, Class<R> resultClass, PluralUri uri) {
+ Optional<List<R>> result = unwrapPlural(pluralClass, resultClass, uri);
+
+ if (result.isPresent() && !result.get().isEmpty()) {
+ return Optional.of(result.get().get(0));
+ }
+
+ return Optional.empty();
+ }
+
+ public <T, R> Optional<Wrapper> getFirstWrapper(Class<T> pluralClass, Class<R> resultClass, PluralUri uri) {
+
+ Optional<R> result = getFirst(pluralClass, resultClass, uri);
+ if (result.isPresent()) {
+ return Optional.of(this.createWrapper(result.get()));
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ public <T, R> Optional<Wrapper> getOneWrapper(Class<T> pluralClass, Class<R> resultClass, PluralUri uri) {
+
+ Optional<R> result = getOne(pluralClass, resultClass, uri);
+ if (result.isPresent()) {
+ return Optional.of(this.createWrapper(result.get()));
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ protected <T, R> Optional<List<R>> unwrapPlural(Class<T> pluralClass, Class<R> resultClass, PluralUri uri) {
+ try {
+ PluralUri clone = (PluralUri) uri.clone().limit(1);
+ Optional<T> obj = client.createClient(clone).get(pluralClass);
+ if (obj.isPresent()) {
+ Optional<Method> listMethod = Arrays.stream(obj.get().getClass().getMethods()).filter(method -> {
+
+ Type returnType = method.getGenericReturnType();
+ if (returnType instanceof ParameterizedType) {
+ Type[] types = ((ParameterizedType) returnType).getActualTypeArguments();
+ if (types != null && types[0] instanceof Class) {
+ Class<?> listClass = (Class<?>) types[0];
+ return resultClass.equals(listClass);
+ }
+ }
+
+ return false;
+ }).findFirst();
+ if (listMethod.isPresent()) {
+ try {
+ return Optional.of((List<R>) listMethod.get().invoke(obj.get()));
+
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ return Optional.empty();
+
+ } catch (NotFoundException e) {
+ if (this.getRestProperties().mapNotFoundToEmpty()) {
+ return Optional.empty();
+ } else {
+ throw e;
+ }
+ }
+ }
+
/**
* Retrieves an object from GraphInventory wrapped in a helper class which offer additional features
*
@@ -269,8 +360,8 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
* @param uri
* @return
*/
- public Self createIfNotExists(Uri uri, Optional<Object> obj) {
- if (!this.exists(uri)) {
+ public Self createIfNotExists(SingleUri uri, Optional<Object> obj) {
+ if (!this.exists((Uri) uri)) {
if (obj.isPresent()) {
this.create(uri, obj.get());
} else {
@@ -281,17 +372,21 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
return (Self) this;
}
- protected Relationship buildRelationship(GraphInventoryResourceUri uri) {
+ protected Relationship buildRelationship(SingleUri uri) {
return buildRelationship(uri, Optional.empty());
}
- protected Relationship buildRelationship(GraphInventoryResourceUri uri, GraphInventoryEdgeLabel label) {
+ protected Relationship buildRelationship(SingleUri uri, GraphInventoryEdgeLabel label) {
return buildRelationship(uri, Optional.of(label));
}
- protected Relationship buildRelationship(GraphInventoryResourceUri uri, Optional<GraphInventoryEdgeLabel> label) {
+ protected Relationship buildRelationship(SingleUri uri, Optional<GraphInventoryEdgeLabel> label) {
final Relationship result = new Relationship();
- result.setRelatedLink(uri.build().toString());
+ if (uri instanceof HttpAwareUri) {
+ result.setRelatedLink(((HttpAwareUri) uri).locateAndBuild().toString());
+ } else {
+ result.setRelatedLink(uri.build().toString());
+ }
if (label.isPresent()) {
result.setRelationshipLabel(label.get().toString());
}
@@ -300,6 +395,8 @@ public abstract class GraphInventoryResourcesClient<Self, Uri extends GraphInven
public abstract Wrapper createWrapper(String json);
+ public abstract Wrapper createWrapper(Object json);
+
/**
* Starts a transaction which encloses multiple GraphInventory mutations
*
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java
index 45ac1f741d..3469d73599 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/GraphInventoryTransactionClient.java
@@ -29,11 +29,12 @@ import javax.ws.rs.core.GenericType;
import org.onap.aai.domain.yang.Relationship;
import org.onap.so.client.graphinventory.entities.GraphInventoryEdgeLabel;
import org.onap.so.client.graphinventory.entities.uri.GraphInventoryResourceUri;
+import org.onap.so.client.graphinventory.entities.uri.GraphInventorySingleResourceUri;
import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInventoryResourceUri, EdgeLabel extends GraphInventoryEdgeLabel> {
+public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInventoryResourceUri<?, ?>, SingleUri extends GraphInventorySingleResourceUri<?, ?, ?, ?>, EdgeLabel extends GraphInventoryEdgeLabel> {
protected static Logger logger = LoggerFactory.getLogger(GraphInventoryTransactionClient.class);
@@ -50,7 +51,7 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uri
* @return
*/
- public Self create(Uri uri, Object obj) {
+ public Self create(SingleUri uri, Object obj) {
this.put(uri.build().toString(), obj);
incrementActionAmount();
return (Self) this;
@@ -62,7 +63,7 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uri
* @return
*/
- public Self createEmpty(Uri uri) {
+ public Self createEmpty(SingleUri uri) {
this.put(uri.build().toString(), new HashMap<String, String>());
incrementActionAmount();
return (Self) this;
@@ -75,8 +76,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uri
* @return
*/
- public Self createIfNotExists(Uri uri, Optional<Object> obj) {
- if (!this.exists(uri)) {
+ public Self createIfNotExists(SingleUri uri, Optional<Object> obj) {
+ if (!this.exists((Uri) uri)) {
if (obj.isPresent()) {
this.create(uri, obj.get());
} else {
@@ -94,8 +95,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uriB
* @return
*/
- public Self connect(Uri uriA, Uri uriB) {
- GraphInventoryResourceUri uriAClone = uriA.clone();
+ public Self connect(SingleUri uriA, SingleUri uriB) {
+ GraphInventorySingleResourceUri uriAClone = uriA.clone();
this.put(uriAClone.relationshipAPI().build().toString(), this.buildRelationship(uriB));
incrementActionAmount();
return (Self) this;
@@ -108,8 +109,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uris
* @return
*/
- public Self connect(Uri uriA, List<Uri> uris) {
- for (Uri uri : uris) {
+ public Self connect(SingleUri uriA, List<SingleUri> uris) {
+ for (SingleUri uri : uris) {
this.connect(uriA, uri);
}
return (Self) this;
@@ -122,8 +123,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uris
* @return
*/
- public Self connect(Uri uriA, Uri uriB, EdgeLabel label) {
- GraphInventoryResourceUri uriAClone = uriA.clone();
+ public Self connect(SingleUri uriA, SingleUri uriB, EdgeLabel label) {
+ GraphInventorySingleResourceUri uriAClone = uriA.clone();
this.put(uriAClone.relationshipAPI().build().toString(), this.buildRelationship(uriB, label));
return (Self) this;
}
@@ -135,8 +136,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uris
* @return
*/
- public Self connect(Uri uriA, List<Uri> uris, EdgeLabel label) {
- for (Uri uri : uris) {
+ public Self connect(SingleUri uriA, List<SingleUri> uris, EdgeLabel label) {
+ for (SingleUri uri : uris) {
this.connect(uriA, uri, label);
}
return (Self) this;
@@ -149,8 +150,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uriB
* @return
*/
- public Self disconnect(Uri uriA, Uri uriB) {
- GraphInventoryResourceUri uriAClone = uriA.clone();
+ public Self disconnect(SingleUri uriA, SingleUri uriB) {
+ GraphInventorySingleResourceUri uriAClone = uriA.clone();
this.delete(uriAClone.relationshipAPI().build().toString(), this.buildRelationship(uriB));
incrementActionAmount();
return (Self) this;
@@ -163,8 +164,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uris
* @return
*/
- public Self disconnect(Uri uriA, List<Uri> uris) {
- for (Uri uri : uris) {
+ public Self disconnect(SingleUri uriA, List<SingleUri> uris) {
+ for (SingleUri uri : uris) {
this.disconnect(uriA, uri);
}
return (Self) this;
@@ -176,8 +177,8 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
* @param uri
* @return
*/
- public Self delete(Uri uri) {
- Map<String, Object> result = this.get(new GenericType<Map<String, Object>>() {}, (Uri) uri.clone())
+ public Self delete(SingleUri uri) {
+ Map<String, Object> result = this.get(new GenericType<Map<String, Object>>() {}, (Uri) uri)
.orElseThrow(() -> new NotFoundException(uri.build() + " does not exist in " + this.getGraphDBName()));
String resourceVersion = (String) result.get("resource-version");
this.delete(uri.resourceVersion(resourceVersion).build().toString());
@@ -223,15 +224,15 @@ public abstract class GraphInventoryTransactionClient<Self, Uri extends GraphInv
*/
public abstract void execute() throws BulkProcessFailed;
- private Relationship buildRelationship(Uri uri) {
+ private Relationship buildRelationship(SingleUri uri) {
return buildRelationship(uri, Optional.empty());
}
- private Relationship buildRelationship(Uri uri, EdgeLabel label) {
+ private Relationship buildRelationship(SingleUri uri, EdgeLabel label) {
return buildRelationship(uri, Optional.of(label));
}
- private Relationship buildRelationship(Uri uri, Optional<EdgeLabel> label) {
+ private Relationship buildRelationship(SingleUri uri, Optional<EdgeLabel> label) {
final Relationship result = new Relationship();
result.setRelatedLink(uri.build().toString());
if (label.isPresent()) {
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryRelationships.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryRelationships.java
index 6703416832..6e7b9c9f08 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryRelationships.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryRelationships.java
@@ -30,12 +30,12 @@ import java.util.function.Predicate;
import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
import org.onap.so.client.graphinventory.GraphInventoryObjectName;
import org.onap.so.client.graphinventory.GraphInventoryObjectType;
-import org.onap.so.client.graphinventory.entities.uri.GraphInventoryResourceUri;
+import org.onap.so.client.graphinventory.entities.uri.GraphInventorySingleResourceUri;
import org.onap.so.jsonpath.JsonPathUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-public abstract class GraphInventoryRelationships<Wrapper extends GraphInventoryResultWrapper, Uri extends GraphInventoryResourceUri, Type extends GraphInventoryObjectType> {
+public abstract class GraphInventoryRelationships<Wrapper extends GraphInventoryResultWrapper<?>, Uri extends GraphInventorySingleResourceUri<?, ?, ?, ?>, Type extends GraphInventoryObjectType> {
protected final ObjectMapper mapper;
protected Map<String, Object> map;
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryPluralResourceUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryPluralResourceUri.java
new file mode 100644
index 0000000000..aa09702be8
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryPluralResourceUri.java
@@ -0,0 +1,8 @@
+package org.onap.so.client.graphinventory.entities.uri;
+
+import org.onap.so.client.graphinventory.GraphInventoryObjectBase;
+
+public interface GraphInventoryPluralResourceUri<T extends GraphInventoryResourceUri<?, ?>, OT extends GraphInventoryObjectBase>
+ extends GraphInventoryResourceUri<T, OT> {
+
+}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryResourceUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryResourceUri.java
index c579a285d2..64933863d5 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryResourceUri.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryResourceUri.java
@@ -21,42 +21,11 @@
package org.onap.so.client.graphinventory.entities.uri;
import org.onap.so.client.graphinventory.Format;
-import org.onap.so.client.graphinventory.entities.uri.Depth;
-import org.onap.so.client.graphinventory.GraphInventoryObjectPlurals;
-import org.onap.so.client.graphinventory.GraphInventoryObjectType;
+import org.onap.so.client.graphinventory.GraphInventoryObjectBase;
-public interface GraphInventoryResourceUri extends GraphInventoryUri {
- public GraphInventoryResourceUri relationshipAPI();
+public interface GraphInventoryResourceUri<T extends GraphInventoryResourceUri<?, ?>, OT extends GraphInventoryObjectBase>
+ extends GraphInventoryUri<T, OT> {
- public GraphInventoryResourceUri relatedTo(GraphInventoryObjectPlurals plural);
+ public T format(Format format);
- public GraphInventoryResourceUri relatedTo(GraphInventoryObjectType type, String... values);
-
- public GraphInventoryResourceUri resourceVersion(String version);
-
- public GraphInventoryResourceUri format(Format format);
-
- @Override
- public GraphInventoryResourceUri depth(Depth depth);
-
- @Override
- public GraphInventoryResourceUri nodesOnly(boolean nodesOnly);
-
- @Override
- public GraphInventoryResourceUri queryParam(String name, String... values);
-
- @Override
- public GraphInventoryResourceUri replaceQueryParam(String name, String... values);
-
- @Override
- public GraphInventoryResourceUri resultIndex(int index);
-
- @Override
- public GraphInventoryResourceUri resultSize(int size);
-
- @Override
- public GraphInventoryResourceUri limit(int size);
-
- @Override
- public GraphInventoryResourceUri clone();
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventorySingleResourceUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventorySingleResourceUri.java
new file mode 100644
index 0000000000..e45ff14a5e
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventorySingleResourceUri.java
@@ -0,0 +1,16 @@
+package org.onap.so.client.graphinventory.entities.uri;
+
+import org.onap.so.client.graphinventory.GraphInventoryObjectPlurals;
+import org.onap.so.client.graphinventory.GraphInventoryObjectType;
+
+public interface GraphInventorySingleResourceUri<T extends GraphInventorySingleResourceUri<?, ?, ?, ?>, P extends GraphInventoryPluralResourceUri<?, ?>, SingleObject extends GraphInventoryObjectType, PluralObject extends GraphInventoryObjectPlurals>
+ extends GraphInventoryResourceUri<T, SingleObject> {
+
+ public T resourceVersion(String version);
+
+ public T relationshipAPI();
+
+ public P relatedTo(PluralObject plural);
+
+ public T relatedTo(SingleObject type, String... values);
+}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java
index 6b48ad44ef..e3fda2fa23 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/GraphInventoryUri.java
@@ -20,11 +20,15 @@
package org.onap.so.client.graphinventory.entities.uri;
+import java.io.Serializable;
import java.net.URI;
import java.util.Map;
+import java.util.regex.Pattern;
+import org.onap.so.client.graphinventory.GraphInventoryObjectBase;
import org.onap.so.client.graphinventory.GraphInventoryObjectType;
-public interface GraphInventoryUri {
+public interface GraphInventoryUri<T extends GraphInventoryUri<?, ?>, OT extends GraphInventoryObjectBase>
+ extends Serializable {
public URI build();
@@ -39,26 +43,26 @@ public interface GraphInventoryUri {
* @param depth
* @return
*/
- public GraphInventoryUri depth(Depth depth);
+ public T depth(Depth depth);
/**
* Makes client only return object fields, no relationships
*
* @return
*/
- public GraphInventoryUri nodesOnly(boolean nodesOnly);
+ public T nodesOnly(boolean nodesOnly);
- public GraphInventoryUri queryParam(String name, String... values);
+ public T queryParam(String name, String... values);
- public GraphInventoryUri replaceQueryParam(String name, String... values);
+ public T replaceQueryParam(String name, String... values);
- public GraphInventoryUri resultIndex(int index);
+ public T resultIndex(int index);
- public GraphInventoryUri resultSize(int size);
+ public T resultSize(int size);
- public GraphInventoryUri limit(int size);
+ public T limit(int size);
- public GraphInventoryUri clone();
+ public T clone();
/**
* returns all key values of the URI as a map. Key names can be found in {@link GraphInventoryObjectType}
@@ -67,9 +71,11 @@ public interface GraphInventoryUri {
*/
public Map<String, String> getURIKeys();
- public GraphInventoryObjectType getObjectType();
+ public OT getObjectType();
public boolean equals(Object o);
public int hashCode();
+
+ public Pattern getPrefixPattern();
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java
index fcfde74b33..1ee3d57b6c 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java
@@ -21,9 +21,12 @@
package org.onap.so.client.graphinventory.entities.uri;
import java.net.URI;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
-public interface HttpAwareUri {
+public interface HttpAwareUri extends AAIResourceUri {
public URI buildNoNetwork();
+
+ public URI locateAndBuild();
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleBaseUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleBaseUri.java
new file mode 100644
index 0000000000..fc1a008466
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleBaseUri.java
@@ -0,0 +1,237 @@
+package org.onap.so.client.graphinventory.entities.uri;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import org.onap.so.client.graphinventory.Format;
+import org.onap.so.client.graphinventory.GraphInventoryObjectBase;
+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 abstract class SimpleBaseUri<T extends GraphInventoryResourceUri<?, ?>, Parent extends GraphInventorySingleResourceUri<?, ?, ?, ?>, S extends GraphInventoryObjectBase>
+ implements GraphInventoryResourceUri<T, S> {
+
+ private static final long serialVersionUID = -1011069933894179423L;
+ protected transient UriBuilder internalURI;
+ protected static final String relationshipAPI = "/relationship-list/relationship";
+ protected static final String relatedTo = "/related-to";
+ protected Object[] values;
+ protected final S type;
+ protected final Parent parentUri;
+ protected final Map<String, Set<String>> queryParams = new HashMap<>();
+
+ protected SimpleBaseUri(S type, Object... values) {
+ this.type = type;
+ this.internalURI = UriBuilder.fromPath(this.getTemplate(type));
+ this.values = values;
+ this.parentUri = null;
+ validateValuesSize(this.getTemplate(type), values);
+ }
+
+ protected SimpleBaseUri(S type, URI uri) {
+ if (!type.passThrough()) {
+ this.type = type;
+ this.internalURI = UriBuilder.fromPath(this.getTemplate(type));
+ this.values =
+ this.getURIKeys(uri.getRawPath().replaceAll(getPrefixPattern().toString(), "")).values().toArray();
+ this.parentUri = null;
+ } else {
+ this.type = type;
+ this.internalURI = UriBuilder.fromPath(uri.getRawPath().replaceAll(getPrefixPattern().toString(), ""));
+ this.values = new Object[0];
+ this.parentUri = null;
+ }
+
+ }
+
+ protected SimpleBaseUri(S type, UriBuilder builder, Object... values) {
+ this.internalURI = builder;
+ this.values = values;
+ this.type = type;
+ this.parentUri = null;
+
+ }
+
+ protected SimpleBaseUri(Parent parentUri, S childType, Object... childValues) {
+ this.type = childType;
+ this.internalURI = UriBuilder.fromUri(type.partialUri());
+ this.values = childValues;
+ this.parentUri = parentUri;
+
+ validateValuesSize(childType.partialUri(), values);
+ }
+
+ protected SimpleBaseUri(SimpleBaseUri<T, Parent, S> copy) {
+ this.type = copy.type;
+ this.internalURI = copy.internalURI.clone();
+ this.values = copy.values.clone();
+ if (copy.parentUri != null) {
+ this.parentUri = (Parent) copy.parentUri.clone();
+ } else {
+ this.parentUri = null;
+ }
+ }
+
+ protected void setInternalURI(UriBuilder builder) {
+ this.internalURI = builder;
+ }
+
+ @Override
+ public T queryParam(String name, String... values) {
+ this.internalURI = internalURI.queryParam(name, values);
+ if (queryParams.containsKey(name)) {
+ queryParams.get(name).addAll(Arrays.asList(values));
+ } else {
+ queryParams.put(name, Stream.of(values).collect(Collectors.toSet()));
+ }
+ return (T) this;
+ }
+
+ @Override
+ public T replaceQueryParam(String name, String... values) {
+ this.internalURI = internalURI.replaceQueryParam(name, values);
+ queryParams.put(name, Stream.of(values).collect(Collectors.toSet()));
+ return (T) this;
+ }
+
+ @Override
+ public T resultIndex(int index) {
+ this.internalURI = internalURI.replaceQueryParam("resultIndex", index);
+ return (T) this;
+ }
+
+ @Override
+ public T resultSize(int size) {
+ this.internalURI = internalURI.replaceQueryParam("resultSize", size);
+ return (T) this;
+ }
+
+ @Override
+ public T limit(int size) {
+ this.resultIndex(0).resultSize(size);
+ return (T) this;
+ }
+
+ @Override
+ public URI build() {
+ return build(this.values);
+ }
+
+ protected URI build(Object... values) {
+
+ // This is a workaround because resteasy does not encode URIs correctly
+ final String[] encoded = new String[values.length];
+ for (int i = 0; i < values.length; i++) {
+ encoded[i] = UriUtils.encode(values[i].toString(), StandardCharsets.UTF_8.toString());
+ }
+ if (this.parentUri != null) {
+ return UriBuilder
+ .fromUri(this.parentUri.build().toString() + internalURI.buildFromEncoded(encoded).toString())
+ .build();
+ } else {
+ return internalURI.buildFromEncoded(encoded);
+ }
+ }
+
+ @Override
+ public Map<String, String> getURIKeys() {
+ return this.getURIKeys(this.build().toString());
+ }
+
+ protected Map<String, String> getURIKeys(String uri) {
+ UriParser parser;
+ if (!("".equals(this.getTemplate(type)))) {
+ parser = new UriParserSpringImpl(this.getTemplate(type));
+ } else {
+ return new HashMap<>();
+ }
+
+
+ return parser.parse(uri);
+ }
+
+ @Override
+ public abstract T clone();
+
+ @Override
+ public S getObjectType() {
+ return this.type;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o != null) {
+ return this.toString().equals(o.toString());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(this.toString()).toHashCode();
+ }
+
+
+ @Override
+ public T depth(Depth depth) {
+ this.internalURI.replaceQueryParam("depth", depth.toString());
+ return (T) this;
+ }
+
+ @Override
+ public T nodesOnly(boolean nodesOnly) {
+ if (nodesOnly) {
+ this.internalURI.replaceQueryParam("nodes-only", "");
+ }
+ return (T) this;
+ }
+
+ @Override
+ public T format(Format format) {
+ this.internalURI.replaceQueryParam("format", format);
+ return (T) 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(GraphInventoryObjectBase type) {
+ return type.uriTemplate();
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ oos.defaultWriteObject();
+ oos.writeUTF(this.internalURI.toTemplate());
+ }
+
+ private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ String uri = ois.readUTF();
+ this.setInternalURI(UriBuilder.fromUri(uri));
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(null, ToStringStyle.NO_CLASS_NAME_STYLE).append("type", type)
+ .append("parentUri", parentUri).append("values", values).append("queryParams", queryParams).toString();
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimplePluralUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimplePluralUri.java
new file mode 100644
index 0000000000..c0b6d573c1
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimplePluralUri.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.graphinventory.entities.uri;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import javax.ws.rs.core.UriBuilder;
+import org.onap.so.client.graphinventory.GraphInventoryObjectPlurals;
+import org.onap.so.client.graphinventory.GraphInventoryObjectType;
+
+public abstract class SimplePluralUri<T extends GraphInventoryPluralResourceUri<?, ?>, Parent extends GraphInventorySingleResourceUri<?, ?, ?, ?>, PT extends GraphInventoryObjectPlurals, OT extends GraphInventoryObjectType>
+ extends SimpleBaseUri<T, Parent, PT> implements GraphInventoryPluralResourceUri<T, PT>, Serializable {
+
+ private static final long serialVersionUID = -337701171277616439L;
+
+ protected final PT pluralType;
+
+ protected SimplePluralUri(PT type, UriBuilder builder, Object... values) {
+ super(type, builder, values);
+ this.pluralType = type;
+ }
+
+ protected SimplePluralUri(PT type) {
+ super(type, new Object[0]);
+ this.pluralType = type;
+ }
+
+ protected SimplePluralUri(PT type, Object... values) {
+ super(type, values);
+ this.pluralType = type;
+ }
+
+ protected SimplePluralUri(Parent parentUri, PT childType) {
+ super(parentUri, childType, new Object[0]);
+ this.pluralType = childType;
+ }
+
+ public SimplePluralUri(SimplePluralUri<T, Parent, PT, OT> copy) {
+ super(copy);
+ this.pluralType = copy.pluralType;
+ }
+
+ protected void setInternalURI(UriBuilder builder) {
+ this.internalURI = builder;
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ oos.defaultWriteObject();
+ oos.writeUTF(this.internalURI.toTemplate());
+ }
+
+ private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ String uri = ois.readUTF();
+ this.setInternalURI(UriBuilder.fromUri(uri));
+ }
+}
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 ffe47c5c51..aff7392efe 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
@@ -23,254 +23,50 @@ package org.onap.so.client.graphinventory.entities.uri;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.Serializable;
import java.net.URI;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
import javax.ws.rs.core.UriBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.onap.so.client.graphinventory.Format;
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 {
+public abstract class SimpleUri<T extends GraphInventorySingleResourceUri<?, ?, ?, ?>, PT extends GraphInventoryPluralResourceUri<?, ?>, S extends GraphInventoryObjectType, P extends GraphInventoryObjectPlurals>
+ extends SimpleBaseUri<T, T, S> implements GraphInventorySingleResourceUri<T, PT, S, P> {
private static final long serialVersionUID = -337701171277616439L;
-
- protected transient UriBuilder internalURI;
protected static final String relationshipAPI = "/relationship-list/relationship";
protected static final String relatedTo = "/related-to";
- protected final Object[] values;
- protected final GraphInventoryObjectType type;
- protected final GraphInventoryObjectPlurals pluralType;
-
- protected SimpleUri(GraphInventoryObjectType type, Object... values) {
- this.type = type;
- 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;
- this.pluralType = null;
- this.internalURI = UriBuilder.fromPath(uri.getRawPath().replaceAll(getPrefixPattern().toString(), ""));
- this.values = new Object[0];
- }
- protected SimpleUri(GraphInventoryObjectType type, UriBuilder builder, Object... values) {
- this.internalURI = builder;
- this.values = values;
- this.type = type;
- this.pluralType = null;
+ protected SimpleUri(S type, Object... values) {
+ super(type, values);
}
- protected SimpleUri(GraphInventoryObjectPlurals type, UriBuilder builder, Object... values) {
- this.internalURI = builder;
- this.values = values;
- this.type = null;
- this.pluralType = type;
- }
+ protected SimpleUri(S type, URI uri) {
+ super(type, uri);
- protected SimpleUri(GraphInventoryObjectPlurals type) {
- this.type = null;
- this.pluralType = type;
- this.internalURI = UriBuilder.fromPath(this.getTemplate(type));
- this.values = new Object[0];
}
- protected SimpleUri(GraphInventoryObjectPlurals type, Object... values) {
- this.type = null;
- this.pluralType = type;
- this.internalURI = UriBuilder.fromPath(this.getTemplate(type));
- this.values = values;
- validateValuesSize(this.getTemplate(type), values);
- }
+ protected SimpleUri(S type, UriBuilder builder, Object... values) {
+ super(type, builder, 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 SimpleUri(GraphInventoryResourceUri parentUri, GraphInventoryObjectPlurals childType) {
- this.type = null;
- this.pluralType = childType;
- this.internalURI = UriBuilder.fromUri(parentUri.build()).path(childType.partialUri());
- this.values = new Object[0];
+ protected SimpleUri(T parentUri, S childType, Object... childValues) {
+ super(parentUri, childType, childValues);
}
- protected void setInternalURI(UriBuilder builder) {
- this.internalURI = builder;
+ protected SimpleUri(SimpleBaseUri<T, T, S> copy) {
+ super(copy);
}
@Override
- public SimpleUri relationshipAPI() {
- this.internalURI = internalURI.path(relationshipAPI);
- return this;
- }
-
- @Override
- public SimpleUri relatedTo(GraphInventoryObjectPlurals plural) {
-
- this.internalURI = internalURI.path(relatedTo).path(plural.partialUri());
- return this;
- }
-
- @Override
- public SimpleUri relatedTo(GraphInventoryObjectType type, String... values) {
- this.internalURI =
- internalURI.path(relatedTo).path(UriBuilder.fromPath(type.partialUri()).build(values).toString());
- return this;
- }
-
- @Override
- public SimpleUri resourceVersion(String version) {
+ public T resourceVersion(String version) {
this.internalURI = internalURI.replaceQueryParam("resource-version", version);
- return this;
- }
-
- @Override
- public SimpleUri queryParam(String name, String... values) {
- this.internalURI = internalURI.queryParam(name, values);
- return this;
- }
-
- @Override
- public SimpleUri replaceQueryParam(String name, String... values) {
- this.internalURI = internalURI.replaceQueryParam(name, values);
- return this;
- }
-
- @Override
- public SimpleUri resultIndex(int index) {
- this.internalURI = internalURI.replaceQueryParam("resultIndex", index);
- return this;
- }
-
- @Override
- public SimpleUri resultSize(int size) {
- this.internalURI = internalURI.replaceQueryParam("resultSize", size);
- return this;
- }
-
- @Override
- public SimpleUri limit(int size) {
- return this.resultIndex(0).resultSize(size);
- }
-
- @Override
- public URI build() {
- return build(this.values);
- }
-
- protected Pattern getPrefixPattern() {
- return Pattern.compile("/.*?/v\\d+");
- }
-
- protected URI build(Object... values) {
- // This is a workaround because resteasy does not encode URIs correctly
- final String[] encoded = new String[values.length];
- for (int i = 0; i < values.length; i++) {
- encoded[i] = UriUtils.encode(values[i].toString(), StandardCharsets.UTF_8.toString());
- }
- return internalURI.buildFromEncoded(encoded);
- }
-
- @Override
- public Map<String, String> getURIKeys() {
- return this.getURIKeys(this.build().toString());
- }
-
- protected Map<String, String> getURIKeys(String uri) {
- UriParser parser;
- if (this.type != null) {
- if (!("".equals(this.getTemplate(type)))) {
- parser = new UriParserSpringImpl(this.getTemplate(type));
- } else {
- return new HashMap<>();
- }
- } else {
- parser = new UriParserSpringImpl(this.getTemplate(pluralType));
- }
-
-
- return parser.parse(uri);
- }
-
- @Override
- public SimpleUri clone() {
- if (this.type != null) {
- return new SimpleUri(this.type, this.internalURI.clone(), values);
- } else {
- return new SimpleUri(this.pluralType, this.internalURI.clone(), values);
- }
- }
-
- @Override
- public GraphInventoryObjectType getObjectType() {
- return this.type;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof GraphInventoryUri) {
- return this.build().equals(((GraphInventoryUri) o).build());
- }
- return false;
+ return (T) this;
}
@Override
- public int hashCode() {
- return new HashCodeBuilder().append(this.build()).toHashCode();
- }
-
-
- @Override
- public SimpleUri depth(Depth depth) {
- this.internalURI.replaceQueryParam("depth", depth.toString());
- return this;
- }
-
- @Override
- public SimpleUri nodesOnly(boolean nodesOnly) {
- if (nodesOnly) {
- this.internalURI.replaceQueryParam("nodes-only", "");
- }
- return this;
- }
-
- @Override
- public SimpleUri format(Format format) {
- this.internalURI.replaceQueryParam("format", format);
- 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();
- }
-
- protected String getTemplate(GraphInventoryObjectPlurals type) {
- return type.uriTemplate();
+ public T relationshipAPI() {
+ this.internalURI = internalURI.path(relationshipAPI);
+ return (T) this;
}
private void writeObject(ObjectOutputStream oos) throws IOException {
@@ -283,4 +79,5 @@ public class SimpleUri implements GraphInventoryResourceUri, Serializable {
String uri = ois.readUTF();
this.setInternalURI(UriBuilder.fromUri(uri));
}
+
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryMultipleItemsException.java b/common/src/main/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryMultipleItemsException.java
new file mode 100644
index 0000000000..d3c17ce9e9
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryMultipleItemsException.java
@@ -0,0 +1,13 @@
+package org.onap.so.client.graphinventory.exceptions;
+
+import org.onap.so.client.graphinventory.entities.uri.GraphInventoryPluralResourceUri;
+
+public class GraphInventoryMultipleItemsException extends RuntimeException {
+
+ private static final long serialVersionUID = -1596266941681036917L;
+
+ public GraphInventoryMultipleItemsException(int size, GraphInventoryPluralResourceUri uri) {
+ super(String.format("Found %s objects at %s when we only expected to find one.", size, uri.build()));
+ }
+
+}