swagger expose Northbound endpoints

Change-Id: I8c19590e24fdf45655386f4abeee2828cc9cb30a
diff --git a/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerAccessPodController.java b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerAccessPodController.java
new file mode 100644
index 0000000..07ad804
--- /dev/null
+++ b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerAccessPodController.java
@@ -0,0 +1,75 @@
+/*-

+ * ============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.controllers;

+

+import io.swagger.annotations.ApiOperation;

+import org.onap.osam.common.dto.AccessPodDTO;

+import org.onap.osam.common.dto.ChassisDTO;

+import org.springframework.beans.factory.annotation.Autowired;

+import org.springframework.http.HttpEntity;

+import org.springframework.http.ResponseEntity;

+import org.springframework.web.bind.annotation.*;

+import org.springframework.web.client.RestTemplate;

+

+import java.util.Arrays;

+import java.util.List;

+

+// TODO log

+@RestController

+@RequestMapping("accessPod")

+public class OnapEnablerAccessPodController extends OnapEnablerController {

+

+	private static final String ACCESS_POD = "accessPod";

+

+	@Autowired

+	public OnapEnablerAccessPodController(RestTemplate restTemplate){

+		this.restTemplate = restTemplate;

+	}

+

+    @ApiOperation(value = "Get all PODs registered in OSAM Core",

+            response = AccessPodDTO.class,

+            responseContainer = "List")

+	@RequestMapping(method = RequestMethod.GET)

+	public List<AccessPodDTO> getAccessPods() {

+		return Arrays.asList(restTemplate.getForObject(buildRequestPath(ACCESS_POD), AccessPodDTO[].class));

+	}

+

+    @ApiOperation(value = "Register a new POD in OSAM Core",

+            response = AccessPodDTO.class)

+	@RequestMapping(method = RequestMethod.POST)

+	public ResponseEntity<AccessPodDTO> postAccessPod(@RequestBody AccessPodDTO accessPodDTO) {

+		return restTemplate.postForEntity(buildRequestPath(ACCESS_POD), new HttpEntity<>(accessPodDTO), AccessPodDTO.class);

+	}

+

+    @ApiOperation(value = "Unregister a POD from OSAM Core by pnfId field")

+    @RequestMapping(method = RequestMethod.DELETE, value = "pnf/{pnfId}")

+	public void deleteAccessPodByPnfId(@PathVariable String pnfId) {

+		restTemplate.delete(buildRequestPath(ACCESS_POD, "pnf", pnfId));

+	}

+

+    @ApiOperation(value = "Unregister a POD from OSAM Core by id field")

+	@RequestMapping(method = RequestMethod.DELETE, value = "{id}")

+	public void deleteAccessPod(@PathVariable Long id) {

+		restTemplate.delete(buildRequestPath(ACCESS_POD, String.valueOf(id)));

+	}

+

+

+

+}

diff --git a/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerController.java b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerController.java
new file mode 100644
index 0000000..51efa8e
--- /dev/null
+++ b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerController.java
@@ -0,0 +1,39 @@
+/*-
+ * ============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.controllers;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+abstract class OnapEnablerController {
+	private static final String SLASH = "/";
+
+	@Value("${osam.client.url}")
+	private String osamUrl;
+
+	RestTemplate restTemplate;
+
+	String buildRequestPath(String... args){
+		return osamUrl.concat(Stream.of(args).collect(Collectors.joining(SLASH)));
+	}
+}
diff --git a/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerDeviceController.java b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerDeviceController.java
new file mode 100644
index 0000000..d57b61f
--- /dev/null
+++ b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerDeviceController.java
@@ -0,0 +1,101 @@
+/*-

+ * ============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.controllers;

+

+import io.swagger.annotations.ApiOperation;

+import io.swagger.annotations.ApiParam;

+import org.onap.osam.common.dto.ChassisDTO;

+import org.onap.osam.common.dto.OLTChassisDTO;

+import org.onap.osam.common.dto.ONTDTO;

+import org.springframework.beans.factory.annotation.Autowired;

+import org.springframework.core.ParameterizedTypeReference;

+import org.springframework.http.HttpEntity;

+import org.springframework.http.HttpMethod;

+import org.springframework.http.ResponseEntity;

+import org.springframework.web.bind.annotation.*;

+import org.springframework.web.client.RestTemplate;

+

+import java.util.List;

+import java.util.Map;

+

+// TODO log

+@RestController

+@RequestMapping("device/chassis")

+public class OnapEnablerDeviceController extends OnapEnablerController {

+

+	private static final String DEVICE_CHASSIS = "device/chassis";

+

+	@Autowired

+	public OnapEnablerDeviceController(RestTemplate restTemplate){

+		this.restTemplate = restTemplate;

+	}

+

+    @ApiOperation(value = "Register a chassis on top of a POD",

+            response = ChassisDTO.class)

+	@RequestMapping(method = RequestMethod.POST)

+	public ResponseEntity<ChassisDTO> postChassis(@RequestBody ChassisDTO chassisDTO) {

+		return restTemplate.postForEntity(buildRequestPath(DEVICE_CHASSIS), new HttpEntity<>(chassisDTO), ChassisDTO.class);

+	}

+

+    @ApiOperation(value = "Unregister a chassis from a POD")

+	@RequestMapping(method = RequestMethod.DELETE, value = "{clli}")

+	public void deleteChassisByClli(@PathVariable String clli) {

+		restTemplate.delete(buildRequestPath(DEVICE_CHASSIS, clli));

+	}

+

+    @ApiOperation(value = "Register OLT-specific chassis on top of a chassis",

+            response = OLTChassisDTO.class)

+	@RequestMapping(method = RequestMethod.POST, value = "olt")

+	public ResponseEntity<OLTChassisDTO> postOLTChassis(@RequestBody OLTChassisDTO oltChassisDTO) {

+		return restTemplate.postForEntity(buildRequestPath(DEVICE_CHASSIS, "olt"), new HttpEntity<>(oltChassisDTO), OLTChassisDTO.class);

+	}

+

+    @ApiOperation(value = "Register an ONT device on top of a OLT-specific chassis",

+            response = ONTDTO.class)

+	@RequestMapping(method = RequestMethod.POST, value = "olt/ont")

+	public ResponseEntity<ONTDTO> postONTDevice(@RequestBody ONTDTO ontDTO) {

+		return restTemplate.postForEntity(buildRequestPath(DEVICE_CHASSIS, "olt/ont"), new HttpEntity<>(ontDTO), ONTDTO.class);

+	}

+

+    @ApiOperation(value = "Get all chassis entities from all PODs",

+            response = ChassisDTO.class,

+    responseContainer = "List")

+	@RequestMapping(method = RequestMethod.GET)

+	public ResponseEntity<List<ChassisDTO>> getAllChassis() {

+		return restTemplate.exchange(buildRequestPath(DEVICE_CHASSIS), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<List<ChassisDTO>>(){});

+	}

+

+

+    @ApiOperation(value = "Get all OLT-specific chassis entities from all PODs, grouped by POD pnfId",

+            response = OLTChassisDTO.class,

+            responseContainer = "Map")

+	@RequestMapping(method = RequestMethod.GET, value = "olt")

+	public ResponseEntity<Map<String, List<OLTChassisDTO>>> getAllOLTDevices(){

+		return restTemplate.exchange(buildRequestPath(DEVICE_CHASSIS, "olt"), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<Map<String, List<OLTChassisDTO>>>(){});

+	}

+

+    @ApiOperation(value = "Get all ONT devices from all PODs, grouped by POD pnfId",

+            response = ONTDTO.class,

+            responseContainer = "Map")

+	@RequestMapping(method = RequestMethod.GET, value = "olt/ont")

+	public ResponseEntity<Map<String, List<ONTDTO>>> getAllONTDevices(){

+		return restTemplate.exchange(buildRequestPath(DEVICE_CHASSIS, "olt/ont"), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<Map<String, List<ONTDTO>>>(){});

+	}

+}

diff --git a/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerServiceController.java b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerServiceController.java
new file mode 100644
index 0000000..cf6e6cb
--- /dev/null
+++ b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerServiceController.java
@@ -0,0 +1,90 @@
+/*-
+ * ============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.controllers;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.List;
+
+// TODO log
+@RestController
+@RequestMapping("service")
+
+// *** Return and request types should be in osam-common. Types such as SpeedProfile, TechnologyProfile that are under model.dao temporarily reduced to Object *** //
+public class OnapEnablerServiceController extends OnapEnablerController {
+
+	private static final String SERVICE = "service";
+	private static final String SPEED_PROFILE = "speedProfile";
+	private static final String SPEED_PROFILE_ID = "speedProfile/{id}";
+	private static final String TECH_PROFILE = "technologyProfile";
+	private static final String TECH_PROFILE_ID = "technologyProfile/{id}";
+
+	@Autowired
+	public OnapEnablerServiceController(RestTemplate restTemplate){
+		this.restTemplate = restTemplate;
+	}
+
+	@RequestMapping(method = RequestMethod.GET, value = SPEED_PROFILE)
+	public ResponseEntity<List</*SpeedProfile*/Object>> getSpeedProfiles() {
+		return restTemplate.exchange(buildRequestPath(SERVICE, SPEED_PROFILE), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<List</*SpeedProfile*/Object>>(){});
+	}
+
+	@RequestMapping(method = RequestMethod.GET, value = SPEED_PROFILE_ID)
+	public ResponseEntity</*SpeedProfile*/Object> getSpeedProfile(@PathVariable Long id) {
+		return restTemplate.getForEntity(buildRequestPath(SERVICE, SPEED_PROFILE, String.valueOf(id)), /*SpeedProfile*/Object.class);
+	}
+
+	@RequestMapping(method = RequestMethod.DELETE, value = SPEED_PROFILE_ID)
+	public void deleteSpeedProfile(@PathVariable Long id) {
+		restTemplate.delete(buildRequestPath(SERVICE, SPEED_PROFILE, String.valueOf(id)));
+	}
+
+	@RequestMapping(method = RequestMethod.POST, value = SPEED_PROFILE)
+	public ResponseEntity</*SpeedProfile*/Object> createSpeedProfile(@RequestBody /*SpeedProfile*/ Object speedProfile) {
+		return restTemplate.postForEntity(buildRequestPath(SERVICE, SPEED_PROFILE), speedProfile, /*SpeedProfile*/Object.class);
+	}
+
+	@RequestMapping(method = RequestMethod.GET, value = TECH_PROFILE)
+	public ResponseEntity<List</*TechnologyProfile*/Object>> getTechnologyProfiles() {
+	    return restTemplate.exchange(buildRequestPath(SERVICE, TECH_PROFILE), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<List</*TechnologyProfile*/Object>>(){});
+	}
+
+	@RequestMapping(method = RequestMethod.GET, value = TECH_PROFILE_ID)
+	public ResponseEntity</*TechnologyProfile*/Object> getTechnologyProfile(@PathVariable Long id) {
+		return restTemplate.getForEntity(buildRequestPath(SERVICE, TECH_PROFILE, String.valueOf(id)), /*TechnologyProfile*/Object.class);
+	}
+
+	@RequestMapping(method = RequestMethod.DELETE, value = TECH_PROFILE_ID)
+	public void deleteTechnologyProfile(@PathVariable Long id) {
+		restTemplate.delete(buildRequestPath(SERVICE, TECH_PROFILE, String.valueOf(id)));
+	}
+
+	@RequestMapping(method = RequestMethod.POST, value = TECH_PROFILE)
+	public ResponseEntity</*TechnologyProfile*/Object> createTechnologyProfile(@RequestBody /*TechnologyProfile*/ Object technologyProfile) {
+		return restTemplate.postForEntity(buildRequestPath(SERVICE, TECH_PROFILE), technologyProfile, /*TechnologyProfile*/Object.class);
+	}
+}
diff --git a/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerTopologyController.java b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerTopologyController.java
new file mode 100644
index 0000000..d24ac04
--- /dev/null
+++ b/onap-enabler-be/src/main/java/org/onap/osam/controllers/OnapEnablerTopologyController.java
@@ -0,0 +1,47 @@
+/*-
+ * ============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.controllers;
+
+import org.onap.osam.common.dto.AccessPodDTO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+// TODO log
+@RestController
+@RequestMapping("topology")
+public class OnapEnablerTopologyController extends OnapEnablerController {
+
+	private static final String TOPOLOGY = "topology";
+
+	@Autowired
+	public OnapEnablerTopologyController(RestTemplate restTemplate) {
+		this.restTemplate = restTemplate;
+	}
+
+	@RequestMapping(method = RequestMethod.GET, value = "accessPod/{pnfId}")
+	public ResponseEntity<AccessPodDTO> getTopologyWithPnfId(@PathVariable String pnfId) {
+		return restTemplate.getForEntity(buildRequestPath(TOPOLOGY, "accessPod", pnfId), AccessPodDTO.class);
+	}
+}
diff --git a/onap-enabler-be/src/main/java/org/onap/osam/controllers/WebConfig.java b/onap-enabler-be/src/main/java/org/onap/osam/controllers/WebConfig.java
index 32e0510..d184cb5 100644
--- a/onap-enabler-be/src/main/java/org/onap/osam/controllers/WebConfig.java
+++ b/onap-enabler-be/src/main/java/org/onap/osam/controllers/WebConfig.java
@@ -45,6 +45,7 @@
 import org.springframework.beans.factory.annotation.Qualifier;

 import org.springframework.context.annotation.Bean;

 import org.springframework.context.annotation.Configuration;

+import org.springframework.web.client.RestTemplate;

 

 import javax.servlet.ServletContext;

 import java.io.File;

@@ -122,4 +123,9 @@
     public SchedulerRestInterfaceIfc getSchedulerRestInterface(){

         return new SchedulerRestInterface();

     }

+

+	@Bean

+	public RestTemplate restTemplate() {

+		return new RestTemplate();

+	}

 }