Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homepage and Authorization #44

Merged
merged 11 commits into from
Feb 29, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.sjsu.wildfirestorage;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientException;
import picocli.CommandLine;

import java.nio.file.Files;
Expand All @@ -23,45 +25,56 @@ static class Cli {
public void datasetInfo(@CommandLine.Parameters(paramLabel = "fileName") String fileName, @CommandLine.Parameters(paramLabel = "hostname") String hostname) throws InterruptedException {
System.out.println("GET returned: " + Client.get(Client.getWebClient(hostname + "/api/metadata"),
new LinkedMultiValueMap<String, String>(Map.of("filename", List.of(fileName))),
new ParameterizedTypeReference<ArrayList<Metadata>>(){}));
new ParameterizedTypeReference<ArrayList<Metadata>>() {
}));
}

@CommandLine.Command
public void share(@CommandLine.Option(description = "Absolute file name", names = "--file", required = true) String fileName,
@CommandLine.Parameters(paramLabel = "hostname") String hostname,
@CommandLine.Option(names = "--token") String token) throws InterruptedException, ExecutionException {
System.out.println("POST returned: " + Client.post(Client.getWebClient(hostname + "/api/share-link/create"),
fileName.replace("\"", ""),
new ParameterizedTypeReference<String>(){}, httpHeaders -> {
httpHeaders.setBearerAuth(token);
}));
public void share(@CommandLine.Option(names = "--meta-url", description = "URL of metadata server", defaultValue = "http://127.0.0.1:27777") String metaURL,
@CommandLine.Parameters(description = "Absolute file name", index = "0..*") String[] fileNames,
@CommandLine.Option(names = "--token", required = true) String token) throws InterruptedException, ExecutionException {
for (var fileName : fileNames) {
try {
System.out.println(Client.post(Client.getWebClient(metaURL + "/api/share-link/create"),
fileName,
new ParameterizedTypeReference<String>() {
}, httpHeaders -> {
httpHeaders.setBearerAuth(token);
}));
} catch (ExecutionException e) {
var message = e.getMessage();
// if this is a message about a connection problem, drop all the text before connection
if (message.contains("Connection")) message = message.substring(message.indexOf("Connection"));
System.err.printf("%s: %s\n", message, fileName);
}
}
}

@CommandLine.Command
public void search(@CommandLine.Parameters(paramLabel = "query") String query, @CommandLine.Parameters(paramLabel = "hostname") String hostname,
@CommandLine.Parameters(paramLabel = "<option>", defaultValue = "all", description = "Which information to print - 'all' or 'basic'") String option,
@CommandLine.Option(names="--limit", defaultValue = "10") int limit,
@CommandLine.Option(names = "--limit", defaultValue = "10") int limit,
@CommandLine.Option(names = "--offset", defaultValue = "0") int offset,
@CommandLine.Option(names = "--token") String token) throws InterruptedException, ExecutionException {

MetadataRequest metadataRequest = new MetadataRequest();
metadataRequest.searchQuery = query;
metadataRequest.limit = limit;
metadataRequest.offset = offset;
metadataRequest.excludeFields = new String[] {"globalAttributes", "variables"};
metadataRequest.excludeFields = new String[]{"globalAttributes", "variables"};
WebClient webClient = Client.getWebClient(hostname + "/api/metadata/search?excludeFields=globalAttributes,variables");
var res = (ArrayList<Metadata>)(Client.post(webClient, metadataRequest, new ParameterizedTypeReference<ArrayList<Metadata>>(){}, httpHeaders -> {
var res = (ArrayList<Metadata>) (Client.post(webClient, metadataRequest, new ParameterizedTypeReference<ArrayList<Metadata>>() {
}, httpHeaders -> {
httpHeaders.setBearerAuth(token);
}));
System.out.println("SEARCH returned: " + res.size() + " results");
if (option.equals("all")) {
for (Metadata m: res) {
for (Metadata m : res) {
System.out.println("========================================================================");
PrintData.printAllData(m);
}
}
else {
for (Metadata m: res){
} else {
for (Metadata m : res) {
System.out.println("========================================================================");
PrintData.printBasic(m);
}
Expand All @@ -77,18 +90,20 @@ public void clean(@CommandLine.Parameters(paramLabel = "limit") int limit,
LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
parameters.add("limit", String.valueOf(limit));
List<String> result;
int i=0;
int i = 0;
WebClient webClient = Client.getWebClient(hostname + "/api/metadata/filepath");

do {
parameters.put("offset", List.of(String.valueOf(offset)));
result = (List<String>) Client.get(webClient,
parameters,
new ParameterizedTypeReference<List<String>>() {});
new ParameterizedTypeReference<List<String>>() {
});
System.out.println("The following Metadata documents will be removed from the database:");
result.forEach(str -> System.out.println(str));
List<String> deletedFiles = result.stream().filter(item -> !Files.exists(Paths.get(item))).toList();
System.out.println("DELETE RESULT:" + Client.post(webClient, deletedFiles, new ParameterizedTypeReference<Integer>() {}, httpHeaders -> {
System.out.println("DELETE RESULT:" + Client.post(webClient, deletedFiles, new ParameterizedTypeReference<Integer>() {
}, httpHeaders -> {
httpHeaders.setBearerAuth(token);
}));
offset += limit;
Expand Down
42 changes: 42 additions & 0 deletions wildfirestorage-spring/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wildfirestorage-spring/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
},
"devDependencies": {
"daisyui": "^3.9.3",
"react-router-dom": "^6.22.1",
"tailwindcss": "^3.3.3"
}
}
56 changes: 38 additions & 18 deletions wildfirestorage-spring/app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
import './App.css';
import SideBar from './components/sidebar/sidebar';
import MapContainer from './components/map-container/mapContainer';
import Navbar from './components/navbar/navbar';
import Workspace from './components/workspace/workspace';
import Home from './components/home/home';
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Landing from './components/landing/landing';
import Token from './components/token/token';
import Forbidden from './components/forbidden/forbidden';
import { useDispatch } from 'react-redux';
import { setOpaqueToken } from './redux/userSlice';
import { useEffect } from 'react';

function App() {
const dispatch = useDispatch();

const getToken = async () => {
const response = await fetch("/api/oauth/token", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "text/plain, application/json",
},
credentials: "include",
redirect: "follow",
});
if (response.redirected) {
document.location = response.url;
}
let d = await response.text();
dispatch(setOpaqueToken(d));
console.log("tokennnn", d)
}
useEffect(() => {
getToken();
}, [])

return (
<div className='flex flex-col w-screen h-screen absolute'>
<Navbar />
<div className='flex-1 grid grid-cols-[100px_repeat(12,_minmax(0,_1fr))]'>
<div id="sidebar" className='basis-20 text-white bg-primary shadow-lg shadow-primary'>
<SideBar />
</div>
<div id="workspace" className='col-span-4 shadow-lg' style={{"height": `calc(100vh - 4rem)`, "overflowY": "scroll"}}>
<Workspace />
</div>
<div id="map" className='col-span-8'>
<MapContainer style={{"height": `calc(100vh - 4rem)`}}/>
</div>
</div>
</div>
<BrowserRouter>
<Routes>
<Route path="/" element={<Landing />} />
<Route path="/home" element={<Home />} />
<Route path="/token" element={<Token />} />
<Route path="/forbidden" element={<Forbidden />} />
</Routes>
</BrowserRouter>
)
}

Expand Down
12 changes: 12 additions & 0 deletions wildfirestorage-spring/app/src/components/forbidden/forbidden.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Forbidden = () => {
return (
<div className="flex place-content-center">
<div className="h-screen flex flex-col place-content-center w-9/12">
<h1 className="h-40 flex flex-col justify-center text-center text-5xl font-bold">Uh oh! Looks like you do not have access to use this feature :( </h1>
<h1 className="h-40 flex flex-col justify-center text-center text-xl">Please contact the admin if you think this is incorrect! </h1>
</div>
</div>
);
}

export default Forbidden;
25 changes: 25 additions & 0 deletions wildfirestorage-spring/app/src/components/home/home.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import SideBar from '../sidebar/sidebar';
import MapContainer from '../map-container/mapContainer';
import Workspace from '../workspace/workspace';
import Navbar from '../navbar/navbar';

const Home = () => {
return (
<div className='flex flex-col w-screen h-screen absolute'>
<Navbar />
<div className='flex-1 grid grid-cols-[100px_repeat(12,_minmax(0,_1fr))]'>
<div id="sidebar" className='basis-20 text-white bg-primary shadow-lg shadow-primary'>
<SideBar />
</div>
<div id="workspace" className='col-span-4 shadow-lg' style={{ "height": `calc(100vh - 4rem)`, "overflowY": "scroll" }}>
<Workspace />
</div>
<div id="map" className='col-span-8'>
<MapContainer style={{ "height": `calc(100vh - 4rem)` }} />
</div>
</div>
</div>
);
}

export default Home;
44 changes: 44 additions & 0 deletions wildfirestorage-spring/app/src/components/landing/landing.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Link, useNavigate } from "react-router-dom";

const Landing = () => {
const navigate = useNavigate();

const goToSearch = async () => {
const response = await fetch("/api/oauth/checkAccess", {
method: "GET",
headers: {
"Content-Type": "application/json",
"Accept": "text/plain, application/json",
},
credentials: "include",
redirect: "follow",
});
if (response.redirected) {
document.location = response.url;
} else if (response.status === 403) {
navigate("/forbidden");
} else {
navigate("/home");
}
}

return (
<div className="flex place-content-center">
<div className="h-screen flex flex-col place-content-center w-9/12">
<h1 className="h-40 flex flex-col justify-center text-center text-5xl font-bold">Hello! What would you like to do?</h1>
<div className="h-40 flex justify-center">
<div className="flex items-center w-4/6">
<div className="grid h-20 w-40 flex-grow btn btn-outline rounded-box place-items-center"><span className="font-normal text-lg"><Link to="/token">Generate Token</Link></span></div>
<div className="divider divider-horizontal"></div>
<div className="grid h-20 w-40 flex-grow btn btn-outline rounded-box place-items-center"><a className="font-normal text-lg" onClick={goToSearch}>Search</a></div>
</div>
</div>
<div className="h-40 p-8 flex flex-col justify-center">
<button className="btn flex-none self-center"><a href="/logout">Logout</a></button>
</div>
</div>
</div>
);
}

export default Landing;
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ const MapContainer = () => {
map.data.remove(feature);
})
for (let record of metadataRecords) {
let geoJsonFeature = feature(record.location);
geoJsonFeature.properties = { "id": record.digestString }
map.data.addGeoJson(geoJsonFeature);
map.data.addGeoJson(centroid(record.location));
if(record.location) {
let geoJsonFeature = feature(record.location);
geoJsonFeature.properties = { "id": record.digestString }
map.data.addGeoJson(geoJsonFeature);
map.data.addGeoJson(centroid(record.location));
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions wildfirestorage-spring/app/src/components/token/token.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { GoCopy } from 'react-icons/go';
import { useSelector } from 'react-redux';

const Token = () => {

const token = useSelector(state => state.userReducer.opaqueToken)


const copyToClipboard = (event) => {
navigator.clipboard.writeText(token);
}

return (
<div className="flex place-content-center">
<div className="h-screen flex flex-col place-content-center w-9/12">
<h1 className="h-40 flex flex-col justify-center text-center text-5xl font-normal">Your token is </h1>
<div className="flex flex-row px-6 justify-between h-20 card bg-base-300 rounded-box place-items-center text-3xl font-bold">
<div>{token}</div>
<div>
<div className="tooltip focus:tooltip-open" data-tip="Copy">
<button className="btn btn-square btn-outline" onClick={copyToClipboard}>
<GoCopy size="28" />
</button>
</div>
</div>
</div>
</div>
</div>
)
}

export default Token;
Loading
Loading