Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-1900 Create a SHACL exception in the ProtocolExceptionResolver ins…
…tead of relying on a generic exception with a message Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
- Loading branch information
1 parent
90d6e16
commit 3fab174
Showing
6 changed files
with
187 additions
and
38 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
core/http/client/src/main/java/org/eclipse/rdf4j/http/client/ModelInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Eclipse RDF4J contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.rdf4j.http.client; | ||
|
||
import org.eclipse.rdf4j.model.Model; | ||
import org.eclipse.rdf4j.model.Resource; | ||
import org.eclipse.rdf4j.model.impl.DynamicModelFactory; | ||
|
||
public interface ModelInterface { | ||
|
||
default Model asModel() { | ||
return asModel(new DynamicModelFactory().createEmptyModel()); | ||
} | ||
|
||
Model asModel(Model model); | ||
|
||
Resource getId(); | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...lient/src/main/java/org/eclipse/rdf4j/http/client/RemoteShaclSailValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Eclipse RDF4J contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.rdf4j.http.client; | ||
|
||
import org.eclipse.rdf4j.model.Model; | ||
import org.eclipse.rdf4j.model.vocabulary.SHACL; | ||
import org.eclipse.rdf4j.rio.RDFFormat; | ||
|
||
import java.io.StringReader; | ||
|
||
public class RemoteShaclSailValidationException extends Exception { | ||
|
||
private final RemoteValidation remoteValidation; | ||
|
||
public RemoteShaclSailValidationException(StringReader stringReader, String s, RDFFormat format) { | ||
remoteValidation = new RemoteValidation(stringReader, s, format); | ||
} | ||
|
||
/** | ||
* @return A Model containing the validation report as specified by the SHACL Recommendation | ||
*/ | ||
@SuppressWarnings("WeakerAccess") | ||
public Model validationReportAsModel() { | ||
Model model = remoteValidation.asModel(); | ||
model.setNamespace(SHACL.PREFIX, SHACL.NAMESPACE); | ||
return model; | ||
|
||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
core/http/client/src/main/java/org/eclipse/rdf4j/http/client/RemoteValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.eclipse.rdf4j.http.client; | ||
|
||
import org.eclipse.rdf4j.model.Model; | ||
import org.eclipse.rdf4j.model.Resource; | ||
import org.eclipse.rdf4j.rio.RDFFormat; | ||
import org.eclipse.rdf4j.rio.Rio; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
|
||
public class RemoteValidation implements ModelInterface { | ||
|
||
StringReader stringReader; | ||
String baseUri; | ||
RDFFormat format; | ||
|
||
Model model; | ||
|
||
public RemoteValidation(StringReader stringReader, String baseUri, RDFFormat format) { | ||
this.stringReader = stringReader; | ||
this.baseUri = baseUri; | ||
this.format = format; | ||
} | ||
|
||
@Override | ||
public Model asModel(Model model) { | ||
model.addAll(asModel()); | ||
return model; | ||
} | ||
|
||
@Override | ||
public Model asModel() { | ||
if (model == null) { | ||
try { | ||
model = Rio.parse(stringReader, baseUri, format); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
return model; | ||
} | ||
|
||
@Override | ||
public Resource getId() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.