Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM Core
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 Netsia
|
| 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 |
|
| 22 |
|
| 23 | package org.onap.osam.helper;
|
| 24 |
|
| 25 | import com.google.common.collect.Lists;
|
Aharoni, Pavel (pa0916) | 0a8080c | 2018-11-22 15:45:19 +0200 | [diff] [blame] | 26 | import org.onap.osam.common.dto.AccessPodDTO;
|
| 27 | import org.onap.osam.common.dto.ChassisDTO;
|
| 28 | import org.onap.osam.common.dto.OLTChassisDTO;
|
| 29 | import org.onap.osam.common.dto.OLTPortDTO;
|
| 30 | import org.onap.osam.common.dto.ONTDTO;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 31 | import org.onap.osam.model.dao.*;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 32 |
|
| 33 | import java.util.ArrayList;
|
| 34 | import java.util.List;
|
| 35 | import java.util.Map;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 36 | import java.util.stream.Collectors;
|
| 37 |
|
| 38 |
|
| 39 | public final class DTOMapper {
|
| 40 |
|
| 41 | private DTOMapper () {
|
| 42 |
|
| 43 | }
|
| 44 |
|
| 45 | public static Chassis convertToChassis (ChassisDTO chassisDTO) {
|
| 46 | Chassis chassis = new Chassis();
|
| 47 | chassis.setClli(chassisDTO.getClli());
|
| 48 | chassis.setShelf(chassisDTO.getShelf());
|
| 49 | chassis.setRack(chassisDTO.getRack());
|
| 50 | chassis.setState(ActivityState.ACTIVE);
|
| 51 | AccessPod accessPod = new AccessPod();
|
| 52 | accessPod.setPnfId(chassisDTO.getPnfId());
|
| 53 | chassis.setAccessPod(accessPod);
|
| 54 | return chassis;
|
| 55 | }
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 | public static OLTSlot convertToOLT (OLTChassisDTO oltChassisDTO) {
|
| 61 | OLTSlot oltSlot = new OLTSlot();
|
| 62 | oltSlot.setIpAddress(oltChassisDTO.getIpAddress());
|
| 63 | oltSlot.setPort(oltChassisDTO.getPortNumber());
|
| 64 | oltSlot.setName(oltChassisDTO.getName());
|
| 65 | oltSlot.setOltDriver(OltDriver.valueOf(oltChassisDTO.getOltDriver()));
|
| 66 | oltSlot.setOltType(OltType.valueOf(oltChassisDTO.getOltType()));
|
| 67 | return oltSlot;
|
| 68 | }
|
| 69 |
|
| 70 | public static ChassisDTO convertChassisToDTO(Chassis chassis) {
|
| 71 | ChassisDTO chassisDTO = new ChassisDTO();
|
| 72 | chassisDTO.setId(chassis.getId());
|
| 73 | chassisDTO.setClli(chassis.getClli());
|
| 74 | chassisDTO.setRack(chassis.getRack());
|
| 75 | chassisDTO.setShelf(chassis.getShelf());
|
| 76 | chassisDTO.setPnfId(chassis.getAccessPod().getPnfId());
|
| 77 | return chassisDTO;
|
| 78 | }
|
| 79 |
|
| 80 | public static List<ChassisDTO> convertChassisToDTO(List<Chassis> chassises) {
|
| 81 | return chassises.stream().map(x -> convertChassisToDTO(x)).collect(Collectors.toList());
|
| 82 | }
|
| 83 |
|
| 84 | public static Map<String, List<OLTChassisDTO>> convertFromOLT(List<OLTSlot> oltSlots){
|
| 85 | return oltSlots.stream().map(x -> convertFromOLT(x)).collect(Collectors.toList()).stream().collect(Collectors.groupingBy(OLTChassisDTO::getClli));
|
| 86 | }
|
| 87 |
|
| 88 | public static OLTChassisDTO convertFromOLT (OLTSlot oltSlot) {
|
| 89 | OLTChassisDTO oltChassisDTO = new OLTChassisDTO();
|
| 90 | oltChassisDTO.setClli(oltSlot.getChassis().getClli());
|
| 91 | oltChassisDTO.setIpAddress(oltSlot.getIpAddress());
|
| 92 | oltChassisDTO.setName(oltSlot.getName());
|
| 93 | oltChassisDTO.setOltDriver(oltSlot.getOltDriver().name());
|
| 94 | oltChassisDTO.setOltType(oltSlot.getOltType().name());
|
| 95 | oltChassisDTO.setPortNumber(oltSlot.getPort());
|
| 96 | oltChassisDTO.setId(oltSlot.getId());
|
| 97 | return oltChassisDTO;
|
| 98 | }
|
| 99 |
|
| 100 | public static ONTDTO convertFromONTDevice (ONTDevice ontDevice) {
|
| 101 | ONTDTO ontdto = new ONTDTO();
|
| 102 | ontdto.setSerialNumber(ontDevice.getSerialNumber());
|
| 103 | ontdto.setPortNumber(ontDevice.getOLTPort().getPortNumber());
|
| 104 | ontdto.setId(ontDevice.getId());
|
| 105 | ontdto.setSlotNumber(ontDevice.getOLTPort().getOltSlot().getNumber());
|
| 106 | ontdto.setClli(ontDevice.getOLTPort().getOltSlot().getChassis().getClli());
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 107 | ontdto.setCtag(ontDevice.getCTag());
|
| 108 | ontdto.setStag(ontDevice.getSTag());
|
| 109 | ontdto.setCircuitId(ontDevice.getCircuitId());
|
| 110 | ontdto.setNasPortId(ontDevice.getNasPortId());
|
| 111 | if (ontDevice.getTechProfile() != null) {
|
| 112 | ontdto.setTechnologyProfile(ontDevice.getTechProfile().getName());
|
| 113 | }
|
| 114 | if (ontDevice.getSpeedProfile() != null) {
|
| 115 | ontdto.setSpeedProfile(ontDevice.getSpeedProfile().getName());
|
| 116 | }
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 117 | return ontdto;
|
| 118 | }
|
| 119 |
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 120 | public static ONTDevice convertToONTDevice (ONTDTO ontdto) {
|
| 121 | ONTDevice ontDevice = new ONTDevice();
|
| 122 | ontDevice.setNumber(ontdto.getOntNumber());
|
| 123 | ontDevice.setSerialNumber(ontdto.getSerialNumber());
|
| 124 | ontDevice.setCTag(ontdto.getCtag());
|
| 125 | ontDevice.setSTag(ontdto.getStag());
|
| 126 | ontDevice.setCircuitId(ontdto.getCircuitId());
|
| 127 | ontDevice.setNasPortId(ontdto.getNasPortId());
|
| 128 | TechnologyProfile technologyProfile = new TechnologyProfile();
|
| 129 | technologyProfile.setName(ontdto.getTechnologyProfile());
|
| 130 | ontDevice.setTechProfile(technologyProfile);
|
| 131 | SpeedProfile speedProfile = new SpeedProfile();
|
| 132 | speedProfile.setName(ontdto.getSpeedProfile());
|
| 133 | ontDevice.setSpeedProfile(speedProfile);
|
| 134 | Chassis chassis = new Chassis();
|
| 135 | chassis.setClli(ontdto.getClli());
|
| 136 | OLTSlot oltSlot = new OLTSlot();
|
| 137 | oltSlot.setChassis(chassis);
|
| 138 | OLTPort oltPort = new OLTPort();
|
| 139 | oltPort.setPortNumber(ontdto.getPortNumber());
|
| 140 | oltPort.setOltSlot(oltSlot);
|
| 141 | ontDevice.setOLTPort(oltPort);
|
| 142 | return ontDevice;
|
| 143 | }
|
| 144 |
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 145 | public static Map<String, List<ONTDTO>> convertFromONTDevice(List<ONTDevice> ontDevices){
|
| 146 | return ontDevices.stream().map(x -> convertFromONTDevice(x)).collect(Collectors.toList()).stream().collect(Collectors.groupingBy(ONTDTO::getClli));
|
| 147 | }
|
| 148 |
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 149 | public static AccessPod convertDtoToAccessPod(AccessPodDTO dto) {
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 150 | //TODO validate..
|
| 151 | AccessPod accessPod = new AccessPod();
|
| 152 | accessPod.setPnfId(dto.getPnfId());
|
| 153 | accessPod.setId(dto.getId());
|
| 154 | accessPod.setCoreIp(dto.getCoreIp());
|
| 155 | accessPod.setCorePort(dto.getCorePort());
|
| 156 | accessPod.setUsername(dto.getUsername());
|
| 157 | accessPod.setPassword(dto.getPassword());
|
| 158 | accessPod.setIp(dto.getIp());
|
| 159 | accessPod.setPort(dto.getPort());
|
| 160 | return accessPod;
|
| 161 | }
|
| 162 |
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 163 | public static AccessPodDTO convertAccessPodToDto(AccessPod accessPod) {
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 164 | //TODO validate..
|
| 165 | AccessPodDTO dto = new AccessPodDTO();
|
| 166 | dto.setPnfId(accessPod.getPnfId());
|
| 167 | dto.setCoreIp(accessPod.getCoreIp());
|
| 168 | dto.setCorePort(accessPod.getCorePort());
|
| 169 | dto.setUsername(accessPod.getUsername());
|
| 170 | dto.setPassword(accessPod.getPassword());
|
| 171 | dto.setIp(accessPod.getIp());
|
| 172 | dto.setId(accessPod.getId());
|
| 173 | dto.setPort(accessPod.getPort());
|
| 174 | return dto;
|
| 175 | }
|
| 176 |
|
| 177 | private static OLTPortDTO convertOLTPortToDTO(OLTPort oltPort) {
|
| 178 | OLTPortDTO oltPortDTO = new OLTPortDTO();
|
| 179 | oltPortDTO.setId(oltPort.getId());
|
Aharoni, Pavel (pa0916) | 0a8080c | 2018-11-22 15:45:19 +0200 | [diff] [blame] | 180 | oltPortDTO.setAdminState(oltPort.getAdminState().name());
|
| 181 | oltPortDTO.setPortAuthState(oltPort.getPortAuthState().name());
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 182 | oltPortDTO.setPortNumber(oltPort.getPortNumber());
|
| 183 | return oltPortDTO;
|
| 184 | }
|
| 185 |
|
| 186 | public static List<AccessPodDTO> covertAccessPodsToDtos(List<AccessPod> accessPodList) {
|
| 187 | //TODO validate..
|
| 188 | List<AccessPodDTO> dtos = new ArrayList<>();
|
| 189 | for (AccessPod accessPod : accessPodList) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 190 | dtos.add(convertAccessPodToDto(accessPod));
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 191 | }
|
| 192 | return dtos;
|
| 193 | }
|
| 194 |
|
| 195 | public static AccessPodDTO representTheAccessPod(List<Chassis> chassisList, AccessPod accessPod) {
|
| 196 | if (accessPod == null) {
|
| 197 | return null;
|
| 198 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 199 | AccessPodDTO accessPodDTO = convertAccessPodToDto(accessPod);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 200 | if (chassisList == null || chassisList.isEmpty()) {
|
| 201 | return accessPodDTO;
|
| 202 | }
|
| 203 | List<ChassisDTO> chassisDTOS = new ArrayList<>();
|
| 204 | accessPodDTO.setChassises(chassisDTOS);
|
| 205 | for (Chassis chassis : chassisList) {
|
| 206 | chassisDTOS.add(representTheChassis(chassis));
|
| 207 | }
|
| 208 | return accessPodDTO;
|
| 209 | }
|
| 210 |
|
| 211 | public static ChassisDTO representTheChassis(Chassis chassis) {
|
| 212 | ChassisDTO chassisDTO = convertChassisToDTO(chassis);
|
| 213 | if (chassis.getOltSlots() == null || chassis.getOltSlots().isEmpty()) {
|
| 214 | return chassisDTO;
|
| 215 | }
|
| 216 | List<OLTChassisDTO> oltChassisDTOS = Lists.newArrayList();
|
| 217 | chassisDTO.setOlts(oltChassisDTOS);
|
| 218 | for (OLTSlot oltSlot : chassis.getOltSlots()) {
|
| 219 | oltChassisDTOS.add(representTheOLTSlot(oltSlot));
|
| 220 | }
|
| 221 | return chassisDTO;
|
| 222 | }
|
| 223 |
|
| 224 | public static OLTChassisDTO representTheOLTSlot(OLTSlot oltSlot) {
|
| 225 | OLTChassisDTO oltChassisDTO = convertFromOLT(oltSlot);
|
| 226 | if (oltSlot.getOltPorts() == null || oltSlot.getOltPorts().isEmpty()) {
|
| 227 | return oltChassisDTO;
|
| 228 | }
|
| 229 | List<OLTPortDTO> oltPortDTOS = Lists.newArrayList();
|
| 230 | oltChassisDTO.setOltPorts(oltPortDTOS);
|
| 231 | for (OLTPort oltPort : oltSlot.getOltPorts()) {
|
| 232 | oltPortDTOS.add(representTheOLTPort(oltPort));
|
| 233 | }
|
| 234 | return oltChassisDTO;
|
| 235 | }
|
| 236 |
|
| 237 | public static OLTPortDTO representTheOLTPort(OLTPort oltPort) {
|
| 238 | OLTPortDTO portDTO = convertOLTPortToDTO(oltPort);
|
| 239 | if (oltPort.getOntDevices() == null || oltPort.getOntDevices().isEmpty()) {
|
| 240 | return portDTO;
|
| 241 | }
|
| 242 | List<ONTDTO> ontdtos = Lists.newArrayList();
|
| 243 | portDTO.setOntDevices(ontdtos);
|
| 244 | for (ONTDevice ontDevice : oltPort.getOntDevices()) {
|
| 245 | ontdtos.add(convertFromONTDevice(ontDevice));
|
| 246 | }
|
| 247 | return portDTO;
|
| 248 | }
|
| 249 | }
|