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 org.openecomp.sdc.common.errors.BaseErrorBuilder;
24 import org.openecomp.sdc.common.errors.ErrorCategory;
25 import org.openecomp.sdc.datatypes.error.ErrorMessage;
27 import java.util.List;
30 public class ValidationInvalidErrorBuilder extends BaseErrorBuilder {
31 private static final String VALIDATION_INVALID_DETAILED_MSG = "File is invalid: %s";
32 private static final String VALIDATION_INVALID_MSG = "Validated file is invalid";
35 * Instantiates a new Validation invalid error builder.
37 * @param errors the errors
39 public ValidationInvalidErrorBuilder(Map<String, List<ErrorMessage>> errors) {
40 getErrorCodeBuilder().withId(ValidationErrorCodes.VALIDATION_INVALID);
41 getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
43 .withMessage(String.format(VALIDATION_INVALID_DETAILED_MSG, toString(errors)));
47 * Instantiates a new Validation invalid error builder.
49 public ValidationInvalidErrorBuilder() {
50 getErrorCodeBuilder().withId(ValidationErrorCodes.VALIDATION_INVALID);
51 getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
52 getErrorCodeBuilder().withMessage(VALIDATION_INVALID_MSG);
55 private String toString(Map<String, List<ErrorMessage>> errors) {
56 StringBuffer sb = new StringBuffer();
57 errors.entrySet().stream()
58 .forEach(entry -> singleErrorToString(sb, entry.getKey(), entry.getValue()));
62 private void singleErrorToString(StringBuffer sb, String fileName, List<ErrorMessage> errors) {
63 sb.append(System.lineSeparator());
65 sb.append(sb.append(": "));
66 errors.stream().forEach(
67 error -> sb.append(error.getMessage()).append("[").append(error.getLevel()).append("], "));