Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POST/PATCH must advertise constraints if triples not persisted
- Create ConstraintViolationException subclass of MalformedRdfException - Create OutOfDomainSubjectException subclass of ConstraintViolationException - Move ServerManagedPropertyException to subclass of ConstraintViolationException - Add OutOfDomainSubjectExceptionMapper, ConstraintViolationExceptionMapper - Change some Exceptions thrown at JcrPropertyStatementListener - Propagate out of PersistingRdfStreamConsumer and FedoraResourceImpl - Add ManagedTypeException, Mapper and throw from PersistingRdfStreamConsumer - Rename ManagedTypeException to ServerManagedTypeException - Make ConstraintExceptionMapper superclass. Resolves to: https://jira.duraspace.org/browse/FCREPO-1418
- Loading branch information
Showing
23 changed files
with
704 additions
and
28 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
...ns/src/main/java/org/fcrepo/http/commons/exceptionhandlers/ConstraintExceptionMapper.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,54 @@ | ||
/** | ||
* Copyright 2015 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static org.fcrepo.kernel.RdfLexicon.CONSTRAINED_BY; | ||
|
||
import javax.ws.rs.core.Link; | ||
import javax.ws.rs.core.UriInfo; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
|
||
import org.fcrepo.kernel.exception.ConstraintViolationException; | ||
|
||
/** | ||
* Abstract class for constraint violation subclasses | ||
* | ||
* @author whikloj | ||
* @since 2015-06-24 | ||
* @param <T> Throwable subclass of ConstraintViolationException | ||
*/ | ||
public abstract class ConstraintExceptionMapper<T extends ConstraintViolationException> implements ExceptionMapper<T> { | ||
|
||
/** | ||
* Where the RDF exception files sit. | ||
*/ | ||
private static final String CONSTRAINT_DIR = "/static/constraints/"; | ||
|
||
/** | ||
* Creates a constrainedBy link header with the appropriate RDF URL for the exception. | ||
* | ||
* @param e ConstraintViolationException Exception which implements the buildContraintUri method. | ||
* @param uriInfo UriInfo UriInfo from the ExceptionMapper. | ||
* @return Link A http://www.w3.org/ns/ldp#constrainedBy link header | ||
*/ | ||
public static Link buildConstraintLink(final ConstraintViolationException e, final UriInfo uriInfo) { | ||
final String constraintURI = uriInfo == null ? "" : String.format("%s://%s%s%s.rdf", | ||
uriInfo.getBaseUri().getScheme(), uriInfo.getBaseUri().getAuthority(), | ||
CONSTRAINT_DIR, e.getClass().toString().substring(e.getClass().toString().lastIndexOf('.') + 1)); | ||
return Link.fromUri(constraintURI).rel(CONSTRAINED_BY.getURI()).build(); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...in/java/org/fcrepo/http/commons/exceptionhandlers/ConstraintViolationExceptionMapper.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,47 @@ | ||
/** | ||
* Copyright 2015 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ||
|
||
import org.fcrepo.kernel.exception.ConstraintViolationException; | ||
|
||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Link; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriInfo; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
/** | ||
* @author whikloj | ||
* @since 2015-06-01 | ||
*/ | ||
@Provider | ||
public class ConstraintViolationExceptionMapper extends ConstraintExceptionMapper<ConstraintViolationException> { | ||
|
||
@Context | ||
private UriInfo uriInfo; | ||
|
||
@Override | ||
public Response toResponse(final ConstraintViolationException e) { | ||
|
||
final Link link = buildConstraintLink(e, uriInfo); | ||
final String msg = e.getMessage(); | ||
return status(BAD_REQUEST).entity(msg).links(link).build(); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...ain/java/org/fcrepo/http/commons/exceptionhandlers/OutOfDomainSubjectExceptionMapper.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,47 @@ | ||
/** | ||
* Copyright 2015 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ||
|
||
import org.fcrepo.kernel.exception.OutOfDomainSubjectException; | ||
|
||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Link; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriInfo; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
/** | ||
* @author whikloj | ||
* @since 2015-05-29 | ||
*/ | ||
@Provider | ||
public class OutOfDomainSubjectExceptionMapper extends ConstraintExceptionMapper<OutOfDomainSubjectException> { | ||
|
||
@Context | ||
private UriInfo uriInfo; | ||
|
||
@Override | ||
public Response toResponse(final OutOfDomainSubjectException e) { | ||
|
||
final Link link = buildConstraintLink(e, uriInfo); | ||
final String msg = e.getMessage(); | ||
return status(BAD_REQUEST).entity(msg).links(link).build(); | ||
} | ||
|
||
} |
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
45 changes: 45 additions & 0 deletions
45
...main/java/org/fcrepo/http/commons/exceptionhandlers/ServerManagedTypeExceptionMapper.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,45 @@ | ||
/** | ||
* Copyright 2015 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.status; | ||
import static javax.ws.rs.core.Response.Status.CONFLICT; | ||
|
||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Link; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriInfo; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.fcrepo.kernel.exception.ServerManagedTypeException; | ||
|
||
/** | ||
* @author whikloj | ||
* @since 2015-06-02 | ||
*/ | ||
@Provider | ||
public class ServerManagedTypeExceptionMapper extends ConstraintExceptionMapper<ServerManagedTypeException> { | ||
|
||
@Context | ||
private UriInfo uriInfo; | ||
|
||
@Override | ||
public Response toResponse(final ServerManagedTypeException e) { | ||
final Link link = buildConstraintLink(e, uriInfo); | ||
final String msg = e.getMessage(); | ||
return status(CONFLICT).entity(msg).links(link).build(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ava/org/fcrepo/http/commons/exceptionhandlers/ConstraintViolationExceptionMapperTest.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,67 @@ | ||
/** | ||
* Copyright 2015 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.fcrepo.http.commons.exceptionhandlers; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.ws.rs.core.Link; | ||
import javax.ws.rs.core.UriInfo; | ||
|
||
import org.fcrepo.kernel.exception.ConstraintViolationException; | ||
|
||
import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl; | ||
import static org.fcrepo.kernel.RdfLexicon.CONSTRAINED_BY; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
/** | ||
* ConstraintViolationExceptionMapperTest | ||
* | ||
* @author whikloj | ||
* @since 2015-06-22 | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class ConstraintViolationExceptionMapperTest { | ||
|
||
private UriInfo mockInfo; | ||
|
||
@Mock | ||
private ConstraintViolationExceptionMapper mapper; | ||
|
||
@Before | ||
public void setUp() throws RepositoryException, URISyntaxException { | ||
this.mockInfo = getUriInfoImpl(); | ||
} | ||
|
||
@Test | ||
public void testBuildConstraintLink() { | ||
final URI testLink = URI.create("http://localhost/static/constraints/ConstraintViolationException.rdf"); | ||
|
||
final ConstraintViolationException ex = new ConstraintViolationException("This is an error."); | ||
|
||
final Link link = ConstraintViolationExceptionMapper.buildConstraintLink(ex, mockInfo); | ||
|
||
assertEquals(link.getRel(), CONSTRAINED_BY.getURI()); | ||
assertEquals(link.getUri(), testLink); | ||
} | ||
} |
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.