Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Migrate to the new oslc4j-client #32

Merged
merged 5 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<lyo.version>${project.version}</lyo.version>
<jena.version>3.6.0</jena.version>

<version.lyo>${project.version}</version.lyo>
<version.jena>3.6.0</version.jena>
<version.jersey>2.25.1</version.jersey>
</properties>

<build>
Expand Down Expand Up @@ -53,31 +55,25 @@
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<!-- TODO move out -->
<groupId>com.j2bugzilla</groupId>
<artifactId>j2bugzilla</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<!-- TODO remove -->
<!-- TODO update to org.eclipse.rdf4j:rdf4j-repository-sparql:jar:2.5.1 -->
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-repository-sparql</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.lyo</groupId>
<artifactId>oslc-trs</artifactId>
<version>${lyo.version}</version>
<version>${version.lyo}</version>
</dependency>
<dependency>
<groupId>org.eclipse.lyo.oslc4j.core</groupId>
<artifactId>oslc4j-core</artifactId>
<version>${lyo.version}</version>
<version>${version.lyo}</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>${jena.version}</version>
<version>${version.jena}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -103,12 +99,11 @@

<dependency>
<groupId>org.eclipse.lyo.clients</groupId>
<artifactId>oslc-java-client</artifactId>
<version>${lyo.version}</version>
<artifactId>oslc4j-client</artifactId>
<version>${version.lyo}</version>
</dependency>

<!--TEST-->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -118,7 +113,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-tdb</artifactId>
<version>${jena.version}</version>
<version>${version.jena}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -127,7 +122,17 @@
<version>1.7.25</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${version.jersey}</version>
</dependency>
<dependency>
<groupId>com.j2bugzilla</groupId>
<artifactId>j2bugzilla</artifactId>
<version>2.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

package org.eclipse.lyo.oslc4j.trs.client.config;

import com.google.common.base.Strings;
import java.util.concurrent.ScheduledExecutorService;
import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
import javax.ws.rs.client.ClientBuilder;
import org.eclipse.lyo.oslc4j.client.OslcClient;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

