Merge "Add DistributionManagement to checkstyle pom"
[cps.git] / cps-service / src / main / java / org / onap / cps / exceptions / CpsExceptionBuilder.java
1 /*
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.cps.exceptions;
21
22 import lombok.AccessLevel;
23 import lombok.NoArgsConstructor;
24
25 /**
26  * Utility class.
27  * Serves error message consistency for same error cases occurred in different CPS modules.
28  */
29 @NoArgsConstructor(access = AccessLevel.PRIVATE)
30 public class CpsExceptionBuilder {
31
32     private static final String SCHEMA_SET_IS_INVALID = "Schema Set is invalid.";
33
34     /**
35      * Generates validation error exception for case when requested dataspace is absent.
36      *
37      * @param dataspaceName dataspace name
38      */
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));
42     }
43
44     /**
45      * Generates validation error exception for case when requested schema set is absent for existing dataspace.
46      *
47      * @param dataspaceName dataspace name
48      * @param schemaSetName schema set name
49      */
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));
53     }
54
55     /**
56      * Returns validation error exception for case when SchemaSet contains no files.
57      */
58     public static CpsException emptySchemaSetException() {
59         return new CpsValidationException(SCHEMA_SET_IS_INVALID, "Schema Set has no YANG resources to store");
60     }
61
62     /**
63      * Generates validation error exception for case when SchemaSet with same name already exists in the dataspace.
64      *
65      * @param dataspaceName dataspace name
66      * @param schemaSetName schema set name
67      */
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));
71     }
72
73     /**
74      * Generates no data found exception for case when requested dataspace is absent.
75      *
76      * @param dataspaceName dataspace name
77      */
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));
81     }
82
83     /**
84      * Generates no data found exception for case when requested SchemaSet is absent for existing dataspace.
85      *
86      * @param dataspaceName dataspace name
87      * @param schemaSetName schema set name
88      */
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));
92     }
93
94 }