summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java59
1 files changed, 3 insertions, 56 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index 2a4a19226..5fe646ff8 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -24,7 +24,6 @@ package org.onap.cps.spi.impl;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
-import com.hazelcast.map.IMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -33,7 +32,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -46,15 +44,11 @@ import org.onap.cps.cpspath.parser.CpsPathUtil;
import org.onap.cps.cpspath.parser.PathParsingException;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.cache.AnchorDataCacheConfig;
-import org.onap.cps.spi.cache.AnchorDataCacheEntry;
import org.onap.cps.spi.entities.AnchorEntity;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.FragmentEntity;
import org.onap.cps.spi.entities.FragmentEntityArranger;
import org.onap.cps.spi.entities.FragmentExtract;
-import org.onap.cps.spi.entities.SchemaSetEntity;
-import org.onap.cps.spi.entities.YangResourceEntity;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch;
import org.onap.cps.spi.exceptions.ConcurrencyException;
@@ -68,8 +62,6 @@ import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.FragmentRepository;
import org.onap.cps.spi.utils.SessionManager;
import org.onap.cps.utils.JsonObjectMapper;
-import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
@@ -83,7 +75,6 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
private final FragmentRepository fragmentRepository;
private final JsonObjectMapper jsonObjectMapper;
private final SessionManager sessionManager;
- private final IMap<String, AnchorDataCacheEntry> anchorDataCache;
private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@[\\s\\S]+?]){0,1})";
private static final Pattern REG_EX_PATTERN_FOR_LIST_ELEMENT_KEY_PREDICATE =
@@ -225,9 +216,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final FetchDescendantsOption fetchDescendantsOption) {
final FragmentEntity fragmentEntity = getFragmentByXpath(dataspaceName, anchorName, xpath,
fetchDescendantsOption);
- final DataNode dataNode = toDataNode(fragmentEntity, fetchDescendantsOption);
- dataNode.setModuleNamePrefix(getRootModuleNamePrefix(fragmentEntity.getAnchor()));
- return dataNode;
+ return toDataNode(fragmentEntity, fetchDescendantsOption);
}
private FragmentEntity getFragmentWithoutDescendantsByXpath(final String dataspaceName,
@@ -285,12 +274,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
fragmentEntities = ancestorXpaths.isEmpty() ? Collections.emptyList()
: fragmentRepository.findAllByAnchorAndXpathIn(anchorEntity, ancestorXpaths);
}
- return fragmentEntities.stream()
- .map(fragmentEntity -> {
- final DataNode dataNode = toDataNode(fragmentEntity, fetchDescendantsOption);
- dataNode.setModuleNamePrefix(getRootModuleNamePrefix(anchorEntity));
- return dataNode;
- }).collect(Collectors.toUnmodifiableList());
+ return fragmentEntities.stream().map(fragmentEntity -> toDataNode(fragmentEntity, fetchDescendantsOption))
+ .collect(Collectors.toUnmodifiableList());
}
@Override
@@ -337,44 +322,6 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
.withChildDataNodes(childDataNodes).build();
}
- private String getRootModuleNamePrefix(final AnchorEntity anchorEntity) {
- final String cachedModuleNamePrefix = getModuleNamePrefixFromCache(anchorEntity.getName());
- if (cachedModuleNamePrefix != null) {
- return cachedModuleNamePrefix;
- }
- final String moduleNamePrefix = buildSchemaContextAndRetrieveModulePrefix(anchorEntity);
- cacheModuleNamePrefix(anchorEntity.getName(), moduleNamePrefix);
- return moduleNamePrefix;
- }
-
- private String buildSchemaContextAndRetrieveModulePrefix(final AnchorEntity anchorEntity) {
- final SchemaSetEntity schemaSetEntity = anchorEntity.getSchemaSet();
- final Map<String, String> yangResourceNameToContent =
- schemaSetEntity.getYangResources().stream().collect(
- Collectors.toMap(YangResourceEntity::getFileName, YangResourceEntity::getContent));
- final SchemaContext schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent)
- .getSchemaContext();
- return schemaContext.getModules().iterator().next().getName();
- }
-
- private void cacheModuleNamePrefix(final String anchorName, final String moduleNamePrefix) {
- final AnchorDataCacheEntry anchorDataCacheEntry = new AnchorDataCacheEntry();
- anchorDataCacheEntry.setProperty(TOP_LEVEL_MODULE_PREFIX_PROPERTY_NAME, moduleNamePrefix);
- if (anchorDataCache.putIfAbsent(anchorName, anchorDataCacheEntry,
- AnchorDataCacheConfig.ANCHOR_DATA_CACHE_TTL_SECS, TimeUnit.SECONDS) == null) {
- log.debug("Module name prefix for an anchor {} is cached", anchorName);
- }
- }
-
- private String getModuleNamePrefixFromCache(final String anchorName) {
- if (anchorDataCache.containsKey(anchorName)) {
- final AnchorDataCacheEntry anchorDataCacheEntry = anchorDataCache.get(anchorName);
- return anchorDataCacheEntry.hasProperty(TOP_LEVEL_MODULE_PREFIX_PROPERTY_NAME)
- ? anchorDataCacheEntry.getProperty(TOP_LEVEL_MODULE_PREFIX_PROPERTY_NAME).toString() : null;
- }
- return null;
- }
-
private List<DataNode> getChildDataNodes(final FragmentEntity fragmentEntity,
final FetchDescendantsOption fetchDescendantsOption) {
if (fetchDescendantsOption.hasNext()) {