fix incorrect dependency
[sdc.git] / openecomp-be / tools / migration / 1702_to_1707_zusammen / src / main / java / org / openecomp / core / migration / convertors / NetworkConvertor.java
1 package org.openecomp.core.migration.convertors;
2
3 import com.amdocs.zusammen.datatypes.item.ElementContext;
4 import com.amdocs.zusammen.datatypes.item.Info;
5 import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
6 import com.amdocs.zusammen.sdk.collaboration.types.CollaborationElement;
7 import org.openecomp.core.migration.MigrationMain;
8 import org.openecomp.core.migration.store.ElementHandler;
9 import org.openecomp.sdc.logging.api.Logger;
10 import org.openecomp.sdc.logging.api.LoggerFactory;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ElementPropertyName;
12 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.ElementType;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.StructureElement;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
15
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Set;
19
20 /**
21  * @author katyr
22  * @since April 23, 2017
23  */
24
25 public class NetworkConvertor {
26
27   private static Set<String> networksLoaded = new HashSet<>();
28   private static Logger logger = LoggerFactory.getLogger(MigrationMain.class);
29
30
31
32   public static CollaborationElement[] convertNetworkToElement(NetworkEntity networkEntity) {
33
34     CollaborationElement[] networkElements;
35     List<String> networkNamespace = getNetworkNamespace();
36
37     int index = 0;
38     String networksEntityId = StructureElement.Networks.name();
39     String uniqueId = networkEntity.getVspId()+"_"+networkEntity.getVersion().toString();
40     if (networksLoaded.contains(uniqueId)) {
41 //      printMessage(logger, "Networks structural elements exist for network " +
42 //          networkEntity.getId());
43       networkElements = new CollaborationElement[1];
44     } else {
45 //      printMessage(logger, "Creating Networks structural element for network " +
46 //          networkEntity.getId());
47       networksLoaded.add(uniqueId);
48       networkElements = new CollaborationElement[2];
49       networkElements[index] = ElementHandler.getElementEntity(
50           networkEntity.getVspId(), networkEntity.getVersion().toString(), networksEntityId,
51           networkNamespace,
52           ElementHandler.getStructuralElementInfo(StructureElement.Networks.name()),
53           null,
54           null,
55           null);
56       index++;
57     }
58
59     networkNamespace.add(networksEntityId);
60
61     networkElements[index] = ElementHandler.getElementEntity(
62         networkEntity.getVspId(), networkEntity.getVersion().toString(), networkEntity.getId(),
63         networkNamespace,
64         getNetworkInfo(networkEntity),
65         null,
66         null,
67         networkEntity.getCompositionData().getBytes());
68
69
70     return networkElements;
71   }
72
73   private static Info getNetworkInfo(NetworkEntity networkEntity) {
74     Info info = new Info();
75     info.addProperty(ElementPropertyName.type.name(), ElementType.Network);
76     info.addProperty(ElementPropertyName.compositionData.name(), networkEntity.getCompositionData());
77
78     return info;
79   }
80
81   private static List<String> getNetworkNamespace() {
82     return ElementHandler.getElementPath();
83   }
84
85   public static ElementEntityContext convertNetworkToElementContext(NetworkEntity networkEntity) {
86
87     return new ElementEntityContext("GLOBAL_USER", new
88         ElementContext(networkEntity.getVspId(), networkEntity.getVersion().toString()));
89   }
90
91 }