aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java/org
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2020-12-14 15:20:58 +0000
committerGerrit Code Review <gerrit@onap.org>2020-12-14 15:20:58 +0000
commitc040bcb4ae61177b1aa691f059d19c96c6cfff7b (patch)
tree7535cf652f46cb0564db24f478575f3eaba99618 /cps-ri/src/main/java/org
parenta0da7f6b3e04ee6f06f4580f8a14e60f3438d5e7 (diff)
parent4ab9d0edb5bc0c5251175078a4b8933a29e73744 (diff)
Merge "Yang resource name persistence"
Diffstat (limited to 'cps-ri/src/main/java/org')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java4
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java34
2 files changed, 22 insertions, 16 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java
index 862b7aea64..b8a58d098f 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java
@@ -55,6 +55,10 @@ public class YangResource implements Serializable {
@NotNull
@Column
+ private String name;
+
+ @NotNull
+ @Column
private String content;
@ManyToMany(mappedBy = "yangResources")
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 e63ae5962f..3067f48345 100644
--- 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
@@ -21,6 +21,7 @@
package org.onap.cps.spi.impl;
import com.google.common.collect.ImmutableSet;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -61,10 +62,10 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
@Override
@Transactional
public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
- final Set<String> yangResourcesAsStrings) {
+ final Map<String, String> yangResourcesNameToContentMap) {
final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
- final Set<YangResource> yangResources = synchronizeYangResources(yangResourcesAsStrings);
+ final Set<YangResource> yangResources = synchronizeYangResources(yangResourcesNameToContentMap);
final SchemaSet schemaSet = new SchemaSet();
schemaSet.setName(schemaSetName);
schemaSet.setDataspace(dataspace);
@@ -76,24 +77,25 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
}
}
- private Set<YangResource> synchronizeYangResources(final Set<String> yangResourcesAsStrings) {
- final Map<String, String> checksumToContentMap = yangResourcesAsStrings.stream()
- .collect(Collectors.toMap(
- content -> DigestUtils.md5DigestAsHex(content.getBytes()),
- content -> content)
- );
-
- final List<YangResource> existingYangResources =
- yangResourceRepository.findAllByChecksumIn(checksumToContentMap.keySet());
- existingYangResources.forEach(yangFile -> checksumToContentMap.remove(yangFile.getChecksum()));
-
- final List<YangResource> newYangResources = checksumToContentMap.entrySet().stream()
+ private Set<YangResource> synchronizeYangResources(final Map<String, String> yangResourcesNameToContentMap) {
+ final Map<String, YangResource> checksumToEntityMap = yangResourcesNameToContentMap.entrySet().stream()
.map(entry -> {
final YangResource yangResource = new YangResource();
- yangResource.setChecksum(entry.getKey());
+ yangResource.setName(entry.getKey());
yangResource.setContent(entry.getValue());
+ yangResource.setChecksum(DigestUtils.md5DigestAsHex(entry.getValue().getBytes()));
return yangResource;
- }).collect(Collectors.toList());
+ })
+ .collect(Collectors.toMap(
+ YangResource::getChecksum,
+ entity -> entity
+ ));
+
+ final List<YangResource> existingYangResources =
+ yangResourceRepository.findAllByChecksumIn(checksumToEntityMap.keySet());
+ existingYangResources.forEach(yangFile -> checksumToEntityMap.remove(yangFile.getChecksum()));
+
+ final Collection<YangResource> newYangResources = checksumToEntityMap.values();
if (!newYangResources.isEmpty()) {
yangResourceRepository.saveAll(newYangResources);
}