Added oparent to sdc main
[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 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen;
21
22 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
23 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
24 import com.amdocs.zusammen.datatypes.Id;
25 import com.amdocs.zusammen.datatypes.item.Relation;
26 import com.amdocs.zusammen.datatypes.item.RelationEdge;
27
28 import java.util.stream.Collectors;
29
30 public class VlmZusammenUtil {
31
32   static ZusammenElement getZusammenElement(ElementInfo elementInfo) {
33     ZusammenElement zusammenElement = new ZusammenElement();
34     zusammenElement.setElementId(elementInfo.getId());
35     zusammenElement.setInfo(elementInfo.getInfo());
36     zusammenElement.setRelations(elementInfo.getRelations());
37     zusammenElement.setSubElements(elementInfo.getSubElements().stream()
38         .map(VlmZusammenUtil::getZusammenElement)
39         .collect(Collectors.toList()));
40     return zusammenElement;
41   }
42
43   public static Relation createRelation(RelationType type, String to) {
44     Relation relation = new Relation();
45     relation.setType(type.name());
46     RelationEdge edge2 = new RelationEdge();
47     edge2.setElementId(new Id(to));
48     relation.setEdge2(edge2);
49     return relation;
50   }
51
52   public static Integer toInteger(Object val) {
53     if (val == null) {
54       return null;
55     }
56     if (val instanceof Double) {
57       return ((Double) val).intValue();
58     } else if (val instanceof String) {
59       return new Integer((String) val);
60     } else if (val instanceof Integer) {
61       return (Integer) val;
62     }
63     throw new RuntimeException("invalid value for integer:" + val.getClass());
64   }
65 }