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 org.openecomp.sdc.common.errors.BaseErrorBuilder;
24 import org.openecomp.sdc.common.errors.ErrorCategory;
25 import org.openecomp.sdc.datatypes.error.ErrorMessage;
26 import org.openecomp.sdc.versioning.dao.types.Version;
28 import java.util.List;
31 public class UploadInvalidErrorBuilder extends BaseErrorBuilder {
32 private static final String UPLOAD_INVALID_DETAILED_MSG =
33 "File uploaded for vendor software product with Id %s and version %s is invalid: %s";
34 private static final String UPLOAD_INVALID_MSG = "Uploaded file is invalid";
37 * Instantiates a new Upload invalid error builder.
39 * @param vendorSoftwareProductId the vendor software product id
40 * @param version the version
41 * @param errors the errors
43 public UploadInvalidErrorBuilder(String vendorSoftwareProductId, Version version,
44 Map<String, List<ErrorMessage>> errors) {
45 getErrorCodeBuilder().withId(VendorSoftwareProductErrorCodes.UPLOAD_INVALID);
46 getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
47 getErrorCodeBuilder().withMessage(String
48 .format(UPLOAD_INVALID_DETAILED_MSG, vendorSoftwareProductId, version.toString(),
53 * Instantiates a new Upload invalid error builder.
55 public UploadInvalidErrorBuilder() {
56 getErrorCodeBuilder().withId(VendorSoftwareProductErrorCodes.UPLOAD_INVALID);
57 getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
58 getErrorCodeBuilder().withMessage(UPLOAD_INVALID_MSG);
61 private String toString(Map<String, List<ErrorMessage>> errors) {
62 StringBuffer sb = new StringBuffer();
63 errors.entrySet().stream()
64 .forEach(entry -> singleErrorToString(sb, entry.getKey(), entry.getValue()));
68 private void singleErrorToString(StringBuffer sb, String fileName, List<ErrorMessage> errors) {
69 sb.append(System.lineSeparator());
71 sb.append(sb.append(": "));
72 errors.stream().forEach(
73 error -> sb.append(error.getMessage()).append("[").append(error.getLevel()).append("], "));