Skip to content

Commit 4c1aab4

Browse files
committed
Incorporated AtomGraph Server code
1 parent 1ebf6a6 commit 4c1aab4

27 files changed

Lines changed: 1671 additions & 3 deletions

pom.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,15 @@
126126
</exclusion>
127127
</exclusions>
128128
</dependency>
129-
<!-- TO-DO: replace with AtomGraph Core -->
129+
<dependency>
130+
<groupId>org.apache.jena</groupId>
131+
<artifactId>jena-shacl</artifactId>
132+
<version>4.7.0</version>
133+
</dependency>
130134
<dependency>
131135
<groupId>${project.groupId}</groupId>
132-
<artifactId>server</artifactId>
133-
<version>4.1.15-SNAPSHOT</version>
136+
<artifactId>twirl</artifactId>
137+
<version>1.0.33</version>
134138
</dependency>
135139
<dependency>
136140
<groupId>${project.groupId}</groupId>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2016 Martynas Jusevičius <martynas@atomgraph.com>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.atomgraph.server.exception;
17+
18+
import org.apache.jena.rdf.model.Model;
19+
20+
/**
21+
*
22+
* @author Martynas Jusevičius {@literal <martynas@atomgraph.com>}
23+
*/
24+
public class ModelException extends RuntimeException
25+
{
26+
27+
private final Model model;
28+
29+
public ModelException(Model model)
30+
{
31+
this.model = model;
32+
}
33+
34+
public ModelException(Throwable throwable, Model model)
35+
{
36+
super(throwable);
37+
this.model = model;
38+
}
39+
40+
public Model getModel()
41+
{
42+
return model;
43+
}
44+
45+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2015 Martynas Jusevičius <martynas@atomgraph.com>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.atomgraph.server.exception;
18+
19+
/**
20+
*
21+
* @author Martynas Jusevičius {@literal <martynas@atomgraph.com>}
22+
*/
23+
public class OntologyException extends RuntimeException
24+
{
25+
26+
public OntologyException()
27+
{
28+
}
29+
30+
public OntologyException(String message)
31+
{
32+
super(message);
33+
}
34+
35+
public OntologyException(String message, Throwable cause)
36+
{
37+
super(message, cause);
38+
}
39+
40+
public OntologyException(Throwable cause)
41+
{
42+
super(cause);
43+
}
44+
45+
public OntologyException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
46+
{
47+
super(message, cause, enableSuppression, writableStackTrace);
48+
}
49+
50+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2021 Martynas Jusevičius <martynas@atomgraph.com>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.atomgraph.server.exception;
17+
18+
import org.apache.jena.rdf.model.Model;
19+
import org.apache.jena.shacl.ValidationReport;
20+
21+
/**
22+
*
23+
* @author Martynas Jusevičius {@literal <martynas@atomgraph.com>}
24+
*/
25+
public class SHACLConstraintViolationException extends ModelException
26+
{
27+
28+
private final ValidationReport report;
29+
30+
public SHACLConstraintViolationException(ValidationReport report, Model model)
31+
{
32+
super(model);
33+
this.report = report;
34+
}
35+
36+
public ValidationReport getValidationReport()
37+
{
38+
return report;
39+
}
40+
41+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2013 Martynas Jusevičius <martynas@atomgraph.com>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.atomgraph.server.exception;
18+
19+
import org.apache.jena.rdf.model.Model;
20+
import java.util.List;
21+
import com.atomgraph.spinrdf.constraints.ConstraintViolation;
22+
23+
/**
24+
*
25+
* @author Martynas Jusevičius {@literal <martynas@atomgraph.com>}
26+
*/
27+
public class SPINConstraintViolationException extends ModelException
28+
{
29+
private final List<ConstraintViolation> cvs;
30+
31+
public SPINConstraintViolationException(List<ConstraintViolation> cvs, Model model, String graphURI)
32+
{
33+
super(model);
34+
this.cvs = cvs;
35+
}
36+
37+
public SPINConstraintViolationException(List<ConstraintViolation> cvs, Model model)
38+
{
39+
this(cvs, model, null);
40+
}
41+
42+
public List<ConstraintViolation> getConstraintViolations()
43+
{
44+
return cvs;
45+
}
46+
47+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2016 Martynas Jusevičius <martynas@atomgraph.com>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.atomgraph.server.exception;
18+
19+
import org.apache.jena.rdf.model.Model;
20+
21+
/**
22+
*
23+
* @author Martynas Jusevičius {@literal <martynas@atomgraph.com>}
24+
*/
25+
public class SkolemizationException extends ModelException
26+
{
27+
28+
public SkolemizationException(IllegalArgumentException ex, Model model)
29+
{
30+
super(ex, model);
31+
}
32+
33+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2017 Martynas Jusevičius <martynas@atomgraph.com>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.atomgraph.server.io;
17+
18+
import com.atomgraph.core.io.ModelProvider;
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.io.OutputStream;
22+
import java.lang.annotation.Annotation;
23+
import java.lang.reflect.Type;
24+
import jakarta.ws.rs.core.Context;
25+
import jakarta.ws.rs.core.MediaType;
26+
import jakarta.ws.rs.core.MultivaluedMap;
27+
import jakarta.ws.rs.core.UriInfo;
28+
import org.apache.jena.rdf.model.Model;
29+
import org.apache.jena.rdf.model.ModelFactory;
30+
import org.apache.jena.riot.Lang;
31+
import org.apache.jena.riot.RDFLanguages;
32+
import org.apache.jena.shared.NoReaderForLangException;
33+
import org.apache.jena.shared.NoWriterForLangException;
34+
import org.slf4j.Logger;
35+
import org.slf4j.LoggerFactory;
36+
37+
38+
/**
39+
* A provider that reads/writes model and resolves relative URIs against request base URI.
40+
*
41+
* @author Martynas Jusevičius {@literal <martynas@atomgraph.com>}
42+
*/
43+
public class BasedModelProvider extends ModelProvider
44+
{
45+
46+
private static final Logger log = LoggerFactory.getLogger(BasedModelProvider.class);
47+
48+
@Context UriInfo uriInfo;
49+
50+
@Override
51+
public Model readFrom(Class<Model> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException
52+
{
53+
if (log.isTraceEnabled()) log.trace("Reading Model with HTTP headers: {} MediaType: {}", httpHeaders, mediaType);
54+
55+
Model model = ModelFactory.createDefaultModel();
56+
57+
MediaType formatType = new MediaType(mediaType.getType(), mediaType.getSubtype()); // discard charset param
58+
Lang lang = RDFLanguages.contentTypeToLang(formatType.toString());
59+
if (lang == null)
60+
{
61+
if (log.isErrorEnabled()) log.error("MediaType '{}' not supported by Jena", formatType);
62+
throw new NoReaderForLangException("MediaType not supported: " + formatType);
63+
}
64+
if (log.isDebugEnabled()) log.debug("RDF language used to read Model: {}", lang);
65+
66+
return read(model, entityStream, lang, getUriInfo().getAbsolutePath().toString());
67+
}
68+
69+
@Override
70+
public void writeTo(Model model, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException
71+
{
72+
if (log.isTraceEnabled()) log.trace("Writing Model with HTTP headers: {} MediaType: {}", httpHeaders, mediaType);
73+
74+
MediaType formatType = new MediaType(mediaType.getType(), mediaType.getSubtype()); // discard charset param
75+
Lang lang = RDFLanguages.contentTypeToLang(formatType.toString());
76+
if (lang == null)
77+
{
78+
if (log.isErrorEnabled()) log.error("MediaType '{}' not supported by Jena", formatType);
79+
throw new NoWriterForLangException("MediaType not supported: " + formatType);
80+
}
81+
if (log.isDebugEnabled()) log.debug("RDF language used to read Model: {}", lang);
82+
83+
write(model, entityStream, lang, getUriInfo().getAbsolutePath().toString());
84+
}
85+
86+
public UriInfo getUriInfo()
87+
{
88+
return uriInfo;
89+
}
90+
91+
}

0 commit comments

Comments
 (0)