aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main
diff options
context:
space:
mode:
authorshivasubedi <shiva.subedi@est.tech>2021-04-26 17:51:04 +0100
committerRishi Chail <rishi.chail@est.tech>2021-04-28 10:14:20 +0000
commita439dfa869d7ba55daeb97ae16735c3fd0a12985 (patch)
tree6ed309a7efd31b42667a94da1ca9462f13991f83 /cps-ri/src/main
parentd006d121ed9044caa1b769cca931fc183c448a3b (diff)
Fix Code smells
Issue-ID: CPS-89 Change-Id: Ib1b6fbc6b6d712f169100825683e6db3e7c85cb9 Signed-off-by: shivasubedi <shiva.subedi@est.tech>
Diffstat (limited to 'cps-ri/src/main')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java17
-rw-r--r--[-rwxr-xr-x]cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java34
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java18
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java12
4 files changed, 39 insertions, 42 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 edc56e4229..64c6ff507e 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
@@ -22,14 +22,13 @@
package org.onap.cps.spi.impl;
-import com.google.common.collect.ImmutableSet;
import java.util.Collection;
+import java.util.Set;
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;
-import org.onap.cps.spi.entities.SchemaSetEntity;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.repository.AnchorRepository;
@@ -66,10 +65,10 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
@Override
public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final SchemaSetEntity schemaSetEntity =
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var schemaSetEntity =
schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
- final AnchorEntity anchorEntity = AnchorEntity.builder()
+ final var anchorEntity = AnchorEntity.builder()
.name(anchorName)
.dataspace(dataspaceEntity)
.schemaSet(schemaSetEntity)
@@ -83,7 +82,7 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
@Override
public Collection<Anchor> getAnchors(final String dataspaceName) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final Collection<AnchorEntity> anchorEntities = anchorRepository.findAllByDataspace(dataspaceEntity);
return anchorEntities.stream().map(CpsAdminPersistenceServiceImpl::toAnchor).collect(Collectors.toList());
}
@@ -96,13 +95,13 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
@Transactional
@Override
public void deleteAnchor(final String dataspaceName, final String anchorName) {
- final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName);
- fragmentRepository.deleteByAnchorIn(ImmutableSet.of(anchorEntity));
+ final var anchorEntity = getAnchorEntity(dataspaceName, anchorName);
+ fragmentRepository.deleteByAnchorIn(Set.of(anchorEntity));
anchorRepository.delete(anchorEntity);
}
private AnchorEntity getAnchorEntity(final String dataspaceName, final String anchorName) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
return anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
}
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 a02b193d9e..48f1de710d 100755..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
@@ -67,7 +67,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
public void addChildDataNode(final String dataspaceName, final String anchorName, final String parentXpath,
final DataNode dataNode) {
final FragmentEntity parentFragment = getFragmentByXpath(dataspaceName, anchorName, parentXpath);
- final FragmentEntity fragmentEntity =
+ final var fragmentEntity =
toFragmentEntity(parentFragment.getDataspace(), parentFragment.getAnchor(), dataNode);
parentFragment.getChildFragments().add(fragmentEntity);
fragmentRepository.save(parentFragment);
@@ -75,9 +75,9 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
@Override
public void storeDataNode(final String dataspaceName, final String anchorName, final DataNode dataNode) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
- final FragmentEntity fragmentEntity = convertToFragmentWithAllDescendants(dataspaceEntity, anchorEntity,
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
+ final var fragmentEntity = convertToFragmentWithAllDescendants(dataspaceEntity, anchorEntity,
dataNode);
try {
fragmentRepository.save(fragmentEntity);
@@ -97,7 +97,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
*/
private static FragmentEntity convertToFragmentWithAllDescendants(final DataspaceEntity dataspaceEntity,
final AnchorEntity anchorEntity, final DataNode dataNodeToBeConverted) {
- final FragmentEntity parentFragment = toFragmentEntity(dataspaceEntity, anchorEntity, dataNodeToBeConverted);
+ final var parentFragment = toFragmentEntity(dataspaceEntity, anchorEntity, dataNodeToBeConverted);
final Builder<FragmentEntity> childFragmentsImmutableSetBuilder = ImmutableSet.builder();
for (final DataNode childDataNode : dataNodeToBeConverted.getChildDataNodes()) {
final FragmentEntity childFragment =
@@ -122,14 +122,14 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
@Override
public DataNode getDataNode(final String dataspaceName, final String anchorName, final String xpath,
final FetchDescendantsOption fetchDescendantsOption) {
- final FragmentEntity fragmentEntity = getFragmentByXpath(dataspaceName, anchorName, xpath);
+ final var fragmentEntity = getFragmentByXpath(dataspaceName, anchorName, xpath);
return toDataNode(fragmentEntity, fetchDescendantsOption);
}
private FragmentEntity getFragmentByXpath(final String dataspaceName, final String anchorName,
final String xpath) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
if (isRootXpath(xpath)) {
return fragmentRepository.getFirstByDataspaceAndAnchor(dataspaceEntity, anchorEntity);
} else {
@@ -141,19 +141,19 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
@Override
public List<DataNode> queryDataNodes(final String dataspaceName, final String anchorName, final String cpsPath,
final FetchDescendantsOption fetchDescendantsOption) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
- final CpsPathQuery cpsPathQuery = CpsPathQuery.createFrom(cpsPath);
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
+ final var cpsPathQuery = CpsPathQuery.createFrom(cpsPath);
final List<FragmentEntity> fragmentEntities;
if (CpsPathQueryType.XPATH_LEAF_VALUE.equals(cpsPathQuery.getCpsPathQueryType())) {
fragmentEntities = fragmentRepository
- .getByAnchorAndXpathAndLeafAttributes(anchorEntity.getId(), cpsPathQuery.getXpathPrefix(), cpsPathQuery
- .getLeafName(), cpsPathQuery.getLeafValue());
+ .getByAnchorAndXpathAndLeafAttributes(anchorEntity.getId(), cpsPathQuery.getXpathPrefix(),
+ cpsPathQuery.getLeafName(), cpsPathQuery.getLeafValue());
} else if (CpsPathQueryType.XPATH_HAS_DESCENDANT_WITH_LEAF_VALUES.equals(cpsPathQuery.getCpsPathQueryType())) {
final String leafDataAsJson = GSON.toJson(cpsPathQuery.getLeavesData());
fragmentEntities = fragmentRepository
- .getByAnchorAndDescendentNameAndLeafValues(anchorEntity.getId(),
- cpsPathQuery.getDescendantName(), leafDataAsJson);
+ .getByAnchorAndDescendentNameAndLeafValues(anchorEntity.getId(), cpsPathQuery.getDescendantName(),
+ leafDataAsJson);
} else {
fragmentEntities = fragmentRepository
.getByAnchorAndXpathEndsInDescendantName(anchorEntity.getId(), cpsPathQuery.getDescendantName());
@@ -186,14 +186,14 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
@Override
public void updateDataLeaves(final String dataspaceName, final String anchorName, final String xpath,
final Map<String, Object> leaves) {
- final FragmentEntity fragmentEntity = getFragmentByXpath(dataspaceName, anchorName, xpath);
+ final var fragmentEntity = getFragmentByXpath(dataspaceName, anchorName, xpath);
fragmentEntity.setAttributes(GSON.toJson(leaves));
fragmentRepository.save(fragmentEntity);
}
@Override
public void replaceDataNodeTree(final String dataspaceName, final String anchorName, final DataNode dataNode) {
- final FragmentEntity fragmentEntity = getFragmentByXpath(dataspaceName, anchorName, dataNode.getXpath());
+ final var fragmentEntity = getFragmentByXpath(dataspaceName, anchorName, dataNode.getXpath());
removeExistingDescendants(fragmentEntity);
fragmentEntity.setAttributes(GSON.toJson(dataNode.getLeaves()));
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
index 9d3298e35e..ae6543dabe 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
@@ -33,12 +33,10 @@ import org.onap.cps.spi.CascadeDeleteAllowed;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.CpsModulePersistenceService;
import org.onap.cps.spi.entities.AnchorEntity;
-import org.onap.cps.spi.entities.DataspaceEntity;
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.SchemaSetInUseException;
-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;
@@ -75,9 +73,9 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
final Map<String, String> yangResourcesNameToContentMap) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final Set<YangResourceEntity> yangResourceEntities = synchronizeYangResources(yangResourcesNameToContentMap);
- final SchemaSetEntity schemaSetEntity = new SchemaSetEntity();
+ final var schemaSetEntity = new SchemaSetEntity();
schemaSetEntity.setName(schemaSetName);
schemaSetEntity.setDataspace(dataspaceEntity);
schemaSetEntity.setYangResources(yangResourceEntities);
@@ -92,7 +90,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
final Map<String, YangResourceEntity> checksumToEntityMap = yangResourcesNameToContentMap.entrySet().stream()
.map(entry -> {
final String checksum = DigestUtils.sha256Hex(entry.getValue().getBytes(StandardCharsets.UTF_8));
- final YangResourceEntity yangResourceEntity = new YangResourceEntity();
+ final var yangResourceEntity = new YangResourceEntity();
yangResourceEntity.setName(entry.getKey());
yangResourceEntity.setContent(entry.getValue());
yangResourceEntity.setChecksum(checksum);
@@ -120,8 +118,8 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
public Map<String, String> getYangSchemaResources(final String dataspaceName, final String schemaSetName) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final SchemaSetEntity schemaSetEntity =
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var schemaSetEntity =
schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
return schemaSetEntity.getYangResources().stream().collect(
Collectors.toMap(YangResourceEntity::getName, YangResourceEntity::getContent));
@@ -129,7 +127,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
public Map<String, String> getYangSchemaSetResources(final String dataspaceName, final String anchorName) {
- final Anchor anchor = cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName);
+ final var anchor = cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName);
return getYangSchemaResources(dataspaceName, anchor.getSchemaSetName());
}
@@ -137,8 +135,8 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Transactional
public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
final CascadeDeleteAllowed cascadeDeleteAllowed) {
- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final SchemaSetEntity schemaSetEntity =
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ final var schemaSetEntity =
schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
final Collection<AnchorEntity> anchorEntities = anchorRepository.findAllBySchemaSet(schemaSetEntity);
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java b/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java
index ac7e7e0ac3..6f53e0013d 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java
@@ -71,8 +71,8 @@ public class CpsPathQuery {
* @return a CpsPath object.
*/
public static CpsPathQuery createFrom(final String cpsPath) {
- Matcher matcher = QUERY_CPS_PATH_WITH_SINGLE_LEAF_PATTERN.matcher(cpsPath);
- final CpsPathQuery cpsPathQuery = new CpsPathQuery();
+ var matcher = QUERY_CPS_PATH_WITH_SINGLE_LEAF_PATTERN.matcher(cpsPath);
+ final var cpsPathQuery = new CpsPathQuery();
if (matcher.matches()) {
return buildCpsPathQueryWithSingleLeafPattern(cpsPath, matcher, cpsPathQuery);
}
@@ -105,7 +105,7 @@ public class CpsPathQuery {
cpsPathQuery.setDescendantName(matcher.group(1));
final Map<String, Object> leafData = new HashMap<>();
for (final String leafValuePair : matcher.group(2).split(INDIVIDUAL_LEAF_DETAIL_PATTERN)) {
- final Matcher descendentMatcher = LEAF_VALUE_PATTERN.matcher(leafValuePair);
+ final var descendentMatcher = LEAF_VALUE_PATTERN.matcher(leafValuePair);
if (descendentMatcher.matches()) {
leafData.put(descendentMatcher.group(1),
convertLeafValueToCorrectType(descendentMatcher.group(2), cpsPath));
@@ -119,17 +119,17 @@ public class CpsPathQuery {
}
private static Object convertLeafValueToCorrectType(final String leafValueString, final String cpsPath) {
- final Matcher stringValueWithSingleQuotesMatcher =
+ final var stringValueWithSingleQuotesMatcher =
LEAF_STRING_VALUE_IN_SINGLE_QUOTES_PATTERN.matcher(leafValueString);
if (stringValueWithSingleQuotesMatcher.matches()) {
return stringValueWithSingleQuotesMatcher.group(1);
}
- final Matcher stringValueWithDoubleQuotesMatcher =
+ final var stringValueWithDoubleQuotesMatcher =
LEAF_STRING_VALUE_IN_DOUBLE_QUOTES_PATTERN.matcher(leafValueString);
if (stringValueWithDoubleQuotesMatcher.matches()) {
return stringValueWithDoubleQuotesMatcher.group(1);
}
- final Matcher integerValueMatcher = LEAF_INTEGER_VALUE_PATTERN.matcher(leafValueString);
+ final var integerValueMatcher = LEAF_INTEGER_VALUE_PATTERN.matcher(leafValueString);
if (integerValueMatcher.matches()) {
return Integer.valueOf(leafValueString);
}