2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.vendorsoftwareproduct.errors;
19 import org.openecomp.sdc.common.errors.ErrorCategory;
20 import org.openecomp.sdc.common.errors.ErrorCode;
22 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.*;
25 * The Image error builder.
27 public class ImageErrorBuilder {
29 private static final String VFC_IMAGE_DUPLICATE_NAME_MSG = "Invalid request, Image with name %s"
30 + " already exists for component with ID %s.";
31 private static final String VFC_IMAGE_NAME_FORMAT_MSG = "Field does not conform to predefined criteria"
32 + ": name : must match %s";
33 private static final String IMAGE_INVALID_FORMAT_MSG = "The format value doesn't meet the "
34 + "expected attribute value.";
36 private static final String IMAGE_HEAT_READONLY_ATTR_MSG = "Update of attribute %s not allowed "
37 + "for VSP onboarded via HEAT.";
38 private static final String VFC_IMAGE_DUPLICATE_VERSION_MSG = "Invalid request, Image with version %s"
39 + " already exists for component with ID %s.";
40 private ImageErrorBuilder() {
45 * Gets duplicate image name error builder.
47 * @return the duplicate image name error builder
49 public static ErrorCode getDuplicateImageNameErrorBuilder(String imageName, String componentId) {
50 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
51 builder.withId(DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
52 builder.withCategory(ErrorCategory.APPLICATION);
53 builder.withMessage(String.format(VFC_IMAGE_DUPLICATE_NAME_MSG, imageName, componentId ));
54 return builder.build();
58 * Gets duplicate image version error builder.
60 * @return the duplicate image version error builder
62 public static ErrorCode getDuplicateImageVersionErrorBuilder(String version, String componentId) {
63 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
64 builder.withId(DUPLICATE_IMAGE_VERSION_NOT_ALLOWED);
65 builder.withCategory(ErrorCategory.APPLICATION);
66 builder.withMessage(String.format(VFC_IMAGE_DUPLICATE_VERSION_MSG, version, componentId ));
67 return builder.build();
70 * Gets image name format error builder.
72 * @return the image name format error builder
74 public static ErrorCode getImageNameFormatErrorBuilder(String pattern) {
75 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
76 builder.withId(IMAGE_NAME_FORMAT_NOT_ALLOWED);
77 builder.withCategory(ErrorCategory.APPLICATION);
78 builder.withMessage(String.format(VFC_IMAGE_NAME_FORMAT_MSG, pattern));
79 return builder.build();
83 * Gets invalid image format error builder.
85 * @return the invalid image format error builder
87 public static ErrorCode getInvalidImageFormatErrorBuilder() {
88 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
89 builder.withId(VFC_IMAGE_INVALID_FORMAT);
90 builder.withCategory(ErrorCategory.APPLICATION);
91 builder.withMessage(IMAGE_INVALID_FORMAT_MSG);
92 return builder.build();
95 public static ErrorCode getImageHeatReadOnlyErrorBuilder(String name) {
96 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
97 builder.withId(UPDATE_IMAGE_NOT_ALLOWED);
98 builder.withCategory(ErrorCategory.APPLICATION);
99 builder.withMessage(String.format(IMAGE_HEAT_READONLY_ATTR_MSG, name));
100 return builder.build();