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.DUPLICATE_IMAGE_NAME_NOT_ALLOWED;
23 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_IMAGE_VERSION_NOT_ALLOWED;
24 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.IMAGE_NAME_FORMAT_NOT_ALLOWED;
25 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.UPDATE_IMAGE_NOT_ALLOWED;
26 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.VFC_IMAGE_INVALID_FORMAT;
29 * The Image error builder.
31 public class ImageErrorBuilder {
33 private static final String VFC_IMAGE_DUPLICATE_NAME_MSG = "Invalid request, Image with name %s"
34 + " already exists for component with ID %s.";
35 private static final String VFC_IMAGE_NAME_FORMAT_MSG = "Field does not conform to predefined criteria"
36 + ": name : must match %s";
37 private static final String IMAGE_INVALID_FORMAT_MSG = "The format value doesn't meet the "
38 + "expected attribute value.";
40 private static final String IMAGE_HEAT_READONLY_ATTR_MSG = "Update of attribute %s not allowed "
41 + "for VSP onboarded via HEAT.";
42 private static final String VFC_IMAGE_DUPLICATE_VERSION_MSG = "Invalid request, Image with version %s"
43 + " already exists for component with ID %s.";
44 private ImageErrorBuilder() {
49 * Gets duplicate image name error builder.
51 * @return the duplicate image name error builder
53 public static ErrorCode getDuplicateImageNameErrorBuilder(String imageName, String componentId) {
54 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
55 builder.withId(DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
56 builder.withCategory(ErrorCategory.APPLICATION);
57 builder.withMessage(String.format(VFC_IMAGE_DUPLICATE_NAME_MSG, imageName, componentId ));
58 return builder.build();
62 * Gets duplicate image version error builder.
64 * @return the duplicate image version error builder
66 public static ErrorCode getDuplicateImageVersionErrorBuilder(String version, String componentId) {
67 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
68 builder.withId(DUPLICATE_IMAGE_VERSION_NOT_ALLOWED);
69 builder.withCategory(ErrorCategory.APPLICATION);
70 builder.withMessage(String.format(VFC_IMAGE_DUPLICATE_VERSION_MSG, version, componentId ));
71 return builder.build();
74 * Gets image name format error builder.
76 * @return the image name format error builder
78 public static ErrorCode getImageNameFormatErrorBuilder(String pattern) {
79 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
80 builder.withId(IMAGE_NAME_FORMAT_NOT_ALLOWED);
81 builder.withCategory(ErrorCategory.APPLICATION);
82 builder.withMessage(String.format(VFC_IMAGE_NAME_FORMAT_MSG, pattern));
83 return builder.build();
87 * Gets invalid image format error builder.
89 * @return the invalid image format error builder
91 public static ErrorCode getInvalidImageFormatErrorBuilder() {
92 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
93 builder.withId(VFC_IMAGE_INVALID_FORMAT);
94 builder.withCategory(ErrorCategory.APPLICATION);
95 builder.withMessage(IMAGE_INVALID_FORMAT_MSG);
96 return builder.build();
99 public static ErrorCode getImageHeatReadOnlyErrorBuilder(String name) {
100 ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
101 builder.withId(UPDATE_IMAGE_NOT_ALLOWED);
102 builder.withCategory(ErrorCategory.APPLICATION);
103 builder.withMessage(String.format(IMAGE_HEAT_READONLY_ATTR_MSG, name));
104 return builder.build();