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.vendorsoftwareproduct.errors;
23 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes
26 import org.openecomp.sdc.common.errors.BaseErrorBuilder;
27 import org.openecomp.sdc.common.errors.ErrorCategory;
28 import org.openecomp.sdc.datatypes.error.ErrorMessage;
29 import org.openecomp.sdc.versioning.dao.types.Version;
31 import java.util.List;
35 * The type Upload invalid error builder.
37 public class UploadInvalidErrorBuilder extends BaseErrorBuilder {
38 private static final String UPLOAD_INVALID_DETAILED_MSG =
39 "File uploaded for vendor software product with Id %s and version %s is invalid: %s";
40 private static final String UPLOAD_INVALID_MSG = "Uploaded file is invalid";
43 * Instantiates a new Upload invalid error builder.
45 * @param vendorSoftwareProductId the vendor software product id
46 * @param version the version
47 * @param errors the errors
49 public UploadInvalidErrorBuilder(String vendorSoftwareProductId, Version version,
50 Map<String, List<ErrorMessage>> errors) {
51 getErrorCodeBuilder().withId(UPLOAD_INVALID);
52 getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
53 getErrorCodeBuilder().withMessage(String
54 .format(UPLOAD_INVALID_DETAILED_MSG, vendorSoftwareProductId, version.toString(),
59 * Instantiates a new Upload invalid error builder.
61 public UploadInvalidErrorBuilder() {
62 getErrorCodeBuilder().withId(UPLOAD_INVALID);
63 getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
64 getErrorCodeBuilder().withMessage(UPLOAD_INVALID_MSG);
67 private String toString(Map<String, List<ErrorMessage>> errors) {
68 StringBuffer sb = new StringBuffer();
69 errors.entrySet().stream()
70 .forEach(entry -> singleErrorToString(sb, entry.getKey(), entry.getValue()));
74 private void singleErrorToString(StringBuffer sb, String fileName, List<ErrorMessage> errors) {
75 sb.append(System.lineSeparator());
77 sb.append(sb.append(": "));
78 errors.stream().forEach(
79 error -> sb.append(error.getMessage()).append("[").append(error.getLevel()).append("], "));