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());
99 map().setIsBaseVfModule(source.getModelInfoVfModule().getIsBaseBoolean());
105 return modelMapper.map(vfModule, org.onap.aai.domain.yang.VfModule.class);
108 public org.onap.aai.domain.yang.VolumeGroup mapVolumeGroup(VolumeGroup volumeGroup) {
109 if (modelMapper.getTypeMap(VolumeGroup.class, org.onap.aai.domain.yang.VolumeGroup.class) == null) {
110 modelMapper.addMappings(new PropertyMap<VolumeGroup, org.onap.aai.domain.yang.VolumeGroup>(){
112 protected void configure() {
113 map().setModelCustomizationId(source.getModelInfoVfModule().getModelCustomizationUUID());
114 map().setVfModuleModelCustomizationId(source.getModelInfoVfModule().getModelCustomizationUUID());
118 return modelMapper.map(volumeGroup, org.onap.aai.domain.yang.VolumeGroup.class);
121 public org.onap.aai.domain.yang.L3Network mapNetwork (L3Network l3Network){
122 if (modelMapper.getTypeMap(L3Network.class, org.onap.aai.domain.yang.L3Network.class) == null) {
123 modelMapper.addMappings(new PropertyMap<L3Network, org.onap.aai.domain.yang.L3Network>(){
125 protected void configure() {
126 map().setModelCustomizationId(source.getModelInfoNetwork().getModelCustomizationUUID());
127 map().setModelInvariantId(source.getModelInfoNetwork().getModelInvariantUUID());
128 map().setModelVersionId(source.getModelInfoNetwork().getModelUUID());
129 map().setNetworkType(source.getModelInfoNetwork().getNetworkType());
130 map().setNetworkRole(source.getModelInfoNetwork().getNetworkRole());
131 map().setNetworkTechnology(source.getModelInfoNetwork().getNetworkTechnology());
132 modelMapper.addConverter(convertSubnets);
133 modelMapper.addConverter(convertCtagAssignments);
134 modelMapper.addConverter(convertSegmentationAssignments);
138 return modelMapper.map(l3Network, org.onap.aai.domain.yang.L3Network.class);
141 public org.onap.aai.domain.yang.InstanceGroup mapInstanceGroup(InstanceGroup instanceGroup) {
142 if (modelMapper.getTypeMap(InstanceGroup.class, org.onap.aai.domain.yang.InstanceGroup.class) == null) {
143 modelMapper.addMappings(new PropertyMap<InstanceGroup, org.onap.aai.domain.yang.InstanceGroup>(){
145 protected void configure() {
146 map().setInstanceGroupRole(source.getModelInfoInstanceGroup().getInstanceGroupRole());
147 map().setModelInvariantId(source.getModelInfoInstanceGroup().getModelInvariantUUID());
148 map().setModelVersionId(source.getModelInfoInstanceGroup().getModelUUID());
149 map().setInstanceGroupType(source.getModelInfoInstanceGroup().getType());
150 map().setDescription(source.getModelInfoInstanceGroup().getDescription());
151 map().setInstanceGroupFunction(source.getModelInfoInstanceGroup().getFunction());
155 return modelMapper.map(instanceGroup, org.onap.aai.domain.yang.InstanceGroup.class);
158 public org.onap.aai.domain.yang.Customer mapCustomer(Customer customer) {
159 return modelMapper.map(customer, org.onap.aai.domain.yang.Customer.class);
162 public Converter<List<Subnet>, org.onap.aai.domain.yang.Subnets> convertSubnets = new Converter<List<Subnet>, org.onap.aai.domain.yang.Subnets>() {
163 public org.onap.aai.domain.yang.Subnets convert(MappingContext<List<Subnet>, org.onap.aai.domain.yang.Subnets> context) {
164 return mapToAAISubNets(context.getSource());
168 public Converter<List<CtagAssignment>, org.onap.aai.domain.yang.CtagAssignments> convertCtagAssignments = new Converter<List<CtagAssignment>, org.onap.aai.domain.yang.CtagAssignments>() {
169 public org.onap.aai.domain.yang.CtagAssignments convert(MappingContext<List<CtagAssignment>, org.onap.aai.domain.yang.CtagAssignments> context) {
170 return mapToAAICtagAssignmentList(context.getSource());
174 public Converter<List<SegmentationAssignment>, org.onap.aai.domain.yang.SegmentationAssignments> convertSegmentationAssignments = new Converter<List<SegmentationAssignment>, org.onap.aai.domain.yang.SegmentationAssignments>() {
175 public org.onap.aai.domain.yang.SegmentationAssignments convert(MappingContext<List<SegmentationAssignment>, org.onap.aai.domain.yang.SegmentationAssignments> context) {
176 return mapToAAISegmentationAssignmentList(context.getSource());
180 public org.onap.aai.domain.yang.Subnets mapToAAISubNets(List<Subnet> subnetList) {
181 org.onap.aai.domain.yang.Subnets subnets = null;
183 if (!subnetList.isEmpty()) {
184 subnets = new org.onap.aai.domain.yang.Subnets();
185 org.onap.aai.domain.yang.Subnet subnet = null;
186 for (Subnet subnetSource : subnetList) {
187 subnet = new org.onap.aai.domain.yang.Subnet();
188 subnet.setSubnetId(subnetSource.getSubnetId());
189 subnet.setSubnetName(subnetSource.getSubnetName());
190 subnet.setNeutronSubnetId(subnetSource.getNeutronSubnetId());
191 subnet.setGatewayAddress(subnetSource.getGatewayAddress());
192 subnet.setCidrMask(subnetSource.getCidrMask());
193 subnet.setIpVersion(subnetSource.getIpVersion());
194 subnet.setOrchestrationStatus(subnetSource.getOrchestrationStatus().toString());
195 subnet.setCidrMask(subnetSource.getCidrMask());
196 subnet.setDhcpEnabled(subnetSource.isDhcpEnabled());
197 subnet.setDhcpStart(subnetSource.getDhcpStart());
198 subnet.setDhcpEnd(subnetSource.getDhcpEnd());
199 subnet.setSubnetRole(subnetSource.getSubnetRole());
200 subnet.setIpAssignmentDirection(subnetSource.getIpAssignmentDirection());
201 subnet.setSubnetSequence(subnetSource.getSubnetSequence());
203 org.onap.aai.domain.yang.HostRoutes hostRoutes = new org.onap.aai.domain.yang.HostRoutes();
204 org.onap.aai.domain.yang.HostRoute hostRoute = null;
205 for (HostRoute hostRouteSource : subnetSource.getHostRoutes()) {
206 hostRoute = new org.onap.aai.domain.yang.HostRoute();
207 hostRoute.setHostRouteId(hostRouteSource.getHostRouteId());
208 hostRoute.setRoutePrefix(hostRouteSource.getRoutePrefix());
209 hostRoute.setNextHop(hostRouteSource.getNextHop());
210 hostRoute.setNextHopType(hostRouteSource.getNextHopType());
211 hostRoutes.getHostRoute().add(hostRoute);
213 subnet.setHostRoutes(hostRoutes);
214 subnets.getSubnet().add(subnet);
220 public org.onap.aai.domain.yang.CtagAssignments mapToAAICtagAssignmentList(List<CtagAssignment> ctagAssignmentsList) {
221 org.onap.aai.domain.yang.CtagAssignments ctagAssignments = null;
222 if (!ctagAssignmentsList.isEmpty()) {
223 ctagAssignments = new org.onap.aai.domain.yang.CtagAssignments();
225 org.onap.aai.domain.yang.CtagAssignment ctagAssignment = null;
226 for (CtagAssignment ctagAssignmentSource : ctagAssignmentsList) {
227 ctagAssignment = new org.onap.aai.domain.yang.CtagAssignment();
228 ctagAssignment.setVlanIdInner(ctagAssignmentSource.getVlanIdInner());
229 ctagAssignments.getCtagAssignment().add(ctagAssignment);
232 return ctagAssignments;
235 public org.onap.aai.domain.yang.SegmentationAssignments mapToAAISegmentationAssignmentList(List<SegmentationAssignment> segmentationAssignmentList) {
236 org.onap.aai.domain.yang.SegmentationAssignments segmentationAssignments = null;
237 if (!segmentationAssignmentList.isEmpty()) {
238 segmentationAssignments = new org.onap.aai.domain.yang.SegmentationAssignments();
239 org.onap.aai.domain.yang.SegmentationAssignment segmentationAssignment = null;
240 for (SegmentationAssignment segmentationAssignmentSource : segmentationAssignmentList) {
241 segmentationAssignment = new org.onap.aai.domain.yang.SegmentationAssignment();
242 segmentationAssignment.setSegmentationId(segmentationAssignmentSource.getSegmentationId());
243 segmentationAssignments.getSegmentationAssignment().add(segmentationAssignment);
246 return segmentationAssignments;
249 public org.onap.aai.domain.yang.Configuration mapConfiguration(Configuration configuration) {
250 if (null == modelMapper.getTypeMap(Configuration.class, org.onap.aai.domain.yang.Configuration.class)) {
251 modelMapper.addMappings(new PropertyMap<Configuration, org.onap.aai.domain.yang.Configuration>(){
253 protected void configure() {
254 map().setModelCustomizationId(source.getModelInfoConfiguration().getModelCustomizationId());
255 map().setModelVersionId(source.getModelInfoConfiguration().getModelVersionId());
256 map().setModelInvariantId(source.getModelInfoConfiguration().getModelInvariantId());
260 return modelMapper.map(configuration, org.onap.aai.domain.yang.Configuration.class);
263 public org.onap.aai.domain.yang.Collection mapCollection (Collection networkCollection){
264 if (modelMapper.getTypeMap(Collection.class, org.onap.aai.domain.yang.Collection.class) == null) {
265 modelMapper.addMappings(new PropertyMap<Collection, org.onap.aai.domain.yang.Collection>(){
267 protected void configure() {
268 map().setModelInvariantId(source.getModelInfoCollection().getModelInvariantUUID());
269 map().setModelVersionId(source.getModelInfoCollection().getModelVersionId());
270 map().setCollectionCustomizationId(source.getModelInfoCollection().getModelCustomizationUUID());
271 map().setCollectionFunction(source.getModelInfoCollection().getCollectionFunction());
272 map().setCollectionRole(source.getModelInfoCollection().getCollectionRole());
273 map().setCollectionType(source.getModelInfoCollection().getCollectionType());
274 map().setCollectionName(source.getName());
278 return modelMapper.map(networkCollection, org.onap.aai.domain.yang.Collection.class);
282 public org.onap.aai.domain.yang.VpnBinding mapVpnBinding(VpnBinding vpnBinding) {
283 org.onap.aai.domain.yang.VpnBinding aaiVpnBinding = modelMapper.map(vpnBinding, org.onap.aai.domain.yang.VpnBinding.class);
284 mapRouteTargetToVpnBinding(aaiVpnBinding,vpnBinding);
285 return aaiVpnBinding;
288 public org.onap.aai.domain.yang.RouteTarget mapRouteTarget(RouteTarget routeTarget) {
289 return modelMapper.map(routeTarget, org.onap.aai.domain.yang.RouteTarget.class);
292 private void mapRouteTargetToVpnBinding(org.onap.aai.domain.yang.VpnBinding aaiVpnBinding, VpnBinding vpnBinding) {
293 if(vpnBinding.getRouteTargets() != null && !vpnBinding.getRouteTargets().isEmpty()) {
294 RouteTargets routeTargets = new RouteTargets();
295 for (RouteTarget routeTarget : vpnBinding.getRouteTargets()) {
296 routeTargets.getRouteTarget().add(mapRouteTarget(routeTarget));
298 aaiVpnBinding.setRouteTargets(routeTargets);