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.workarounds;
23 import java.net.MalformedURLException;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
29 import com.att.aft.dme2.internal.javaxwsrs.core.UriBuilder;
31 public class LegacyURLTransformer {
34 * Instantiates a new legacy URL transformer.
36 private LegacyURLTransformer() {
40 private static class Helper {
41 private static final LegacyURLTransformer INSTANCE = new LegacyURLTransformer();
45 * Gets the single instance of LegacyURLTransformer.
47 * @return single instance of LegacyURLTransformer
49 public static LegacyURLTransformer getInstance() {
50 return Helper.INSTANCE;
54 * Gets the legacy URL.
57 * @return the legacy URL
58 * @throws MalformedURLException the malformed URL exception
60 public URL getLegacyURL(URL url) throws MalformedURLException {
61 String substring = "/aai/(?<version>v\\d+)/cloud-infrastructure/tenants/tenant/(?<tenantKey>.*?)/vservers/vserver/(?<vserverKey>[^/]*?$)";
62 String replacement = "/aai/servers/${version}/${tenantKey}/vservers/${vserverKey}";
63 Pattern p = Pattern.compile(substring);
64 String result = url.toString();
65 Matcher m = p.matcher(result);
67 result = m.replaceFirst(replacement);
70 URL resultUrl = new URL(result);
76 * Gets the current URL.
79 * @return the current URL
80 * @throws MalformedURLException the malformed URL exception
82 public URL getCurrentURL(URL url) throws MalformedURLException {
83 String substring = "/aai/servers/(?<version>v[23])/(?<tenantKey>.*?)/vservers/(?<vserverKey>[^/]*?$)";
84 String replacement = "/aai/${version}/cloud-infrastructure/tenants/tenant/${tenantKey}/vservers/vserver/${vserverKey}";
85 Pattern p = Pattern.compile(substring);
86 String result = url.toString();
87 Matcher m = p.matcher(result);
89 result = m.replaceFirst(replacement);
93 URL resultUrl = new URL(result);