return HTTP_CONFLICT (409) from POST create() in case of AlreadyExists 06/73406/2
authorMichael Vorburger <vorburger@redhat.com>
Mon, 25 Jun 2018 14:05:42 +0000 (16:05 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Wed, 4 Jul 2018 14:18:53 +0000 (16:18 +0200)
see https://lists.opendaylight.org/pipermail/neutron-dev/2018-June/001702.html

Change-Id: Idd0d65e720d209afbf993db2c202b7710ef6c9db
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java

index c1c1dd794cf628df21ba65a6fb73cec4d903d226..9a922c12d27bffe1e45ad1872a00c646c16d6b53 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.neutron.northbound.api;
 
+import static org.opendaylight.neutron.spi.INeutronCRUD.Result.AlreadyExists;
 import static org.opendaylight.neutron.spi.INeutronCRUD.Result.DependencyMissing;
 import static org.opendaylight.neutron.spi.INeutronCRUD.Result.DoesNotExist;
 
@@ -112,8 +113,11 @@ public abstract class AbstractNeutronNorthbound<T extends INeutronObject<T>, R e
                 T singleton = input.getSingleton();
 
                 singleton.initDefaults();
-                if (neutronCRUD.add(singleton).equals(DependencyMissing)) {
+                Result result = neutronCRUD.add(singleton);
+                if (result.equals(DependencyMissing)) {
                     return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build();
+                } else if (result.equals(AlreadyExists)) {
+                    return Response.status(HttpURLConnection.HTTP_CONFLICT).entity(input).build();
                 }
             } else {
                 if (input.getBulk() == null) {
@@ -121,9 +125,12 @@ public abstract class AbstractNeutronNorthbound<T extends INeutronObject<T>, R e
                 }
                 for (T test : input.getBulk()) {
                     test.initDefaults();
-                    if (neutronCRUD.add(test).equals(DependencyMissing)) {
+                    Result result = neutronCRUD.add(test);
+                    if (result.equals(DependencyMissing)) {
                         LOG.warn("create failed due to input missing dependencies: {}", input);
                         return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build();
+                    } else if (result.equals(AlreadyExists)) {
+                        return Response.status(HttpURLConnection.HTTP_CONFLICT).entity(input).build();
                     }
                 }
             }