From a966bab93a17fcba4e7fc28354c01b3f0878fbbe Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Mon, 18 Dec 2023 12:25:41 +0000 Subject: Remove the dependency-cycle between beans - Splitting admin service into AnchorService and DataspaceService (this resolves the cyclic dependency) - Improved Delete dataspace integration error tests (were depending on execution order, now independent) Issue-ID: CPS-871 Change-Id: I47efedb6eb4bd2900f72d689616b7b7b62df2938 Signed-off-by: halil.cakal Signed-off-by: ToineSiebelink --- .../java/org/onap/cps/api/CpsAdminService.java | 147 --------------------- .../java/org/onap/cps/api/CpsAnchorService.java | 108 +++++++++++++++ .../java/org/onap/cps/api/CpsDataspaceService.java | 66 +++++++++ .../org/onap/cps/api/impl/CpsAdminServiceImpl.java | 130 ------------------ .../onap/cps/api/impl/CpsAnchorServiceImpl.java | 100 ++++++++++++++ .../org/onap/cps/api/impl/CpsDataServiceImpl.java | 22 +-- .../onap/cps/api/impl/CpsDataspaceServiceImpl.java | 64 +++++++++ .../onap/cps/api/impl/CpsModuleServiceImpl.java | 12 +- .../java/org/onap/cps/utils/PrefixResolver.java | 6 +- 9 files changed, 358 insertions(+), 297 deletions(-) delete mode 100755 cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java create mode 100644 cps-service/src/main/java/org/onap/cps/api/CpsAnchorService.java create mode 100644 cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java delete mode 100755 cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java create mode 100644 cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java create mode 100644 cps-service/src/main/java/org/onap/cps/api/impl/CpsDataspaceServiceImpl.java (limited to 'cps-service/src/main/java') 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 deleted file mode 100755 index edd052a51c..0000000000 --- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020-2023 Nordix Foundation - * Modifications Copyright (C) 2020-2022 Bell Canada. - * Modifications Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2022 TechMahindra Ltd. - * ================================================================================ - * 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.api; - -import java.util.Collection; -import org.onap.cps.spi.exceptions.AlreadyDefinedException; -import org.onap.cps.spi.exceptions.CpsException; -import org.onap.cps.spi.model.Anchor; -import org.onap.cps.spi.model.Dataspace; - -/** - * CPS Admin Service. - */ -public interface CpsAdminService { - - /** - * Create dataspace. - * - * @param dataspaceName dataspace name - * @throws AlreadyDefinedException if dataspace with same name already exists - */ - void createDataspace(String dataspaceName); - - /** - * Delete dataspace. - * - * @param dataspaceName the name of the dataspace to delete - */ - void deleteDataspace(String dataspaceName); - - /** - * Get dataspace by given dataspace name. - * - * @param dataspaceName dataspace name - * @return a dataspace - */ - Dataspace getDataspace(String dataspaceName); - - /** - * Get All Dataspaces. - * - * - * @return a collection of dataspaces - */ - Collection getAllDataspaces(); - - /** - * Create an Anchor. - * - * @param dataspaceName dataspace name - * @param schemaSetName schema set name - * @param anchorName anchor name - * @throws CpsException if input data is invalid. - */ - void createAnchor(String dataspaceName, String schemaSetName, String anchorName); - - /** - * Read all anchors in the given dataspace. - * - * @param dataspaceName dataspace name - * @return a collection of anchors - */ - Collection getAnchors(String dataspaceName); - - /** - * Read all anchors associated with the given schema-set in the given dataspace. - * - * @param dataspaceName dataspace name - * @param schemaSetName schema-set name - * @return a collection of anchors - */ - Collection getAnchors(String dataspaceName, String schemaSetName); - - /** - * Read all anchors associated with the given schema-sets in the given dataspace. - * - * @param dataspaceName dataspace name - * @param schemaSetNames schema-set names - * @return a collection of anchors - */ - Collection getAnchors(String dataspaceName, Collection schemaSetNames); - - /** - * Get an anchor in the given dataspace using the anchor name. - * - * @param dataspaceName dataspace name - * @param anchorName anchor name - * @return an anchor - */ - Anchor getAnchor(String dataspaceName, String anchorName); - - /** - * Delete anchor by name in given dataspace. - * - * @param dataspaceName dataspace name - * @param anchorName anchor name - */ - void deleteAnchor(String dataspaceName, String anchorName); - - /** - * Delete anchors by name in given dataspace. - * - * @param dataspaceName dataspace name - * @param anchorNames anchor names - */ - void deleteAnchors(String dataspaceName, Collection anchorNames); - - /** - * Query anchor names for the given module names in the provided dataspace. - * - * @param dataspaceName dataspace name - * @param moduleNames a collection of module names - * @return a collection of anchor names in the given dataspace. The schema set for each anchor must include all the - * given module names - */ - Collection queryAnchorNames(String dataspaceName, Collection moduleNames); - - /** - * Update schema set of an anchor. - * - * @param dataspaceName dataspace name - * @param anchorName anchor name - * @param schemaSetName schema set name - */ - void updateAnchorSchemaSet(String dataspaceName, String anchorName, String schemaSetName); -} diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsAnchorService.java b/cps-service/src/main/java/org/onap/cps/api/CpsAnchorService.java new file mode 100644 index 0000000000..a247150c15 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/api/CpsAnchorService.java @@ -0,0 +1,108 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.api; + +import java.util.Collection; +import org.onap.cps.spi.exceptions.CpsException; +import org.onap.cps.spi.model.Anchor; + +public interface CpsAnchorService { + + /** + * Create an Anchor. + * + * @param dataspaceName dataspace name + * @param schemaSetName schema set name + * @param anchorName anchor name + * @throws CpsException if input data is invalid. + */ + void createAnchor(String dataspaceName, String schemaSetName, String anchorName); + + /** + * Read all anchors in the given dataspace. + * + * @param dataspaceName dataspace name + * @return a collection of anchors + */ + Collection getAnchors(String dataspaceName); + + /** + * Read all anchors associated with the given schema-set in the given dataspace. + * + * @param dataspaceName dataspace name + * @param schemaSetName schema-set name + * @return a collection of anchors + */ + Collection getAnchors(String dataspaceName, String schemaSetName); + + /** + * Read all anchors associated with the given schema-sets in the given dataspace. + * + * @param dataspaceName dataspace name + * @param schemaSetNames schema-set names + * @return a collection of anchors + */ + Collection getAnchors(String dataspaceName, Collection schemaSetNames); + + /** + * Get an anchor in the given dataspace using the anchor name. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return an anchor + */ + Anchor getAnchor(String dataspaceName, String anchorName); + + /** + * Delete anchor by name in given dataspace. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + */ + void deleteAnchor(String dataspaceName, String anchorName); + + /** + * Delete anchors by name in given dataspace. + * + * @param dataspaceName dataspace name + * @param anchorNames anchor names + */ + void deleteAnchors(String dataspaceName, Collection anchorNames); + + /** + * Query anchor names for the given module names in the provided dataspace. + * + * @param dataspaceName dataspace name + * @param moduleNames a collection of module names + * @return a collection of anchor names in the given dataspace. The schema set for each anchor must include all the + * given module names + */ + Collection queryAnchorNames(String dataspaceName, Collection moduleNames); + + /** + * Update schema set of an anchor. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param schemaSetName schema set name + */ + void updateAnchorSchemaSet(String dataspaceName, String anchorName, String schemaSetName); +} diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java new file mode 100644 index 0000000000..7b94604261 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataspaceService.java @@ -0,0 +1,66 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020-2023 Nordix Foundation + * Modifications Copyright (C) 2020-2022 Bell Canada. + * Modifications Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2022 TechMahindra Ltd. + * ================================================================================ + * 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.api; + +import java.util.Collection; +import org.onap.cps.spi.exceptions.AlreadyDefinedException; +import org.onap.cps.spi.model.Dataspace; + +/** + * CPS Admin Service. + */ +public interface CpsDataspaceService { + + /** + * Create dataspace. + * + * @param dataspaceName dataspace name + * @throws AlreadyDefinedException if dataspace with same name already exists + */ + void createDataspace(String dataspaceName); + + /** + * Delete dataspace. + * + * @param dataspaceName the name of the dataspace to delete + */ + void deleteDataspace(String dataspaceName); + + /** + * Get dataspace by given dataspace name. + * + * @param dataspaceName dataspace name + * @return a dataspace + */ + Dataspace getDataspace(String dataspaceName); + + /** + * Get All Dataspaces. + * + * + * @return a collection of dataspaces + */ + Collection getAllDataspaces(); + +} diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java deleted file mode 100755 index d83ee434de..0000000000 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020-2023 Nordix Foundation - * Modifications Copyright (C) 2020-2022 Bell Canada. - * Modifications Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2022 TechMahindra Ltd. - * ================================================================================ - * 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.api.impl; - -import java.time.OffsetDateTime; -import java.util.Collection; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import org.onap.cps.api.CpsAdminService; -import org.onap.cps.api.CpsDataService; -import org.onap.cps.spi.CpsAdminPersistenceService; -import org.onap.cps.spi.model.Anchor; -import org.onap.cps.spi.model.Dataspace; -import org.onap.cps.spi.utils.CpsValidator; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; - -@Component("CpsAdminServiceImpl") -@RequiredArgsConstructor(onConstructor = @__(@Lazy)) -public class CpsAdminServiceImpl implements CpsAdminService { - - private final CpsAdminPersistenceService cpsAdminPersistenceService; - @Lazy - private final CpsDataService cpsDataService; - private final CpsValidator cpsValidator; - - @Override - public void createDataspace(final String dataspaceName) { - cpsValidator.validateNameCharacters(dataspaceName); - cpsAdminPersistenceService.createDataspace(dataspaceName); - } - - @Override - public void deleteDataspace(final String dataspaceName) { - cpsValidator.validateNameCharacters(dataspaceName); - cpsAdminPersistenceService.deleteDataspace(dataspaceName); - } - - @Override - public Dataspace getDataspace(final String dataspaceName) { - cpsValidator.validateNameCharacters(dataspaceName); - return cpsAdminPersistenceService.getDataspace(dataspaceName); - } - - @Override - public Collection getAllDataspaces() { - return cpsAdminPersistenceService.getAllDataspaces(); - } - - @Override - public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName, anchorName); - cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName); - } - - @Override - public Collection getAnchors(final String dataspaceName) { - cpsValidator.validateNameCharacters(dataspaceName); - return cpsAdminPersistenceService.getAnchors(dataspaceName); - } - - @Override - public Collection getAnchors(final String dataspaceName, final String schemaSetName) { - cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); - return cpsAdminPersistenceService.getAnchors(dataspaceName, schemaSetName); - } - - @Override - public Collection getAnchors(final String dataspaceName, final Collection schemaSetNames) { - cpsValidator.validateNameCharacters(dataspaceName); - cpsValidator.validateNameCharacters(schemaSetNames); - return cpsAdminPersistenceService.getAnchors(dataspaceName, schemaSetNames); - } - - @Override - public Anchor getAnchor(final String dataspaceName, final String anchorName) { - cpsValidator.validateNameCharacters(dataspaceName, anchorName); - return cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName); - } - - @Override - public void deleteAnchor(final String dataspaceName, final String anchorName) { - cpsValidator.validateNameCharacters(dataspaceName, anchorName); - cpsDataService.deleteDataNodes(dataspaceName, anchorName, OffsetDateTime.now()); - cpsAdminPersistenceService.deleteAnchor(dataspaceName, anchorName); - } - - @Override - public void deleteAnchors(final String dataspaceName, final Collection anchorNames) { - cpsValidator.validateNameCharacters(dataspaceName); - cpsValidator.validateNameCharacters(anchorNames); - cpsDataService.deleteDataNodes(dataspaceName, anchorNames, OffsetDateTime.now()); - cpsAdminPersistenceService.deleteAnchors(dataspaceName, anchorNames); - } - - @Override - public Collection queryAnchorNames(final String dataspaceName, final Collection moduleNames) { - cpsValidator.validateNameCharacters(dataspaceName); - final Collection anchors = cpsAdminPersistenceService.queryAnchors(dataspaceName, moduleNames); - return anchors.stream().map(Anchor::getName).collect(Collectors.toList()); - } - - @Override - public void updateAnchorSchemaSet(final String dataspaceName, - final String anchorName, - final String schemaSetName) { - cpsAdminPersistenceService.updateAnchorSchemaSet(dataspaceName, anchorName, schemaSetName); - } -} diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java new file mode 100644 index 0000000000..f09a795a66 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAnchorServiceImpl.java @@ -0,0 +1,100 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.api.impl; + +import java.util.Collection; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.onap.cps.api.CpsAnchorService; +import org.onap.cps.spi.CpsAdminPersistenceService; +import org.onap.cps.spi.CpsDataPersistenceService; +import org.onap.cps.spi.model.Anchor; +import org.onap.cps.spi.utils.CpsValidator; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class CpsAnchorServiceImpl implements CpsAnchorService { + + private final CpsAdminPersistenceService cpsAdminPersistenceService; + private final CpsDataPersistenceService cpsDataPersistenceService; + private final CpsValidator cpsValidator; + + @Override + public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) { + cpsValidator.validateNameCharacters(dataspaceName, schemaSetName, anchorName); + cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName); + } + + @Override + public Collection getAnchors(final String dataspaceName) { + cpsValidator.validateNameCharacters(dataspaceName); + return cpsAdminPersistenceService.getAnchors(dataspaceName); + } + + @Override + public Collection getAnchors(final String dataspaceName, final String schemaSetName) { + cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); + return cpsAdminPersistenceService.getAnchors(dataspaceName, schemaSetName); + } + + @Override + public Collection getAnchors(final String dataspaceName, final Collection schemaSetNames) { + cpsValidator.validateNameCharacters(dataspaceName); + cpsValidator.validateNameCharacters(schemaSetNames); + return cpsAdminPersistenceService.getAnchors(dataspaceName, schemaSetNames); + } + + @Override + public Anchor getAnchor(final String dataspaceName, final String anchorName) { + cpsValidator.validateNameCharacters(dataspaceName, anchorName); + return cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName); + } + + @Override + public void deleteAnchor(final String dataspaceName, final String anchorName) { + cpsValidator.validateNameCharacters(dataspaceName, anchorName); + cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName); + cpsAdminPersistenceService.deleteAnchor(dataspaceName, anchorName); + } + + @Override + public void deleteAnchors(final String dataspaceName, final Collection anchorNames) { + cpsValidator.validateNameCharacters(dataspaceName); + cpsValidator.validateNameCharacters(anchorNames); + cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorNames); + cpsAdminPersistenceService.deleteAnchors(dataspaceName, anchorNames); + } + + @Override + public Collection queryAnchorNames(final String dataspaceName, final Collection moduleNames) { + cpsValidator.validateNameCharacters(dataspaceName); + final Collection anchors = cpsAdminPersistenceService.queryAnchors(dataspaceName, moduleNames); + return anchors.stream().map(Anchor::getName).collect(Collectors.toList()); + } + + @Override + public void updateAnchorSchemaSet(final String dataspaceName, + final String anchorName, + final String schemaSetName) { + cpsAdminPersistenceService.updateAnchorSchemaSet(dataspaceName, anchorName, schemaSetName); + } +} diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java index 6672d6883f..a1bae6a441 100755 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java @@ -35,7 +35,7 @@ import java.util.Map; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.api.CpsAdminService; +import org.onap.cps.api.CpsAnchorService; import org.onap.cps.api.CpsDataService; import org.onap.cps.api.CpsDeltaService; import org.onap.cps.cpspath.parser.CpsPathUtil; @@ -62,7 +62,7 @@ public class CpsDataServiceImpl implements CpsDataService { private static final long DEFAULT_LOCK_TIMEOUT_IN_MILLISECONDS = 300L; private final CpsDataPersistenceService cpsDataPersistenceService; - private final CpsAdminService cpsAdminService; + private final CpsAnchorService cpsAnchorService; private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache; private final CpsValidator cpsValidator; private final TimedYangParser timedYangParser; @@ -80,7 +80,7 @@ public class CpsDataServiceImpl implements CpsDataService { public void saveData(final String dataspaceName, final String anchorName, final String nodeData, final OffsetDateTime observedTimestamp, final ContentType contentType) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection dataNodes = buildDataNodes(anchor, ROOT_NODE_XPATH, nodeData, contentType); cpsDataPersistenceService.storeDataNodes(dataspaceName, anchorName, dataNodes); } @@ -98,7 +98,7 @@ public class CpsDataServiceImpl implements CpsDataService { final String nodeData, final OffsetDateTime observedTimestamp, final ContentType contentType) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection dataNodes = buildDataNodes(anchor, parentNodeXpath, nodeData, contentType); cpsDataPersistenceService.addChildDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodes); } @@ -109,7 +109,7 @@ public class CpsDataServiceImpl implements CpsDataService { public void saveListElements(final String dataspaceName, final String anchorName, final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection listElementDataNodeCollection = buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON); if (isRootNodeXpath(parentNodeXpath)) { @@ -126,7 +126,7 @@ public class CpsDataServiceImpl implements CpsDataService { public void saveListElementsBatch(final String dataspaceName, final String anchorName, final String parentNodeXpath, final Collection jsonDataList, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection> listElementDataNodeCollections = buildDataNodes(anchor, parentNodeXpath, jsonDataList, ContentType.JSON); cpsDataPersistenceService.addMultipleLists(dataspaceName, anchorName, parentNodeXpath, @@ -160,7 +160,7 @@ public class CpsDataServiceImpl implements CpsDataService { public void updateNodeLeaves(final String dataspaceName, final String anchorName, final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection dataNodesInPatch = buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON); final Map> xpathToUpdatedLeaves = dataNodesInPatch.stream() @@ -176,7 +176,7 @@ public class CpsDataServiceImpl implements CpsDataService { final String dataNodeUpdatesAsJson, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection dataNodeUpdates = buildDataNodes(anchor, parentNodeXpath, dataNodeUpdatesAsJson, ContentType.JSON); for (final DataNode dataNodeUpdate : dataNodeUpdates) { @@ -228,7 +228,7 @@ public class CpsDataServiceImpl implements CpsDataService { final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection dataNodes = buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON); cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, dataNodes); } @@ -240,7 +240,7 @@ public class CpsDataServiceImpl implements CpsDataService { final Map nodesJsonData, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection dataNodes = buildDataNodes(anchor, nodesJsonData); cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, dataNodes); } @@ -251,7 +251,7 @@ public class CpsDataServiceImpl implements CpsDataService { public void replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); final Collection newListElements = buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON); replaceListContent(dataspaceName, anchorName, parentNodeXpath, newListElements, observedTimestamp); diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataspaceServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataspaceServiceImpl.java new file mode 100644 index 0000000000..a7f5da4874 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataspaceServiceImpl.java @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020-2023 Nordix Foundation + * Modifications Copyright (C) 2020-2022 Bell Canada. + * Modifications Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2022 TechMahindra Ltd. + * ================================================================================ + * 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.api.impl; + +import java.util.Collection; +import lombok.RequiredArgsConstructor; +import org.onap.cps.api.CpsDataspaceService; +import org.onap.cps.spi.CpsAdminPersistenceService; +import org.onap.cps.spi.model.Dataspace; +import org.onap.cps.spi.utils.CpsValidator; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class CpsDataspaceServiceImpl implements CpsDataspaceService { + + private final CpsAdminPersistenceService cpsAdminPersistenceService; + private final CpsValidator cpsValidator; + + @Override + public void createDataspace(final String dataspaceName) { + cpsValidator.validateNameCharacters(dataspaceName); + cpsAdminPersistenceService.createDataspace(dataspaceName); + } + + @Override + public void deleteDataspace(final String dataspaceName) { + cpsValidator.validateNameCharacters(dataspaceName); + cpsAdminPersistenceService.deleteDataspace(dataspaceName); + } + + @Override + public Dataspace getDataspace(final String dataspaceName) { + cpsValidator.validateNameCharacters(dataspaceName); + return cpsAdminPersistenceService.getDataspace(dataspaceName); + } + + @Override + public Collection getAllDataspaces() { + return cpsAdminPersistenceService.getAllDataspaces(); + } + +} 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 5337237846..61a4e623af 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 @@ -28,7 +28,7 @@ import java.util.Collection; import java.util.Map; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import org.onap.cps.api.CpsAdminService; +import org.onap.cps.api.CpsAnchorService; import org.onap.cps.api.CpsModuleService; import org.onap.cps.spi.CascadeDeleteAllowed; import org.onap.cps.spi.CpsModulePersistenceService; @@ -49,7 +49,7 @@ public class CpsModuleServiceImpl implements CpsModuleService { private final CpsModulePersistenceService cpsModulePersistenceService; private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache; - private final CpsAdminService cpsAdminService; + private final CpsAnchorService cpsAnchorService; private final CpsValidator cpsValidator; private final TimedYangTextSchemaSourceSetBuilder timedYangTextSchemaSourceSetBuilder; @@ -97,12 +97,12 @@ public class CpsModuleServiceImpl implements CpsModuleService { public void deleteSchemaSet(final String dataspaceName, final String schemaSetName, final CascadeDeleteAllowed cascadeDeleteAllowed) { cpsValidator.validateNameCharacters(dataspaceName, schemaSetName); - final Collection anchors = cpsAdminService.getAnchors(dataspaceName, schemaSetName); + final Collection anchors = cpsAnchorService.getAnchors(dataspaceName, schemaSetName); if (!anchors.isEmpty() && isCascadeDeleteProhibited(cascadeDeleteAllowed)) { throw new SchemaSetInUseException(dataspaceName, schemaSetName); } for (final Anchor anchor : anchors) { - cpsAdminService.deleteAnchor(dataspaceName, anchor.getName()); + cpsAnchorService.deleteAnchor(dataspaceName, anchor.getName()); } cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName); yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName); @@ -114,9 +114,9 @@ public class CpsModuleServiceImpl implements CpsModuleService { public void deleteSchemaSetsWithCascade(final String dataspaceName, final Collection schemaSetNames) { cpsValidator.validateNameCharacters(dataspaceName); cpsValidator.validateNameCharacters(schemaSetNames); - final Collection anchorNames = cpsAdminService.getAnchors(dataspaceName, schemaSetNames) + final Collection anchorNames = cpsAnchorService.getAnchors(dataspaceName, schemaSetNames) .stream().map(Anchor::getName).collect(Collectors.toSet()); - cpsAdminService.deleteAnchors(dataspaceName, anchorNames); + cpsAnchorService.deleteAnchors(dataspaceName, anchorNames); cpsModulePersistenceService.deleteUnusedYangResourceModules(); cpsModulePersistenceService.deleteSchemaSets(dataspaceName, schemaSetNames); for (final String schemaSetName : schemaSetNames) { diff --git a/cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java b/cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java index d58ddf4fa9..35dc7347b2 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java +++ b/cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java @@ -26,7 +26,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; -import org.onap.cps.api.CpsAdminService; +import org.onap.cps.api.CpsAnchorService; import org.onap.cps.api.impl.YangTextSchemaSourceSetCache; import org.onap.cps.cache.AnchorDataCacheEntry; import org.onap.cps.cpspath.parser.CpsPathPrefixType; @@ -48,7 +48,7 @@ public class PrefixResolver { private static final String CACHE_ENTRY_PROPERTY_NAME = "prefixPerContainerName"; - private final CpsAdminService cpsAdminService; + private final CpsAnchorService cpsAnchorService; private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache; @@ -63,7 +63,7 @@ public class PrefixResolver { * @return the prefix of the module the top level element of given xpath */ public String getPrefix(final String dataspaceName, final String anchorName, final String xpath) { - final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); + final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName); return getPrefix(anchor, xpath); } -- cgit 1.2.3-korg