diff options
author | Ruslan Kashapov <ruslan.kashapov@pantheon.tech> | 2021-04-05 12:59:57 +0300 |
---|---|---|
committer | Rishi Chail <rishi.chail@est.tech> | 2021-04-07 11:45:24 +0000 |
commit | 4b8ae57149d157cfe8619f99dd8fb82e067f26ce (patch) | |
tree | 261d5e399b4532d82d2f47847ccee3e0551dd443 /cps-ri/src/main | |
parent | 26effb23f559df0256327b8d37c865e023a41292 (diff) |
Delete anchor part 1: service and persistence layers
Issue-ID: CPS-312
Change-Id: I10ab5a2d115ffdf8179a99b6ec712f3eccfb5f13
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-ri/src/main')
-rwxr-xr-x | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java index 1b8f1968bc..edc56e4229 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 Pantheon.tech * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +22,10 @@ package org.onap.cps.spi.impl; +import com.google.common.collect.ImmutableSet; import java.util.Collection; import java.util.stream.Collectors; +import javax.transaction.Transactional; import org.onap.cps.spi.CpsAdminPersistenceService; import org.onap.cps.spi.entities.AnchorEntity; import org.onap.cps.spi.entities.DataspaceEntity; @@ -31,6 +34,7 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedException; import org.onap.cps.spi.model.Anchor; import org.onap.cps.spi.repository.AnchorRepository; import org.onap.cps.spi.repository.DataspaceRepository; +import org.onap.cps.spi.repository.FragmentRepository; import org.onap.cps.spi.repository.SchemaSetRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; @@ -48,6 +52,9 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic @Autowired private SchemaSetRepository schemaSetRepository; + @Autowired + private FragmentRepository fragmentRepository; + @Override public void createDataspace(final String dataspaceName) { try { @@ -83,10 +90,20 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic @Override public Anchor getAnchor(final String dataspaceName, final String anchorName) { + return toAnchor(getAnchorEntity(dataspaceName, anchorName)); + } + + @Transactional + @Override + public void deleteAnchor(final String dataspaceName, final String anchorName) { + final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName); + fragmentRepository.deleteByAnchorIn(ImmutableSet.of(anchorEntity)); + anchorRepository.delete(anchorEntity); + } + + private AnchorEntity getAnchorEntity(final String dataspaceName, final String anchorName) { final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); - final AnchorEntity anchorEntity = - anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName); - return toAnchor(anchorEntity); + return anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName); } private static Anchor toAnchor(final AnchorEntity anchorEntity) { |