2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Bell Canada
4 * Modifications 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.onap.cps.ncmp.api.models;
24 import lombok.Builder;
26 import lombok.RequiredArgsConstructor;
30 public class CmHandleRegistrationResponse {
32 private final String cmHandle;
33 private final Status status;
34 private RegistrationError registrationError;
35 private String errorText;
38 * Creates a failure response based on exception.
40 * @param cmHandle cmHandle
41 * @param exception exception
42 * @return CmHandleRegistrationResponse
44 public static CmHandleRegistrationResponse createFailureResponse(final String cmHandle, final Exception exception) {
45 return CmHandleRegistrationResponse.builder()
47 .status(Status.FAILURE)
48 .registrationError(RegistrationError.UNKNOWN_ERROR)
49 .errorText(exception.getMessage()).build();
53 * Creates a failure response based on registration error.
55 * @param cmHandle cmHandle
56 * @param registrationError registrationError
57 * @return CmHandleRegistrationResponse
59 public static CmHandleRegistrationResponse createFailureResponse(final String cmHandle,
60 final RegistrationError registrationError) {
61 return CmHandleRegistrationResponse.builder().cmHandle(cmHandle)
62 .status(Status.FAILURE)
63 .registrationError(registrationError)
64 .errorText(registrationError.errorText)
68 public static CmHandleRegistrationResponse createSuccessResponse(final String cmHandle) {
69 return CmHandleRegistrationResponse.builder().cmHandle(cmHandle)
70 .status(Status.SUCCESS).build();
77 @RequiredArgsConstructor
78 public enum RegistrationError {
79 UNKNOWN_ERROR("00", "Unknown error"),
80 CM_HANDLE_ALREADY_EXIST("01", "cm-handle already exists"),
81 CM_HANDLE_DOES_NOT_EXIST("02", "cm-handle does not exist"),
82 CM_HANDLE_INVALID_ID("03", "cm-handle has an invalid character(s) in id");
84 public final String errorCode;
85 public final String errorText;