use new IllegalIdentifierChangeException in SingleResourceManagerAdapter

This commit is contained in:
Eduard Heimbuch
2019-08-21 10:36:48 +02:00
parent 72fe69b2d5
commit 7a29bba339

View File

@@ -2,6 +2,7 @@ package sonia.scm.api.v2.resources;
import de.otto.edison.hal.HalRepresentation; import de.otto.edison.hal.HalRepresentation;
import sonia.scm.ConcurrentModificationException; import sonia.scm.ConcurrentModificationException;
import sonia.scm.IllegalIdentifierChangeException;
import sonia.scm.Manager; import sonia.scm.Manager;
import sonia.scm.ModelObject; import sonia.scm.ModelObject;
import sonia.scm.NotFoundException; import sonia.scm.NotFoundException;
@@ -11,8 +12,6 @@ import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
/** /**
* Adapter from resource http endpoints to managers, for Single resources (e.g. {@code /user/name}). * Adapter from resource http endpoints to managers, for Single resources (e.g. {@code /user/name}).
* *
@@ -55,7 +54,7 @@ class SingleResourceManagerAdapter<MODEL_OBJECT extends ModelObject,
MODEL_OBJECT existingModelObject = reader.get(); MODEL_OBJECT existingModelObject = reader.get();
MODEL_OBJECT changedModelObject = applyChanges.apply(existingModelObject); MODEL_OBJECT changedModelObject = applyChanges.apply(existingModelObject);
if (!hasSameKey.test(changedModelObject)) { if (!hasSameKey.test(changedModelObject)) {
return Response.status(BAD_REQUEST).entity("illegal change of id").build(); throw new IllegalIdentifierChangeException("illegal change of id");
} }
else if (modelObjectWasModifiedConcurrently(existingModelObject, changedModelObject)) { else if (modelObjectWasModifiedConcurrently(existingModelObject, changedModelObject)) {
throw new ConcurrentModificationException(type, keyExtractor.apply(existingModelObject)); throw new ConcurrentModificationException(type, keyExtractor.apply(existingModelObject));