diff options
author | sa282w <sa282w@att.com> | 2018-05-02 17:00:20 -0400 |
---|---|---|
committer | sa282w <sa282w@att.com> | 2018-05-03 16:51:59 -0400 |
commit | 22ed5d7b533cec97713c3b5aef37319d5dead6a3 (patch) | |
tree | df40d050750cab3cf9b78e9820dd0bde8d16eaa9 /ecomp-sdk/epsdk-fw/src/main | |
parent | c607da68bfb7f7440d5be7f0396609dc01eb0e90 (diff) |
API Versioning for ECOMP Components in SDK
Issue-ID: PORTAL-263
Included the api version changes for SDK.
Change-Id: Ib81c5aabe585f6e2775e73a692153d1f286d1f45
Signed-off-by: sa282w <sa282w@att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/main')
7 files changed, 70 insertions, 12 deletions
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java index 6f8c50ae..f82e8737 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java @@ -38,6 +38,7 @@ package org.onap.portalsdk.core.onboarding.crossapi; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -190,5 +191,7 @@ public interface IPortalRestAPIService { * If an unexpected error occurs while processing the request. */ public String getUserId(HttpServletRequest request) throws PortalAPIException; + + public Map<String, String> getCredentials() throws PortalAPIException; } diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java index a82517d8..208e8c3d 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java @@ -39,15 +39,19 @@ package org.onap.portalsdk.core.onboarding.crossapi; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; import org.onap.portalsdk.core.restful.domain.EcompRole; @@ -65,6 +69,8 @@ public class PortalRestAPICentralServiceImpl implements IPortalRestAPIService { private String password; private String appName; IPortalRestCentralService portalRestCentralService; + public static final String API_VERSION = "/v4"; + private static String portalApiVersion = "/v3"; public PortalRestAPICentralServiceImpl() throws ServletException { String centralClassName = PortalApiProperties.getProperty(PortalApiConstants.PORTAL_API_IMPL_CLASS); @@ -99,7 +105,7 @@ public class PortalRestAPICentralServiceImpl implements IPortalRestAPIService { EcompUser user = new EcompUser(); String responseString = null; try { - responseString = RestWebServiceClient.getInstance().getPortalContent("/v2/user/" + loginId, null, + responseString = RestWebServiceClient.getInstance().getPortalContent(API_VERSION + "/user/" + loginId, null, appName, null, username, password, true); logger.debug("responseString is: " + responseString); user = mapper.readValue(responseString, EcompUser.class); @@ -117,7 +123,7 @@ public class PortalRestAPICentralServiceImpl implements IPortalRestAPIService { List<EcompUser> usersList = new ArrayList<>(); String responseString = null; try { - responseString = RestWebServiceClient.getInstance().getPortalContent("/users", null, appName, null, + responseString = RestWebServiceClient.getInstance().getPortalContent(portalApiVersion + "/users", null, appName, null, username, password, true); logger.debug("responseString is: " + responseString); usersList = mapper.readValue(responseString, @@ -136,7 +142,7 @@ public class PortalRestAPICentralServiceImpl implements IPortalRestAPIService { List<EcompRole> rolesList = new ArrayList<>(); String responseString = null; try { - responseString = RestWebServiceClient.getInstance().getPortalContent("/v2/roles", requestedLoginId, + responseString = RestWebServiceClient.getInstance().getPortalContent(API_VERSION + "/roles", requestedLoginId, appName, null, username, password, true); logger.debug("responseString is: " + responseString); rolesList = mapper.readValue(responseString, @@ -163,7 +169,7 @@ public class PortalRestAPICentralServiceImpl implements IPortalRestAPIService { EcompUser user = new EcompUser(); String responseString = null; try { - responseString = RestWebServiceClient.getInstance().getPortalContent("/v2/user/" + loginId, null, + responseString = RestWebServiceClient.getInstance().getPortalContent(API_VERSION + "/user/" + loginId, null, appName, null, username, password, true); logger.debug("responseString is: " + responseString); user = mapper.readValue(responseString, EcompUser.class); @@ -196,5 +202,15 @@ public class PortalRestAPICentralServiceImpl implements IPortalRestAPIService { public String getUserId(HttpServletRequest request) throws PortalAPIException { return portalRestCentralService.getUserId(request); } + + @Override + public Map<String, String> getCredentials() throws PortalAPIException{ + Map<String, String> credentialsMap = new HashMap<>(); + + credentialsMap.put("username", username); + credentialsMap.put("password", password); + credentialsMap.put("appName", appName); + return credentialsMap; + } } diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java index 9d13e431..49b3deaa 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java @@ -164,6 +164,21 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer } else { // User ID obtained from request try { + String appUserName = ""; + String appPassword = ""; + String appName = ""; + + for (Map.Entry<String, String> entry : getCredentials().entrySet()) { + + if (entry.getKey().equalsIgnoreCase("username")) { + appUserName = entry.getValue(); + } else if (entry.getKey().equalsIgnoreCase("password")) { + appPassword = entry.getValue(); + } else { + appName = entry.getValue(); + } + } + String credential = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY); // for now lets also pass uebkey as user name and password String requestBody = readRequestBody(request); @@ -173,7 +188,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer bodyMap.put("userid", userId); requestBody = mapper.writeValueAsString(bodyMap); responseJson = RestWebServiceClient.getInstance().postPortalContent(storeAnalyticsContextPath, - userId, credential, null, credential, credential, "application/json", requestBody, true); + userId, appName, null, appUserName, appPassword, "application/json", requestBody, true); logger.debug("doPost: postPortalContent returns " + responseJson); response.setStatus(HttpServletResponse.SC_OK); } catch (Exception ex) { @@ -346,12 +361,27 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer } else { // User ID obtained from request try { + String appUserName = ""; + String appPassword = ""; + String appName = ""; + + for (Map.Entry<String, String> entry : getCredentials().entrySet()) { + + if (entry.getKey().equalsIgnoreCase("username")) { + appUserName = entry.getValue(); + } else if (entry.getKey().equalsIgnoreCase("password")) { + appPassword = entry.getValue(); + } else { + appName = entry.getValue(); + } + } String credential = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY); // for now lets also pass uebkey as user name and password contentType = "text/javascript"; responseString = RestWebServiceClient.getInstance().getPortalContent(webAnalyticsContextPath, - userId, credential, null, credential, credential, true); + userId, appName, null, appUserName, appPassword, true); + if (logger.isDebugEnabled()) logger.debug("doGet: " + webAnalyticsContextPath + ": " + responseString); response.setStatus(HttpServletResponse.SC_OK); @@ -465,7 +495,8 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer response.setStatus(HttpServletResponse.SC_BAD_REQUEST); logger.error("doGet: getUserRoles: caught exception", ex); } - } else { + } + else { logger.warn("doGet: no match found for request"); responseJson = buildJsonResponse(false, "No match for request"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); @@ -647,5 +678,10 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer public static void setPortalRestApiServiceImpl(IPortalRestAPIService portalRestApiServiceImpl) { PortalRestAPIProxy.portalRestApiServiceImpl = portalRestApiServiceImpl; } + + @Override + public Map<String, String> getCredentials() throws PortalAPIException { + return portalRestApiServiceImpl.getCredentials(); + } } diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java index ae4847cc..e016db07 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java @@ -46,6 +46,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class SessionCommunicationService { + private static String portalApiVersion = "/v3"; private static final Log logger = LogFactory.getLog(SessionCommunicationService.class); @@ -66,7 +67,7 @@ public class SessionCommunicationService { public static String getSessionSlotCheckInterval(String ecompRestURL, String userName, String password, String uebKey) { try { - String url = ecompRestURL + "/getSessionSlotCheckInterval"; + String url = ecompRestURL + portalApiVersion + "/getSessionSlotCheckInterval"; URL obj = new URL(url); diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClient.java index 5049455c..b7d2ca8c 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClient.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClient.java @@ -44,6 +44,7 @@ import java.io.IOException; * from the ECOMP Portal via UEB. */ public class FunctionalMenuClient { + private static String portalApiVersion = "/v3"; /** * Fetches the functional menu data from the configured ECOMP Portal @@ -67,7 +68,7 @@ public class FunctionalMenuClient { */ public static String getFunctionalMenu(String userId, String appName, String requestId, String appUserName, String appPassword) throws IOException { - return RestWebServiceClient.getInstance().getPortalContent("/functionalMenuItemsForUser", userId, appName, + return RestWebServiceClient.getInstance().getPortalContent(portalApiVersion + "/functionalMenuItemsForUser", userId, appName, requestId, appUserName, appPassword,true); } diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java index 72f3670f..7121bd8c 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java @@ -223,8 +223,9 @@ public class RestWebServiceClient { } int responseCode = con.getResponseCode(); - logger.debug("get: received response code '" + responseCode + "' while getting the '" + url + "' for user: " - + loginId); + logger.debug("X-LatestVersion--------------:" + con.getHeaderFields().get("X-LatestVersion")); + logger.debug("X-PatchVersion----------------:" + con.getHeaderFields().get("X-PatchVersion")); + logger.debug("X-MinorVersion-----------------:" + con.getHeaderFields().get("X-MinorVersion")); final String response = readAndCloseStream(con.getInputStream()); if (logger.isDebugEnabled()) diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiConstants.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiConstants.java index 8964dabd..796f99d3 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiConstants.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiConstants.java @@ -38,7 +38,7 @@ package org.onap.portalsdk.core.onboarding.util; public interface PortalApiConstants { - public static final String API_PREFIX = "/api/v2"; + public static final String API_PREFIX = "/api/v3"; public static final String PORTAL_JSESSION_ID = "PORTAL_JSESSION_ID"; public static final String PORTAL_JSESSION_BIND = "PORTAL_JSESSION_BIND"; public static final String ACTIVE_USERS_NAME = "activeUsers"; |