[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-license-lib / openecomp-sdc-vendor-license-core / src / main / java / org / openecomp / sdc / vendorlicense / licenseartifacts / impl / types / VnfLicenseArtifact.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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
21 package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types;
22
23 import com.ctc.wstx.api.WstxInputProperties;
24 import com.ctc.wstx.stax.WstxInputFactory;
25 import com.ctc.wstx.stax.WstxOutputFactory;
26 import com.fasterxml.jackson.annotation.JsonProperty;
27 import com.fasterxml.jackson.dataformat.xml.XmlFactory;
28 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
29 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
30 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
31 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
32 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
33 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
34 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
35 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
36 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinEntitlementPoolEntityForVnfArtifact;
37 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinFeatureGroupModel;
38 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinLicenseKeyGroupEntityForVnfArtifact;
39 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinLimitArtifact;
40
41 import java.io.Writer;
42 import java.util.ArrayList;
43 import java.util.List;
44 import javax.xml.stream.XMLStreamException;
45 import javax.xml.stream.XMLStreamWriter;
46
47 @JacksonXmlRootElement(localName = "vf-license-model",
48     namespace = "http://xmlns.openecomp.org/asdc/license-model/1.0")
49 public class VnfLicenseArtifact extends XmlArtifact {
50   @JsonProperty(value = "vendor-name")
51   String vendorName;
52   @JsonProperty(value = "vf-id")
53   String vspId;
54   List<FeatureGroupModel> featureGroups = new ArrayList<>();
55
56   public String getVspId() {
57     return vspId;
58   }
59
60   public void setVspId(String vspId) {
61     this.vspId = vspId;
62   }
63
64   public String getVendorName() {
65     return vendorName;
66   }
67
68   public void setVendorName(String vendorName) {
69     this.vendorName = vendorName;
70   }
71
72   @JacksonXmlProperty(isAttribute = false, localName = "feature-group")
73   @JacksonXmlElementWrapper(localName = "feature-group-list")
74   public List<FeatureGroupModel> getFeatureGroups() {
75     return featureGroups;
76   }
77
78   public void setFeatureGroups(List<FeatureGroupModel> featureGroups) {
79     this.featureGroups = featureGroups;
80   }
81
82   void initMapper() {
83     WstxOutputFactory wstxOutputFactory = new WstxOutputFactory() {
84       @Override
85       public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException {
86         mConfig.setProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE, true);
87         return super.createXMLStreamWriter(writer);
88       }
89     };
90     XmlFactory factory = new XmlFactory(new WstxInputFactory(), wstxOutputFactory);
91
92     xmlMapper = new XmlMapper(factory);
93
94
95     xmlMapper.addMixIn(EntitlementPoolEntity.class, MixinEntitlementPoolEntityForVnfArtifact.class);
96     xmlMapper.addMixIn(LicenseKeyGroupEntity.class, MixinLicenseKeyGroupEntityForVnfArtifact.class);
97     xmlMapper.addMixIn(FeatureGroupModel.class, MixinFeatureGroupModel.class);
98     xmlMapper.addMixIn(LimitXml.class, MixinLimitArtifact.class);
99   }
100 }