Add collaboration feature
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-license-lib / openecomp-sdc-vendor-license-core / src / main / java / org / openecomp / sdc / vendorlicense / dao / impl / zusammen / VlmZusammenUtil.java
1 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen;
2
3 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
4 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
5 import com.amdocs.zusammen.datatypes.Id;
6 import com.amdocs.zusammen.datatypes.item.Relation;
7 import com.amdocs.zusammen.datatypes.item.RelationEdge;
8
9 import java.util.stream.Collectors;
10
11 public class VlmZusammenUtil {
12
13   static ZusammenElement getZusammenElement(ElementInfo elementInfo) {
14     ZusammenElement zusammenElement = new ZusammenElement();
15     zusammenElement.setElementId(elementInfo.getId());
16     zusammenElement.setInfo(elementInfo.getInfo());
17     zusammenElement.setRelations(elementInfo.getRelations());
18     zusammenElement.setSubElements(elementInfo.getSubElements().stream()
19         .map(VlmZusammenUtil::getZusammenElement)
20         .collect(Collectors.toList()));
21     return zusammenElement;
22   }
23
24   public static Relation createRelation(RelationType type, String to) {
25     Relation relation = new Relation();
26     relation.setType(type.name());
27     RelationEdge edge2 = new RelationEdge();
28     edge2.setElementId(new Id(to));
29     relation.setEdge2(edge2);
30     return relation;
31   }
32
33   public static Integer toInteger(Object val) {
34     if (val == null) {
35       return null;
36     }
37     if (val instanceof Double) {
38       return ((Double) val).intValue();
39     } else if (val instanceof String) {
40       return new Integer((String) val);
41     } else if (val instanceof Integer) {
42       return (Integer) val;
43     }
44     throw new RuntimeException("invalid value for integer:" + val.getClass());
45   }
46 }