diff options
author | 2018-07-30 15:56:09 -0400 | |
---|---|---|
committer | 2018-07-31 11:09:25 -0400 | |
commit | 5a6a6de6f1a26a1897e4917a0df613e25a24eb70 (patch) | |
tree | 59a968f27b4b603aacc9d5e7b51fb598aeec5321 /common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java | |
parent | b6dc38501f3b746426b42d9de4cc883d894149e8 (diff) |
Containerization feature of SO
Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18
Issue-ID: SO-670
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java')
-rw-r--r-- | common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java | 254 |
1 files changed, 0 insertions, 254 deletions
diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java deleted file mode 100644 index c55e5e9eee..0000000000 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java +++ /dev/null @@ -1,254 +0,0 @@ -/*- - * ============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.openecomp.mso.client.aai; - -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - -import javax.ws.rs.NotFoundException; -import javax.ws.rs.client.ResponseProcessingException; -import javax.ws.rs.core.GenericType; - -import javax.ws.rs.core.Response; -import org.onap.aai.domain.yang.Relationship; -import org.openecomp.mso.client.aai.entities.AAIResultWrapper; -import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; -import org.openecomp.mso.client.aai.entities.uri.AAIUri; -import org.openecomp.mso.client.aai.entities.uri.Depth; -import org.openecomp.mso.client.policy.RestClient; - -public class AAIResourcesClient extends AAIClient { - - private final AAIVersion version; - - public AAIResourcesClient() { - super(UUID.randomUUID()); - this.version = super.getVersion(); - } - - public AAIResourcesClient(AAIVersion version) { - super(UUID.randomUUID()); - this.version = version; - } - - public AAIResourcesClient(AAIVersion version, UUID requestId) { - super(requestId); - this.version = version; - } - - /** - * creates a new object in A&AI - * - * @param obj - can be any object which will marshal into a valid A&AI payload - * @param uri - * @return - */ - public void create(AAIResourceUri uri, Object obj) { - RestClient aaiRC = this.createClient(uri); - aaiRC.put(obj); - return; - } - - /** - * creates a new object in A&AI with no payload body - * - * @param uri - * @return - */ - public void createEmpty(AAIResourceUri uri) { - RestClient aaiRC = this.createClient(uri); - aaiRC.put(""); - return; - } - - /** - * returns false if the object does not exist in A&AI - * - * @param uri - * @return - */ - public boolean exists(AAIResourceUri uri) { - AAIUri forceMinimal = this.addParams(Optional.of(Depth.ZERO), true, uri); - RestClient aaiRC = this.createClient(forceMinimal); - try{ - aaiRC.get(); - } catch(ResponseProcessingException e) { - if (e.getCause() instanceof NotFoundException) { - return false; - } else { - throw e; - } - } - return true; - } - - /** - * Adds a relationship between two objects in A&AI - * @param uriA - * @param uriB - * @return - */ - public void connect(AAIResourceUri uriA, AAIResourceUri uriB) { - AAIResourceUri uriAClone = uriA.clone(); - RestClient aaiRC = this.createClient(uriAClone.relationshipAPI()); - aaiRC.put(this.buildRelationship(uriB)); - return; - } - - /** - * Removes relationship from two objects in A&AI - * - * @param uriA - * @param uriB - * @return - */ - public void disconnect(AAIResourceUri uriA, AAIResourceUri uriB) { - AAIResourceUri uriAClone = uriA.clone(); - RestClient aaiRC = this.createClient(uriAClone.relationshipAPI()); - aaiRC.delete(this.buildRelationship(uriB)); - return; - } - - /** - * Deletes object from A&AI. Automatically handles resource-version. - * - * @param uri - * @return - */ - public void delete(AAIResourceUri uri) { - AAIResourceUri clone = uri.clone(); - RestClient aaiRC = this.createClient(clone); - Map<String, Object> result = aaiRC.get(new GenericType<Map<String, Object>>(){}); - String resourceVersion = (String) result.get("resource-version"); - aaiRC = this.createClient(clone.resourceVersion(resourceVersion)); - aaiRC.delete(); - return; - } - - /** - * @param obj - can be any object which will marshal into a valid A&AI payload - * @param uri - * @return - */ - public void update(AAIResourceUri uri, Object obj) { - RestClient aaiRC = this.createClient(uri); - aaiRC.patch(obj); - return; - } - - /** - * Retrieves an object from A&AI and unmarshalls it into the Class specified - * @param clazz - * @param uri - * @return - */ - public <T> T get(Class<T> clazz, AAIResourceUri uri) { - return this.createClient(uri).get(clazz); - } - - /** - * Retrieves an object from A&AI and returns complete response - * @param uri - * @return - */ - public Response getFullResponse(AAIResourceUri uri) { - return this.createClient(uri).get(); - } - - /** - * Retrieves an object from A&AI and automatically unmarshalls it into a Map or List - * @param resultClass - * @param uri - * @return - */ - public <T> T get(GenericType<T> resultClass, AAIResourceUri uri) { - return this.createClient(uri).get(resultClass); - } - - /** - * Retrieves an object from A&AI wrapped in a helper class which offer additional features - * - * @param uri - * @return - */ - public AAIResultWrapper get(AAIResourceUri uri) { - String json = this.createClient(uri).get(String.class); - - return new AAIResultWrapper(json); - - } - private Relationship buildRelationship(AAIResourceUri uri) { - final Relationship result = new Relationship(); - result.setRelatedLink(uri.build().toString()); - return result; - } - - /** - * Will automatically create the object if it does not exist - * - * @param obj - Optional object which serializes to a valid A&AI payload - * @param uri - * @return - */ - public AAIResourcesClient createIfNotExists(AAIResourceUri uri, Optional<Object> obj) { - if(!this.exists(uri)){ - if (obj.isPresent()) { - this.create(uri, obj.get()); - } else { - this.createEmpty(uri); - } - - } - return this; - } - - /** - * Starts a transaction which encloses multiple A&AI mutations - * - * @return - */ - public AAITransactionalClient beginTransaction() { - return new AAITransactionalClient(this.version, this.requestId); - } - - @Override - protected AAIVersion getVersion() { - return this.version; - } - - @Override - protected RestClient createClient(AAIUri uri) { - return super.createClient(uri); - } - - private AAIUri addParams(Optional<Depth> depth, boolean nodesOnly, AAIUri uri) { - AAIUri clone = uri.clone(); - if (depth.isPresent()) { - clone.depth(depth.get()); - } - if (nodesOnly) { - clone.nodesOnly(nodesOnly); - } - - return clone; - } -} |