768c18bd0050fc574392daccf145f8df9829917f
[aai/aai-common.git] / aai-schema-ingest / src / main / java / org / onap / aai / validation / CheckEverythingStrategy.java
1 /** 
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 /**
22  * 
23  */
24 package org.onap.aai.validation;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.apache.commons.lang.StringUtils;
30
31 /**
32  * When an error is found, mark that it is NOT ok to 
33  * continue with installation/whatever other caller function, 
34  * and keep track of the message but
35  * keep validating so all issues are found in one run.
36  */
37 public class CheckEverythingStrategy implements SchemaErrorStrategy {
38         private boolean isOK = true;
39         private List<String> errorMsgs = new ArrayList<>();
40
41         /* (non-Javadoc)
42          * @see org.onap.aai.edges.validation.SchemaErrorStrategy#isOK()
43          */
44         @Override
45         public boolean isOK() {
46                 return isOK;
47         }
48
49         /* (non-Javadoc)
50          * @see org.onap.aai.edges.validation.SchemaErrorStrategy#getErrorMsg()
51          */
52         @Override
53         public String getErrorMsg() {
54                 if (errorMsgs.isEmpty()) {
55                         return "No errors found.";
56                 } else {
57                         return StringUtils.join(errorMsgs, "\n");
58                 }
59         }
60
61         /* (non-Javadoc)
62          * @see org.onap.aai.edges.validation.SchemaErrorStrategy#notifyOnError(java.lang.String)
63          */
64         @Override
65         public void notifyOnError(String errorMsg) {
66                 isOK = false;
67                 errorMsgs.add(errorMsg);
68         }
69
70 }