[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / errors / ImageErrorBuilder.java
1 package org.openecomp.sdc.vendorsoftwareproduct.errors;
2
3 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_IMAGE_NAME_NOT_ALLOWED;
4
5 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.UPDATE_IMAGE_NOT_ALLOWED;
6 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.VFC_IMAGE_INVALID_FORMAT;
7
8 import org.openecomp.sdc.common.errors.ErrorCategory;
9 import org.openecomp.sdc.common.errors.ErrorCode;
10
11 /**
12  * The Image error builder.
13  */
14 public class ImageErrorBuilder {
15
16   private static final String VFC_IMAGE_DUPLICATE_NAME_MSG = "Invalid request, Image with name %s"
17       + " already exists for component with ID %s.";
18
19   private static final String IMAGE_INVALID_FORMAT_MSG = "The format value doesn't meet the "
20       + "expected attribute value.";
21
22   private static final String IMAGE_HEAT_READONLY_ATTR_MSG = "Update of attribute %s not allowed "
23       + "for VSP onboarded via HEAT.";
24
25
26   /**
27    * Gets duplicate image name error builder.
28    *
29    * @return the duplicate image name error builder
30    */
31   public static ErrorCode getDuplicateImageNameErrorBuilder(String imageName, String componenetId) {
32     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
33     builder.withId(DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
34     builder.withCategory(ErrorCategory.APPLICATION);
35     builder.withMessage(String.format(VFC_IMAGE_DUPLICATE_NAME_MSG, imageName, componenetId ));
36     return builder.build();
37   }
38
39   /**
40    * Gets invalid image format error builder.
41    *
42    * @return the invalid image format error builder
43    */
44   public static ErrorCode getInvalidImageFormatErrorBuilder() {
45     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
46     builder.withId(VFC_IMAGE_INVALID_FORMAT);
47     builder.withCategory(ErrorCategory.APPLICATION);
48     builder.withMessage(String.format(IMAGE_INVALID_FORMAT_MSG));
49     return builder.build();
50   }
51
52   public static ErrorCode getImageHeatReadOnlyErrorBuilder(String name) {
53     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
54     builder.withId(UPDATE_IMAGE_NOT_ALLOWED);
55     builder.withCategory(ErrorCategory.APPLICATION);
56     builder.withMessage(String.format(IMAGE_HEAT_READONLY_ATTR_MSG, name));
57     return builder.build();
58   }
59 }