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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcae.analytics.web.validation;
22 import lombok.EqualsAndHashCode;
23 import lombok.ToString;
25 import java.util.Collection;
26 import java.util.LinkedHashMap;
29 import java.util.stream.Collectors;
32 * A generic implementation of Validation Response
34 * @author Rajiv Singla
38 public class GenericValidationResponse implements ValidationResponse {
40 private static final String DEFAULT_DELIMITER = ",";
42 private LinkedHashMap<String, String> errorMessageMap = new LinkedHashMap<>();
45 public boolean hasErrors() {
46 return !errorMessageMap.isEmpty();
50 public Set<String> getFieldNamesWithError() {
51 return errorMessageMap.keySet();
55 public Collection<String> getErrorMessages() {
56 return errorMessageMap.values();
60 public Map<String, String> getValidationResultsAsMap() {
61 return errorMessageMap;
65 public String getAllErrorMessage() {
66 return getAllErrorMessage(DEFAULT_DELIMITER);
70 public String getAllErrorMessage(String delimiter) {
71 return errorMessageMap.values()
72 .stream().collect(Collectors.joining(delimiter));
76 public void addErrorMessage(String fieldName, String filedErrorMessage) {
77 errorMessageMap.put(fieldName, filedErrorMessage);