Skip to content

Commit

Permalink
#550 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Possommi committed Jun 12, 2024
1 parent fd9740a commit 777d686
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 1 deletion.
20 changes: 20 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
<name>ThUniBib Common Files</name>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
Expand All @@ -20,6 +32,14 @@
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-sse</artifactId>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
Expand Down
50 changes: 50 additions & 0 deletions common/src/main/java/de/uni_jena/thunibib/his/Token.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.uni_jena.thunibib.his;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Token {

String access_token;
String scope;
String token_type;
String expires_in;

public Token() {
}

@JsonProperty("access_token")
public String getAccessToken() {
return access_token;
}

public void setAccessToken(String access_token) {
this.access_token = access_token;
}

@JsonProperty("scope")
public String getScope() {
return scope;
}

public void setScope(String scope) {
this.scope = scope;
}

@JsonProperty("expires_in")
public String getExpiresIn() {
return expires_in;
}

public void setExpiresIn(String expires_in) {
this.expires_in = expires_in;
}

@JsonProperty("token_type")
public String getTokenType() {
return token_type;
}

public void setTokenType(String token_type) {
this.token_type = token_type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class PublicationHisResTransformer extends MCRToJSONTransformer {
private static final Logger LOGGER = LogManager.getLogger(PublicationHisResTransformer.class);

static final String HIS_IN_ONE_BASE_URL = MCRConfiguration2.getStringOrThrow("ThUniBib.HISinOne.BaseURL");
public static final String HIS_IN_ONE_BASE_URL = MCRConfiguration2.getStringOrThrow("ThUniBib.HISinOne.BaseURL");

protected JsonObject toJSON(MCRContent source) throws IOException {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
package de.uni_jena.thunibib.his.xml;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import de.uni_jena.thunibib.his.Token;
import de.uni_jena.thunibib.his.content.transformer.PublicationHisResTransformer;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.client.WebTarget;
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.glassfish.jersey.client.ClientConfig;
import org.jdom2.Element;
import org.jdom2.transform.JDOMSource;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.common.xml.MCRFunctionResolver;

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class HISinOneResolver implements URIResolver {
public enum URI_PART {
Expand All @@ -34,6 +49,25 @@ public Source resolve(String href, String base) throws TransformerException {
}

private int resolveLanguage(String rfc5646) {
try (Client client = ClientBuilder.newClient(new ClientConfig().register(HISinOneResolver.class))) {
String clientKeySecret = MCRConfiguration2.getStringOrThrow("ThUniBib.HISinOne.ClientKey") + ":"
+ MCRConfiguration2.getStringOrThrow("ThUniBib.HISinOne.ClientSecret");

WebTarget webTarget = client
.target(PublicationHisResTransformer.HIS_IN_ONE_BASE_URL + "api/v1/")
.path("cs/psv/oauth/token");

Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
invocationBuilder.header("Authorization",
"Basic " + Base64.getEncoder().encodeToString(clientKeySecret.getBytes(StandardCharsets.UTF_8)));
Entity<String> body = Entity.entity("grant_type=client_credentials", MediaType.APPLICATION_FORM_URLENCODED);

try (Response response = invocationBuilder.post(body)) {
Token token = response.readEntity(Token.class);
LOGGER.info(token);
}
}

return 42;
}
}
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
<inceptionYear>2019</inceptionYear>

<properties>
<jackson.version>2.17.1</jackson.version>
<jakarta.servlet-api.version>6.0.0</jakarta.servlet-api.version>
<jdom.version>2.0.6.1</jdom.version>
<jersey.client.version>3.1.3</jersey.client.version>
<mycore.version>2022.06.3-SNAPSHOT</mycore.version>
<oaipmh.version>2.1</oaipmh.version>
<solr.version>8.11.3</solr.version>
Expand Down Expand Up @@ -95,6 +97,21 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>de.uni-jena.thulb.ubo</groupId>
<artifactId>thunibib-common</artifactId>
Expand All @@ -110,6 +127,16 @@
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.client.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-sse</artifactId>
<version>${jersey.client.version}</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
Expand Down Expand Up @@ -151,6 +178,7 @@
<version>${ubo.version}</version>
</dependency>
</dependencies>

</dependencyManagement>
<modules>
<module>common</module>
Expand Down

0 comments on commit 777d686

Please sign in to comment.