2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.aai.mapper;
23 import org.modelmapper.ModelMapper;
24 import org.modelmapper.PropertyMap;
25 import org.onap.aai.domain.yang.RouteTargets;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.*;
27 import org.springframework.stereotype.Component;
29 import java.util.List;
30 import org.modelmapper.Converter;
31 import org.modelmapper.spi.MappingContext;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.SegmentationAssignment;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.CtagAssignment;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
38 public class AAIObjectMapper {
39 private static final ModelMapper modelMapper = new ModelMapper();
41 public org.onap.aai.domain.yang.ServiceInstance mapServiceInstance (ServiceInstance serviceInstance){
42 if (modelMapper.getTypeMap(ServiceInstance.class, org.onap.aai.domain.yang.ServiceInstance.class) == null) {
43 modelMapper.addMappings(new PropertyMap<ServiceInstance, org.onap.aai.domain.yang.ServiceInstance>(){
45 protected void configure() {
46 map().setServiceType(source.getModelInfoServiceInstance().getServiceType());
47 map().setServiceRole(source.getModelInfoServiceInstance().getServiceRole());
48 map().setModelInvariantId(source.getModelInfoServiceInstance().getModelInvariantUuid());
49 map().setModelVersionId(source.getModelInfoServiceInstance().getModelUuid());
50 map().setEnvironmentContext(source.getModelInfoServiceInstance().getEnvironmentContext());
51 map().setWorkloadContext(source.getModelInfoServiceInstance().getWorkloadContext());
56 return modelMapper.map(serviceInstance,org.onap.aai.domain.yang.ServiceInstance.class);
59 public org.onap.aai.domain.yang.Project mapProject (Project project){
60 return modelMapper.map(project,org.onap.aai.domain.yang.Project.class);
63 public org.onap.aai.domain.yang.ServiceSubscription mapServiceSubscription(ServiceSubscription serviceSubscription){
64 return modelMapper.map(serviceSubscription,org.onap.aai.domain.yang.ServiceSubscription.class);
67 public org.onap.aai.domain.yang.OwningEntity mapOwningEntity (OwningEntity owningEntity){
68 return modelMapper.map(owningEntity,org.onap.aai.domain.yang.OwningEntity.class);
71 public org.onap.aai.domain.yang.GenericVnf mapVnf (GenericVnf vnf){
72 if (modelMapper.getTypeMap(GenericVnf.class, org.onap.aai.domain.yang.GenericVnf.class) == null) {
73 modelMapper.addMappings(new PropertyMap<GenericVnf, org.onap.aai.domain.yang.GenericVnf>(){
75 protected void configure() {
76 map().setModelCustomizationId(source.getModelInfoGenericVnf().getModelCustomizationUuid());
77 map().setModelInvariantId(source.getModelInfoGenericVnf().getModelInvariantUuid());
78 map().setModelVersionId(source.getModelInfoGenericVnf().getModelUuid());
79 map().setNfRole(source.getModelInfoGenericVnf().getNfRole());
80 map().setNfType(source.getModelInfoGenericVnf().getNfType());
81 map().setNfFunction(source.getModelInfoGenericVnf().getNfFunction());
82 map().setNfNamingCode(source.getModelInfoGenericVnf().getNfNamingCode());
87 return modelMapper.map(vnf, org.onap.aai.domain.yang.GenericVnf.class);
90 public org.onap.aai.domain.yang.VfModule mapVfModule (VfModule vfModule){
91 if (modelMapper.getTypeMap(VfModule.class, org.onap.aai.domain.yang.VfModule.class) == null) {
92 modelMapper.addMappings(new PropertyMap<VfModule, org.onap.aai.domain.yang.VfModule>(){
94 protected void configure() {
95 map().setModelCustomizationId(source.getModelInfoVfModule().getModelCustomizationUUID());
96 map().setModelInvariantId(source.getModelInfoVfModule().getModelInvariantUUID());
97 map().setModelVersionId(source.getModelInfoVfModule().getModelUUID());
98 map().setPersonaModelVersion(source.getModelInfoVfModule().getModelInvariantUUID());
104 return modelMapper.map(vfModule, org.onap.aai.domain.yang.VfModule.class);
107 public org.onap.aai.domain.yang.VolumeGroup mapVolumeGroup(VolumeGroup volumeGroup) {
108 if (modelMapper.getTypeMap(VolumeGroup.class, org.onap.aai.domain.yang.VolumeGroup.class) == null) {
109 modelMapper.addMappings(new PropertyMap<VolumeGroup, org.onap.aai.domain.yang.VolumeGroup>(){
111 protected void configure() {
112 map().setModelCustomizationId(source.getModelInfoVfModule().getModelCustomizationUUID());
113 map().setVfModuleModelCustomizationId(source.getModelInfoVfModule().getModelCustomizationUUID());
117 return modelMapper.map(volumeGroup, org.onap.aai.domain.yang.VolumeGroup.class);
120 public org.onap.aai.domain.yang.L3Network mapNetwork (L3Network l3Network){
121 if (modelMapper.getTypeMap(L3Network.class, org.onap.aai.domain.yang.L3Network.class) == null) {
122 modelMapper.addMappings(new PropertyMap<L3Network, org.onap.aai.domain.yang.L3Network>(){
124 protected void configure() {
125 map().setModelCustomizationId(source.getModelInfoNetwork().getModelCustomizationUUID());
126 map().setModelInvariantId(source.getModelInfoNetwork().getModelInvariantUUID());
127 map().setModelVersionId(source.getModelInfoNetwork().getModelUUID());
128 map().setNetworkType(source.getModelInfoNetwork().getNetworkType());
129 map().setNetworkRole(source.getModelInfoNetwork().getNetworkRole());
130 map().setNetworkTechnology(source.getModelInfoNetwork().getNetworkTechnology());
131 modelMapper.addConverter(convertSubnets);
132 modelMapper.addConverter(convertCtagAssignments);
133 modelMapper.addConverter(convertSegmentationAssignments);
137 return modelMapper.map(l3Network, org.onap.aai.domain.yang.L3Network.class);
140 public org.onap.aai.domain.yang.InstanceGroup mapInstanceGroup(InstanceGroup instanceGroup) {
141 if (modelMapper.getTypeMap(InstanceGroup.class, org.onap.aai.domain.yang.InstanceGroup.class) == null) {
142 modelMapper.addMappings(new PropertyMap<InstanceGroup, org.onap.aai.domain.yang.InstanceGroup>(){
144 protected void configure() {
145 map().setInstanceGroupRole(source.getModelInfoInstanceGroup().getInstanceGroupRole());
146 map().setModelInvariantId(source.getModelInfoInstanceGroup().getModelInvariantUUID());
147 map().setModelVersionId(source.getModelInfoInstanceGroup().getModelUUID());
148 map().setInstanceGroupType(source.getModelInfoInstanceGroup().getType());
149 map().setDescription(source.getModelInfoInstanceGroup().getDescription());
150 map().setInstanceGroupFunction(source.getModelInfoInstanceGroup().getFunction());
154 return modelMapper.map(instanceGroup, org.onap.aai.domain.yang.InstanceGroup.class);
157 public org.onap.aai.domain.yang.Customer mapCustomer(Customer customer) {
158 return modelMapper.map(customer, org.onap.aai.domain.yang.Customer.class);
161 public Converter<List<Subnet>, org.onap.aai.domain.yang.Subnets> convertSubnets = new Converter<List<Subnet>, org.onap.aai.domain.yang.Subnets>() {
162 public org.onap.aai.domain.yang.Subnets convert(MappingContext<List<Subnet>, org.onap.aai.domain.yang.Subnets> context) {
163 return mapToAAISubNets(context.getSource());
167 public Converter<List<CtagAssignment>, org.onap.aai.domain.yang.CtagAssignments> convertCtagAssignments = new Converter<List<CtagAssignment>, org.onap.aai.domain.yang.CtagAssignments>() {
168 public org.onap.aai.domain.yang.CtagAssignments convert(MappingContext<List<CtagAssignment>, org.onap.aai.domain.yang.CtagAssignments> context) {
169 return mapToAAICtagAssignmentList(context.getSource());
173 public Converter<List<SegmentationAssignment>, org.onap.aai.domain.yang.SegmentationAssignments> convertSegmentationAssignments = new Converter<List<SegmentationAssignment>, org.onap.aai.domain.yang.SegmentationAssignments>() {
174 public org.onap.aai.domain.yang.SegmentationAssignments convert(MappingContext<List<SegmentationAssignment>, org.onap.aai.domain.yang.SegmentationAssignments> context) {
175 return mapToAAISegmentationAssignmentList(context.getSource());
179 public org.onap.aai.domain.yang.Subnets mapToAAISubNets(List<Subnet> subnetList) {
180 org.onap.aai.domain.yang.Subnets subnets = null;
182 if (!subnetList.isEmpty()) {
183 subnets = new org.onap.aai.domain.yang.Subnets();
184 org.onap.aai.domain.yang.Subnet subnet = null;
185 for (Subnet subnetSource : subnetList) {
186 subnet = new org.onap.aai.domain.yang.Subnet();
187 subnet.setSubnetId(subnetSource.getSubnetId());
188 subnet.setSubnetName(subnetSource.getSubnetName());
189 subnet.setNeutronSubnetId(subnetSource.getNeutronSubnetId());
190 subnet.setGatewayAddress(subnetSource.getGatewayAddress());
191 subnet.setCidrMask(subnetSource.getCidrMask());
192 subnet.setIpVersion(subnetSource.getIpVersion());
193 subnet.setOrchestrationStatus(subnetSource.getOrchestrationStatus().toString());
194 subnet.setCidrMask(subnetSource.getCidrMask());
195 subnet.setDhcpEnabled(subnetSource.isDhcpEnabled());
196 subnet.setDhcpStart(subnetSource.getDhcpStart());
197 subnet.setDhcpEnd(subnetSource.getDhcpEnd());
198 subnet.setSubnetRole(subnetSource.getSubnetRole());
199 subnet.setIpAssignmentDirection(subnetSource.getIpAssignmentDirection());
200 subnet.setSubnetSequence(subnetSource.getSubnetSequence());
202 org.onap.aai.domain.yang.HostRoutes hostRoutes = new org.onap.aai.domain.yang.HostRoutes();
203 org.onap.aai.domain.yang.HostRoute hostRoute = null;
204 for (HostRoute hostRouteSource : subnetSource.getHostRoutes()) {
205 hostRoute = new org.onap.aai.domain.yang.HostRoute();
206 hostRoute.setHostRouteId(hostRouteSource.getHostRouteId());
207 hostRoute.setRoutePrefix(hostRouteSource.getRoutePrefix());
208 hostRoute.setNextHop(hostRouteSource.getNextHop());
209 hostRoute.setNextHopType(hostRouteSource.getNextHopType());
210 hostRoutes.getHostRoute().add(hostRoute);
212 subnet.setHostRoutes(hostRoutes);
213 subnets.getSubnet().add(subnet);
219 public org.onap.aai.domain.yang.CtagAssignments mapToAAICtagAssignmentList(List<CtagAssignment> ctagAssignmentsList) {
220 org.onap.aai.domain.yang.CtagAssignments ctagAssignments = null;
221 if (!ctagAssignmentsList.isEmpty()) {
222 ctagAssignments = new org.onap.aai.domain.yang.CtagAssignments();
224 org.onap.aai.domain.yang.CtagAssignment ctagAssignment = null;
225 for (CtagAssignment ctagAssignmentSource : ctagAssignmentsList) {
226 ctagAssignment = new org.onap.aai.domain.yang.CtagAssignment();
227 ctagAssignment.setVlanIdInner(ctagAssignmentSource.getVlanIdInner());
228 ctagAssignments.getCtagAssignment().add(ctagAssignment);
231 return ctagAssignments;
234 public org.onap.aai.domain.yang.SegmentationAssignments mapToAAISegmentationAssignmentList(List<SegmentationAssignment> segmentationAssignmentList) {
235 org.onap.aai.domain.yang.SegmentationAssignments segmentationAssignments = null;
236 if (!segmentationAssignmentList.isEmpty()) {
237 segmentationAssignments = new org.onap.aai.domain.yang.SegmentationAssignments();
238 org.onap.aai.domain.yang.SegmentationAssignment segmentationAssignment = null;
239 for (SegmentationAssignment segmentationAssignmentSource : segmentationAssignmentList) {
240 segmentationAssignment = new org.onap.aai.domain.yang.SegmentationAssignment();
241 segmentationAssignment.setSegmentationId(segmentationAssignmentSource.getSegmentationId());
242 segmentationAssignments.getSegmentationAssignment().add(segmentationAssignment);
245 return segmentationAssignments;
248 public org.onap.aai.domain.yang.Configuration mapConfiguration(Configuration configuration) {
249 if (null == modelMapper.getTypeMap(Configuration.class, org.onap.aai.domain.yang.Configuration.class)) {
250 modelMapper.addMappings(new PropertyMap<Configuration, org.onap.aai.domain.yang.Configuration>(){
252 protected void configure() {
253 map().setModelCustomizationId(source.getModelInfoConfiguration().getModelCustomizationId());
254 map().setModelVersionId(source.getModelInfoConfiguration().getModelVersionId());
255 map().setModelInvariantId(source.getModelInfoConfiguration().getModelInvariantId());
259 return modelMapper.map(configuration, org.onap.aai.domain.yang.Configuration.class);
262 public org.onap.aai.domain.yang.Collection mapCollection (Collection networkCollection){
263 if (modelMapper.getTypeMap(Collection.class, org.onap.aai.domain.yang.Collection.class) == null) {
264 modelMapper.addMappings(new PropertyMap<Collection, org.onap.aai.domain.yang.Collection>(){
266 protected void configure() {
267 map().setModelInvariantId(source.getModelInfoCollection().getModelInvariantUUID());
268 map().setModelVersionId(source.getModelInfoCollection().getModelVersionId());
269 map().setCollectionCustomizationId(source.getModelInfoCollection().getModelCustomizationUUID());
270 map().setCollectionFunction(source.getModelInfoCollection().getCollectionFunction());
271 map().setCollectionRole(source.getModelInfoCollection().getCollectionRole());
272 map().setCollectionType(source.getModelInfoCollection().getCollectionType());
273 map().setCollectionName(source.getName());
277 return modelMapper.map(networkCollection, org.onap.aai.domain.yang.Collection.class);
281 public org.onap.aai.domain.yang.VpnBinding mapVpnBinding(VpnBinding vpnBinding) {
282 org.onap.aai.domain.yang.VpnBinding aaiVpnBinding = modelMapper.map(vpnBinding, org.onap.aai.domain.yang.VpnBinding.class);
283 mapRouteTargetToVpnBinding(aaiVpnBinding,vpnBinding);
284 return aaiVpnBinding;
287 public org.onap.aai.domain.yang.RouteTarget mapRouteTarget(RouteTarget routeTarget) {
288 return modelMapper.map(routeTarget, org.onap.aai.domain.yang.RouteTarget.class);
291 private void mapRouteTargetToVpnBinding(org.onap.aai.domain.yang.VpnBinding aaiVpnBinding, VpnBinding vpnBinding) {
292 if(vpnBinding.getRouteTargets() != null && !vpnBinding.getRouteTargets().isEmpty()) {
293 RouteTargets routeTargets = new RouteTargets();
294 for (RouteTarget routeTarget : vpnBinding.getRouteTargets()) {
295 routeTargets.getRouteTarget().add(mapRouteTarget(routeTarget));
297 aaiVpnBinding.setRouteTargets(routeTargets);