-/**
- * 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
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