/**
* Created on 2018-02-27
Expand All @@ -29,20 +32,24 @@ public class TrsConsumerConfiguration {
private final String sparqlUpdateUrl;
private final String sparqlUsername;
private final String sparqlPassword;
private final TrsBasicAuthOslcClient httpClient;
private final String mqttClientId;
private final ScheduledExecutorService scheduler;
private final String basicUsername;
private final String basicPassword;
private OslcClient httpClient;

public TrsConsumerConfiguration(final String sparqlQueryUrl, final String sparqlUpdateUrl,
final String sparqlUsername, final String sparqlPassword, final TrsBasicAuthOslcClient httpClient,
final String mqttClientId, final ScheduledExecutorService scheduler) {
final String sparqlUsername, final String sparqlPassword, final String mqttClientId,
final ScheduledExecutorService scheduler, final String basicUsername,
final String basicPassword) {
this.sparqlQueryUrl = sparqlQueryUrl;
this.sparqlUpdateUrl = sparqlUpdateUrl;
this.sparqlUsername = sparqlUsername;
this.sparqlPassword = sparqlPassword;
this.httpClient = httpClient;
this.mqttClientId = mqttClientId;
this.scheduler = scheduler;
this.basicUsername = basicUsername;
this.basicPassword = basicPassword;
}

public ScheduledExecutorService getScheduler() {
Expand All @@ -69,7 +76,14 @@ public String getSparqlPassword() {
return sparqlPassword;
}

public TrsBasicAuthOslcClient getHttpClient() {
public OslcClient getHttpClient() {
if (httpClient == null) {
final ClientBuilder builder = ClientBuilder.newBuilder();
if (!Strings.isNullOrEmpty(basicUsername)) {
builder.register(HttpAuthenticationFeature.basic(basicUsername, basicPassword));
}
new OslcClient(builder);
}
return httpClient;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.eclipse.lyo.oslc4j.trs.client.exceptions;

import org.apache.wink.client.ClientResponse;

/**
* TRS Client has a wrong configuration of a TRS Server endpoint.
Expand All @@ -25,10 +24,6 @@ public TrsEndpointConfigException(final Throwable cause) {
super(cause);
}

public TrsEndpointConfigException(final ClientResponse response) {
super(response);
}

protected TrsEndpointConfigException(final String message, final Throwable cause,
final boolean enableSuppression, final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.eclipse.lyo.oslc4j.trs.client.exceptions;

import org.apache.wink.client.ClientResponse;

/**
* TRS Server endpoint returns a server error.
Expand All @@ -25,10 +24,6 @@ public TrsEndpointErrorExpection(final Throwable cause) {
super(cause);
}

public TrsEndpointErrorExpection(final ClientResponse response) {
super(response);
}

protected TrsEndpointErrorExpection(final String message, final Throwable cause,
final boolean enableSuppression, final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.eclipse.lyo.oslc4j.trs.client.exceptions;

import org.apache.wink.client.ClientResponse;
import javax.xml.ws.Response;

/**
* High-level exception for connection problems to the TRS Server endpoints.
Expand All @@ -10,40 +10,25 @@
*/
public class TrsEndpointException extends Exception {

private final ClientResponse response;

public TrsEndpointException() {
super();
response = null;
}

public TrsEndpointException(final String message) {
super(message);
response = null;
}

public TrsEndpointException(final String message, final Throwable cause) {
super(message, cause);
response = null;
}

public TrsEndpointException(final Throwable cause) {
super(cause);
response = null;
}

public TrsEndpointException(final ClientResponse response) {
super();
this.response = response;
}

protected TrsEndpointException(final String message, final Throwable cause,
final boolean enableSuppression, final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
response = null;
}

public ClientResponse getResponse() {
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import net.oauth.OAuthException;
import org.apache.jena.rdf.model.Model;
import org.eclipse.lyo.oslc4j.client.OslcClient;
import org.eclipse.lyo.oslc4j.trs.client.util.SparqlUtil;
import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,7 +34,7 @@
*/
public class BaseMemberHandler extends TRSTaskHandler {

final static Logger logger = LoggerFactory.getLogger(BaseMemberHandler.class);
private final static Logger logger = LoggerFactory.getLogger(BaseMemberHandler.class);
/*
* the uri of the base member to be processed
*/ String baseMemberUri;
Expand All @@ -47,9 +46,9 @@ public class BaseMemberHandler extends TRSTaskHandler {
* the size of the rdf representation of the rdf member
*/ AtomicLong modelSize;

public BaseMemberHandler(TrsBasicAuthOslcClient oslcClient, String sparqlQueryService,
String sparqlUpdateService, String baseAuth_userName, String baseAuth_pwd,
String baseMemberUri, List<String> queries, AtomicLong modelSize) {
public BaseMemberHandler(String baseMemberUri, List<String> queries, AtomicLong modelSize,
OslcClient oslcClient, String sparqlQueryService, String sparqlUpdateService, String baseAuth_userName,
String baseAuth_pwd) {
// TODO Andrew@2018-03-01: use a common SPARQL interface
super(oslcClient,
sparqlQueryService,
Expand All @@ -69,7 +68,7 @@ public BaseMemberHandler(TrsBasicAuthOslcClient oslcClient, String sparqlQuerySe
protected void processTRSTask() {
try {
processBaseMemberAddition();
} catch (IOException | OAuthException | URISyntaxException e) {
} catch (IOException | URISyntaxException e) {
logger.error("Error processing TRS task", e);
}
}
Expand All @@ -78,7 +77,7 @@ protected void processTRSTask() {
* create the necessary sparql update for processing the base member
*/
private void processBaseMemberAddition()
throws IOException, OAuthException, URISyntaxException {
throws IOException, URISyntaxException {

logger.debug("processing base member " + baseMemberUri + " addition. Creating necessary " +
"" + "" + "sparql update query ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import net.oauth.OAuthException;
import org.apache.jena.rdf.model.Model;
import org.eclipse.lyo.core.trs.ChangeEvent;
import org.eclipse.lyo.core.trs.Deletion;
import org.eclipse.lyo.oslc4j.client.OslcClient;
import org.eclipse.lyo.oslc4j.trs.client.util.SparqlUtil;
import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -53,9 +52,9 @@ public class ChangeEventHandler extends TRSTaskHandler {
*/
AtomicLong modelSize;

public ChangeEventHandler(TrsBasicAuthOslcClient oslcClient, String sparqlQueryService,
String sparqlUpdateService, String basicAuthUsername, String basicAuthPassword,
ChangeEvent handledChangeEvent, List<String> queries, AtomicLong modelSize) {
public ChangeEventHandler(ChangeEvent handledChangeEvent, List<String> queries,
AtomicLong modelSize, OslcClient oslcClient, String sparqlUpdateService, String sparqlQueryService,
String basicAuthUsername, String basicAuthPassword) {
// here we assume the triplestore is not auth-protected, hence nulls
super(oslcClient,
sparqlUpdateService,
Expand All @@ -73,7 +72,7 @@ public ChangeEventHandler(TrsBasicAuthOslcClient oslcClient, String sparqlQueryS
this.modelSize = modelSize;
}

private void processChangeEvent() throws IOException, OAuthException, URISyntaxException {
private void processChangeEvent() throws IOException, URISyntaxException {
URI changed = handledChangeEvent.getChanged();
logger.debug("creating query for resource " + changed.toString() + " change event ");
String query;
Expand Down Expand Up @@ -105,7 +104,7 @@ private void processChangeEvent() throws IOException, OAuthException, URISyntaxE
protected void processTRSTask() {
try {
processChangeEvent();
} catch (IOException | OAuthException | URISyntaxException e) {
} catch (IOException | URISyntaxException e) {
logger.error("Error processing Change Events", e);
}
}
Expand Down
Loading