2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Pantheon.tech
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
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.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.cps.exceptions;
22 import lombok.AccessLevel;
23 import lombok.NoArgsConstructor;
27 * Serves error message consistency for same error cases occurred in different CPS modules.
29 @NoArgsConstructor(access = AccessLevel.PRIVATE)
30 public class CpsExceptionBuilder {
32 private static final String SCHEMA_SET_IS_INVALID = "Schema Set is invalid.";
35 * Generates validation error exception for case when requested dataspace is absent.
37 * @param dataspaceName dataspace name
39 public static CpsException invalidDataspaceException(final String dataspaceName) {
40 return new CpsValidationException("Dataspace is invalid.",
41 String.format("Dataspace with name %s does not exist.", dataspaceName));
45 * Generates validation error exception for case when requested schema set is absent for existing dataspace.
47 * @param dataspaceName dataspace name
48 * @param schemaSetName schema set name
50 public static CpsException invalidSchemaSetException(final String dataspaceName, final String schemaSetName) {
51 return new CpsValidationException(SCHEMA_SET_IS_INVALID,
52 String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName));
56 * Returns validation error exception for case when SchemaSet contains no files.
58 public static CpsException emptySchemaSetException() {
59 return new CpsValidationException(SCHEMA_SET_IS_INVALID, "Schema Set has no YANG resources to store");
63 * Generates validation error exception for case when SchemaSet with same name already exists in the dataspace.
65 * @param dataspaceName dataspace name
66 * @param schemaSetName schema set name
68 public static CpsException duplicateSchemaSetException(final String dataspaceName, final String schemaSetName) {
69 return new CpsValidationException(SCHEMA_SET_IS_INVALID,
70 String.format("Schema Set with name %s already exists for dataspace %s.", schemaSetName, dataspaceName));
74 * Generates no data found exception for case when requested dataspace is absent.
76 * @param dataspaceName dataspace name
78 public static CpsException dataspaceNotFoundException(final String dataspaceName) {
79 return new CpsNotFoundException("Dataspace was not found.",
80 String.format("Dataspace with name %s does not exist.", dataspaceName));
84 * Generates no data found exception for case when requested SchemaSet is absent for existing dataspace.
86 * @param dataspaceName dataspace name
87 * @param schemaSetName schema set name
89 public static CpsException schemaSetNotFoundException(final String dataspaceName, final String schemaSetName) {
90 return new CpsNotFoundException("Schema Set was not found.",
91 String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName));