push addional code
[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.licenseartifacts.impl.types.mixins.MixinEntitlementPoolEntityForVnfArtifact;
36 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinFeatureGroupModel;
37 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinLicenseKeyGroupEntityForVnfArtifact;
38
39 import java.io.Writer;
40 import java.util.ArrayList;
41 import java.util.List;
42 import javax.xml.stream.XMLStreamException;
43 import javax.xml.stream.XMLStreamWriter;
44
45 @JacksonXmlRootElement(localName = "vf-license-model",
46     namespace = "http://xmlns.openecomp.org/asdc/license-model/1.0")
47 public class VnfLicenseArtifact extends XmlArtifact {
48   @JsonProperty(value = "vendor-name")
49   String vendorName;
50   @JsonProperty(value = "vf-id")
51   String vspId;
52   List<FeatureGroupModel> featureGroups = new ArrayList<>();
53
54   public String getVspId() {
55     return vspId;
56   }
57
58   public void setVspId(String vspId) {
59     this.vspId = vspId;
60   }
61
62   public String getVendorName() {
63     return vendorName;
64   }
65
66   public void setVendorName(String vendorName) {
67     this.vendorName = vendorName;
68   }
69
70   @JacksonXmlProperty(isAttribute = false, localName = "feature-group")
71   @JacksonXmlElementWrapper(localName = "feature-group-list")
72   public List<FeatureGroupModel> getFeatureGroups() {
73     return featureGroups;
74   }
75
76   public void setFeatureGroups(List<FeatureGroupModel> featureGroups) {
77     this.featureGroups = featureGroups;
78   }
79
80   void initMapper() {
81     WstxOutputFactory wstxOutputFactory = new WstxOutputFactory() {
82       @Override
83       public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException {
84         mConfig.setProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE, true);
85         return super.createXMLStreamWriter(writer);
86       }
87     };
88     XmlFactory factory = new XmlFactory(new WstxInputFactory(), wstxOutputFactory);
89
90     xmlMapper = new XmlMapper(factory);
91
92
93     xmlMapper.addMixIn(EntitlementPoolEntity.class, MixinEntitlementPoolEntityForVnfArtifact.class);
94     xmlMapper.addMixIn(LicenseKeyGroupEntity.class, MixinLicenseKeyGroupEntityForVnfArtifact.class);
95     xmlMapper.addMixIn(FeatureGroupModel.class, MixinFeatureGroupModel.class);
96   }
97 }