diff --git a/common/src/main/java/de/uni_jena/thunibib/his/api/client/HISInOneClient.java b/common/src/main/java/de/uni_jena/thunibib/his/api/client/HISInOneClient.java index dab1a03e6..c27232765 100644 --- a/common/src/main/java/de/uni_jena/thunibib/his/api/client/HISInOneClient.java +++ b/common/src/main/java/de/uni_jena/thunibib/his/api/client/HISInOneClient.java @@ -15,11 +15,21 @@ enum AuthType { Basic, Bearer } - Response get(String path, Map params); + default Response get(String path) { + return get(path, false); + } - Response get(String path); + default Response get(String path, Map params) { + return get(path, params, false); + } - Response put(String path, String body); + default Response get(String path, boolean omitToken){ + return get(path, null, omitToken); + } + + Response get(String path, Map params, boolean omitToken); Response post(String path, String body); + + Response put(String path, String body); } diff --git a/common/src/main/java/de/uni_jena/thunibib/his/api/client/HISInOneClientDefaultImpl.java b/common/src/main/java/de/uni_jena/thunibib/his/api/client/HISInOneClientDefaultImpl.java index a89cd26c9..d19918986 100644 --- a/common/src/main/java/de/uni_jena/thunibib/his/api/client/HISInOneClientDefaultImpl.java +++ b/common/src/main/java/de/uni_jena/thunibib/his/api/client/HISInOneClientDefaultImpl.java @@ -34,7 +34,8 @@ class HISInOneClientDefaultImpl implements HISInOneClient { MCRShutdownHandler.getInstance().addCloseable(this); } - public Response get(String path, Map parameters) { + @Override + public Response get(String path, Map parameters, boolean omitToken) { WebTarget webTarget = getJerseyClient() .target(HISInOneClientDefaultImpl.HIS_IN_ONE_BASE_URL + API_PATH); @@ -46,21 +47,27 @@ public Response get(String path, Map parameters) { webTarget = webTarget.path(path); - Token token; - try { - token = fetchToken(); - } catch (Exception e) { - LOGGER.error("Could not fetch token", e); - return Response.serverError().entity(e.getMessage()).build(); + Token token = null; + if (!omitToken) { + try { + token = fetchToken(); + } catch (Exception e) { + LOGGER.error("Could not fetch token", e); + return Response.serverError().entity(e.getMessage()).build(); + } } Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); - invocationBuilder.header("Authorization", getAuthorizationHeaderValue(AuthType.Bearer, token.getAccessToken())); + if (token != null) { + invocationBuilder.header("Authorization", + getAuthorizationHeaderValue(AuthType.Bearer, token.getAccessToken())); + } Response response = invocationBuilder.get(); return response; } + @Override public Response post(String path, String bodySource) { WebTarget webTarget = getJerseyClient() .target(HISInOneClientDefaultImpl.HIS_IN_ONE_BASE_URL + API_PATH) @@ -83,6 +90,7 @@ public Response post(String path, String bodySource) { return response; } + @Override public Response put(String path, String bodySource) { WebTarget webTarget = getJerseyClient() .target(HISInOneClientDefaultImpl.HIS_IN_ONE_BASE_URL + API_PATH) @@ -105,10 +113,6 @@ public Response put(String path, String bodySource) { return response; } - public Response get(String path) { - return get(path, null); - } - protected Token fetchToken() { WebTarget webTarget = getJerseyClient() .target(HISInOneClientDefaultImpl.HIS_IN_ONE_BASE_URL + API_PATH) diff --git a/common/src/main/java/de/uni_jena/thunibib/his/rsc/HISinOneProjectsResource.java b/common/src/main/java/de/uni_jena/thunibib/his/rsc/HISinOneProjectsResource.java new file mode 100644 index 000000000..47534df3e --- /dev/null +++ b/common/src/main/java/de/uni_jena/thunibib/his/rsc/HISinOneProjectsResource.java @@ -0,0 +1,48 @@ +package de.uni_jena.thunibib.his.rsc; + +import de.uni_jena.thunibib.his.api.client.HISInOneClient; +import de.uni_jena.thunibib.his.api.client.HISinOneClientFactory; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.mycore.frontend.jersey.access.MCRRequireLogin; +import org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess; + +import java.util.HashMap; + +@Path("/project") +public class HISinOneProjectsResource { + private static final Logger LOGGER = LogManager.getLogger(HISinOneProjectsResource.class); + + @GET + @MCRRestrictedAccess(MCRRequireLogin.class) + @Produces(MediaType.APPLICATION_JSON) + public Response searchProjects(@QueryParam("q") String q) { + HashMap p = new HashMap<>(); + p.put("q", q); + + try (HISInOneClient client = HISinOneClientFactory.create(); + Response resp = client.get("fs/res/project", p, true)) { + String json = resp.readEntity(String.class); + return Response.ok(json).build(); + } + } + + @GET + @MCRRestrictedAccess(MCRRequireLogin.class) + @Path("{projectId:.+}") + @Produces(MediaType.APPLICATION_JSON) + public Response getProject(@PathParam("projectId") String projectId) { + try (HISInOneClient client = HISinOneClientFactory.create(); + Response resp = client.get("fs/res/project/" + projectId, true)) { + String json = resp.readEntity(String.class); + return Response.ok(json).build(); + } + } +} diff --git a/common/src/main/resources/META-INF/resources/import-editor.xed b/common/src/main/resources/META-INF/resources/import-editor.xed index 5137a03bd..08a274fc2 100644 --- a/common/src/main/resources/META-INF/resources/import-editor.xed +++ b/common/src/main/resources/META-INF/resources/import-editor.xed @@ -997,6 +997,55 @@ + + +
+ + + +