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