1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.utils.fileutils.FileUtils;
import org.openecomp.core.utilities.json.JsonUtil;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.core.zusammen.api.ZusammenUtil;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
import java.util.Optional;
public class OrchestrationTemplateCandidateDaoZusammenImpl
implements OrchestrationTemplateCandidateDao {
private static final Logger logger =
LoggerFactory.getLogger(OrchestrationTemplateCandidateDaoZusammenImpl.class);
private ZusammenAdaptor zusammenAdaptor;
public OrchestrationTemplateCandidateDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
this.zusammenAdaptor = zusammenAdaptor;
}
@Override
public void registerVersioning(String versionableEntityType) {
}
@Override
public OrchestrationTemplateCandidateData get(String vspId, Version version) {
logger.info("Getting orchestration template for vsp id -> " + vspId);
SessionContext context = ZusammenUtil.createSessionContext();
Id itemId = new Id(vspId);
Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor);
ElementContext elementContext = new ElementContext(itemId, versionId,
VspZusammenUtil.getVersionTag(version));
Optional<Element> candidateElement =
zusammenAdaptor.getElementByName(context, elementContext, null,
StructureElement.OrchestrationTemplateCandidate.name());
if (candidateElement.isPresent()) {
OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData();
candidateData.setFilesDataStructure(
new String(FileUtils.toByteArray(candidateElement.get().getData())));
zusammenAdaptor
.getElementByName(context, elementContext, candidateElement.get().getElementId(),
StructureElement.OrchestrationTemplateCandidateContent.name())
.ifPresent(candidateContentElement -> candidateData.setContentData(
ByteBuffer.wrap(FileUtils.toByteArray(candidateContentElement.getData()))));
logger.info("Finished getting orchestration template for vsp id -> " + vspId);
return candidateData;
}
logger.info(String.format("Orchestration template for vsp id %s does not exist", vspId));
return null;
}
@Override
public void update(String vspId, OrchestrationTemplateCandidateData candidateData) {
logger.info("Uploading candidate data entity for vsp id -> " + vspId);
SessionContext context = ZusammenUtil.createSessionContext();
Id itemId = new Id(vspId);
Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor);
ElementContext elementContext = new ElementContext(itemId, versionId);
ZusammenElement candidateElement = VspZusammenUtil
.buildStructuralElement(StructureElement.OrchestrationTemplateCandidate, Action.UPDATE);
candidateElement
.setData(new ByteArrayInputStream(candidateData.getFilesDataStructure().getBytes()));
ZusammenElement candidateContentElement = VspZusammenUtil
.buildStructuralElement(StructureElement.OrchestrationTemplateCandidateContent, Action.UPDATE);
candidateContentElement
.setData(new ByteArrayInputStream(candidateData.getContentData().array()));
candidateElement.addSubElement(candidateContentElement);
zusammenAdaptor.saveElement(context, elementContext, candidateElement,
"Update Orchestration Template Candidate");
logger.info("Finished uploading candidate data entity for vsp id -> " + vspId);
}
@Override
public void updateStructure(String vspId, Version version, FilesDataStructure fileDataStructure) {
logger.info("Updating orchestration template for VSP id -> " + vspId);
SessionContext context = ZusammenUtil.createSessionContext();
Id itemId = new Id(vspId);
Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor);
ElementContext elementContext = new ElementContext(itemId, versionId);
ZusammenElement candidateElement = VspZusammenUtil
.buildStructuralElement(StructureElement.OrchestrationTemplateCandidate, Action.UPDATE);
candidateElement
.setData(new ByteArrayInputStream(JsonUtil.object2Json(fileDataStructure).getBytes()));
zusammenAdaptor.saveElement(context, elementContext, candidateElement,
"Update Orchestration Template Candidate structure");
logger.info("Finished uploading candidate data entity for vsp id -> " + vspId);
}
@Override
public Optional<String> getStructure(String vspId, Version version) {
logger.info("Getting orchestration template structure for vsp id -> " + vspId);
SessionContext context = ZusammenUtil.createSessionContext();
Id itemId = new Id(vspId);
Id versionId = VspZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor);
ElementContext elementContext = new ElementContext(itemId, versionId,
VspZusammenUtil.getVersionTag(version));
logger.info("Finished getting orchestration template structure for vsp id -> " + vspId);
Optional<Element> element = zusammenAdaptor.getElementByName(context, elementContext, null,
StructureElement.OrchestrationTemplateCandidate.name());
if (element.isPresent()) {
return Optional.of(new String(FileUtils.toByteArray(element.get().getData())));
} else {
return Optional.empty();
}
}
}
|