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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdcrests.vendorlicense.rest.exception;
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;
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;
37 * Supplies exceptions happened for a Vendor License Model operation .
39 @NoArgsConstructor(access = AccessLevel.PRIVATE)
40 public class VendorLicenseModelExceptionSupplier {
43 * Provides a could not find Vendor License Model exception.
45 * @param vlmId the Vendor License Model id
46 * @return a Supplier for the exception
48 public static Supplier<CoreException> couldNotFindVlm(final String vlmId) {
49 final ErrorCode errorCode = new VendorLicenseModelNotFoundErrorBuilder(vlmId).build();
50 return () -> new CoreException((errorCode));
54 * Provides a cannot delete used Vendor License Model exception.
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
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)
65 final ErrorCode errorCode = new ErrorCodeBuilder()
66 .withId(VLM_IS_IN_USE_DELETE_ERROR)
67 .withMessage(errorMsg)
69 return () -> new CoreException((errorCode));
73 * Provides a cannot delete certified Vendor License Model exception.
75 * @param vmlId the Vendor License Model id
76 * @return a Supplier for the exception
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)
84 return () -> new CoreException((errorCode));