2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.aai.serialization.queryformats.utils;
23 import java.io.UnsupportedEncodingException;
25 import java.net.URISyntaxException;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.openecomp.aai.db.props.AAIProperties;
29 import org.openecomp.aai.exceptions.AAIException;
30 import org.openecomp.aai.introspection.Version;
31 import org.openecomp.aai.serialization.db.DBSerializer;
32 import org.openecomp.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
33 import org.openecomp.aai.util.AAIApiServerURLBase;
34 import org.openecomp.aai.workarounds.LegacyURITransformer;
36 public class UrlBuilder {
38 private final DBSerializer serializer;
39 private final Version version;
40 private final String serverBase;
42 public UrlBuilder (Version version, DBSerializer serializer) throws AAIException {
43 this.serializer = serializer;
44 this.version = version;
45 this.serverBase = AAIApiServerURLBase.get(AAIProperties.LATEST);
48 public UrlBuilder (Version version, DBSerializer serializer, String serverBase) {
49 this.serializer = serializer;
50 this.version = version;
51 this.serverBase = serverBase;
54 public String pathed(Vertex v) throws AAIFormatVertexException {
57 final StringBuilder result = new StringBuilder();
58 final URI uri = this.serializer.getURIForVertex(v);
60 result.append(this.serverBase);
61 result.append(this.version);
62 result.append(uri.getRawPath());
64 return result.toString();
65 } catch (UnsupportedEncodingException | IllegalArgumentException | SecurityException e) {
66 throw new AAIFormatVertexException(e);
70 public String id(Vertex v) {
71 final StringBuilder result = new StringBuilder();
73 result.append("/resources/id/" + v.id());
74 result.insert(0, this.version);
75 result.insert(0, this.serverBase);
77 return result.toString();
80 protected String getServerBase(Version v) throws AAIException {
81 return AAIApiServerURLBase.get(v);