re base code
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / errors / ImageErrorBuilder.java
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.vendorsoftwareproduct.errors;
18
19 import org.openecomp.sdc.common.errors.ErrorCategory;
20 import org.openecomp.sdc.common.errors.ErrorCode;
21
22 import static org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes.*;
23
24 /**
25  * The Image error builder.
26  */
27 public class ImageErrorBuilder {
28
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.";
35
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() {
41
42   }
43
44   /**
45    * Gets duplicate image name error builder.
46    *
47    * @return the duplicate image name error builder
48    */
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();
55   }
56
57   /**
58    * Gets duplicate image version error builder.
59    *
60    * @return the duplicate image version error builder
61    */
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();
68   }
69   /**
70    * Gets image name format error builder.
71    *
72    * @return the image name format error builder
73    */
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();
80   }
81
82   /**
83    * Gets invalid image format error builder.
84    *
85    * @return the invalid image format error builder
86    */
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();
93   }
94
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();
101   }
102 }