1 package org.openecomp.core.tools.store;
3 import com.amdocs.zusammen.datatypes.Id;
4 import com.amdocs.zusammen.datatypes.SessionContext;
5 import com.amdocs.zusammen.datatypes.item.Info;
6 import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
7 import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository;
8 import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
10 import java.util.HashMap;
11 import java.util.List;
13 import java.util.Optional;
14 import java.util.Objects;
16 public class VspGeneralLoader {
18 public static final String NAME = "name";
19 public static final String GENERAL = "General";
21 private static CassandraElementRepository cassandraElementRepository =
22 new CassandraElementRepository();
24 public static Map<String, ElementEntity> load(SessionContext context,
25 Map<String, List<String>> vspItemVersionsMap,
26 Map<String, List<String>> vspItemChangeRefssMap) {
27 Map<String, ElementEntity> elementEntityMap = new HashMap<>();
28 System.setProperty("cassandra.dox.keystore", "zusammen_dox");
33 for (Map.Entry<String, List<String>> entry : vspItemVersionsMap.entrySet()) {
35 for (String version : entry.getValue()) {
38 itemId = new Id(entry.getKey());
39 changeRefId = new Id(version);
40 entityId = getEntityIdByInfoNameValue(context, itemId, changeRefId, null, null, NAME,
42 if (entityId != null) {
43 Optional<ElementEntity> result =
44 cassandraElementRepository.get(context, new ElementEntityContext(
45 context.getUser().getUserName(),
48 new ElementEntity(entityId));
49 if (result.isPresent()) {
50 elementEntityMap.put(buildKey(context, entry, version), result.get());
57 for (Map.Entry<String, List<String>> entry : vspItemChangeRefssMap.entrySet()) {
59 for (String changeRef : entry.getValue()) {
62 itemId = new Id(entry.getKey());
64 entityId = getEntityIdByInfoNameValue(context, itemId, null, changeRef,null, NAME,
66 if (entityId != null) {
67 ElementEntityContext elementContext = new ElementEntityContext(
68 context.getUser().getUserName(),
71 elementContext.setChangeRef(changeRef);
72 Optional<ElementEntity> result =
73 cassandraElementRepository.get(context, elementContext,
74 new ElementEntity(entityId));
75 if (result.isPresent()) {
76 elementEntityMap.put(buildKey(context, entry, changeRef), result.get());
83 return elementEntityMap;
86 public static String buildKey(SessionContext context, Map.Entry<String, List<String>> entry, String version) {
87 return String.format("%s_%s_%s", context.getUser().getUserName(), entry.getKey(), version);
90 private static Id getEntityIdByInfoNameValue(SessionContext context,
99 ElementEntityContext elementContext = new ElementEntityContext(
100 context.getUser().getUserName(),
103 if (changeRef != null) {
104 elementContext.setChangeRef(changeRef);
106 Optional<ElementEntity> result =
107 cassandraElementRepository.get(context, elementContext,
108 new ElementEntity(Id.ZERO));
109 if (result.isPresent()) {
110 ElementEntity elementEntity = result.get();
111 return elementEntity.getSubElementIds().stream().filter(subelementId -> {
112 ElementEntityContext subElementContext = new ElementEntityContext(
113 context.getUser().getUserName(),
116 if(changeRef!= null){
117 subElementContext.setChangeRef(changeRef);
119 Optional<ElementEntity> subElementEntityOptional =
120 cassandraElementRepository.get(context, subElementContext,
121 new ElementEntity(subelementId));
122 if (subElementEntityOptional.isPresent()) {
123 Info info = subElementEntityOptional.get().getInfo();
124 if (isValid(name, info)) {
127 if (NAME.equals(name)) {
128 if (value.equals(info.getName())) {
132 if (value.equals(info.getProperty(name))) {
138 }).findFirst().orElse(null);
145 private static boolean isValid(String name, Info info) {
146 return Objects.isNull(info)|| Objects.isNull(info.getProperty(name));