ab0881268e4e6a58aa66e447e7468b743db02a7e
[sdc.git] /
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 import org.openecomp.sdc.versioning.dao.types.Version;
22
23 public class DeploymentFlavorErrorBuilder {
24     private static final String CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING_MSG =
25             "Deployment Flavor cannot be added for VSPs onboarded with HEAT.";
26     private static final String FEATURE_GROUP_NOT_EXIST_FOR_VSP_MSG =
27             "Invalid request, Feature Group provided does not exist for this Vsp.";
28     private static final String INVALID_COMPONENT_COMPUTE_ASSOCIATION_MSG
29             = "Invalid request,for valid association please provide ComponentId for Compute Flavor";
30     private static final String SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED_MSG =
31             "Invalid Request,Same Vfc cannot be associated more than once.";
32     private static final String DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED_MSG =
33             "Invalid request, Deployment Flavor with model %s already exists for Vsp with Id %s.";
34     private static final String DEPLOYMENT_FLAVOUR_NAME_FORMAT_MSG = "Field does not conform to predefined criteria"
35             + ": name : must match %s";
36     private static final String INVALID_COMPUTE_FLAVOR_ID_MSG =
37             "Invalid request, Compute Flavor provided does not exist for this VFC.";
38     private static final String INVALID_COMPONENT_ID_MSG =
39             "Invalid request, Component provided does not exist for this VSP.";
40     private static final String INVALID_COMPONENT_COMPUTE_ASSOCIATION_ERROR_MSG="VSP cannot be " +
41             "submitted with an invalid Deployment Flavor. All Deployment Flavor should have atleast a VFC included with it's required Compute needs. " +
42             "Please fix the Deployment Flavor %s and re-submit the VSP.";
43
44     private static final String FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR_MSG = "VSP cannot be " +
45             "submitted with an invalid Deployment Flavor. All Deployment Flavor should have " +
46             "FeatureGroup. Please fix the Deployment Flavor %s and re-submit the VSP.";
47
48     private DeploymentFlavorErrorBuilder(){
49
50     }
51
52     public static ErrorCode getAddDeploymentNotSupportedHeatOnboardErrorBuilder(){
53         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
54         builder.withId(VendorSoftwareProductErrorCodes.CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING);
55         builder.withCategory(ErrorCategory.APPLICATION);
56         builder.withMessage(CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING_MSG);
57         return builder.build();
58     }
59
60     public static ErrorCode getFeatureGroupNotexistErrorBuilder(){
61         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
62         builder.withId(VendorSoftwareProductErrorCodes.FEATURE_GROUP_NOT_EXIST_FOR_VSP);
63         builder.withCategory(ErrorCategory.APPLICATION);
64         builder.withMessage(FEATURE_GROUP_NOT_EXIST_FOR_VSP_MSG);
65         return builder.build();
66     }
67
68     public static ErrorCode getDuplicateVfcAssociationErrorBuilder(){
69         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
70         builder.withId(VendorSoftwareProductErrorCodes
71                 .SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED);
72         builder.withCategory(ErrorCategory.APPLICATION);
73         builder.withMessage(SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED_MSG);
74         return builder.build();
75     }
76
77     public static ErrorCode getInvalidAssociationErrorBuilder() {
78         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
79         builder.withId(VendorSoftwareProductErrorCodes.INVALID_COMPONENT_COMPUTE_ASSOCIATION);
80         builder.withCategory(ErrorCategory.APPLICATION);
81         builder.withMessage(INVALID_COMPONENT_COMPUTE_ASSOCIATION_MSG);
82         return builder.build();
83     }
84
85     public static ErrorCode getDuplicateDeploymentFlavorModelErrorBuilder(String name,
86                                                                           String vspId) {
87         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
88         builder.withId(VendorSoftwareProductErrorCodes.DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED);
89         builder.withCategory(ErrorCategory.APPLICATION);
90         builder.withMessage(String.format(DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED_MSG,name,vspId));
91         return builder.build();
92     }
93
94     public static ErrorCode getInvalidComputeIdErrorBuilder() {
95         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
96         builder.withId(VendorSoftwareProductErrorCodes.INVALID_COMPUTE_FLAVOR_ID);
97         builder.withCategory(ErrorCategory.APPLICATION);
98         builder.withMessage(INVALID_COMPUTE_FLAVOR_ID_MSG);
99         return builder.build();
100     }
101
102     public static ErrorCode getInvalidComponentIdErrorBuilder() {
103         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
104         builder.withId(VendorSoftwareProductErrorCodes.INVALID_COMPONENT_ID);
105         builder.withCategory(ErrorCategory.APPLICATION);
106         builder.withMessage(INVALID_COMPONENT_ID_MSG);
107         return builder.build();
108     }
109
110     public static ErrorCode getInvalidComponentComputeAssociationErrorBuilder(String model) {
111         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
112         builder.withId(VendorSoftwareProductErrorCodes.INVALID_COMPONENT_COMPUTE_ASSOCIATION);
113         builder.withCategory(ErrorCategory.APPLICATION);
114         builder.withMessage(String.format(INVALID_COMPONENT_COMPUTE_ASSOCIATION_ERROR_MSG, model));
115         return builder.build();
116     }
117
118     public static ErrorCode getFeatureGroupMandatoryErrorBuilder(String model) {
119         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
120         builder.withId(VendorSoftwareProductErrorCodes.FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR);
121         builder.withCategory(ErrorCategory.APPLICATION);
122         builder.withMessage(String.format(FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR_MSG, model));
123         return builder.build();
124     }
125
126     public static ErrorCode getDeploymentFlavorNameFormatErrorBuilder(String pattern){
127         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
128         builder.withId(VendorSoftwareProductErrorCodes.DEPLOYMENT_FLAVOR_NAME_FORMAT_NOT_ALLOWED);
129         builder.withCategory(ErrorCategory.APPLICATION);
130         builder.withMessage(String.format(DEPLOYMENT_FLAVOUR_NAME_FORMAT_MSG, pattern));
131         return builder.build();
132     }
133 }