Improve error's message readability
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / errors / VendorSoftwareProductInvalidErrorBuilder.java
1 /*
2  * Copyright © 2016-2018 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 package org.openecomp.sdc.vendorsoftwareproduct.errors;
17
18 import lombok.AccessLevel;
19 import lombok.NoArgsConstructor;
20 import org.openecomp.sdc.common.errors.ErrorCategory;
21 import org.openecomp.sdc.common.errors.ErrorCode;
22 import org.openecomp.sdc.versioning.dao.types.Version;
23
24 @NoArgsConstructor(access = AccessLevel.PRIVATE)
25 public class VendorSoftwareProductInvalidErrorBuilder {
26
27     private static final String VSP_INVALID_MSG = "Vendor software product with Id %s and version %s is invalid - does not contain service model.";
28     private static final String VSP_INVALID_MISSING_DEPLOYMENT_FLAVOR_MSG = "VSP has to have a minimum of one Deployment Flavor defined for being able to be instantiated.Please add a Deployment Flavor and re-submit the VSP.";
29     private static final String CANDIDATE_DATA_NOT_PROCESSED_OR_ABORTED = "Uploaded network package file %s was not processed/aborted.";
30     private static final String INVALID_PROCESSED_CANDIDATE = "Uploaded network package file %s is invalid and need to be aborted";
31
32     /**
33      * Instantiates a new Vendor software product invalid error builder.
34      *
35      * @param vendorSoftwareProductId the vendor software product id
36      * @param version                 the version
37      */
38     public static ErrorCode vendorSoftwareProductMissingServiceModelErrorBuilder(String vendorSoftwareProductId, Version version) {
39         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
40         builder.withId(VendorSoftwareProductErrorCodes.VSP_INVALID);
41         builder.withCategory(ErrorCategory.APPLICATION);
42         builder.withMessage(String.format(VSP_INVALID_MSG, vendorSoftwareProductId, version.getId()));
43         return builder.build();
44     }
45
46     /**
47      * Instantiates a new Vendor software product invalid error builder.
48      */
49     public static ErrorCode vspMissingDeploymentFlavorErrorBuilder() {
50         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
51         builder.withId(VendorSoftwareProductErrorCodes.VSP_INVALID);
52         builder.withCategory(ErrorCategory.APPLICATION);
53         builder.withMessage(VSP_INVALID_MISSING_DEPLOYMENT_FLAVOR_MSG);
54         return builder.build();
55     }
56
57     public static ErrorCode candidateDataNotProcessedOrAbortedErrorBuilder(String fileName) {
58         ErrorCode.ErrorCodeBuilder builder = getErrorCodeBuilder(VendorSoftwareProductErrorCodes.VSP_INVALID, ErrorCategory.APPLICATION);
59         builder.withMessage(String.format(CANDIDATE_DATA_NOT_PROCESSED_OR_ABORTED, fileName));
60         return builder.build();
61     }
62
63     public static ErrorCode invalidProcessedCandidate(String fileName) {
64         ErrorCode.ErrorCodeBuilder builder = getErrorCodeBuilder(VendorSoftwareProductErrorCodes.VSP_INVALID, ErrorCategory.APPLICATION);
65         builder.withMessage(String.format(INVALID_PROCESSED_CANDIDATE, fileName));
66         return builder.build();
67     }
68
69     public static ErrorCode.ErrorCodeBuilder getErrorCodeBuilder(String errorCode, ErrorCategory errorCategory) {
70         ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
71         builder.withId(errorCode);
72         builder.withCategory(errorCategory);
73         return builder;
74     }
75 }