Changes on reviews

try_it
Thashmi-nil 2 years ago
parent 0f6db69c18
commit 2d1879d1b6

@ -92,12 +92,14 @@ public class MetadataManagementServiceImpl implements MetadataManagementService
} }
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
int tenantId;
if (metaKey.equals("EVALUATE_TENANTS")){ if (metaKey.equals("EVALUATE_TENANTS")){
return metadataDAO.getMetadata(MultitenantConstants.SUPER_TENANT_ID, metaKey); // for getting evaluate tenant list to provide the live chat feature
tenantId = MultitenantConstants.SUPER_TENANT_ID;
} else { } else {
return metadataDAO.getMetadata( tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true), metaKey);
} }
return metadataDAO.getMetadata(tenantId, metaKey);
} catch (MetadataManagementDAOException e) { } catch (MetadataManagementDAOException e) {
String msg = "Error occurred while retrieving the metadata entry for metaKey:" + metaKey; String msg = "Error occurred while retrieving the metadata entry for metaKey:" + metaKey;
log.error(msg, e); log.error(msg, e);

@ -1,3 +1,21 @@
/*
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you 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.
*/
package io.entgra.ui.request.interceptor; package io.entgra.ui.request.interceptor;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -51,12 +69,10 @@ public class HubspotHandler extends HttpServlet {
} catch (IOException e) { } catch (IOException e) {
log.error("Error occurred when processing POST request.", e); log.error("Error occurred when processing POST request.", e);
} }
} }
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) { protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
try { try {
if (validateRequest(req, resp)) { if (validateRequest(req, resp)) {
HttpGet getRequest = new HttpGet(HandlerUtil.generateBackendRequestURL(req,hubspotEndpoint)); HttpGet getRequest = new HttpGet(HandlerUtil.generateBackendRequestURL(req,hubspotEndpoint));
@ -80,29 +96,25 @@ public class HubspotHandler extends HttpServlet {
*/ */
private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) private boolean validateRequest(HttpServletRequest req, HttpServletResponse resp)
throws IOException { throws IOException {
if (httpSession == null) {
httpSession = req.getSession(false); log.error("Unauthorized, You are not logged in. Please log in to the portal");
gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR) HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED);
+ HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme()); return false;
iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR) }
+ HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme()); if (req.getMethod() == null) {
String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT; log.error("Bad Request, Request method is empty");
uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp); HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST);
chatConfig = uiConfigJsonObject.get("chatConfig").getAsString(); return false;
hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL; }
httpSession = req.getSession(false);
if (httpSession == null) { gatewayUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR)
log.error("Unauthorized, You are not logged in. Please log in to the portal"); + HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme());
HandlerUtil.handleError(resp, HttpStatus.SC_UNAUTHORIZED); iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_CORE_HOST_ENV_VAR)
return false; + HandlerConstants.COLON + HandlerUtil.getCorePort(req.getScheme());
} String uiConfigUrl = iotsCoreUrl + HandlerConstants.UI_CONFIG_ENDPOINT;
uiConfigJsonObject = HandlerUtil.getUIConfigAndPersistInSession(uiConfigUrl, gatewayUrl, httpSession, resp);
if (req.getMethod() == null) { chatConfig = uiConfigJsonObject.get("chatConfig").getAsString();
log.error("Bad Request, Request method is empty"); hubspotEndpoint = HandlerConstants.HTTPS_PROTOCOL + HandlerConstants.SCHEME_SEPARATOR + HandlerConstants.HUBSPOT_CHAT_URL;
HandlerUtil.handleError(resp, HttpStatus.SC_BAD_REQUEST); return true;
return false;
}
return true;
} }
} }

@ -24,6 +24,7 @@
<SessionTimeOut>3600</SessionTimeOut> <SessionTimeOut>3600</SessionTimeOut>
<!-- maximum number of login cache entries --> <!-- maximum number of login cache entries -->
<LoginCacheCapacity>10000</LoginCacheCapacity> <LoginCacheCapacity>10000</LoginCacheCapacity>
<!-- access token for hubspot live chat feature - whenever the access token will be rotated, needs to be changed this with the new token -->
<ChatConfig>pat-na1-33bc59e0-3526-45b0-b9cf-f353d0ae0ced</ChatConfig> <ChatConfig>pat-na1-33bc59e0-3526-45b0-b9cf-f353d0ae0ced</ChatConfig>
<Billing> <Billing>
<HideBillGenerationInSuperTenant>false</HideBillGenerationInSuperTenant> <HideBillGenerationInSuperTenant>false</HideBillGenerationInSuperTenant>

Loading…
Cancel
Save