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.plugin.statestore.cassandra.dao.types.ElementEntityContext;
6 import org.openecomp.core.zusammen.plugin.dao.impl.CassandraElementRepository;
7 import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
9 import java.util.HashMap;
10 import java.util.List;
12 import java.util.Optional;
14 public class VspGeneralLoader {
15 private static CassandraElementRepository cassandraElementRepository =
16 new CassandraElementRepository();
18 public static Map<String, ElementEntity> load(SessionContext context,
19 Map<String, List<String>> vspItemVersionsMap) {
20 Map<String, ElementEntity> elementEntityMap = new HashMap<>();
21 System.setProperty("cassandra.dox.keystore", "zusammen_dox");
26 for (Map.Entry<String, List<String>> entry : vspItemVersionsMap.entrySet()) {
28 for (String version : entry.getValue()) {
31 itemId = new Id(entry.getKey());
32 versionId = new Id(version);
33 entityId = getEntityIdByInfoNameValue(context, itemId, versionId, null, "name",
35 if (entityId != null) {
36 Optional<ElementEntity> result =
37 cassandraElementRepository.get(context, new ElementEntityContext(
38 context.getUser().getUserName(),
41 new ElementEntity(entityId));
42 if (result.isPresent()) {
43 elementEntityMap.put(context.getUser().getUserName() + "_" + entry.getKey()
44 + "_" + version, result.get());
50 return elementEntityMap;
53 private static Id getEntityIdByInfoNameValue(SessionContext context, Id itemId, Id versionId,
58 Optional<ElementEntity> result =
59 cassandraElementRepository.get(context, new ElementEntityContext(
60 context.getUser().getUserName(),
63 new ElementEntity(Id.ZERO));
64 if (result.isPresent()) {
65 ElementEntity elementEntity = result.get();
66 return elementEntity.getSubElementIds().stream().filter(subelementId -> {
67 Optional<ElementEntity> subElementEntity =
68 cassandraElementRepository.get(context, new ElementEntityContext(
69 context.getUser().getUserName(),
72 new ElementEntity(subelementId));
73 if (subElementEntity.isPresent()) {
74 if("name".equals(name)){
75 if(value.equals(subElementEntity.get().getInfo().getName())){
79 if (value.equals(subElementEntity.get().getInfo().getProperty(name))) {
85 }).findFirst().orElse(null);