import org.opendaylight.restconf.common.errors.SettableRestconfFuture;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
+import org.opendaylight.restconf.common.patch.PatchStatusEntity;
import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
import org.opendaylight.restconf.nb.rfc8040.ReadDataParams;
import org.opendaylight.restconf.nb.rfc8040.databind.ChildBody;
import org.opendaylight.restconf.nb.rfc8040.databind.XmlPatchBody;
import org.opendaylight.restconf.nb.rfc8040.databind.XmlResourceBody;
import org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams;
+import org.opendaylight.restconf.nb.rfc8040.legacy.ErrorTags;
import org.opendaylight.restconf.nb.rfc8040.legacy.InstanceIdentifierContext;
import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy.CreateOrReplaceResult;
.addCallback(new JaxRsRestconfCallback<>(ar) {
@Override
Response transform(final PatchStatusContext result) {
- return Response.ok().entity(result).build();
+ return Response.status(getStatusCode(result)).entity(result).build();
}
});
}
+ private static Status getStatusCode(final PatchStatusContext result) {
+ if (result.ok()) {
+ return Status.OK;
+ } else {
+ if (result.globalErrors() == null || result.globalErrors().isEmpty()) {
+ return result.editCollection().stream()
+ .filter(patchStatus -> !patchStatus.isOk() && !patchStatus.getEditErrors().isEmpty())
+ .findFirst()
+ .map(PatchStatusEntity::getEditErrors)
+ .flatMap(errors -> errors.stream().findFirst())
+ .map(error -> ErrorTags.statusOf(error.getErrorTag()))
+ .orElse(Status.INTERNAL_SERVER_ERROR);
+ } else {
+ final var error = result.globalErrors().iterator().next();
+ return ErrorTags.statusOf(error.getErrorTag());
+ }
+ }
+ }
+
private static @NonNull PatchContext parsePatchBody(final @NonNull EffectiveModelContext context,
final @NonNull YangInstanceIdentifier urlPath, final @NonNull PatchBody body) {
try {
doReturn(true).when(asyncResponse).resume(responseCaptor.capture());
dataService.yangPatchData(JUKEBOX_SCHEMA, patch, null, asyncResponse);
final var response = responseCaptor.getValue();
- assertEquals(200, response.getStatus());
+ assertEquals(409, response.getStatus());
final var status = assertInstanceOf(PatchStatusContext.class, response.getEntity());
assertFalse(status.ok());