]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
NOJIRA: Improved error message when post/putting payloads that contain unknown fields.
authorRichard Millet <remillet@yahoo.com>
Fri, 3 Aug 2018 04:58:22 +0000 (21:58 -0700)
committerRichard Millet <remillet@yahoo.com>
Fri, 3 Aug 2018 04:58:22 +0000 (21:58 -0700)
services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java

index 1e74a1848643df3d75e68357cf714b4c7ffc6e65..184d6d75c72458d2275d980cf8516e698952aba1 100644 (file)
@@ -1355,6 +1355,8 @@ public class DocumentUtils {
                        result = loadSchema(schema, document, ctx);
                } catch (IllegalArgumentException iae) {
                        throw iae;
+               } catch (DocumentException de) {
+                   throw de;
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
@@ -1519,9 +1521,16 @@ public class DocumentUtils {
                                while (it.hasNext()) {
                                        org.dom4j.Element el = it.next();
                                        String name = el.getName();
-                                       Object value = getElementData(el,
-                                                       ctype.getField(el.getName()).getType(), ctx);
-                                       map.put(name, value);
+                                       String elementText = el.getTextTrim();
+                                       Field field = ctype.getField(el.getName());
+                                       if (field != null) {
+                                           Object value = getElementData(el, field.getType(), ctx); // Break this up and check for null -i.e., does the field exist
+                           map.put(name, value);
+                                       } else {
+                                           String msg = String.format("Unknown field '%s' in group '%s' with the value '%s'.",
+                                                   name, ctype.getName(), elementText);
+                                           throw new DocumentException(msg);
+                                       }
                                }
                                result = map;
                        }