Standalone TCA with EELF Logger
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-web / src / main / java / org / onap / dcae / analytics / web / validation / GenericValidationResponse.java
1 /*
2  * ================================================================================
3  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  *
18  */
19
20 package org.onap.dcae.analytics.web.validation;
21
22 import lombok.EqualsAndHashCode;
23 import lombok.ToString;
24
25 import java.util.Collection;
26 import java.util.LinkedHashMap;
27 import java.util.Map;
28 import java.util.Set;
29 import java.util.stream.Collectors;
30
31 /**
32  * A generic implementation of Validation Response
33  *
34  * @author Rajiv Singla
35  */
36 @ToString
37 @EqualsAndHashCode
38 public class GenericValidationResponse implements ValidationResponse {
39
40     private static final String DEFAULT_DELIMITER = ",";
41
42     private LinkedHashMap<String, String> errorMessageMap = new LinkedHashMap<>();
43
44     @Override
45     public boolean hasErrors() {
46         return !errorMessageMap.isEmpty();
47     }
48
49     @Override
50     public Set<String> getFieldNamesWithError() {
51         return errorMessageMap.keySet();
52     }
53
54     @Override
55     public Collection<String> getErrorMessages() {
56         return errorMessageMap.values();
57     }
58
59     @Override
60     public Map<String, String> getValidationResultsAsMap() {
61         return errorMessageMap;
62     }
63
64     @Override
65     public String getAllErrorMessage() {
66         return getAllErrorMessage(DEFAULT_DELIMITER);
67     }
68
69     @Override
70     public String getAllErrorMessage(String delimiter) {
71         return errorMessageMap.values()
72                 .stream().collect(Collectors.joining(delimiter));
73     }
74
75     @Override
76     public void addErrorMessage(String fieldName, String filedErrorMessage) {
77         errorMessageMap.put(fieldName, filedErrorMessage);
78     }
79
80 }