aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2020-12-10 10:49:59 +0200
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>2020-12-14 08:23:13 +0000
commit4ab9d0edb5bc0c5251175078a4b8933a29e73744 (patch)
treeccf342787a59af944708edcc9e5541c71fc85f41 /cps-ri/src/main/java
parente182a6b6cb4a87b4f461adf83fe60a65948fc230 (diff)
Yang resource name persistence
Issue-ID: CPS-125 Change-Id: I5ee2e893dd7c30abe86287150e8bef62966dd909 Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-ri/src/main/java')
-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);
}