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/entities/uri/SimpleUri.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/entities/uri/SimpleUri.java')
-rw-r--r-- | common/src/main/java/org/openecomp/mso/client/aai/entities/uri/SimpleUri.java | 187 |
1 files changed, 0 insertions, 187 deletions
diff --git a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/SimpleUri.java b/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/SimpleUri.java deleted file mode 100644 index f3e6fad48b..0000000000 --- a/common/src/main/java/org/openecomp/mso/client/aai/entities/uri/SimpleUri.java +++ /dev/null @@ -1,187 +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.entities.uri; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.core.UriBuilder; - -import org.openecomp.mso.client.aai.AAIObjectPlurals; -import org.openecomp.mso.client.aai.AAIObjectType; -import org.openecomp.mso.client.aai.entities.uri.parsers.UriParser; -import org.openecomp.mso.client.aai.entities.uri.parsers.UriParserSpringImpl; -import org.springframework.web.util.UriUtils; - -public class SimpleUri implements AAIResourceUri { - - protected UriBuilder internalURI; - protected final static String relationshipAPI = "/relationship-list/relationship"; - protected final static String relatedTo = "/related-to"; - protected final Object[] values; - protected final AAIObjectType type; - protected final AAIObjectPlurals pluralType; - protected SimpleUri(AAIObjectType type, Object... values) { - this.type = type; - this.pluralType = null; - this.internalURI = UriBuilder.fromPath(this.getTemplate(type)); - this.values = values; - } - protected SimpleUri(AAIObjectType type, URI uri) { - this.type = type; - this.pluralType = null; - this.internalURI = UriBuilder.fromPath(uri.getRawPath().replaceAll("/aai/v\\d+", "")); - this.values = new Object[0]; - } - protected SimpleUri(AAIObjectType type, UriBuilder builder, Object... values) { - this.internalURI = builder; - this.values = values; - this.type = type; - this.pluralType = null; - } - protected SimpleUri(AAIObjectPlurals type, UriBuilder builder, Object... values) { - this.internalURI = builder; - this.values = values; - this.type = null; - this.pluralType = type; - } - protected SimpleUri(AAIObjectPlurals type) { - this.type = null; - this.pluralType = type; - this.internalURI = UriBuilder.fromPath(this.getTemplate(type)); - this.values = new Object[0]; - } - - @Override - public SimpleUri relationshipAPI() { - this.internalURI = internalURI.path(relationshipAPI); - return this; - } - - @Override - public SimpleUri relatedTo(AAIObjectPlurals plural) { - - this.internalURI = internalURI.path(relatedTo).path(plural.partialUri()); - return this; - } - @Override - public SimpleUri relatedTo(AAIObjectType type, String... values) { - this.internalURI = internalURI.path(relatedTo).path(UriBuilder.fromPath(type.partialUri()).build(values).toString()); - return this; - } - - @Override - public SimpleUri resourceVersion(String version) { - this.internalURI = internalURI.queryParam("resource-version", version); - return this; - } - - @Override - public SimpleUri queryParam(String name, String... values) { - this.internalURI = internalURI.queryParam(name, values); - return 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++) { - try { - encoded[i] = UriUtils.encode(values[i].toString(), StandardCharsets.UTF_8.toString()); - } catch (UnsupportedEncodingException e) { - encoded[i] = values[i].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 AAIObjectType getObjectType() { - return this.type; - } - - @Override - public boolean equals(Object o) { - if (o instanceof AAIUri) { - return this.build().equals(((AAIUri)o).build()); - } - return false; - } - @Override - public SimpleUri depth(Depth depth) { - this.internalURI.queryParam("depth", depth.toString()); - return this; - } - @Override - public SimpleUri nodesOnly(boolean nodesOnly) { - if (nodesOnly) { - this.internalURI.queryParam("nodes-only", ""); - } - return this; - } - - protected String getTemplate(AAIObjectType type) { - return type.uriTemplate(); - } - - protected String getTemplate(AAIObjectPlurals type) { - return type.uriTemplate(); - } - -} |