Add collaboration feature
[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 org.openecomp.sdc.common.errors.ErrorCategory;
4 import org.openecomp.sdc.common.errors.ErrorCode;
5
6 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_IMAGE_NAME_NOT_ALLOWED;
7 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.DUPLICATE_IMAGE_VERSION_NOT_ALLOWED;
8 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.IMAGE_NAME_FORMAT_NOT_ALLOWED;
9 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.UPDATE_IMAGE_NOT_ALLOWED;
10 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.VFC_IMAGE_INVALID_FORMAT;
11
12 /**
13  * The Image error builder.
14  */
15 public class ImageErrorBuilder {
16
17   private static final String VFC_IMAGE_DUPLICATE_NAME_MSG = "Invalid request, Image with name %s"
18       + " already exists for component with ID %s.";
19   private static final String VFC_IMAGE_NAME_FORMAT_MSG = "Field does not conform to predefined criteria"
20           + ": name : must match %s";
21   private static final String IMAGE_INVALID_FORMAT_MSG = "The format value doesn't meet the "
22       + "expected attribute value.";
23
24   private static final String IMAGE_HEAT_READONLY_ATTR_MSG = "Update of attribute %s not allowed "
25       + "for VSP onboarded via HEAT.";
26   private static final String VFC_IMAGE_DUPLICATE_VERSION_MSG = "Invalid request, Image with version %s"
27           + " already exists for component with ID %s.";
28
29
30   /**
31    * Gets duplicate image name error builder.
32    *
33    * @return the duplicate image name error builder
34    */
35   public static ErrorCode getDuplicateImageNameErrorBuilder(String imageName, String componentId) {
36     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
37     builder.withId(DUPLICATE_IMAGE_NAME_NOT_ALLOWED);
38     builder.withCategory(ErrorCategory.APPLICATION);
39     builder.withMessage(String.format(VFC_IMAGE_DUPLICATE_NAME_MSG, imageName, componentId ));
40     return builder.build();
41   }
42
43   /**
44    * Gets duplicate image version error builder.
45    *
46    * @return the duplicate image version error builder
47    */
48   public static ErrorCode getDuplicateImageVersionErrorBuilder(String version, String componentId) {
49     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
50     builder.withId(DUPLICATE_IMAGE_VERSION_NOT_ALLOWED);
51     builder.withCategory(ErrorCategory.APPLICATION);
52     builder.withMessage(String.format(VFC_IMAGE_DUPLICATE_VERSION_MSG, version, componentId ));
53     return builder.build();
54   }
55   /**
56    * Gets image name format error builder.
57    *
58    * @return the image name format error builder
59    */
60   public static ErrorCode getImageNameFormatErrorBuilder(String pattern) {
61     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
62     builder.withId(IMAGE_NAME_FORMAT_NOT_ALLOWED);
63     builder.withCategory(ErrorCategory.APPLICATION);
64     builder.withMessage(String.format(VFC_IMAGE_NAME_FORMAT_MSG, pattern));
65     return builder.build();
66   }
67
68   /**
69    * Gets invalid image format error builder.
70    *
71    * @return the invalid image format error builder
72    */
73   public static ErrorCode getInvalidImageFormatErrorBuilder() {
74     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
75     builder.withId(VFC_IMAGE_INVALID_FORMAT);
76     builder.withCategory(ErrorCategory.APPLICATION);
77     builder.withMessage(String.format(IMAGE_INVALID_FORMAT_MSG));
78     return builder.build();
79   }
80
81   public static ErrorCode getImageHeatReadOnlyErrorBuilder(String name) {
82     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
83     builder.withId(UPDATE_IMAGE_NOT_ALLOWED);
84     builder.withCategory(ErrorCategory.APPLICATION);
85     builder.withMessage(String.format(IMAGE_HEAT_READONLY_ATTR_MSG, name));
86     return builder.build();
87   }
88 }