From 098a93c84aae8d8d74e7589518a576b84c38ca27 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Tue, 8 Dec 2020 12:08:31 +0000 Subject: Improve CPS Exception handling - Removing unnecessary level of CPS(Validation)Exception - Moved exception inside spi package - Rename exceptions are per agreed new exception hierarchy - Use new exceptions - Added SchemaSetAlreadDefined Exception - Added AnchorAlreadyDefined Exception - Ensure unique serialVersionUIDs - Fixed CpsAdmin(Persistence)ServiceImplSpec tests (there was a mix-up about what this class was testing) - Replaced exception builder with dedicated exception (constructors) Issue-ID: CPS-8 Change-Id: I9cb80af4951e69ee7b0e99303853955de9d4399f Signed-off-by: ToineSiebelink --- .../java/org/onap/cps/api/CpsAdminService.java | 4 +- .../java/org/onap/cps/api/CpsModuleService.java | 4 +- .../onap/cps/api/impl/CpsModuleServiceImpl.java | 8 +- .../org/onap/cps/exceptions/CpsAdminException.java | 60 -------------- .../java/org/onap/cps/exceptions/CpsException.java | 63 --------------- .../onap/cps/exceptions/CpsExceptionBuilder.java | 94 ---------------------- .../onap/cps/exceptions/CpsNotFoundException.java | 58 ------------- .../cps/exceptions/CpsValidationException.java | 55 ------------- .../cps/exceptions/DataspaceNotFoundException.java | 57 ------------- .../exceptions/AnchorAlreadyDefinedException.java | 37 +++++++++ .../onap/cps/spi/exceptions/CpsAdminException.java | 50 ++++++++++++ .../org/onap/cps/spi/exceptions/CpsException.java | 75 +++++++++++++++++ .../spi/exceptions/DataValidationException.java | 37 +++++++++ .../spi/exceptions/DataspaceNotFoundException.java | 39 +++++++++ .../spi/exceptions/ModelValidationException.java | 39 +++++++++ .../exceptions/NotFoundInDataspaceException.java | 34 ++++++++ .../SchemaSetAlreadyDefinedException.java | 39 +++++++++ 17 files changed, 358 insertions(+), 395 deletions(-) delete mode 100644 cps-service/src/main/java/org/onap/cps/exceptions/CpsAdminException.java delete mode 100644 cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java delete mode 100644 cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java delete mode 100644 cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java delete mode 100644 cps-service/src/main/java/org/onap/cps/exceptions/CpsValidationException.java delete mode 100644 cps-service/src/main/java/org/onap/cps/exceptions/DataspaceNotFoundException.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsAdminException.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/DataValidationException.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/ModelValidationException.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java create mode 100644 cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java (limited to 'cps-service/src/main') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java index 406655e5e2..98ea8ebd8d 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java @@ -20,7 +20,7 @@ package org.onap.cps.api; -import org.onap.cps.exceptions.CpsValidationException; +import org.onap.cps.spi.exceptions.CpsException; import org.onap.cps.spi.model.Anchor; /** @@ -33,7 +33,7 @@ public interface CpsAdminService { * * @param anchor the anchor details object. * @return the anchor name. - * @throws CpsValidationException if input data is invalid. + * @throws CpsException if input data is invalid. */ String createAnchor(Anchor anchor); } diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java index 02553d0741..94ebea2fc2 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java @@ -20,7 +20,7 @@ package org.onap.cps.api; import java.io.File; -import org.onap.cps.exceptions.CpsValidationException; +import org.onap.cps.spi.exceptions.CpsException; import org.opendaylight.yangtools.yang.model.api.SchemaContext; /** @@ -49,7 +49,7 @@ public interface CpsModuleService { * * @param schemaContext the schema context * @param dataspaceName the dataspace name - * @throws CpsValidationException if input data already exists. + * @throws CpsException if input data already exists. */ void storeSchemaContext(SchemaContext schemaContext, String dataspaceName); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java index 87ffdd3d90..c7fa04759a 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java @@ -26,9 +26,9 @@ import java.io.FileWriter; import java.io.IOException; import java.util.Optional; import org.onap.cps.api.CpsModuleService; -import org.onap.cps.exceptions.CpsException; -import org.onap.cps.exceptions.CpsValidationException; import org.onap.cps.spi.CpsModulePersistenceService; +import org.onap.cps.spi.exceptions.CpsException; +import org.onap.cps.spi.exceptions.ModelValidationException; import org.onap.cps.utils.YangUtils; import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.model.api.Module; @@ -47,7 +47,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { public SchemaContext parseAndValidateModel(final String yangModelContent) { try { final File tempFile = File.createTempFile("yang", ".yang"); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile))) { + try (final BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile))) { writer.write(yangModelContent); } return parseAndValidateModel(tempFile); @@ -61,7 +61,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { try { return YangUtils.parseYangModelFile(yangModelFile); } catch (final YangParserException e) { - throw new CpsValidationException("Yang file validation failed", e.getMessage()); + throw new ModelValidationException("Yang file validation failed", e.getMessage(), e); } catch (final IOException e) { throw new CpsException(e); } diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsAdminException.java b/cps-service/src/main/java/org/onap/cps/exceptions/CpsAdminException.java deleted file mode 100644 index a088913375..0000000000 --- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsAdminException.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Bell Canada. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.exceptions; - -import lombok.Getter; - -/** - * CPS Admin exception. - */ -public class CpsAdminException extends CpsValidationException { - - private static final long serialVersionUID = 5573438585188332404L; - - /** - * Constructor. - * - * @param cause the cause of the exception - */ - public CpsAdminException(final Throwable cause) { - super(cause.getMessage(), cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param cause the cause of the exception - */ - public CpsAdminException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param details the error details - */ - public CpsAdminException(final String message, final String details) { - super(message, details); - this.details = details; - } -} diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java b/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java deleted file mode 100644 index acdada14ae..0000000000 --- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Pantheon.tech - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.exceptions; - -import lombok.Getter; - -/** - * CP Service exception. - */ -public class CpsException extends RuntimeException { - - private static final long serialVersionUID = 5573438585188332404L; - - @Getter - String details; - - /** - * Constructor. - * - * @param cause the cause of the exception - */ - public CpsException(final Throwable cause) { - super(cause.getMessage(), cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param cause the cause of the exception - */ - public CpsException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param details the error details - */ - public CpsException(final String message, final String details) { - super(message); - this.details = details; - } -} diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java b/cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java deleted file mode 100644 index 2acbb92322..0000000000 --- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsExceptionBuilder.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Pantheon.tech - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.exceptions; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * Utility class. - * Serves error message consistency for same error cases occurred in different CPS modules. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CpsExceptionBuilder { - - private static final String SCHEMA_SET_IS_INVALID = "Schema Set is invalid."; - - /** - * Generates validation error exception for case when requested dataspace is absent. - * - * @param dataspaceName dataspace name - */ - public static CpsException invalidDataspaceException(final String dataspaceName) { - return new CpsValidationException("Dataspace is invalid.", - String.format("Dataspace with name %s does not exist.", dataspaceName)); - } - - /** - * Generates validation error exception for case when requested schema set is absent for existing dataspace. - * - * @param dataspaceName dataspace name - * @param schemaSetName schema set name - */ - public static CpsException invalidSchemaSetException(final String dataspaceName, final String schemaSetName) { - return new CpsValidationException(SCHEMA_SET_IS_INVALID, - String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName)); - } - - /** - * Returns validation error exception for case when SchemaSet contains no files. - */ - public static CpsException emptySchemaSetException() { - return new CpsValidationException(SCHEMA_SET_IS_INVALID, "Schema Set has no YANG resources to store"); - } - - /** - * Generates validation error exception for case when SchemaSet with same name already exists in the dataspace. - * - * @param dataspaceName dataspace name - * @param schemaSetName schema set name - */ - public static CpsException duplicateSchemaSetException(final String dataspaceName, final String schemaSetName) { - return new CpsValidationException(SCHEMA_SET_IS_INVALID, - String.format("Schema Set with name %s already exists for dataspace %s.", schemaSetName, dataspaceName)); - } - - /** - * Generates no data found exception for case when requested dataspace is absent. - * - * @param dataspaceName dataspace name - */ - public static CpsException dataspaceNotFoundException(final String dataspaceName) { - return new CpsNotFoundException("Dataspace was not found.", - String.format("Dataspace with name %s does not exist.", dataspaceName)); - } - - /** - * Generates no data found exception for case when requested SchemaSet is absent for existing dataspace. - * - * @param dataspaceName dataspace name - * @param schemaSetName schema set name - */ - public static CpsException schemaSetNotFoundException(final String dataspaceName, final String schemaSetName) { - return new CpsNotFoundException("Schema Set was not found.", - String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName)); - } - -} diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java b/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java deleted file mode 100644 index e66c3bd3b9..0000000000 --- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsNotFoundException.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Pantheon.tech - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.exceptions; - - -/** - * CP Service exception. Indicates the requested data being absent. - */ -public class CpsNotFoundException extends CpsException { - - private static final long serialVersionUID = -1852996415384288431L; - - /** - * Constructor. - * - * @param cause the cause of the exception - */ - public CpsNotFoundException(final Throwable cause) { - super(cause.getMessage(), cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param cause the cause of the exception - */ - public CpsNotFoundException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param details the error details - */ - public CpsNotFoundException(final String message, final String details) { - super(message, details); - } -} diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/CpsValidationException.java b/cps-service/src/main/java/org/onap/cps/exceptions/CpsValidationException.java deleted file mode 100644 index 8e049c66e4..0000000000 --- a/cps-service/src/main/java/org/onap/cps/exceptions/CpsValidationException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Pantheon.tech - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.exceptions; - -/** - * CP Service exception. Indicates the parameter validation failure. - */ -public class CpsValidationException extends CpsException { - - /** - * Constructor. - * - * @param cause the cause of the exception - */ - public CpsValidationException(final Throwable cause) { - super(cause.getMessage(), cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param cause the cause of the exception - */ - public CpsValidationException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param details the error details - */ - public CpsValidationException(final String message, final String details) { - super(message, details); - } -} diff --git a/cps-service/src/main/java/org/onap/cps/exceptions/DataspaceNotFoundException.java b/cps-service/src/main/java/org/onap/cps/exceptions/DataspaceNotFoundException.java deleted file mode 100644 index 1b09cdd1eb..0000000000 --- a/cps-service/src/main/java/org/onap/cps/exceptions/DataspaceNotFoundException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Bell Canada. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.exceptions; - - -/** - * Dataspace Not Found Exception. Indicates the requested data being absent. - */ -public class DataspaceNotFoundException extends CpsAdminException { - - private static final long serialVersionUID = -1852996415384288431L; - - /** - * Constructor. - * - * @param cause the cause of the exception - */ - public DataspaceNotFoundException(final Throwable cause) { - super(cause.getMessage(), cause); - } - - /** - * Constructor. - * - * @param message the error message - * @param cause the cause of the exception - */ - public DataspaceNotFoundException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * Constructor. - * - * @param details the error details - */ - public DataspaceNotFoundException(final String details) { - super("Dataspace Not Found", details); - } -} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java new file mode 100644 index 0000000000..efdb86e970 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + +public class AnchorAlreadyDefinedException extends CpsAdminException { + + private static final long serialVersionUID = 5744381546778730691L; + + /** + * Constructor. + * + * @param dataspaceName the name dataspace + * @param anchorName the name of the schema set + * @param cause the cause of the exception + */ + public AnchorAlreadyDefinedException(final String dataspaceName, final String anchorName, final Throwable cause) { + super("Duplicate Anchor", + String.format("Anchor with name %s already exists for dataspace %s.", anchorName, dataspaceName), cause); + } +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsAdminException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsAdminException.java new file mode 100644 index 0000000000..6d6a6c31fa --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsAdminException.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + +/** + * CPS Admin exception. + */ +public class CpsAdminException extends CpsException { + + private static final long serialVersionUID = 5573438585188332404L; + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + */ + public CpsAdminException(final String message, final String details) { + super(message, details); + } + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + * @param cause the error cause + */ + public CpsAdminException(final String message, final String details, final Throwable cause) { + super(message, details, cause); + } + +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java new file mode 100644 index 0000000000..406ade688b --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/CpsException.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Pantheon.tech + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + +import lombok.Getter; + +/** + * CP Service exception. + */ +public class CpsException extends RuntimeException { + + private static final long serialVersionUID = 1592619410918497467L; + + @Getter String details; + + /** + * Constructor. + * + * @param cause the cause of the exception + */ + public CpsException(final Throwable cause) { + super(cause.getMessage(), cause); + } + + /** + * Constructor. + * + * @param message the error message + * @param cause the cause of the exception + */ + public CpsException(final String message, final Throwable cause) { + super(message, cause); + } + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + */ + public CpsException(final String message, final String details) { + super(message); + this.details = details; + } + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + * @param cause the cause of the exception + */ + public CpsException(final String message, final String details, final Throwable cause) { + super(message, cause); + this.details = details; + } + +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataValidationException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataValidationException.java new file mode 100644 index 0000000000..e6af607601 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataValidationException.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + +public class DataValidationException extends CpsException { + + private static final long serialVersionUID = 7747941311132087621L; + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + * @param cause the error cause + */ + public DataValidationException(final String message, final String details, final Throwable cause) { + super(message, details, cause); + } +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java new file mode 100644 index 0000000000..58fcde3d14 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceNotFoundException.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + + +/** + * Dataspace Not Found Exception. Indicates the requested data being absent. + */ +public class DataspaceNotFoundException extends CpsAdminException { + + private static final long serialVersionUID = -1852996415384288431L; + + /** + * Constructor. + * + * @param dataspaceName the name of the dataspace + */ + + public DataspaceNotFoundException(final String dataspaceName) { + super("Dataspace not found", String.format("Dataspace with name %s does not exist.", dataspaceName)); + } +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/ModelValidationException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/ModelValidationException.java new file mode 100644 index 0000000000..04a8836aca --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/ModelValidationException.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + +/** + * Yang Model Validation exception. + */ +public class ModelValidationException extends CpsException { + + private static final long serialVersionUID = 650368325928748496L; + + /** + * Constructor. + * + * @param message the error message + * @param details the error details + * @param cause the cause of the exception + */ + public ModelValidationException(final String message, final String details, final Throwable cause) { + super(message, details, cause); + } +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java new file mode 100644 index 0000000000..66cce1bfce --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/NotFoundInDataspaceException.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Pantheon.tech + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + + +/** + * CP Service exception. Indicates the requested data being absent in a given dataspace + */ +public class NotFoundInDataspaceException extends CpsException { + + private static final long serialVersionUID = 3838769447129047713L; + + public NotFoundInDataspaceException(final String dataspaceName, final String descriptionOfObject) { + super("Object not found", + String.format("%s does not exist in dataspace %s.", descriptionOfObject, dataspaceName)); + } +} diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java new file mode 100644 index 0000000000..b3766726f0 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + +public class SchemaSetAlreadyDefinedException extends CpsAdminException { + + private static final long serialVersionUID = 501929839139881112L; + + /** + * Constructor. + * + * @param dataspaceName the name dataspace + * @param schemaSetName the name of the schema set + * @param cause the cause of the exception + */ + public SchemaSetAlreadyDefinedException(final String dataspaceName, final String schemaSetName, + final Throwable cause) { + super("Duplicate Schema Set", + String.format("Schema Set with name %s already exists for dataspace %s.", schemaSetName, dataspaceName), + cause); + } +} -- cgit 1.2.3-korg