diff options
Diffstat (limited to 'cps-service/src/main')
7 files changed, 80 insertions, 134 deletions
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 ed89c43091..0379ac21d6 100755 --- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java @@ -22,8 +22,8 @@ package org.onap.cps.api; import java.util.Collection; import org.checkerframework.checker.nullness.qual.NonNull; +import org.onap.cps.spi.exceptions.AlreadyDefinedException; import org.onap.cps.spi.exceptions.CpsException; -import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException; import org.onap.cps.spi.model.Anchor; /** @@ -35,7 +35,7 @@ public interface CpsAdminService { * Create dataspace. * * @param dataspaceName dataspace name - * @throws DataspaceAlreadyDefinedException if dataspace with same name already exists + * @throws AlreadyDefinedException if dataspace with same name already exists */ void createDataspace(@NonNull String dataspaceName); diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java index 06c04ceb62..f47af5f976 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java @@ -23,7 +23,7 @@ package org.onap.cps.spi; import java.util.Collection; import org.checkerframework.checker.nullness.qual.NonNull; -import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException; +import org.onap.cps.spi.exceptions.AlreadyDefinedException; import org.onap.cps.spi.model.Anchor; /* @@ -35,7 +35,7 @@ public interface CpsAdminPersistenceService { * Create dataspace. * * @param dataspaceName dataspace name - * @throws DataspaceAlreadyDefinedException if dataspace with same name already exists + * @throws AlreadyDefinedException if dataspace with same name already exists */ void createDataspace(@NonNull String dataspaceName); diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/AlreadyDefinedException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AlreadyDefinedException.java new file mode 100644 index 0000000000..9e54f34937 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AlreadyDefinedException.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 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; + +/** + * Already defined exception. Indicates the cps object with same name already exists. + */ + +@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS Exceptions +public class AlreadyDefinedException extends CpsAdminException { + + private static final long serialVersionUID = 501929839139881112L; + + /** + * Constructor. + * + * @param objectType the object type + * @param objectName the name of the object + * @param contextName the context name e.g. Anchor or Dataspace + * @param cause the cause of the exception + */ + private AlreadyDefinedException(final String objectType, final String objectName, final String contextName, + final Throwable cause) { + super("Already defined exception", + String.format("%s with name %s already exists for %s.", objectType, objectName, contextName), cause); + } + + /** + * Constructor. + * + * @param objectName the name of the object + * @param cause the cause of the exception + */ + private AlreadyDefinedException(final String objectName, final Throwable cause) { + super("Already defined exception", String.format("%s already exists.", objectName), cause); + } + + public static AlreadyDefinedException forDataspace(final String dataspaceName, final Throwable cause) { + return new AlreadyDefinedException(dataspaceName, cause); + } + + public static AlreadyDefinedException forAnchor(final String anchorName, final String contextName, + final Throwable cause) { + return new AlreadyDefinedException("Anchor", anchorName, contextName, cause); + } + + public static AlreadyDefinedException forSchemaSet(final String schemaSetName, final String contextName, + final Throwable cause) { + return new AlreadyDefinedException("Schema Set", schemaSetName, contextName, cause); + } + + public static AlreadyDefinedException forDataNode(final String xpath, final String contextName, + final Throwable cause) { + return new AlreadyDefinedException("Data node", xpath, contextName, cause); + } +} 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 deleted file mode 100644 index 2a4abad319..0000000000 --- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorAlreadyDefinedException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ============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; - -/** - * Anchor already defined exception. Indicates the an anchor with same name already exists in the same dataspace - */ - -@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS 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/DataspaceAlreadyDefinedException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceAlreadyDefinedException.java deleted file mode 100644 index fcc085aa08..0000000000 --- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataspaceAlreadyDefinedException.java +++ /dev/null @@ -1,42 +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.spi.exceptions; - -/** - * Dataspace already defined exception. Indicates the dataspace with same name already exists. - */ - -@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS Exceptions -public class DataspaceAlreadyDefinedException extends CpsAdminException { - - private static final long serialVersionUID = -5813793951842079228L; - - /** - * Constructor. - * - * @param dataspaceName dataspace name - * @param cause the cause of this exception - */ - public DataspaceAlreadyDefinedException(final String dataspaceName, final Throwable cause) { - super("Duplicate Dataspace.", - String.format("Dataspace with name %s already exists.", dataspaceName), - cause); - } -} 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 deleted file mode 100644 index 1e0b8dbb65..0000000000 --- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetAlreadyDefinedException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * ============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; - -/** - * Schema set already defined exception. Indicates the a schema set with same name already exists in the same dataspace - */ - -@SuppressWarnings("squid:S110") // Team agreed to accept 6 levels of inheritance for CPS 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); - } -} diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java index 733378ecba..873e14cd3a 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java +++ b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java @@ -21,6 +21,7 @@ package org.onap.cps.utils; +import com.google.gson.JsonSyntaxException; import com.google.gson.stream.JsonReader; import java.io.IOException; import java.io.StringReader; @@ -93,9 +94,9 @@ public class YangUtils { final JsonReader jsonReader = new JsonReader(new StringReader(jsonData)); jsonParserStream.parse(jsonReader); - } catch (final IOException | IllegalStateException e) { + } catch (final IOException | IllegalStateException | JsonSyntaxException exception) { throw new DataValidationException("Failed to parse json data.", String - .format("Exception occurred on parsing string %s.", jsonData), e); + .format("Exception occurred on parsing string %s.", jsonData), exception); } return normalizedNodeResult.getResult(); } |