|
19 | 19 | import com.atomgraph.core.util.ModelUtils; |
20 | 20 | import com.atomgraph.linkeddatahub.apps.model.Application; |
21 | 21 | import com.atomgraph.linkeddatahub.server.io.ValidatingModelProvider; |
| 22 | +import com.atomgraph.linkeddatahub.vocabulary.LAPP; |
22 | 23 | import jakarta.inject.Inject; |
23 | 24 | import jakarta.ws.rs.BadRequestException; |
24 | 25 | import jakarta.ws.rs.GET; |
25 | 26 | import jakarta.ws.rs.InternalServerErrorException; |
26 | 27 | import jakarta.ws.rs.NotFoundException; |
27 | 28 | import jakarta.ws.rs.PATCH; |
| 29 | +import jakarta.ws.rs.WebApplicationException; |
| 30 | +import static com.atomgraph.server.status.UnprocessableEntityStatus.UNPROCESSABLE_ENTITY; |
28 | 31 | import jakarta.ws.rs.core.Context; |
29 | 32 | import jakarta.ws.rs.core.EntityTag; |
30 | 33 | import jakarta.ws.rs.core.Request; |
|
36 | 39 | import org.apache.jena.query.DatasetFactory; |
37 | 40 | import org.apache.jena.rdf.model.Model; |
38 | 41 | import org.apache.jena.rdf.model.ModelFactory; |
| 42 | +import org.apache.jena.rdf.model.Resource; |
| 43 | +import org.apache.jena.rdf.model.ResourceFactory; |
39 | 44 | import org.apache.jena.update.UpdateAction; |
40 | 45 | import org.apache.jena.update.UpdateRequest; |
| 46 | +import org.apache.jena.vocabulary.RDF; |
41 | 47 | import org.slf4j.Logger; |
42 | 48 | import org.slf4j.LoggerFactory; |
43 | 49 |
|
@@ -127,11 +133,12 @@ public Response patch(UpdateRequest updateRequest) throws IOException |
127 | 133 | Dataset dataset = DatasetFactory.wrap(mutableModel); |
128 | 134 | UpdateAction.execute(updateRequest, dataset); |
129 | 135 |
|
130 | | - // if PATCH results in an empty model, reject it as Bad Request |
131 | | - if (mutableModel.isEmpty()) |
| 136 | + // Verify the application resource still exists with correct type after PATCH |
| 137 | + Resource appResource = ResourceFactory.createResource(getApplication().getURI()); |
| 138 | + if (!mutableModel.contains(appResource, RDF.type, LAPP.EndUserApplication)) |
132 | 139 | { |
133 | | - if (log.isWarnEnabled()) log.warn("PATCH resulted in empty dataspace model for <{}>", getApplication().getURI()); |
134 | | - throw new BadRequestException("PATCH cannot result in empty dataspace model"); |
| 140 | + if (log.isWarnEnabled()) log.warn("PATCH removed application resource or its type for <{}>", getApplication().getURI()); |
| 141 | + throw new WebApplicationException("PATCH cannot remove the application resource or its type", UNPROCESSABLE_ENTITY.getStatusCode()); // 422 Unprocessable Entity |
135 | 142 | } |
136 | 143 |
|
137 | 144 | // validate the updated model |
|
0 commit comments