fixes to accomodate docker creation in ONF - added onap-enabler parent POM, renamed osam-core to osam-core-framework and removed junit that requires connection to DB
Change-Id: Ifdc95438c8b1e5856860882824a11eecac80e19a
Signed-off-by: Aharoni, Pavel (pa0916) <pavel.aharoni@intl.att.com>
diff --git a/osam-core-framework/web/pom.xml b/osam-core-framework/web/pom.xml
new file mode 100644
index 0000000..f29c599
--- /dev/null
+++ b/osam-core-framework/web/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 Netsia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>osam-core-framework</artifactId>
+ <groupId>org.onap.osam</groupId>
+ <version>0.0.2</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>web</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.osam</groupId>
+ <artifactId>core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- For the async jobs demo controller -->
+ <dependency>
+ <groupId>org.onap.osam</groupId>
+ <artifactId>async-jobs</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger-ui</artifactId>
+ <version>${swagger.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger2</artifactId>
+ <version>${swagger.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/osam-core-framework/web/src/main/java/org/onap/osam/controller/AbstractController.java b/osam-core-framework/web/src/main/java/org/onap/osam/controller/AbstractController.java
new file mode 100644
index 0000000..474c2c9
--- /dev/null
+++ b/osam-core-framework/web/src/main/java/org/onap/osam/controller/AbstractController.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 Netsia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+
+package org.onap.osam.controller;
+
+import org.onap.osam.common.exception.BadFormatException;
+import org.onap.osam.common.exception.NotFoundException;
+import org.onap.osam.common.exception.ServerException;
+import org.onap.osam.common.exception.UnknownTypeException;
+import org.slf4j.Logger;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * Created by cemturker on 30.09.2018.
+ */
+public abstract class AbstractController {
+
+ private Logger logger;
+
+ public AbstractController(Logger logger) {
+ this.logger = logger;
+ }
+
+ public <T> ResponseEntity<T> proceedException(Exception e) {
+ if (e instanceof BadFormatException || e instanceof UnknownTypeException) {
+ return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
+ } else if(e instanceof NotFoundException) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
+ } else if(e instanceof ServerException) {
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
+ } else {
+ logger.error("",e);
+ return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
+ }
+ }
+}
diff --git a/osam-core-framework/web/src/main/java/org/onap/osam/controller/AccessPodRestController.java b/osam-core-framework/web/src/main/java/org/onap/osam/controller/AccessPodRestController.java
new file mode 100644
index 0000000..46b21f7
--- /dev/null
+++ b/osam-core-framework/web/src/main/java/org/onap/osam/controller/AccessPodRestController.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 Netsia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+
+package org.onap.osam.controller;
+
+import lombok.extern.slf4j.Slf4j;
+import org.onap.osam.common.dto.AccessPodDTO;
+import org.onap.osam.helper.DTOMapper;
+import org.onap.osam.model.dao.AccessPod;
+import org.onap.osam.api.service.AccessPodService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * Created by cemturker on 27.09.2018.
+ */
+@RestController
+@RequestMapping("/accessPod")
+@Slf4j
+public class AccessPodRestController extends AbstractController {
+
+ private AccessPodService accessPodService;
+
+ @Autowired
+ public AccessPodRestController(AccessPodService accessPodService) {
+ super(log);
+ this.accessPodService = accessPodService;
+ }
+
+ @GetMapping
+ public List<AccessPodDTO> getAccessPods(){
+ return DTOMapper.covertAccessPodsToDtos(accessPodService.getAll());
+ }
+
+ @PostMapping
+ public ResponseEntity<AccessPodDTO> postAccessPod(@RequestBody AccessPodDTO accessPodDTO){
+ try {
+ log.info("Post request for {} is received",accessPodDTO);
+ AccessPod accessPod = DTOMapper.convertDtoToAccessPod(accessPodDTO);
+ accessPod = accessPodService.addOrUpdate(accessPod);
+ return new ResponseEntity<>(DTOMapper.convertAccessPodToDto(accessPod),HttpStatus.CREATED);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+ }
+
+ @DeleteMapping("pnf/{pnfId}")
+ public ResponseEntity deleteAccessPodByPnfId(@PathVariable("pnfId") String pnfId) {
+ try{
+ this.accessPodService.removeByPnfId(pnfId);
+ return ResponseEntity.ok().build();
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+
+ }
+
+ @DeleteMapping("/{id}")
+ public ResponseEntity deleteAccessPod(@PathVariable("id") Long id) {
+ try {
+ this.accessPodService.removeById(id);
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+ return ResponseEntity.ok().build();
+ }
+
+}
diff --git a/osam-core-framework/web/src/main/java/org/onap/osam/controller/AsyncJobDemoController.java b/osam-core-framework/web/src/main/java/org/onap/osam/controller/AsyncJobDemoController.java
new file mode 100644
index 0000000..77936e5
--- /dev/null
+++ b/osam-core-framework/web/src/main/java/org/onap/osam/controller/AsyncJobDemoController.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.osam.controller;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.osam.job.AsyncJobService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.jackson.JsonComponent;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.UUID;
+
+@RestController
+@RequestMapping("/async")
+@Slf4j
+public class AsyncJobDemoController extends AbstractController{
+ private AsyncJobService asyncJobService;
+
+ @Autowired
+ public AsyncJobDemoController(AsyncJobService asyncJobService) {
+ super(log);
+ this.asyncJobService = asyncJobService;
+ }
+
+ @PostMapping("/chassis")
+ public ResponseEntity<String> createChassisWithAsyncJob(@RequestBody AsyncJobDemoControllerData data){
+ try {
+ final List<UUID> asyncJob = asyncJobService.pushBulkJob("demoUser", data.getIsRootJobSuccessful(), data.getIsRootDependantOnChildren());
+ return new ResponseEntity<String>(asyncJob.get(0).toString(), HttpStatus.OK);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+ }
+
+
+ @AllArgsConstructor
+ @NoArgsConstructor
+ @Setter
+ @Getter
+ @JsonAutoDetect
+ public static class AsyncJobDemoControllerData {
+ private Boolean isRootJobSuccessful;
+ private Boolean isRootDependantOnChildren;
+ }
+}
diff --git a/osam-core-framework/web/src/main/java/org/onap/osam/controller/DeviceController.java b/osam-core-framework/web/src/main/java/org/onap/osam/controller/DeviceController.java
new file mode 100644
index 0000000..f6c7aec
--- /dev/null
+++ b/osam-core-framework/web/src/main/java/org/onap/osam/controller/DeviceController.java
@@ -0,0 +1,166 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 Netsia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+
+package org.onap.osam.controller;
+
+import lombok.extern.slf4j.Slf4j;
+import org.onap.osam.api.service.DeviceService;
+import org.onap.osam.common.dto.ChassisDTO;
+import org.onap.osam.common.dto.OLTChassisDTO;
+import org.onap.osam.common.dto.ONTDTO;
+import org.onap.osam.helper.DTOMapper;
+import org.onap.osam.model.dao.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by Zafer Kaban on 27.09.2018.
+ */
+@CrossOrigin
+@RestController
+@RequestMapping("/device")
+@Slf4j
+public class DeviceController extends AbstractController {
+
+ private DeviceService deviceService;
+
+ @Autowired
+ public DeviceController(DeviceService deviceService) {
+ super(log);
+ this.deviceService = deviceService;
+ }
+
+ @PostMapping("/chassis")
+ public ResponseEntity<ChassisDTO> postChassis(@RequestBody ChassisDTO chassisDTO){
+ try {
+ log.info("postChassis request is received {}",chassisDTO);
+ Chassis chassis = DTOMapper.convertToChassis(chassisDTO);
+ chassis = deviceService.addChassis(chassis);
+ return new ResponseEntity<>(DTOMapper.convertChassisToDTO(chassis),HttpStatus.CREATED);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+
+ }
+
+ @DeleteMapping("chassis/{clli}")
+ public ResponseEntity deleteChassisByClli(@PathVariable("clli") String clli) {
+ try{
+ this.deviceService.deleteChassisByClli(clli);
+ return ResponseEntity.ok().build();
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+
+ }
+
+
+ @PostMapping("/chassis/olt")
+ public ResponseEntity<OLTChassisDTO> postOLTChassis(@RequestBody OLTChassisDTO oltChassisDTO){
+ try {
+ Chassis chassis = this.deviceService.getChassisByClli(oltChassisDTO.getClli());
+ OLTSlot oltSlot = DTOMapper.convertToOLT(oltChassisDTO);
+ oltSlot.setChassis(chassis);
+ this.deviceService.addOLTSlot(oltSlot, chassis);
+ return new ResponseEntity<> (DTOMapper.convertFromOLT(oltSlot),HttpStatus.CREATED);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+
+ }
+
+ @PostMapping("/chassis/olt/ont-provision")
+ public ResponseEntity<ONTDTO> provisionONTDevice(@RequestBody ONTDTO ontDTO){
+ try {
+ ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.PROVISION);
+ return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+
+ }
+
+ @PostMapping("/chassis/olt/ont-full")
+ public ResponseEntity<ONTDTO> provisionONTDeviceFull(@RequestBody ONTDTO ontDTO){
+ try {
+ ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.FULL);
+ return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+
+ }
+
+ @PostMapping("/chassis/olt/ont-preprovision")
+ public ResponseEntity<ONTDTO> preprovisionONTDevice(@RequestBody ONTDTO ontDTO){
+ try {
+ ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.PREPROVISION);
+ return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+
+ }
+
+ @DeleteMapping("chassis/olt/ont/{ontid}")
+ public ResponseEntity deleteOntById(@PathVariable("ontid") String ontid) {
+ try{
+ this.deviceService.deleteONTDevice(new Long(ontid));
+ return ResponseEntity.ok().build();
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+
+ }
+
+ @GetMapping("/chassis")
+ public ResponseEntity<List<ChassisDTO>> getAllChassis(){
+ try {
+ return new ResponseEntity<> (DTOMapper.convertChassisToDTO(deviceService.getAllChassis()), HttpStatus.OK);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+ }
+
+ @GetMapping("/chassis/olt")
+ public ResponseEntity<Map<String, List<OLTChassisDTO>>> getAllOLTDevices(){
+ try {
+ return new ResponseEntity<> (DTOMapper.convertFromOLT(deviceService.getAllOLTSlots()), HttpStatus.OK);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+ }
+
+ @GetMapping("/chassis/olt/ont")
+ public ResponseEntity<Map<String, List<ONTDTO>>> getAllONTDevices(){
+ try {
+ return new ResponseEntity<> (DTOMapper.convertFromONTDevice(deviceService.getAllONTDevices()), HttpStatus.OK);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+ }
+}
diff --git a/osam-core-framework/web/src/main/java/org/onap/osam/controller/ServiceController.java b/osam-core-framework/web/src/main/java/org/onap/osam/controller/ServiceController.java
new file mode 100644
index 0000000..d033a1a
--- /dev/null
+++ b/osam-core-framework/web/src/main/java/org/onap/osam/controller/ServiceController.java
@@ -0,0 +1,135 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 Netsia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+
+package org.onap.osam.controller;
+
+import lombok.extern.slf4j.Slf4j;
+import org.onap.osam.model.dao.SpeedProfile;
+import org.onap.osam.model.dao.TechnologyProfile;
+import org.onap.osam.api.service.BroadBandService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * Created by cemturker on 19.09.2018.
+ */
+@RestController
+@RequestMapping("/service")
+@Slf4j
+public class ServiceController extends AbstractController {
+
+ private BroadBandService broadBandService;
+
+ //TODOs add validations for post reqs...
+
+ @Autowired
+ public ServiceController(BroadBandService broadBandService){
+ super(log);
+ this.broadBandService = broadBandService;
+ }
+
+ @GetMapping("/speedProfile")
+ public ResponseEntity<List<SpeedProfile>> getSpeedProfiles() {
+ try{
+ return ResponseEntity.ok(this.broadBandService.getSpeedProfiles());
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+ }
+
+ @GetMapping("/speedProfile/{id}")
+ public ResponseEntity<SpeedProfile> getSpeedProfile(@PathVariable("id") Long id) {
+ try {
+ return ResponseEntity.ok(this.broadBandService.getSpeedProfile(id));
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+ }
+
+ @DeleteMapping("/speedProfile/{id}")
+ public ResponseEntity deleteSpeedProfile(@PathVariable("id") Long id) {
+ try {
+ this.broadBandService.removeSpeedProfile(id);
+ return ResponseEntity.ok().build();
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+ }
+
+ @PostMapping("/speedProfile")
+ public ResponseEntity<SpeedProfile> createSpeedProfile(@RequestBody SpeedProfile speedProfile) {
+ try {
+ return new ResponseEntity<>(this.broadBandService.addSpeedProfile(speedProfile),
+ HttpStatus.CREATED);
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+
+ }
+
+ @GetMapping("/technologyProfile")
+ public ResponseEntity<List<TechnologyProfile>> getTechnologyProfiles() {
+ try {
+ return ResponseEntity.ok(this.broadBandService.getTechnologyProfiles());
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+ }
+
+ @GetMapping("/technologyProfile/{id}")
+ public ResponseEntity<TechnologyProfile> getTechnologyProfile(@PathVariable("id") Long id) {
+ try {
+ return ResponseEntity.ok(this.broadBandService.getTechnologyProfile(id));
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+ }
+
+ @DeleteMapping("/technologyProfile/{id}")
+ public ResponseEntity deleteTechnologyProfile(@PathVariable("id") Long id) {
+ try {
+ this.broadBandService.removeSpeedProfile(id);
+ return ResponseEntity.ok().build();
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+ }
+
+ @PostMapping("/technologyProfile")
+ public ResponseEntity<TechnologyProfile> createTechnologyProfile(@RequestBody TechnologyProfile technologyProfile) {
+ try {
+ return new ResponseEntity<>(this.broadBandService.addTechnologyProfile(technologyProfile),HttpStatus.CREATED);
+ }catch (Exception e){
+ return super.proceedException(e);
+ }
+ }
+}
diff --git a/osam-core-framework/web/src/main/java/org/onap/osam/controller/TopologyController.java b/osam-core-framework/web/src/main/java/org/onap/osam/controller/TopologyController.java
new file mode 100644
index 0000000..18ea729
--- /dev/null
+++ b/osam-core-framework/web/src/main/java/org/onap/osam/controller/TopologyController.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 Netsia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+
+package org.onap.osam.controller;
+
+import lombok.extern.slf4j.Slf4j;
+import org.onap.osam.api.service.AccessPodService;
+import org.onap.osam.api.service.DeviceService;
+import org.onap.osam.common.dto.AccessPodDTO;
+import org.onap.osam.helper.DTOMapper;
+import org.onap.osam.model.dao.AccessPod;
+import org.onap.osam.model.dao.Chassis;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * Created by cemturker on 03.10.2018.
+ */
+@RestController
+@RequestMapping("topology")
+@Slf4j
+public class TopologyController extends AbstractController {
+ private AccessPodService accessPodService;
+ private DeviceService deviceService;
+
+ @Autowired
+ public TopologyController(AccessPodService accessPodService,
+ DeviceService deviceService) {
+ super(log);
+ this.accessPodService = accessPodService;
+ this.deviceService = deviceService;
+ }
+
+ @GetMapping("/accessPod/{pnfId}")
+ public ResponseEntity<AccessPodDTO> getTopologyWithPnfId(@PathVariable("pnfId") String pnfId) {
+ try{
+ log.info("GetTopology with pnfId:{} is received.",pnfId);
+ AccessPod accessPod = accessPodService.findByPnfId(pnfId);
+ List<Chassis> chassisList = deviceService.getByPnfId(pnfId);
+ return ResponseEntity.ok(DTOMapper.representTheAccessPod(chassisList,accessPod));
+ }catch (Exception e) {
+ return super.proceedException(e);
+ }
+ }
+}
diff --git a/osam-core-framework/web/src/main/java/org/onap/osam/controller/config/SwaggerConfig.java b/osam-core-framework/web/src/main/java/org/onap/osam/controller/config/SwaggerConfig.java
new file mode 100644
index 0000000..20a538c
--- /dev/null
+++ b/osam-core-framework/web/src/main/java/org/onap/osam/controller/config/SwaggerConfig.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 Netsia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+
+package org.onap.osam.controller.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+/**
+ * Created by cemturker on 04.10.2018.
+ */
+@Configuration
+@EnableSwagger2
+public class SwaggerConfig extends WebMvcConfigurationSupport {
+ @Bean
+ public Docket osamApi() {
+ return new Docket(DocumentationType.SWAGGER_2)
+ .select() .apis(RequestHandlerSelectors.any())
+ .paths(PathSelectors.any())
+ .build();
+ }
+
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("swagger-ui.html")
+ .addResourceLocations("classpath:/META-INF/resources/");
+
+ registry.addResourceHandler("/webjars/**")
+ .addResourceLocations("classpath:/META-INF/resources/webjars/");
+ }
+}
diff --git a/osam-core-framework/web/src/main/java/org/onap/osam/helper/DTOMapper.java b/osam-core-framework/web/src/main/java/org/onap/osam/helper/DTOMapper.java
new file mode 100644
index 0000000..8a941ee
--- /dev/null
+++ b/osam-core-framework/web/src/main/java/org/onap/osam/helper/DTOMapper.java
@@ -0,0 +1,249 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 Netsia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+
+package org.onap.osam.helper;
+
+import com.google.common.collect.Lists;
+import org.onap.osam.common.dto.AccessPodDTO;
+import org.onap.osam.common.dto.ChassisDTO;
+import org.onap.osam.common.dto.OLTChassisDTO;
+import org.onap.osam.common.dto.OLTPortDTO;
+import org.onap.osam.common.dto.ONTDTO;
+import org.onap.osam.model.dao.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+public final class DTOMapper {
+
+ private DTOMapper () {
+
+ }
+
+ public static Chassis convertToChassis (ChassisDTO chassisDTO) {
+ Chassis chassis = new Chassis();
+ chassis.setClli(chassisDTO.getClli());
+ chassis.setShelf(chassisDTO.getShelf());
+ chassis.setRack(chassisDTO.getRack());
+ chassis.setState(ActivityState.ACTIVE);
+ AccessPod accessPod = new AccessPod();
+ accessPod.setPnfId(chassisDTO.getPnfId());
+ chassis.setAccessPod(accessPod);
+ return chassis;
+ }
+
+
+
+
+ public static OLTSlot convertToOLT (OLTChassisDTO oltChassisDTO) {
+ OLTSlot oltSlot = new OLTSlot();
+ oltSlot.setIpAddress(oltChassisDTO.getIpAddress());
+ oltSlot.setPort(oltChassisDTO.getPortNumber());
+ oltSlot.setName(oltChassisDTO.getName());
+ oltSlot.setOltDriver(OltDriver.valueOf(oltChassisDTO.getOltDriver()));
+ oltSlot.setOltType(OltType.valueOf(oltChassisDTO.getOltType()));
+ return oltSlot;
+ }
+
+ public static ChassisDTO convertChassisToDTO(Chassis chassis) {
+ ChassisDTO chassisDTO = new ChassisDTO();
+ chassisDTO.setId(chassis.getId());
+ chassisDTO.setClli(chassis.getClli());
+ chassisDTO.setRack(chassis.getRack());
+ chassisDTO.setShelf(chassis.getShelf());
+ chassisDTO.setPnfId(chassis.getAccessPod().getPnfId());
+ return chassisDTO;
+ }
+
+ public static List<ChassisDTO> convertChassisToDTO(List<Chassis> chassises) {
+ return chassises.stream().map(x -> convertChassisToDTO(x)).collect(Collectors.toList());
+ }
+
+ public static Map<String, List<OLTChassisDTO>> convertFromOLT(List<OLTSlot> oltSlots){
+ return oltSlots.stream().map(x -> convertFromOLT(x)).collect(Collectors.toList()).stream().collect(Collectors.groupingBy(OLTChassisDTO::getClli));
+ }
+
+ public static OLTChassisDTO convertFromOLT (OLTSlot oltSlot) {
+ OLTChassisDTO oltChassisDTO = new OLTChassisDTO();
+ oltChassisDTO.setClli(oltSlot.getChassis().getClli());
+ oltChassisDTO.setIpAddress(oltSlot.getIpAddress());
+ oltChassisDTO.setName(oltSlot.getName());
+ oltChassisDTO.setOltDriver(oltSlot.getOltDriver().name());
+ oltChassisDTO.setOltType(oltSlot.getOltType().name());
+ oltChassisDTO.setPortNumber(oltSlot.getPort());
+ oltChassisDTO.setId(oltSlot.getId());
+ return oltChassisDTO;
+ }
+
+ public static ONTDTO convertFromONTDevice (ONTDevice ontDevice) {
+ ONTDTO ontdto = new ONTDTO();
+ ontdto.setSerialNumber(ontDevice.getSerialNumber());
+ ontdto.setPortNumber(ontDevice.getOLTPort().getPortNumber());
+ ontdto.setId(ontDevice.getId());
+ ontdto.setSlotNumber(ontDevice.getOLTPort().getOltSlot().getNumber());
+ ontdto.setClli(ontDevice.getOLTPort().getOltSlot().getChassis().getClli());
+ ontdto.setCtag(ontDevice.getCTag());
+ ontdto.setStag(ontDevice.getSTag());
+ ontdto.setCircuitId(ontDevice.getCircuitId());
+ ontdto.setNasPortId(ontDevice.getNasPortId());
+ if (ontDevice.getTechProfile() != null) {
+ ontdto.setTechnologyProfile(ontDevice.getTechProfile().getName());
+ }
+ if (ontDevice.getSpeedProfile() != null) {
+ ontdto.setSpeedProfile(ontDevice.getSpeedProfile().getName());
+ }
+ return ontdto;
+ }
+
+ public static ONTDevice convertToONTDevice (ONTDTO ontdto) {
+ ONTDevice ontDevice = new ONTDevice();
+ ontDevice.setNumber(ontdto.getOntNumber());
+ ontDevice.setSerialNumber(ontdto.getSerialNumber());
+ ontDevice.setCTag(ontdto.getCtag());
+ ontDevice.setSTag(ontdto.getStag());
+ ontDevice.setCircuitId(ontdto.getCircuitId());
+ ontDevice.setNasPortId(ontdto.getNasPortId());
+ TechnologyProfile technologyProfile = new TechnologyProfile();
+ technologyProfile.setName(ontdto.getTechnologyProfile());
+ ontDevice.setTechProfile(technologyProfile);
+ SpeedProfile speedProfile = new SpeedProfile();
+ speedProfile.setName(ontdto.getSpeedProfile());
+ ontDevice.setSpeedProfile(speedProfile);
+ Chassis chassis = new Chassis();
+ chassis.setClli(ontdto.getClli());
+ OLTSlot oltSlot = new OLTSlot();
+ oltSlot.setChassis(chassis);
+ OLTPort oltPort = new OLTPort();
+ oltPort.setPortNumber(ontdto.getPortNumber());
+ oltPort.setOltSlot(oltSlot);
+ ontDevice.setOLTPort(oltPort);
+ return ontDevice;
+ }
+
+ public static Map<String, List<ONTDTO>> convertFromONTDevice(List<ONTDevice> ontDevices){
+ return ontDevices.stream().map(x -> convertFromONTDevice(x)).collect(Collectors.toList()).stream().collect(Collectors.groupingBy(ONTDTO::getClli));
+ }
+
+ public static AccessPod convertDtoToAccessPod(AccessPodDTO dto) {
+ //TODO validate..
+ AccessPod accessPod = new AccessPod();
+ accessPod.setPnfId(dto.getPnfId());
+ accessPod.setId(dto.getId());
+ accessPod.setCoreIp(dto.getCoreIp());
+ accessPod.setCorePort(dto.getCorePort());
+ accessPod.setUsername(dto.getUsername());
+ accessPod.setPassword(dto.getPassword());
+ accessPod.setIp(dto.getIp());
+ accessPod.setPort(dto.getPort());
+ return accessPod;
+ }
+
+ public static AccessPodDTO convertAccessPodToDto(AccessPod accessPod) {
+ //TODO validate..
+ AccessPodDTO dto = new AccessPodDTO();
+ dto.setPnfId(accessPod.getPnfId());
+ dto.setCoreIp(accessPod.getCoreIp());
+ dto.setCorePort(accessPod.getCorePort());
+ dto.setUsername(accessPod.getUsername());
+ dto.setPassword(accessPod.getPassword());
+ dto.setIp(accessPod.getIp());
+ dto.setId(accessPod.getId());
+ dto.setPort(accessPod.getPort());
+ return dto;
+ }
+
+ private static OLTPortDTO convertOLTPortToDTO(OLTPort oltPort) {
+ OLTPortDTO oltPortDTO = new OLTPortDTO();
+ oltPortDTO.setId(oltPort.getId());
+ oltPortDTO.setAdminState(oltPort.getAdminState().name());
+ oltPortDTO.setPortAuthState(oltPort.getPortAuthState().name());
+ oltPortDTO.setPortNumber(oltPort.getPortNumber());
+ return oltPortDTO;
+ }
+
+ public static List<AccessPodDTO> covertAccessPodsToDtos(List<AccessPod> accessPodList) {
+ //TODO validate..
+ List<AccessPodDTO> dtos = new ArrayList<>();
+ for (AccessPod accessPod : accessPodList) {
+ dtos.add(convertAccessPodToDto(accessPod));
+ }
+ return dtos;
+ }
+
+ public static AccessPodDTO representTheAccessPod(List<Chassis> chassisList, AccessPod accessPod) {
+ if (accessPod == null) {
+ return null;
+ }
+ AccessPodDTO accessPodDTO = convertAccessPodToDto(accessPod);
+ if (chassisList == null || chassisList.isEmpty()) {
+ return accessPodDTO;
+ }
+ List<ChassisDTO> chassisDTOS = new ArrayList<>();
+ accessPodDTO.setChassises(chassisDTOS);
+ for (Chassis chassis : chassisList) {
+ chassisDTOS.add(representTheChassis(chassis));
+ }
+ return accessPodDTO;
+ }
+
+ public static ChassisDTO representTheChassis(Chassis chassis) {
+ ChassisDTO chassisDTO = convertChassisToDTO(chassis);
+ if (chassis.getOltSlots() == null || chassis.getOltSlots().isEmpty()) {
+ return chassisDTO;
+ }
+ List<OLTChassisDTO> oltChassisDTOS = Lists.newArrayList();
+ chassisDTO.setOlts(oltChassisDTOS);
+ for (OLTSlot oltSlot : chassis.getOltSlots()) {
+ oltChassisDTOS.add(representTheOLTSlot(oltSlot));
+ }
+ return chassisDTO;
+ }
+
+ public static OLTChassisDTO representTheOLTSlot(OLTSlot oltSlot) {
+ OLTChassisDTO oltChassisDTO = convertFromOLT(oltSlot);
+ if (oltSlot.getOltPorts() == null || oltSlot.getOltPorts().isEmpty()) {
+ return oltChassisDTO;
+ }
+ List<OLTPortDTO> oltPortDTOS = Lists.newArrayList();
+ oltChassisDTO.setOltPorts(oltPortDTOS);
+ for (OLTPort oltPort : oltSlot.getOltPorts()) {
+ oltPortDTOS.add(representTheOLTPort(oltPort));
+ }
+ return oltChassisDTO;
+ }
+
+ public static OLTPortDTO representTheOLTPort(OLTPort oltPort) {
+ OLTPortDTO portDTO = convertOLTPortToDTO(oltPort);
+ if (oltPort.getOntDevices() == null || oltPort.getOntDevices().isEmpty()) {
+ return portDTO;
+ }
+ List<ONTDTO> ontdtos = Lists.newArrayList();
+ portDTO.setOntDevices(ontdtos);
+ for (ONTDevice ontDevice : oltPort.getOntDevices()) {
+ ontdtos.add(convertFromONTDevice(ontDevice));
+ }
+ return portDTO;
+ }
+}