Skip to content

Commit

Permalink
NPO - documentation - swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-stastny committed Oct 2, 2024
1 parent 38eed91 commit c77d7da
Show file tree
Hide file tree
Showing 26 changed files with 350 additions and 451 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=cz.incad.kramerius
version=7.0.37
version=7.0.38-dev
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ protected void configureServlets() {
bind(cz.incad.kramerius.rest.apiNew.client.v70.pdf.PDFResource.class);
bind(cz.incad.kramerius.rest.apiNew.client.v70.pdf.AsyncPDFResource.class);
bind(cz.incad.kramerius.rest.apiNew.client.v70.LocksResource.class);
bind(cz.incad.kramerius.rest.apiNew.client.v70.res.EmbeddedFilesResource.class);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ public class ItemsResource extends AdminApiResource {
private static final Integer DEFAULT_OFFSET = 0;
private static final Integer DEFAULT_LIMIT = 10;

//TODO: prejmenovat role podle spravy uctu

/*
private static final String ROLE_READ_ITEMS = "kramerius_admin";
private static final String ROLE_READ_FOXML = "kramerius_admin";
private static final String ROLE_EDIT_OBJECTS = "kramerius_admin";
private static final String ROLE_DELETE_OBJECTS = "kramerius_admin";
*/


@javax.inject.Inject
Provider<User> userProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class IndexReflectionResource extends AdminApiResource {
@Inject
Provider<User> userProvider;



@GET
@Path("/search/schema")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (C) Sep 28, 2024 Pavel Stastny
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.incad.kramerius.rest.apiNew.client.v70.res;

import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.commons.io.IOUtils;

@Path("/client/v7.0/embedded/files")
public class EmbeddedFilesResource {

public static final String OPENAPI_PREFIX = "openapi";

private static final Map<String, String> mimeTypeMap = new HashMap<>();

static {
mimeTypeMap.put("js", "application/javascript");
mimeTypeMap.put("html", "text/html");
mimeTypeMap.put("map", "application/json");
mimeTypeMap.put("css", "text/css");
mimeTypeMap.put("png", "image/png");
mimeTypeMap.put("yaml", "application/x-yaml");
mimeTypeMap.put("yml", "application/x-yaml");
mimeTypeMap.put("openapi", "application/vnd.oai.openapi");
}

@GET
@Path("/{path: (.+)?}")
@Produces(MediaType.APPLICATION_JSON)
public Response getEmbbededFile(@PathParam("path") String path) {
try {
URL resource = this.getClass().getClassLoader().getResource("/"+OPENAPI_PREFIX + File.separator + path);
if (resource != null) {
String content = IOUtils.toString(resource.openStream(), "UTF-8");
String file = resource.getFile();
if (file.contains(".")) {
String postfix = file.substring(file.lastIndexOf('.')+1);
if (mimeTypeMap.containsKey(postfix)) {
return Response.ok().entity(content).type(mimeTypeMap.get(postfix)+ "; charset=UTF-8").build();
} else {
return Response.ok().entity(content).type("text/html; charset=UTF-8").build();
}
} else {
return Response.ok().entity(content).type("text/html; charset=UTF-8").build();
}
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}

}
354 changes: 0 additions & 354 deletions rest/src/main/java/cz/incad/kramerius/rest/oai/MetadataExport.java.bak

This file was deleted.

86 changes: 0 additions & 86 deletions search/docs/mods.xml

This file was deleted.

Binary file added search/web/openapi/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added search/web/openapi/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions search/web/openapi/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
background: #fafafa;
}
110 changes: 110 additions & 0 deletions search/web/openapi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
/* Styl pro vlastní tlačítka */
.custom-auth-buttons {
position: absolute;
top: 180px;
left: 30px;
}
.custom-auth-buttons button {
margin-left: 5px;
padding: 5px 10px;
}
</style>
</head>

<body>

<div class="custom-auth-buttons">
<button id="login-button" onclick="login()">Login</button>
<button id="logout-button">Logout</button>
</div>

<div id="swagger-ui"></div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>

<script>

var TOKEN = null;

function login() {
const redirectUri = window.location.origin + '/search/openapi/index.html';
const authorizationUrl = `../api/client/v7.0/user/auth/login?redirect_uri=${encodeURIComponent(redirectUri)}`;
window.location.href = authorizationUrl;
}

function logout() {
const redirectUri = window.location.origin + '/search/openapi/index.html';
const authorizationUrl = `../api/client/v7.0/user/auth/logout?redirect_uri=${encodeURIComponent(redirectUri)}`;
window.location.href = authorizationUrl;
}

const currentUrl = window.location.origin;
window.onload = function() {
const ui = SwaggerUIBundle({
url: "../api/client/v7.0/embedded/files/openapi.yaml",
dom_id: '#swagger-ui',
deepLinking: true,
defaultModelsExpandDepth: -1,
validatorUrl : null,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],

requestInterceptor: (request) => {
if (TOKEN && TOKEN["access_token"]) {
request.headers['Authorization'] = `Bearer ${TOKEN["access_token"]}`;
}
return request;
},

layout: "StandaloneLayout"
});
window.ui = ui;

setTimeout(function() {
const url = new URL(window.location.href);
const code = url.searchParams.get('code');
const tokenSet = url.searchParams.get('tokenSet');
if (code && !tokenSet) {
const redirectUri = window.location.origin + '/search/openapi/index.html';
const encodedRedirectUri = encodeURIComponent(redirectUri);
const tokenUrl = window.location.origin + `/search/api/client/v7.0/user/auth/token?code=${encodeURIComponent(code)}&redirect_uri=${encodedRedirectUri}`;

$.get(tokenUrl)
.done(function(response) {

if (response.error) {
logout();
} else {
TOKEN = response;
}
}).fail(function(jqXHR, textStatus, errorThrown) {
logout();
console.error('Error fetching token:', textStatus, errorThrown);
});
}
},1000);

};
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions search/web/openapi/oauth2-redirect-kram.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="UTF-8">
<title>OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
// Tento skript umožňuje Swagger UI správně zpracovat OAuth2 redirect
function run() {
const params = window.location.hash.substring(1);
const query = {};
params.split('&').forEach(pair => {
const [key, value] = pair.split('=');
query[key] = decodeURIComponent(value);
});
window.opener.swaggerUIRedirectOauth2 && window.opener.swaggerUIRedirectOauth2(query);
window.close();
}

run();
</script>
</body>
</html>
Loading

0 comments on commit c77d7da

Please sign in to comment.