aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service
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-service
parentd006d121ed9044caa1b769cca931fc183c448a3b (diff)
Fix Code smells
Issue-ID: CPS-89 Change-Id: Ib1b6fbc6b6d712f169100825683e6db3e7c85cb9 Signed-off-by: shivasubedi <shiva.subedi@est.tech>
Diffstat (limited to 'cps-service')
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java13
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java5
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java6
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/YangUtils.java16
-rw-r--r--cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java7
5 files changed, 21 insertions, 26 deletions
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 cc290bf29d..fd0f76b536 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
@@ -26,7 +26,6 @@ import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.DataNodeBuilder;
import org.onap.cps.utils.YangUtils;
@@ -54,14 +53,14 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public void saveData(final String dataspaceName, final String anchorName, final String jsonData) {
- final DataNode dataNode = buildDataNodeFromJson(dataspaceName, anchorName, ROOT_NODE_XPATH, jsonData);
+ final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, ROOT_NODE_XPATH, jsonData);
cpsDataPersistenceService.storeDataNode(dataspaceName, anchorName, dataNode);
}
@Override
public void saveData(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData) {
- final DataNode dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService.addChildDataNode(dataspaceName, anchorName, parentNodeXpath, dataNode);
}
@@ -74,7 +73,7 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public void updateNodeLeaves(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData) {
- final DataNode dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService
.updateDataLeaves(dataspaceName, anchorName, dataNode.getXpath(), dataNode.getLeaves());
}
@@ -82,15 +81,15 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public void replaceNodeTree(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData) {
- final DataNode dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService.replaceDataNodeTree(dataspaceName, anchorName, dataNode);
}
private DataNode buildDataNodeFromJson(final String dataspaceName, final String anchorName,
final String parentNodeXpath, final String jsonData) {
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
- final SchemaContext schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
+ final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final var schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
if (ROOT_NODE_XPATH.equals(parentNodeXpath)) {
final NormalizedNode<?, ?> normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext);
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 990b7bb931..0b20c8a2bb 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
@@ -24,7 +24,6 @@ import org.onap.cps.api.CpsModuleService;
import org.onap.cps.spi.CascadeDeleteAllowed;
import org.onap.cps.spi.CpsModulePersistenceService;
import org.onap.cps.spi.model.SchemaSet;
-import org.onap.cps.yang.YangTextSchemaSourceSet;
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -41,7 +40,7 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Override
public void createSchemaSet(final String dataspaceName, final String schemaSetName,
final Map<String, String> yangResourcesNameToContentMap) {
- final YangTextSchemaSourceSet yangTextSchemaSourceSet
+ final var yangTextSchemaSourceSet
= YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap);
cpsModulePersistenceService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap);
yangTextSchemaSourceSetCache.updateCache(dataspaceName, schemaSetName, yangTextSchemaSourceSet);
@@ -49,7 +48,7 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Override
public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) {
- final YangTextSchemaSourceSet yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
+ final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
.get(dataspaceName, schemaSetName);
return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName)
.moduleReferences(yangTextSchemaSourceSet.getModuleReferences()).build();
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
index cf79ad7e0b..253d4c6242 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
@@ -120,7 +120,7 @@ public class DataNodeBuilder {
}
private DataNode buildFromAttributes() {
- final DataNode dataNode = new DataNode();
+ final var dataNode = new DataNode();
dataNode.setXpath(xpath);
dataNode.setLeaves(leaves);
dataNode.setChildDataNodes(childDataNodes);
@@ -128,7 +128,7 @@ public class DataNodeBuilder {
}
private DataNode buildFromNormalizedNodeTree() {
- final DataNode parentDataNode = new DataNodeBuilder().withXpath(parentNodeXpath).build();
+ final var parentDataNode = new DataNodeBuilder().withXpath(parentNodeXpath).build();
addDataNodeFromNormalizedNode(parentDataNode, normalizedNodeTree);
return parentDataNode.getChildDataNodes().iterator().next();
}
@@ -187,7 +187,7 @@ public class DataNodeBuilder {
private static DataNode createAndAddChildDataNode(final DataNode parentDataNode, final String childXpath) {
- final DataNode newChildDataNode = new DataNodeBuilder()
+ final var newChildDataNode = new DataNodeBuilder()
.withXpath(parentDataNode.getXpath() + childXpath)
.build();
final Set<DataNode> allChildDataNodes = new ImmutableSet.Builder<DataNode>()
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 edef5cbca5..0b66d37fba 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
@@ -37,8 +37,6 @@ import lombok.extern.slf4j.Slf4j;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory;
import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
@@ -77,23 +75,23 @@ public class YangUtils {
@SuppressWarnings("squid:S1452") // Generic type <? ,?> is returned by external librray, opendaylight.yangtools
public static NormalizedNode<?, ?> parseJsonData(final String jsonData, final SchemaContext schemaContext,
final String parentNodeXpath) {
- final DataSchemaNode parentSchemaNode = getDataSchemaNodeByXpath(parentNodeXpath, schemaContext);
+ final var parentSchemaNode = getDataSchemaNodeByXpath(parentNodeXpath, schemaContext);
return parseJsonData(jsonData, schemaContext, Optional.of(parentSchemaNode));
}
private static NormalizedNode<?, ?> parseJsonData(final String jsonData, final SchemaContext schemaContext,
final Optional<DataSchemaNode> optionalParentSchemaNode) {
- final JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02
+ final var jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02
.getShared(schemaContext);
- final NormalizedNodeResult normalizedNodeResult = new NormalizedNodeResult();
- final NormalizedNodeStreamWriter normalizedNodeStreamWriter = ImmutableNormalizedNodeStreamWriter
+ final var normalizedNodeResult = new NormalizedNodeResult();
+ final var normalizedNodeStreamWriter = ImmutableNormalizedNodeStreamWriter
.from(normalizedNodeResult);
try (final JsonParserStream jsonParserStream = optionalParentSchemaNode.isPresent()
? JsonParserStream.create(normalizedNodeStreamWriter, jsonCodecFactory, optionalParentSchemaNode.get())
: JsonParserStream.create(normalizedNodeStreamWriter, jsonCodecFactory)
) {
- final JsonReader jsonReader = new JsonReader(new StringReader(jsonData));
+ final var jsonReader = new JsonReader(new StringReader(jsonData));
jsonParserStream.parse(jsonReader);
} catch (final IOException | IllegalStateException | JsonSyntaxException exception) {
@@ -110,7 +108,7 @@ public class YangUtils {
* @return an xpath
*/
public static String buildXpath(final YangInstanceIdentifier.PathArgument nodeIdentifier) {
- final StringBuilder xpathBuilder = new StringBuilder();
+ final var xpathBuilder = new StringBuilder();
xpathBuilder.append("/").append(nodeIdentifier.getNodeType().getLocalName());
if (nodeIdentifier instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
@@ -173,7 +171,7 @@ public class YangUtils {
}
private static String[] getNextLevelXpathNodeIdSequence(final String[] xpathNodeIdSequence) {
- final String[] nextXpathNodeIdSequence = new String[xpathNodeIdSequence.length - 1];
+ final var nextXpathNodeIdSequence = new String[xpathNodeIdSequence.length - 1];
System.arraycopy(xpathNodeIdSequence, 1, nextXpathNodeIdSequence, 0, nextXpathNodeIdSequence.length);
return nextXpathNodeIdSequence;
}
diff --git a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
index 712d9a0e27..0e8d939ee1 100644
--- a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
@@ -30,7 +30,6 @@ import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.NoArgsConstructor;
@@ -62,7 +61,7 @@ public final class YangTextSchemaSourceSetBuilder {
}
public YangTextSchemaSourceSet build() {
- final SchemaContext schemaContext = generateSchemaContext(yangModelMap.build());
+ final var schemaContext = generateSchemaContext(yangModelMap.build());
return new YangTextSchemaSourceSetImpl(schemaContext);
}
@@ -148,7 +147,7 @@ public final class YangTextSchemaSourceSetBuilder {
}
private static YangTextSchemaSource toYangTextSchemaSource(final String sourceName, final String source) {
- final RevisionSourceIdentifier revisionSourceIdentifier =
+ final var revisionSourceIdentifier =
createIdentifierFromSourceName(checkNotNull(sourceName));
return new YangTextSchemaSource(revisionSourceIdentifier) {
@@ -166,7 +165,7 @@ public final class YangTextSchemaSourceSetBuilder {
}
private static RevisionSourceIdentifier createIdentifierFromSourceName(final String sourceName) {
- final Matcher matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName);
+ final var matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName);
if (matcher.matches()) {
return RevisionSourceIdentifier.create(matcher.group(1), Revision.of(matcher.group(2)));
}