]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1133, CSPACE-1140: Updated Intake and CollectionObject validation handlers...
authorRichard Millet <richard.millet@berkeley.edu>
Fri, 7 Jan 2011 23:13:35 +0000 (23:13 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Fri, 7 Jan 2011 23:13:35 +0000 (23:13 +0000)
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectValidatorHandler.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeValidatorHandler.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java

index 492de0df430f5fa9563b303142983c22869cce45..8d6db72cd8788ff80fa079742be9a879d87792fa 100644 (file)
-/**
- *  This document is a part of the source code and related artifacts
- *  for CollectionSpace, an open source collections management system
- *  for museums and related institutions:
-
- *  http://www.collectionspace.org
- *  http://wiki.collectionspace.org
-
- *  Copyright 2009 University of California at Berkeley
-
- *  Licensed under the Educational Community License (ECL), Version 2.0.
- *  You may not use this file except in compliance with this License.
-
- *  You may obtain a copy of the ECL 2.0 License at
-
- *  https://source.collectionspace.org/collection-space/LICENSE.txt
-
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *//**
- *  This document is a part of the source code and related artifacts
- *  for CollectionSpace, an open source collections management system
- *  for museums and related institutions:
-
- *  http://www.collectionspace.org
- *  http://wiki.collectionspace.org
-
- *  Copyright 2009 University of California at Berkeley
-
- *  Licensed under the Educational Community License (ECL), Version 2.0.
- *  You may not use this file except in compliance with this License.
-
- *  You may obtain a copy of the ECL 2.0 License at
-
- *  https://source.collectionspace.org/collection-space/LICENSE.txt
-
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.collectionspace.services.collectionobject.nuxeo;
-
-import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
-import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.document.DocumentHandler.Action;
-import org.collectionspace.services.common.document.InvalidDocumentException;
-import org.collectionspace.services.common.document.ValidatorHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author 
- */
-public class CollectionObjectValidatorHandler implements ValidatorHandler {
-
-    final Logger logger = LoggerFactory.getLogger(CollectionObjectValidatorHandler.class);
-
-    @Override
-    public void validate(Action action, ServiceContext ctx)
-            throws InvalidDocumentException {
-        if(logger.isDebugEnabled()) {
-            logger.debug("validate() action=" + action.name());
-        }
-        try {
-            MultipartServiceContext mctx = (MultipartServiceContext) ctx;
-            CollectionobjectsCommon co = (CollectionobjectsCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
-                    CollectionobjectsCommon.class);
-            StringBuilder msgBldr = new StringBuilder("validate()");
-            boolean invalid = false;
-            if (co.getObjectNumber() == null || co.getObjectNumber().isEmpty()) {
-                invalid = true;
-                msgBldr.append("\nobjectNumber : missing");
-            }
-            if(action.equals(Action.CREATE)) {
-                //create specific validation here
-            } else if(action.equals(Action.UPDATE)) {
-                //update specific validation here
-            }
-
-            if (invalid) {
-                String msg = msgBldr.toString();
-                logger.error(msg);
-                throw new InvalidDocumentException(msg);
-            }
-        } catch (InvalidDocumentException ide) {
-            throw ide;
-        } catch (Exception e) {
-            throw new InvalidDocumentException(e);
-        }
-    }
-}
+/**\r
+ *  This document is a part of the source code and related artifacts\r
+ *  for CollectionSpace, an open source collections management system\r
+ *  for museums and related institutions:\r
+\r
+ *  http://www.collectionspace.org\r
+ *  http://wiki.collectionspace.org\r
+\r
+ *  Copyright 2009 University of California at Berkeley\r
+\r
+ *  Licensed under the Educational Community License (ECL), Version 2.0.\r
+ *  You may not use this file except in compliance with this License.\r
+\r
+ *  You may obtain a copy of the ECL 2.0 License at\r
+\r
+ *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
+\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ *//**\r
+ *  This document is a part of the source code and related artifacts\r
+ *  for CollectionSpace, an open source collections management system\r
+ *  for museums and related institutions:\r
+\r
+ *  http://www.collectionspace.org\r
+ *  http://wiki.collectionspace.org\r
+\r
+ *  Copyright 2009 University of California at Berkeley\r
+\r
+ *  Licensed under the Educational Community License (ECL), Version 2.0.\r
+ *  You may not use this file except in compliance with this License.\r
+\r
+ *  You may obtain a copy of the ECL 2.0 License at\r
+\r
+ *  https://source.collectionspace.org/collection-space/LICENSE.txt\r
+\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+/*\r
+ * To change this template, choose Tools | Templates\r
+ * and open the template in the editor.\r
+ */\r
+package org.collectionspace.services.collectionobject.nuxeo;\r
+\r
+import org.collectionspace.services.collectionobject.CollectionobjectsCommon;\r
+//import org.collectionspace.services.common.context.MultipartServiceContext;\r
+//import org.collectionspace.services.common.context.ServiceContext;\r
+import org.collectionspace.services.common.document.InvalidDocumentException;\r
+import org.collectionspace.services.common.document.ValidatorHandlerImpl;\r
+\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ *\r
+ * @author \r
+ */\r
+public class CollectionObjectValidatorHandler extends ValidatorHandlerImpl<MultipartInput, MultipartOutput> {\r
+\r
+    final Logger logger = LoggerFactory.getLogger(CollectionObjectValidatorHandler.class);\r
+\r
+    //\r
+    // Error Strings\r
+    //\r
+    private static final String VALIDATION_ERROR = "The collection object record payload was invalid. See log file for more details.";\r
+    private static final String OBJECTNUMBER_NULL_ERROR = "The collection object field \"objectNumber\" cannot be empty or missing.";\r
+\r
+    @Override\r
+    protected Class<?> getCommonPartClass() {\r
+       return CollectionobjectsCommon.class;\r
+    }\r
+    \r
+       @Override\r
+       protected void handleGet(){\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       protected void handleGetAll() {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       protected void handleUpdate()\r
+                       throws InvalidDocumentException {\r
+       try {\r
+            CollectionobjectsCommon co = (CollectionobjectsCommon) getCommonPart();\r
+            validateCollectionobjectsCommon(co);                        \r
+       } catch (AssertionError e) {\r
+               if (logger.isErrorEnabled() == true) {\r
+                       logger.error(e.getMessage(), e);\r
+               }\r
+               throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
+       }\r
+       }\r
+\r
+       @Override\r
+       protected void handleDelete() {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+    \r
+    @Override\r
+    protected void handleCreate()\r
+               throws InvalidDocumentException {\r
+       try {\r
+            CollectionobjectsCommon co = (CollectionobjectsCommon) getCommonPart();\r
+            validateCollectionobjectsCommon(co);                        \r
+       } catch (AssertionError e) {\r
+               if (logger.isErrorEnabled() == true) {\r
+                       logger.error(e.getMessage(), e);\r
+               }\r
+               throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
+       }\r
+    }\r
+    \r
+    //\r
+    // Private Methods\r
+    //    \r
+    private void validateCollectionobjectsCommon(CollectionobjectsCommon co) throws AssertionError {\r
+        assert(co != null);\r
+        String objectNumber = co.getObjectNumber();\r
+        assert(objectNumber != null);\r
+        assert(objectNumber.isEmpty() == false) : OBJECTNUMBER_NULL_ERROR;\r
+\r
+    }\r
+}\r
index 7656ef1e3f5f8d5c6201641638efd8987b024836..d03640444b11e07101b53a7a98482d62d34e9634 100644 (file)
@@ -1,18 +1,64 @@
 package org.collectionspace.services.intake.nuxeo;\r
 \r
-import org.collectionspace.services.common.context.ServiceContext;\r
 import org.collectionspace.services.common.document.InvalidDocumentException;\r
-import org.collectionspace.services.common.document.ValidatorHandler;\r
-import org.collectionspace.services.common.document.DocumentHandler.Action;\r
+import org.collectionspace.services.common.document.ValidatorHandlerImpl;\r
+import org.collectionspace.services.intake.IntakesCommon;\r
 \r
-public class IntakeValidatorHandler implements ValidatorHandler {\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class IntakeValidatorHandler extends ValidatorHandlerImpl<MultipartInput, MultipartOutput> {\r
+\r
+    /** The logger. */\r
+    private final Logger logger = LoggerFactory.getLogger(IntakeValidatorHandler.class);\r
+    \r
+    /** Error Messages **/\r
+    private static final String VALIDATION_ERROR = "The intake record payload was invalid. See log file for more details.";\r
+    \r
+       \r
+    @Override\r
+    protected Class<?> getCommonPartClass() {\r
+       return IntakesCommon.class;\r
+    }\r
+       \r
+       @Override\r
+       protected void handleCreate() throws InvalidDocumentException {\r
+               try {\r
+                       IntakesCommon intakesCommon = (IntakesCommon)getCommonPart();\r
+                       assert(intakesCommon != null);\r
+       } catch (AssertionError e) {\r
+               if (logger.isErrorEnabled() == true) {\r
+                       logger.error(e.getMessage(), e);\r
+               }\r
+               throw new InvalidDocumentException(VALIDATION_ERROR, e);\r
+       }\r
+       }\r
+\r
+       @Override\r
+       protected void handleGet() throws InvalidDocumentException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+       @Override\r
+       protected void handleGetAll() throws InvalidDocumentException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
 \r
        @Override\r
-       public void validate(Action action, ServiceContext ctx)\r
-                       throws InvalidDocumentException {\r
+       protected void handleUpdate() throws InvalidDocumentException {\r
                // TODO Auto-generated method stub\r
-               System.out.println("IntakeValidatorHandler executed.");\r
+               \r
+       }\r
 \r
+       @Override\r
+       protected void handleDelete() throws InvalidDocumentException {\r
+               // TODO Auto-generated method stub\r
+               \r
        }\r
 \r
 }\r
index 1299076a2d92e7ef59b013de6d3b884b81b7fb0a..01fc0228f612ab091d8f9fcd32183932abc6a1d9 100644 (file)
@@ -2,15 +2,8 @@ package org.collectionspace.services.relation.nuxeo;
 \r
 //import junit.framework.Assert;\r
 \r
-import org.collectionspace.services.common.context.MultipartServiceContext;\r
-import org.collectionspace.services.common.context.ServiceContext;\r
-\r
 import org.collectionspace.services.common.document.InvalidDocumentException;\r
-import org.collectionspace.services.common.document.ValidatorHandler;\r
 import org.collectionspace.services.common.document.ValidatorHandlerImpl;\r
-import org.collectionspace.services.common.document.DocumentHandler.Action;\r
-\r
-import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;\r
 import org.collectionspace.services.relation.RelationsCommon;\r
 \r
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
@@ -27,7 +20,7 @@ public class RelationValidatorHandler extends ValidatorHandlerImpl<MultipartInpu
     \r
     /* Error messages \r
      */\r
-    private static final String VALIDATION_ERROR = "The relation record is invalid. See log file for more details.";\r
+    private static final String VALIDATION_ERROR = "The relation record payload was invalid. See log file for more details.";\r
     private static final String SUBJECT_EQUALS_PREDICATE_ERROR = "The subject ID and object ID cannot be the same.";\r
     \r
     @Override\r
@@ -38,7 +31,6 @@ public class RelationValidatorHandler extends ValidatorHandlerImpl<MultipartInpu
     @Override\r
     protected void handleCreate()\r
                throws InvalidDocumentException{\r
-       ServiceContext<MultipartInput, MultipartOutput> ctx = getServiceContext();\r
        try {\r
                RelationsCommon relationsCommon = (RelationsCommon)getCommonPart();\r
                assert(relationsCommon != null);\r