Skip to content

Commit 54eb134

Browse files
rahulvudutalaSanjeevani19
authored andcommitted
DHFPROD-10455: Consume basepath in HC UI and navigate
1 parent 03e6bab commit 54eb134

File tree

5 files changed

+21
-41
lines changed

5 files changed

+21
-41
lines changed

marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/controllers/SinglePageAppController.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import javax.servlet.http.HttpServletRequest;
1515
import javax.servlet.http.HttpServletResponse;
1616
import java.util.Collections;
17-
import java.util.HashMap;
1817
import java.util.Map;
1918
import java.util.stream.Collectors;
2019

@@ -42,7 +41,6 @@ public String index(HttpServletRequest httpServletRequest, HttpServletResponse h
4241
if(environment.getProperty("mlAuthentication").equalsIgnoreCase("cloud")) {
4342
Map<String, String> headers = Collections.list(httpServletRequest.getHeaderNames()).stream()
4443
.collect(Collectors.toMap(h -> h, httpServletRequest::getHeader));
45-
logger.info("Headers Map: " + headers);
4644
CloudParameters.updateCloudParameters(headers);
4745
createHubConfigurations(headers.getOrDefault("mlCloudApiKey".toLowerCase(), ""));
4846
addCookiesToResponse(httpServletResponse);
@@ -56,28 +54,6 @@ private void createHubConfigurations(String cloudApikey) {
5654
hubClientProvider.setHubClientDelegate(hubClientConfig.newHubClient());
5755
}
5856

59-
private Map<String, String> getHeadersMap(HttpServletRequest httpServletRequest) {
60-
Map<String, String> headers = Collections.list(httpServletRequest.getHeaderNames()).stream()
61-
.collect(Collectors.toMap(h -> h, httpServletRequest::getHeader));
62-
// These values are for testing
63-
addHeadersFromCloudForTesting(headers);
64-
return headers;
65-
}
66-
67-
private void addHeadersFromCloudForTesting(Map<String, String> headers) {
68-
headers.put("mlCloudApiKey", "hub-developer:password");
69-
headers.put("mlHost", "localhost");
70-
headers.put("mlAuthentication", "cloud");
71-
headers.put("mlManageAuthentication", "cloud");
72-
headers.put("mlHcBasePath", "/hc");
73-
headers.put("mlStagingBasePath", "/data-hub/staging");
74-
headers.put("mlFinalBasePath", "/data-hub/final");
75-
headers.put("mlJobBasePath", "/data-hub/jobs");
76-
headers.put("mlManageBasePath", "/local/manage");
77-
headers.put("mlAppServicesBasePath", "/local/app-services");
78-
headers.put("mlAdminBasePath", "/local/admin");
79-
}
80-
8157
private void addCookiesToResponse(HttpServletResponse response) {
8258
response.addCookie(new Cookie("mlHcBasePath", CloudParameters.HC_BASE_PATH));
8359
response.addCookie(new Cookie("mlAuthentication", CloudParameters.AUTHENTICATION_TYPE));

marklogic-data-hub-central/ui/e2e/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6+
"homepage": "./",
67
"scripts": {
78
"test": "echo \"Error: no test specified\" && exit 1",
89
"cy:open": "cypress open",

marklogic-data-hub-central/ui/src/App.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect, useContext} from "react";
1+
import React, {useEffect, useContext, useState} from "react";
22
import axios from "@config/axios";
33
import {Switch} from "react-router";
44
import {Route, Redirect, RouteComponentProps, withRouter} from "react-router-dom";
@@ -29,6 +29,7 @@ interface Props extends RouteComponentProps<any> {}
2929

3030
const App: React.FC<Props> = ({history, location}) => {
3131
const {user, handleError} = useContext(UserContext);
32+
const [loginPath, setLoginPath] = useState("/");
3233

3334
const PrivateRoute = ({children, ...rest}) => (
3435
<Route
@@ -97,6 +98,20 @@ const App: React.FC<Props> = ({history, location}) => {
9798
}
9899
}, [location.pathname]);
99100

101+
useEffect(() => {
102+
let mlAuthenticationFlag = document.cookie.split("; ").filter(row => row.startsWith("mlAuthentication=")).map(c => c.split("=")[1])[0];
103+
let basePathURL = document.cookie.split("; ").filter(row => row.startsWith("mlHcBasePath=")).map(c => c.split("=")[1])[0];
104+
if (basePathURL) {
105+
window.localStorage.setItem("dataHubBasePath", basePathURL);
106+
setLoginPath(basePathURL);
107+
} else {
108+
window.localStorage.setItem("dataHubBasePath", "");
109+
}
110+
if (mlAuthenticationFlag && mlAuthenticationFlag === "cloud") {
111+
window.localStorage.setItem("dataHubEnvironmentSettings", mlAuthenticationFlag);
112+
}
113+
}, []);
114+
100115
const path = location["pathname"];
101116
const pageTheme = themeMap[path] ? themes[themeMap[path]] : themes["default"];
102117
document.body.classList.add(pageTheme["bodyBg"]);
@@ -119,7 +134,7 @@ const App: React.FC<Props> = ({history, location}) => {
119134
<ErrorBoundary>
120135
<div className="contentContainer">
121136
<Switch>
122-
<Route path="/" exact component={Login} />
137+
<Route path={loginPath} exact component={Login} />
123138
<Route path="/noresponse" exact component={NoResponse} />
124139
<PrivateRoute path="/tiles" exact>
125140
<TilesView />

marklogic-data-hub-central/ui/src/components/login-form/login-form.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,9 @@ const LoginForm: React.FC = () => {
1818
const formRef = useRef<any>();
1919

2020
useEffect(() => {
21-
let mlAuthenticationFlag = document.cookie.split("; ").filter(row => row.startsWith("mlAuthentication=")).map(c => c.split("=")[1])[0];
22-
let basePathURL = document.cookie.split("; ").filter(row => row.startsWith("mlHcBasePath=")).map(c => c.split("=")[1])[0];
23-
if (basePathURL) {
24-
window.localStorage.setItem("dataHubBasePath", basePathURL);
25-
} else {
26-
window.localStorage.setItem("dataHubBasePath", "");
27-
}
28-
if (mlAuthenticationFlag && mlAuthenticationFlag === "cloud") {
29-
window.localStorage.setItem("dataHubEnvironmentSettings", mlAuthenticationFlag);
30-
31-
//automatically submit empty username and password if environment is cloud
32-
if (formRef && formRef.current) {
33-
formRef.current.dispatchEvent(new Event("submit", {cancelable: true}));
34-
}
21+
//automatically submit empty username and password if environment is cloud
22+
if (window.localStorage.getItem("dataHubEnvironmentSettings") === "cloud" && formRef && formRef.current) {
23+
formRef.current.dispatchEvent(new Event("submit", {cancelable: true}));
3524
} else {
3625
window.localStorage.setItem("dataHubEnvironmentSettings", "");
3726
}

marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/ConfigureAppServerBasePaths.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ private String getAccessToken() {
8181
byte[] returnedData = IOUtils.toByteArray(entity.getContent());
8282

8383
JsonNode tokenMap = mapper.readTree(returnedData);
84-
logger.info("Access Token Map: " + tokenMap);
8584
return tokenMap.get("access_token").asText();
8685
}
8786
} catch (IOException e) {

0 commit comments

Comments
 (0)