]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
f76b28867366e9ebd1834c471e210a3354c35d7f
[tmp/jakarta-migration.git] /
1 /*
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Licensed under the Educational Community License (ECL), Version 2.0.
10  * You may not use this file except in compliance with this License.
11  *
12  * You may obtain a copy of the ECL 2.0 License at
13  * https://source.collectionspace.org/collection-space/LICENSE.txt
14  */
15 package org.collectionspace.services.nagpraclaim.nuxeo;
16
17 import org.collectionspace.services.client.PoxPayloadIn;
18 import org.collectionspace.services.client.PoxPayloadOut;
19 import org.collectionspace.services.common.document.InvalidDocumentException;
20 import org.collectionspace.services.common.document.ValidatorHandlerImpl;
21 import org.collectionspace.services.nagpraclaim.NagpraclaimsCommon;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * Validation handler for NagpraClaim. Checks for the common part and claimNumber on create.
27  */
28 public class NagpraClaimValidatorHandler extends ValidatorHandlerImpl<PoxPayloadIn, PoxPayloadOut> {
29
30     private static final String COMMON_PART_MISSING = "Validation exception: nagpraclaims_common part is missing";
31     private static final String CLAIM_NUMBER_MISSING =
32             "Validation exception: The nagpra claim field \"claimNumber\" cannot be empty or missing";
33
34     private final Logger logger = LoggerFactory.getLogger(NagpraClaimValidatorHandler.class);
35
36     @Override
37     protected Class<?> getCommonPartClass() {
38         return NagpraclaimsCommon.class;
39     }
40
41     @Override
42     protected void handleCreate() throws InvalidDocumentException {
43         final NagpraclaimsCommon claim = (NagpraclaimsCommon) getCommonPart();
44         if (claim == null) {
45             logger.error(COMMON_PART_MISSING);
46             throw new InvalidDocumentException(COMMON_PART_MISSING);
47         }
48
49         final String claimNumber = claim.getClaimNumber();
50         if (claimNumber == null || claimNumber.isEmpty()) {
51             logger.error(CLAIM_NUMBER_MISSING);
52             throw new InvalidDocumentException(CLAIM_NUMBER_MISSING);
53         }
54     }
55
56     @Override
57     protected void handleGet() {}
58
59     @Override
60     protected void handleGetAll() {}
61
62     @Override
63     protected void handleUpdate() {}
64
65     @Override
66     protected void handleDelete() {}
67 }