c3a2862e398c35d41218303c86c6302b8927fdc6
[sdc.git] /
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
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 VendorSoftwareProductInvalidErrorBuilder {
24   private static final String VSP_INVALID_MSG =
25       "Vendor software product with Id %s and version %s is invalid - does not contain "
26           + "service model.";
27   private static final String VSP_INVALID_MISSING_DEPLOYMENT_FLAVOR_MSG = "VSP has to have a "
28       + "minimum of one Deployment Flavor defined for being able to be instantiated.Please add a "
29       + "Deployment Flavor and re-submit the VSP.";
30   private static final String CANDIDATE_DATA_NOT_PROCESSED_OR_ABORTED = "Uploaded network package"
31       + " file %s was not processed/aborted.";
32   private static final String INVALID_PROCESSED_CANDIDATE = "Uploaded network package file %s"
33       + " is invalid and need to be aborted";
34
35   private VendorSoftwareProductInvalidErrorBuilder() {
36
37   }
38
39   /**
40    * Instantiates a new Vendor software product invalid error builder.
41    *
42    * @param vendorSoftwareProductId the vendor software product id
43    * @param version                 the version
44    */
45   public static ErrorCode vendorSoftwareProductMissingServiceModelErrorBuilder(String
46                                                                                    vendorSoftwareProductId,
47                                                                                Version version) {
48     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
49     builder.withId(VendorSoftwareProductErrorCodes.VSP_INVALID);
50     builder.withCategory(ErrorCategory.APPLICATION);
51     builder
52         .withMessage(String.format(VSP_INVALID_MSG, vendorSoftwareProductId, version.getId()));
53     return builder.build();
54   }
55
56   /**
57    * Instantiates a new Vendor software product invalid error builder.
58    */
59   public static ErrorCode vspMissingDeploymentFlavorErrorBuilder() {
60     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
61     builder.withId(VendorSoftwareProductErrorCodes.VSP_INVALID);
62     builder.withCategory(ErrorCategory.APPLICATION);
63     builder
64         .withMessage(VSP_INVALID_MISSING_DEPLOYMENT_FLAVOR_MSG);
65     return builder.build();
66   }
67
68   public static ErrorCode candidateDataNotProcessedOrAbortedErrorBuilder(String fileName) {
69     ErrorCode.ErrorCodeBuilder builder = getErrorCodeBuilder(VendorSoftwareProductErrorCodes
70         .VSP_INVALID, ErrorCategory.APPLICATION);
71     builder.withMessage(String.format(CANDIDATE_DATA_NOT_PROCESSED_OR_ABORTED, fileName));
72     return builder.build();
73   }
74
75   public static ErrorCode invalidProcessedCandidate(String fileName) {
76     ErrorCode.ErrorCodeBuilder builder = getErrorCodeBuilder(VendorSoftwareProductErrorCodes
77         .VSP_INVALID, ErrorCategory.APPLICATION);
78     builder.withMessage(String.format(INVALID_PROCESSED_CANDIDATE, fileName));
79     return builder.build();
80   }
81
82   public static ErrorCode.ErrorCodeBuilder getErrorCodeBuilder(String errorCode, ErrorCategory
83       errorCategory) {
84     ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
85     builder.withId(errorCode);
86     builder.withCategory(errorCategory);
87     return builder;
88   }
89 }