Skip to content

Commit e729edc

Browse files
committed
Empty model returns 422 instead of 400
1 parent f5d8adc commit e729edc

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed
File renamed without changes.

http-tests/misc/PATCH-settings-empty.sh renamed to http-tests/misc/PATCH-settings-empty-422.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ purge_cache "$END_USER_VARNISH_SERVICE"
77
purge_cache "$ADMIN_VARNISH_SERVICE"
88
purge_cache "$FRONTEND_VARNISH_SERVICE"
99

10-
# Test: PATCH /settings - Empty result (should fail with 400)
10+
# Test: PATCH /settings - Empty result (should fail with 422)
1111

1212
curl -k -w "%{http_code}\n" -o /dev/null -s \
1313
-X PATCH \
1414
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
1515
-H "Content-Type: application/sparql-update" \
1616
-d "DELETE WHERE { ?s ?p ?o }" \
1717
"${END_USER_BASE_URL}settings" \
18-
| grep -q "$STATUS_BAD_REQUEST"
18+
| grep -q "$STATUS_UNPROCESSABLE_ENTITY"

src/main/java/com/atomgraph/linkeddatahub/resource/Settings.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
import com.atomgraph.core.util.ModelUtils;
2020
import com.atomgraph.linkeddatahub.apps.model.Application;
2121
import com.atomgraph.linkeddatahub.server.io.ValidatingModelProvider;
22+
import com.atomgraph.linkeddatahub.vocabulary.LAPP;
2223
import jakarta.inject.Inject;
2324
import jakarta.ws.rs.BadRequestException;
2425
import jakarta.ws.rs.GET;
2526
import jakarta.ws.rs.InternalServerErrorException;
2627
import jakarta.ws.rs.NotFoundException;
2728
import jakarta.ws.rs.PATCH;
29+
import jakarta.ws.rs.WebApplicationException;
30+
import static com.atomgraph.server.status.UnprocessableEntityStatus.UNPROCESSABLE_ENTITY;
2831
import jakarta.ws.rs.core.Context;
2932
import jakarta.ws.rs.core.EntityTag;
3033
import jakarta.ws.rs.core.Request;
@@ -36,8 +39,11 @@
3639
import org.apache.jena.query.DatasetFactory;
3740
import org.apache.jena.rdf.model.Model;
3841
import org.apache.jena.rdf.model.ModelFactory;
42+
import org.apache.jena.rdf.model.Resource;
43+
import org.apache.jena.rdf.model.ResourceFactory;
3944
import org.apache.jena.update.UpdateAction;
4045
import org.apache.jena.update.UpdateRequest;
46+
import org.apache.jena.vocabulary.RDF;
4147
import org.slf4j.Logger;
4248
import org.slf4j.LoggerFactory;
4349

@@ -127,11 +133,12 @@ public Response patch(UpdateRequest updateRequest) throws IOException
127133
Dataset dataset = DatasetFactory.wrap(mutableModel);
128134
UpdateAction.execute(updateRequest, dataset);
129135

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))
132139
{
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
135142
}
136143

137144
// validate the updated model

0 commit comments

Comments
 (0)