330a2dd4d1f9151ca6618c28b7e8aecfbbc87642
[sdc.git] /
1 /*
2  * -
3  *  ============LICENSE_START=======================================================
4  *  Copyright (C) 2022 Nordix Foundation.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdcrests.vendorlicense.rest.exception;
23
24 import static org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes.VLM_IS_CERTIFIED_DELETE_ERROR;
25 import static org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes.VLM_IS_IN_USE_DELETE_ERROR;
26
27 import java.util.List;
28 import java.util.function.Supplier;
29 import lombok.AccessLevel;
30 import lombok.NoArgsConstructor;
31 import org.openecomp.sdc.common.errors.CoreException;
32 import org.openecomp.sdc.common.errors.ErrorCode;
33 import org.openecomp.sdc.common.errors.ErrorCode.ErrorCodeBuilder;
34 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseModelNotFoundErrorBuilder;
35
36 /**
37  * Supplies exceptions happened for a Vendor License Model operation .
38  */
39 @NoArgsConstructor(access = AccessLevel.PRIVATE)
40 public class VendorLicenseModelExceptionSupplier {
41
42     /**
43      * Provides a could not find Vendor License Model exception.
44      *
45      * @param vlmId the Vendor License Model id
46      * @return a Supplier for the exception
47      */
48     public static Supplier<CoreException> couldNotFindVlm(final String vlmId) {
49         final ErrorCode errorCode = new VendorLicenseModelNotFoundErrorBuilder(vlmId).build();
50         return () -> new CoreException((errorCode));
51     }
52
53     /**
54      * Provides a cannot delete used Vendor License Model exception.
55      *
56      * @param vmlId the Vendor License Model id
57      * @param vspNameList the list of VSP names that uses the VLM
58      * @return a Supplier for the exception
59      */
60     public static Supplier<CoreException> cantDeleteUsedVlm(final String vmlId, final List<String> vspNameList) {
61         final String errorMsg = String.format(
62             "Vendor License Model '%s' is in use by %s Vendor Software Product(s) and cannot be deleted.",
63             vmlId, String.join(", ", vspNameList)
64         );
65         final ErrorCode errorCode = new ErrorCodeBuilder()
66             .withId(VLM_IS_IN_USE_DELETE_ERROR)
67             .withMessage(errorMsg)
68             .build();
69         return () -> new CoreException((errorCode));
70     }
71
72     /**
73      * Provides a cannot delete certified Vendor License Model exception.
74      *
75      * @param vmlId the Vendor License Model id
76      * @return a Supplier for the exception
77      */
78     public static Supplier<CoreException> cantDeleteCertifiedVlm(final String vmlId) {
79         final String errorMsg = String.format("Vendor License Model '%s' has been certified and cannot be deleted.", vmlId);
80         final ErrorCode errorCode = new ErrorCodeBuilder()
81             .withId(VLM_IS_CERTIFIED_DELETE_ERROR)
82             .withMessage(errorMsg)
83             .build();
84         return () -> new CoreException((errorCode));
85     }
86
87 }