From 37147dce474887900aa63c639180b37003e070c8 Mon Sep 17 00:00:00 2001 From: Andrew Berezovskyi Date: Mon, 7 Jun 2021 12:59:24 +0200 Subject: [PATCH] Allow Bases with rdf:nil or null next pages (#102) --- CHANGELOG.md | 1 + .../config/TrsProviderConfiguration.java | 39 +++++++++++++++++++ .../ConcurrentTrsProviderHandler.java | 11 ++++++ .../lyo/trs/client/util/ClientUtil.java | 11 +++--- .../client/config/TrsProviderConfiguration.kt | 32 --------------- 5 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/config/TrsProviderConfiguration.java delete mode 100644 trs/client/trs-client/src/main/kotlin/org/eclipse/lyo/trs/client/config/TrsProviderConfiguration.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 62410f764..5b6cade56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ ### Fixed - Make sure every Lyo dependency uses the same version of Guava (30.0) +- Fix a few issues around rdf:nil handling in the TRS Client ## [4.0.0] - 2020-12-16 diff --git a/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/config/TrsProviderConfiguration.java b/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/config/TrsProviderConfiguration.java new file mode 100644 index 000000000..18c41c52c --- /dev/null +++ b/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/config/TrsProviderConfiguration.java @@ -0,0 +1,39 @@ +package org.eclipse.lyo.trs.client.config; + +import java.net.URI; + +public final class TrsProviderConfiguration { + private final URI trsUri; + private final String basicAuthUsername; + private final String basicAuthPassword; + + public final URI getTrsUri() { + return this.trsUri; + } + + public final String getBasicAuthUsername() { + return this.basicAuthUsername; + } + + public final String getBasicAuthPassword() { + return this.basicAuthPassword; + } + + public TrsProviderConfiguration(URI trsUri, String basicAuthUsername, String basicAuthPassword) { + super(); + this.trsUri = trsUri; + this.basicAuthUsername = basicAuthUsername; + this.basicAuthPassword = basicAuthPassword; + } + + public static final TrsProviderConfiguration forHttp(String trsEndpointUri) { + URI trsUri = URI.create(trsEndpointUri); + return new TrsProviderConfiguration(trsUri, null, null); + } + + public static final TrsProviderConfiguration forHttpWithBasicAuth(String trsEndpointUri, String trsEndpointUsername, String trsEndpointPassword) { + URI trsUri = URI.create(trsEndpointUri); + return new TrsProviderConfiguration(trsUri, trsEndpointUsername, trsEndpointPassword); + } + +} diff --git a/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/handlers/ConcurrentTrsProviderHandler.java b/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/handlers/ConcurrentTrsProviderHandler.java index 74dfd0b65..5fc6b49f7 100644 --- a/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/handlers/ConcurrentTrsProviderHandler.java +++ b/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/handlers/ConcurrentTrsProviderHandler.java @@ -22,6 +22,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; + import org.apache.jena.rdf.model.Model; import org.apache.jena.vocabulary.RDF; import org.eclipse.lyo.core.trs.Base; @@ -98,6 +99,16 @@ public boolean fetchRemoteChangeLogs(ChangeLog currentChangeLog, List break; } previousChangeLog = currentChangeLog.getPrevious(); + if(previousChangeLog == null || URI.create(RDF.nil.getURI()).equals(previousChangeLog)) { + if(URI.create(RDF.nil.getURI()).equals(lastProcessedChangeEventUri)) { + log.debug("First ChangeLog page reached"); + foundChangeEvent = true; + } + else { + log.error("Changelog read to the end without finding the cutoff event URI"); + } + break; + } currentChangeLog = trsClient.fetchRemoteChangeLog(previousChangeLog); } else { break; diff --git a/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/util/ClientUtil.java b/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/util/ClientUtil.java index 6f13fb8c9..cf689ed32 100644 --- a/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/util/ClientUtil.java +++ b/trs/client/trs-client/src/main/java/org/eclipse/lyo/trs/client/util/ClientUtil.java @@ -97,19 +97,20 @@ static Base extractBaseFromRdfModel(Model rdFModel) throws LyoModelException { } if (baseObj == null) { - // FIXME Andrew@2019-07-15: nulls + log.error("Base page object is null"); + //FIXME nulls +// throw new IllegalStateException(); return null; } if (ProviderUtil.isNotEmptySingletonArray(nextPageArray) && nextPageArray[0] instanceof Page) { nextPage = (Page) nextPageArray[0]; baseObj.setNextPage(nextPage); - log.debug("finished extracting base from rdf model"); - return baseObj; + } else { + log.debug("Base page {} is the last one", baseObj.getAbout()); } log.debug("finished extracting base from rdf model"); - // FIXME Andrew@2019-07-15: nulls - return null; + return baseObj; } /** diff --git a/trs/client/trs-client/src/main/kotlin/org/eclipse/lyo/trs/client/config/TrsProviderConfiguration.kt b/trs/client/trs-client/src/main/kotlin/org/eclipse/lyo/trs/client/config/TrsProviderConfiguration.kt deleted file mode 100644 index de9e64cba..000000000 --- a/trs/client/trs-client/src/main/kotlin/org/eclipse/lyo/trs/client/config/TrsProviderConfiguration.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License 1.0 - * which is available at http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - */ - -package org.eclipse.lyo.trs.client.config - -import java.net.URI - -class TrsProviderConfiguration(val trsUri: URI, val basicAuthUsername: String?, - val basicAuthPassword: String?) { - companion object { - fun forHttp(trsEndpointUri: String): TrsProviderConfiguration { - return TrsProviderConfiguration(URI.create(trsEndpointUri), null, null) - } - - fun forHttpWithBasicAuth(trsEndpointUri: String, trsEndpointUsername: String, - trsEndpointPassword: String): TrsProviderConfiguration { - return TrsProviderConfiguration(URI.create(trsEndpointUri), trsEndpointUsername, - trsEndpointPassword) - } - } -}