2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.validation.errors;
23 import static org.openecomp.sdc.validation.errors.ValidationErrorCodes.VALIDATION_INVALID;
25 import org.openecomp.sdc.common.errors.BaseErrorBuilder;
26 import org.openecomp.sdc.common.errors.ErrorCategory;
27 import org.openecomp.sdc.datatypes.error.ErrorMessage;
29 import java.util.List;
33 * The type Validation invalid error builder.
35 public class ValidationInvalidErrorBuilder extends BaseErrorBuilder {
36 private static final String VALIDATION_INVALID_DETAILED_MSG = "File is invalid: %s";
37 private static final String VALIDATION_INVALID_MSG = "Validated file is invalid";
40 * Instantiates a new Validation invalid error builder.
42 * @param errors the errors
44 public ValidationInvalidErrorBuilder(Map<String, List<ErrorMessage>> errors) {
45 getErrorCodeBuilder().withId(VALIDATION_INVALID);
46 getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
48 .withMessage(String.format(VALIDATION_INVALID_DETAILED_MSG, toString(errors)));
52 * Instantiates a new Validation invalid error builder.
54 public ValidationInvalidErrorBuilder() {
55 getErrorCodeBuilder().withId(VALIDATION_INVALID);
56 getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
57 getErrorCodeBuilder().withMessage(VALIDATION_INVALID_MSG);
60 private String toString(Map<String, List<ErrorMessage>> errors) {
61 StringBuffer sb = new StringBuffer();
62 errors.entrySet().stream()
63 .forEach(entry -> singleErrorToString(sb, entry.getKey(), entry.getValue()));
67 private void singleErrorToString(StringBuffer sb, String fileName, List<ErrorMessage> errors) {
68 sb.append(System.lineSeparator());
70 sb.append(sb.append(": "));
71 errors.stream().forEach(
72 error -> sb.append(error.getMessage()).append("[").append(error.getLevel()).append("], "));