5e80d4c355a602efa43b6b15a50cc29ba6a253e3
[sdc.git] /
1 package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen;
2
3 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
4 import com.amdocs.zusammen.datatypes.Id;
5 import com.amdocs.zusammen.datatypes.SessionContext;
6 import com.amdocs.zusammen.datatypes.item.Action;
7 import com.amdocs.zusammen.datatypes.item.ItemVersion;
8 import org.openecomp.core.zusammen.api.ZusammenAdaptor;
9 import org.openecomp.core.zusammen.api.ZusammenUtil;
10 import org.openecomp.sdc.common.errors.CoreException;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.VendorSoftwareProductNotFoundErrorBuilder;
12 import org.openecomp.sdc.versioning.dao.types.Version;
13 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
14
15 import java.util.Objects;
16 import java.util.Optional;
17
18 class VspZusammenUtil {
19
20   static ItemVersion getFirstVersion(SessionContext context, Id itemId, ZusammenAdaptor
21       zusammenAdaptor) {
22
23     Optional<ItemVersion> itemVersion = zusammenAdaptor.getFirstVersion(context, itemId);
24
25     if (!itemVersion.isPresent()) {
26       throw new CoreException(
27           new VendorSoftwareProductNotFoundErrorBuilder(itemId.getValue()).build());
28     }
29     return itemVersion.get();
30   }
31
32   static Id getFirstVersionId(SessionContext context, Id itemId, ZusammenAdaptor zusammenAdaptor) {
33     return getFirstVersion(context, itemId, zusammenAdaptor).getId();
34   }
35
36   // TODO: 4/25/2017 remove upon working with more than one single version
37   static String getVersionTag(Version version) {
38     return version.getStatus() == VersionStatus.Locked
39         ? null
40         : version.toString();
41   }
42
43   static ZusammenElement buildStructuralElement(StructureElement structureElement, Action action) {
44     return ZusammenUtil.buildStructuralElement(structureElement.name(), action);
45   }
46
47   static ZusammenElement aggregateElements(ZusammenElement... elements) {
48     ZusammenElement head = null;
49     ZusammenElement father = null;
50     for (ZusammenElement element : elements) {
51       if (Objects.isNull(head)) {
52         head = father = element;
53       } else {
54         if (father != null) {
55           father.getSubElements().add(element);
56           father = element;
57         }
58       }
59     }
60
61     return head;
62   }
63 }