20674c669a186ac3e614f7b834e12c27f71dc636
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor;
17
18 import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
19 import org.openecomp.convertor.ElementConvertor;
20 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
21 import org.openecomp.sdc.vendorlicense.dao.types.LimitType;
22
23 /**
24  * Created by ayalaben on 9/26/2017
25  */
26 public class ElementToLimitConvertor extends ElementConvertor<LimitEntity> {
27   @Override
28   public LimitEntity convert(Element element) {
29     if (element == null) {
30       return null;
31     }
32     return mapElementToLimitEntity(element);
33   }
34
35   private LimitEntity mapElementToLimitEntity(Element element) {
36     LimitEntity limit = new LimitEntity();
37     limit.setId(element.getElementId().getValue());
38     limit.setName(element.getInfo().getName());
39     limit.setDescription(element.getInfo().getDescription());
40     limit.setUnit(element.getInfo().getProperty("unit"));
41     limit.setMetric(element.getInfo().getProperty("metric"));
42     limit.setValue(element.getInfo().getProperty("value"));
43     limit.setTime(element.getInfo().getProperty("time"));
44     limit.setAggregationFunction(element.getInfo().getProperty("aggregationFunction"));
45     setLimitType(limit,element.getInfo().getProperty("type"));
46
47     return limit;
48   }
49
50   private void setLimitType(LimitEntity limit, String type) {
51     switch (LimitType.valueOf(type)) {
52       case ServiceProvider:
53         limit.setType(LimitType.ServiceProvider);
54         break;
55       case Vendor:
56         limit.setType(LimitType.Vendor);
57     }
58   }
59 }