]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0bd4dd9345a3100eee565718d24d742dc09aa69d
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.movement.nuxeo;
2
3 import java.util.List;
4
5 import org.collectionspace.services.common.context.ServiceContext;
6 import org.collectionspace.services.common.context.MultipartServiceContext;
7 import org.collectionspace.services.common.datetime.DateTimeFormatUtils;
8 import org.collectionspace.services.common.document.InvalidDocumentException;
9 import org.collectionspace.services.common.document.ValidatorHandler;
10 import org.collectionspace.services.common.document.DocumentHandler.Action;
11 import org.collectionspace.services.movement.MovementsCommon;
12
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 public class MovementValidatorHandler implements ValidatorHandler {
17
18         final Logger logger = LoggerFactory.getLogger(MovementValidatorHandler.class);
19
20         @Override
21         public void validate(Action action, ServiceContext ctx)
22                         throws InvalidDocumentException {
23
24                 if(logger.isDebugEnabled()) {
25                     logger.debug("validate() action=" + action.name());
26                 }
27                 try {
28                     MultipartServiceContext mctx = (MultipartServiceContext) ctx;
29                     MovementsCommon mc = (MovementsCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
30                             MovementsCommon.class);
31                     StringBuilder msgBldr = new StringBuilder("validate()");
32                     boolean invalid = false;
33
34                     List<String> patterns = DateTimeFormatUtils.getDateFormatPatternsForTenant(ctx);
35
36                     // FIXME: This is an early proof-of-concept.
37                     //
38                     // We need a better way of determining which fields
39                     // in the incoming payload are date fields whose values we
40                     // might wish to validate, and of extracting their values,
41                     // than hard-coding them here.
42
43                     /*
44                     boolean validDateFormat = false;
45                     String locDate = mc.getLocationDate();
46                     for (String pattern : patterns) {
47                         if (DateTimeFormatUtils.isParseableByDatePattern(locDate, pattern)) {
48                             validDateFormat = true;
49                         }
50                     }
51                     if (! validDateFormat) {
52                         invalid = true;
53                         msgBldr.append("\nlocationDate : unrecognized date format '" + locDate + "'");
54                     }
55                     *
56                     */
57
58                     if(action.equals(Action.CREATE)) {
59                         //create specific validation here
60                     } else if(action.equals(Action.UPDATE)) {
61                         //update specific validation here
62                     }
63
64                     if (invalid) {
65                         String msg = msgBldr.toString();
66                         logger.error(msg);
67                         throw new InvalidDocumentException(msg);
68                     }
69                 } catch (InvalidDocumentException ide) {
70                     throw ide;
71                 } catch (Exception e) {
72                     throw new InvalidDocumentException(e);
73                 }
74
75         }
76
77 }