2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Bell Canada
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.models;
23 import lombok.Builder;
25 import lombok.RequiredArgsConstructor;
29 public class CmHandleRegistrationResponse {
31 private final String cmHandle;
32 private final Status status;
33 private RegistrationError registrationError;
34 private String errorText;
37 * Creates a failure response based on exception.
39 * @param cmHandle cmHandle
40 * @param exception exception
41 * @return CmHandleRegistrationResponse
43 public static CmHandleRegistrationResponse createFailureResponse(final String cmHandle, final Exception exception) {
44 return CmHandleRegistrationResponse.builder()
46 .status(Status.FAILURE)
47 .registrationError(RegistrationError.UNKNOWN_ERROR)
48 .errorText(exception.getMessage()).build();
52 * Creates a failure response based on registration error.
54 * @param cmHandle cmHandle
55 * @param registrationError registrationError
56 * @return CmHandleRegistrationResponse
58 public static CmHandleRegistrationResponse createFailureResponse(final String cmHandle,
59 final RegistrationError registrationError) {
60 return CmHandleRegistrationResponse.builder().cmHandle(cmHandle)
61 .status(Status.FAILURE)
62 .registrationError(registrationError)
63 .errorText(registrationError.errorText)
67 public static CmHandleRegistrationResponse createSuccessResponse(final String cmHandle) {
68 return CmHandleRegistrationResponse.builder().cmHandle(cmHandle)
69 .status(Status.SUCCESS).build();
76 @RequiredArgsConstructor
77 public enum RegistrationError {
78 UNKNOWN_ERROR("00", "Unknown error"),
79 CM_HANDLE_ALREADY_EXIST("01", "cm-handle already exists"),
80 CM_HANDLE_DOES_NOT_EXIST("02", "cm-handle does not exist");
82 public final String errorCode;
83 public final String errorText;