aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/openecomp/vid/controller
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java/org/openecomp/vid/controller')
-rwxr-xr-xvid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java924
-rwxr-xr-xvid-app-common/src/main/java/org/openecomp/vid/controller/MsoController.java1373
-rwxr-xr-xvid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java20
-rw-r--r--vid-app-common/src/main/java/org/openecomp/vid/controller/WebConfig.java18
4 files changed, 1214 insertions, 1121 deletions
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java
index 861ddf8d..c0b6a514 100755
--- a/vid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java
+++ b/vid-app-common/src/main/java/org/openecomp/vid/controller/AaiController.java
@@ -18,31 +18,27 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.vid.controller;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.ws.rs.BadRequestException;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
+package org.openecomp.vid.controller;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.openecomp.aai.util.AAIRestInterface;
+import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
+import org.openecomp.portalsdk.core.domain.User;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.openecomp.vid.aai.AaiResponse;
+import org.openecomp.vid.aai.SubscriberData;
+import org.openecomp.vid.aai.SubscriberFilteredResults;
+import org.openecomp.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.openecomp.vid.roles.Role;
+import org.openecomp.vid.roles.RoleProvider;
+import org.openecomp.vid.roles.RoleValidator;
+import org.openecomp.vid.services.AaiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -53,35 +49,292 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
-import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
-import org.openecomp.portalsdk.core.domain.User;
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.openecomp.portalsdk.core.util.SystemProperties;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
/**
* Controller to handle a&ai requests.
*/
@RestController
-public class AaiController extends RestrictedBaseController{
+public class AaiController extends RestrictedBaseController {
+
+ public AaiController() {
+
+ }
+public AaiController(ServletContext servletContext) {
+ this.servletContext = servletContext;
+
+ }
+
+
+
- /** The view name. */
+ /**
+ * The Constant dateFormat.
+ */
+ final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
+ /**
+ * The from app id.
+ */
+ protected String fromAppId = "VidAaiController";
+ /**
+ * The view name.
+ */
String viewName;
-
- /** The logger. */
+ /**
+ * The logger.
+ */
EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiController.class);
- /** The Constant dateFormat. */
- final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
- /** The from app id. */
- protected String fromAppId = "VidAaiController";
+ /**
+ * The model.
+ */
+ private Map<String, Object> model = new HashMap<String, Object>();
+ /**
+ * The servlet context.
+ */
+ @Autowired
+ private ServletContext servletContext;
+
+ /**
+ * aai service
+ */
+ @Autowired
+ private AaiService aaiService;
+
+
+
+ /**
+ * Return tenant details.
+ *
+ * @param jsonObject the json object
+ * @return String The parsing results
+ */
+ public static String parseCustomerObjectForTenants(JSONObject jsonObject) {
+
+ JSONArray tenantArray = new JSONArray();
+ boolean bconvert = false;
+
+ try {
+
+ JSONObject serviceSubsObj = (JSONObject) jsonObject.get("service-subscriptions");
+
+ if (serviceSubsObj != null) {
+ JSONArray srvcSubArray = (JSONArray) serviceSubsObj.get("service-subscription");
+
+ if (srvcSubArray != null) {
+ Iterator i = srvcSubArray.iterator();
+
+ while (i.hasNext()) {
+
+ JSONObject innerObj = (JSONObject) i.next();
+
+ if (innerObj == null)
+ continue;
+
+ JSONObject relationShipListsObj = (JSONObject) innerObj.get("relationship-list");
+ if (relationShipListsObj != null) {
+ JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
+ if (rShipArray != null) {
+ Iterator i1 = rShipArray.iterator();
+
+ while (i1.hasNext()) {
+
+ JSONObject inner1Obj = (JSONObject) i1.next();
+
+ if (inner1Obj == null)
+ continue;
+
+ String relatedTo = checkForNull((String) inner1Obj.get("related-to"));
+ if (relatedTo.equalsIgnoreCase("tenant")) {
+ JSONObject tenantNewObj = new JSONObject();
+
+ String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
+ tenantNewObj.put("link", relatedLink);
+
+ JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
+ if (rDataArray != null) {
+ Iterator i2 = rDataArray.iterator();
+
+ while (i2.hasNext()) {
+ JSONObject inner2Obj = (JSONObject) i2.next();
+
+ if (inner2Obj == null)
+ continue;
+
+ String rShipKey = checkForNull((String) inner2Obj.get("relationship-key"));
+ String rShipVal = checkForNull((String) inner2Obj.get("relationship-value"));
+ if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner")) {
+ tenantNewObj.put("cloudOwner", rShipVal);
+ } else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id")) {
+ tenantNewObj.put("cloudRegionID", rShipVal);
+ }
+
+ if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) {
+ tenantNewObj.put("tenantID", rShipVal);
+ }
+ }
+ }
+
+ JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
+ if (relatedTPropArray != null) {
+ Iterator i3 = relatedTPropArray.iterator();
+
+ while (i3.hasNext()) {
+ JSONObject inner3Obj = (JSONObject) i3.next();
+
+ if (inner3Obj == null)
+ continue;
+
+ String propKey = checkForNull((String) inner3Obj.get("property-key"));
+ String propVal = checkForNull((String) inner3Obj.get("property-value"));
+ if (propKey.equalsIgnoreCase("tenant.tenant-name")) {
+ tenantNewObj.put("tenantName", propVal);
+ }
+ }
+ }
+ bconvert = true;
+ tenantArray.add(tenantNewObj);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (NullPointerException ex) {
+
+
+ }
+
+ if (bconvert)
+ return tenantArray.toJSONString();
+ else
+ return "";
+
+ }
- /** The model. */
- private Map<String,Object> model = new HashMap<String,Object>();
- /** The servlet context. */
- private @Autowired ServletContext servletContext;
+
+ /**
+ * Retrieve the service subscription from the jsonObject.
+ *
+ * @param jsonObject the json object
+ * @return String
+ */
+ public static String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) {
+
+ JSONArray tenantArray = new JSONArray();
+ boolean bconvert = false;
+
+ try {
+ JSONObject relationShipListsObj = (JSONObject) jsonObject.get("relationship-list");
+ if (relationShipListsObj != null) {
+ JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
+ if (rShipArray != null) {
+ Iterator i1 = rShipArray.iterator();
+
+ while (i1.hasNext()) {
+
+ JSONObject inner1Obj = (JSONObject) i1.next();
+
+ if (inner1Obj == null)
+ continue;
+
+ String relatedTo = checkForNull((String) inner1Obj.get("related-to"));
+ if (relatedTo.equalsIgnoreCase("tenant")) {
+ JSONObject tenantNewObj = new JSONObject();
+
+ String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
+ tenantNewObj.put("link", relatedLink);
+
+ JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
+ if (rDataArray != null) {
+ Iterator i2 = rDataArray.iterator();
+
+ while (i2.hasNext()) {
+ JSONObject inner2Obj = (JSONObject) i2.next();
+
+ if (inner2Obj == null)
+ continue;
+
+ String rShipKey = checkForNull((String) inner2Obj.get("relationship-key"));
+ String rShipVal = checkForNull((String) inner2Obj.get("relationship-value"));
+ if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner")) {
+ tenantNewObj.put("cloudOwner", rShipVal);
+ } else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id")) {
+ tenantNewObj.put("cloudRegionID", rShipVal);
+ }
+
+ if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) {
+ tenantNewObj.put("tenantID", rShipVal);
+ }
+ }
+ }
+
+ JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
+ if (relatedTPropArray != null) {
+ Iterator i3 = relatedTPropArray.iterator();
+
+ while (i3.hasNext()) {
+ JSONObject inner3Obj = (JSONObject) i3.next();
+
+ if (inner3Obj == null)
+ continue;
+
+ String propKey = checkForNull((String) inner3Obj.get("property-key"));
+ String propVal = checkForNull((String) inner3Obj.get("property-value"));
+ if (propKey.equalsIgnoreCase("tenant.tenant-name")) {
+ tenantNewObj.put("tenantName", propVal);
+ }
+ }
+ }
+ bconvert = true;
+ tenantArray.add(tenantNewObj);
+ }
+ }
+
+ }
+ }
+ } catch (NullPointerException ex) {
+
+
+ }
+
+ if (bconvert)
+ return tenantArray.toJSONString();
+ else
+ return "";
+
+ }
+
+ /**
+ * Check for null.
+ *
+ * @param local the local
+ * @return the string
+ */
+ private static String checkForNull(String local) {
+ if (local != null)
+ return local;
+ else
+ return "";
+
+ }
/**
* Welcome method.
@@ -89,10 +342,18 @@ public class AaiController extends RestrictedBaseController{
* @param request the request
* @return ModelAndView The view
*/
- @RequestMapping(value = {"/subscriberSearch" }, method = RequestMethod.GET)
+ @RequestMapping(value = {"/subscriberSearch"}, method = RequestMethod.GET)
public ModelAndView welcome(HttpServletRequest request) {
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== AaiController welcome start");
- return new ModelAndView(getViewName());
+ return new ModelAndView(getViewName());
+ }
+
+ @RequestMapping(value = {"/aai_get_aic_zones"}, method = RequestMethod.GET)
+ public ResponseEntity<String> getAicZones(HttpServletRequest request) throws JsonGenerationException, JsonMappingException, IOException {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== getAicZones controller start");
+ AaiResponse response = aaiService.getAaiZones();
+ return aaiResponseToResponseEntity(response);
+
}
/* (non-Javadoc)
@@ -113,19 +374,17 @@ public class AaiController extends RestrictedBaseController{
* Get services from a&ai.
*
* @return ResponseEntity<String> The response entity with the logged in user uuid.
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @RequestMapping(value = {"/getuserID" }, method = RequestMethod.GET)
+ @RequestMapping(value = {"/getuserID"}, method = RequestMethod.GET)
public ResponseEntity<String> getUserID(HttpServletRequest request) throws IOException, InterruptedException {
String userId = "";
HttpSession session = request.getSession();
- if (session != null)
- {
+ if (session != null) {
User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME));
- if (user != null)
- {
+ if (user != null) {
//userId = user.getHrid();
userId = user.getLoginId();
if (userId == null)
@@ -133,23 +392,39 @@ public class AaiController extends RestrictedBaseController{
}
}
- return new ResponseEntity<String>( userId, HttpStatus.OK);
+ return new ResponseEntity<String>(userId, HttpStatus.OK);
}
-
/**
* Get services from a&ai.
*
* @return ResponseEntity<String> The response entity
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @RequestMapping(value="/aai_get_services",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<String> doGetServices() throws IOException, InterruptedException {
- File certiPath = GetCertificatesPath();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/services", false);
+ @RequestMapping(value = "/aai_get_services", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ public ResponseEntity<String> doGetServices(HttpServletRequest request) throws IOException, InterruptedException {
+
+ RoleValidator roleValidator = new RoleValidator(new RoleProvider().getUserRoles(request));
- return convertResponseToResponseEntity(resp);
+ AaiResponse subscriberList = aaiService.getServices(roleValidator);
+ ResponseEntity<String> responseEntity = aaiResponseToResponseEntity( subscriberList);
+
+ return responseEntity;
+ }
+
+
+
+ private ResponseEntity<String> aaiResponseToResponseEntity( AaiResponse aaiResponseData)
+ throws IOException, JsonGenerationException, JsonMappingException {
+ ResponseEntity<String> responseEntity;
+ ObjectMapper objectMapper = new ObjectMapper();
+ if (aaiResponseData.getHttpCode() == 200) {
+ responseEntity = new ResponseEntity<String>(objectMapper.writeValueAsString(aaiResponseData.getT()), HttpStatus.OK);
+ } else {
+ responseEntity = new ResponseEntity<String>(aaiResponseData.getErrorMessage(), HttpStatus.valueOf(aaiResponseData.getHttpCode()));
+ }
+ return responseEntity;
}
/**
@@ -157,41 +432,40 @@ public class AaiController extends RestrictedBaseController{
*
* @param serviceInstanceId the service instance Id
* @return ResponseEntity The response entity
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @RequestMapping(value="/aai_get_service_instance/{service-instance-id}/{service-instance-type}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<String> doGetServiceInstance(@PathVariable("service-instance-id") String serviceInstanceId,@PathVariable("service-instance-type") String serviceInstanceType) throws IOException, InterruptedException {
+ @RequestMapping(value = "/aai_get_service_instance/{service-instance-id}/{service-instance-type}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ public ResponseEntity<String> doGetServiceInstance(@PathVariable("service-instance-id") String serviceInstanceId, @PathVariable("service-instance-type") String serviceInstanceType) throws IOException, InterruptedException {
File certiPath = GetCertificatesPath();
- Response resp=null;
+ Response resp = null;
- if(serviceInstanceType.equalsIgnoreCase("Service Instance Id")){
- resp = doAaiGet( certiPath.getAbsolutePath(),
- "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:"
+ if (serviceInstanceType.equalsIgnoreCase("Service Instance Id")) {
+ resp = doAaiGet(certiPath.getAbsolutePath(),
+ "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:"
+ serviceInstanceId, false);
} else {
- resp = doAaiGet( certiPath.getAbsolutePath(),
- "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:"
+ resp = doAaiGet(certiPath.getAbsolutePath(),
+ "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:"
+ serviceInstanceId, false);
}
return convertResponseToResponseEntity(resp);
}
-
/**
* Get services from a&ai.
*
- * @param globalCustomerId the global customer id
+ * @param globalCustomerId the global customer id
* @param serviceSubscriptionId the service subscription id
* @return ResponseEntity The response entity
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @RequestMapping(value="/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ @RequestMapping(value = "/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> doGetServices(@PathVariable("global-customer-id") String globalCustomerId,
- @PathVariable("service-subscription-id") String serviceSubscriptionId) throws IOException, InterruptedException {
+ @PathVariable("service-subscription-id") String serviceSubscriptionId) throws IOException, InterruptedException {
File certiPath = GetCertificatesPath();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId
+ Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId
+ "/service-subscriptions/service-subscription/" + serviceSubscriptionId + "?depth=0", false);
return convertResponseToResponseEntity(resp);
}
@@ -201,23 +475,22 @@ public class AaiController extends RestrictedBaseController{
*
* @param fullSet the full set
* @return ResponseEntity The response entity
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @RequestMapping(value="/aai_get_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<String> doGetSubscriberList(@DefaultValue("n") @QueryParam("fullSet") String fullSet) throws IOException, InterruptedException {
- Response resp = getSubscribers(false);
- return convertResponseToResponseEntity(resp);
+ @RequestMapping(value = "/aai_get_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ public ResponseEntity<String> doGetSubscriberList(HttpServletRequest request,@DefaultValue("n") @QueryParam("fullSet") String fullSet) throws IOException, InterruptedException {
+ return getFullSubscriberList(request);
}
/**
* Obtain the Target Prov Status from the System.Properties file.
*
* @return ResponseEntity The response entity
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
- */
- @RequestMapping(value="/get_system_prop_vnf_prov_status",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ */
+ @RequestMapping(value = "/get_system_prop_vnf_prov_status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getTargetProvStatus() throws IOException, InterruptedException {
String p = SystemProperties.getProperty("aai.vnf.provstatus");
return new ResponseEntity<String>(p, HttpStatus.OK);
@@ -225,17 +498,27 @@ public class AaiController extends RestrictedBaseController{
/**
* Obtain the full subscriber list from a&ai.
+ * <p>
+ * g @return ResponseEntity The response entity
*
- * @return ResponseEntity The response entity
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @RequestMapping(value="/aai_get_full_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<String> getFullSubscriberList() throws IOException, InterruptedException {
- Response resp = getSubscribers(true);
- return convertResponseToResponseEntity(resp);
- }
+ @RequestMapping(value = "/aai_get_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ public ResponseEntity<String> getFullSubscriberList(HttpServletRequest request) throws IOException, InterruptedException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ ResponseEntity<String> responseEntity;
+ RoleValidator roleValidator = new RoleValidator(new RoleProvider().getUserRoles(request));
+ SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator);
+ if (subscriberList.getHttpCode() == 200) {
+ responseEntity = new ResponseEntity<String>(objectMapper.writeValueAsString(subscriberList.getSubscriberList()), HttpStatus.OK);
+ } else {
+ responseEntity = new ResponseEntity<String>(subscriberList.getErrorMessage(), HttpStatus.valueOf(subscriberList.getHttpCode()));
+ }
+
+ return responseEntity;
+ }
/**
* Refresh the subscriber list from a&ai.
@@ -243,7 +526,7 @@ public class AaiController extends RestrictedBaseController{
* @return ResponseEntity The response entity
* @throws IOException Signals that an I/O exception has occurred.
*/
- @RequestMapping(value="/aai_refresh_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ @RequestMapping(value = "/aai_refresh_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> doRefreshSubscriberList() throws IOException {
Response resp = getSubscribers(false);
return convertResponseToResponseEntity(resp);
@@ -255,7 +538,7 @@ public class AaiController extends RestrictedBaseController{
* @return ResponseEntity The response entity
* @throws IOException Signals that an I/O exception has occurred.
*/
- @RequestMapping(value="/aai_refresh_full_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ @RequestMapping(value = "/aai_refresh_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> doRefreshFullSubscriberList() throws IOException {
Response resp = getSubscribers(false);
return convertResponseToResponseEntity(resp);
@@ -267,75 +550,88 @@ public class AaiController extends RestrictedBaseController{
* @param subscriberId the subscriber id
* @return ResponseEntity The response entity
*/
- @RequestMapping(value="/aai_sub_details/{subscriberId}", method = RequestMethod.GET)
- public ResponseEntity<String> GetSubscriber(@PathVariable("subscriberId") String subscriberId) {
- Response resp = getSubscriberDetails(subscriberId);
- return convertResponseToResponseEntity(resp);
+ @RequestMapping(value = "/aai_sub_details/{subscriberId}", method = RequestMethod.GET)
+ public ResponseEntity<String> GetSubscriberDetails(HttpServletRequest request,@PathVariable("subscriberId") String subscriberId) throws IOException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ ResponseEntity responseEntity;
+ List<Role> roles = new RoleProvider().getUserRoles(request);
+ RoleValidator roleValidator = new RoleValidator(roles);
+ AaiResponse<SubscriberData> subscriberData = aaiService.getSubscriberData(subscriberId,roleValidator);
+ String httpMessage = subscriberData.getT() != null ?
+ objectMapper.writeValueAsString(subscriberData.getT()) :
+ subscriberData.getErrorMessage();
+
+ responseEntity = new ResponseEntity<String>(httpMessage, HttpStatus.valueOf(subscriberData.getHttpCode()));
+ return responseEntity;
}
/**
* Issue a named query to a&ai.
*
- * @param namedQueryId the named query id
+ * @param namedQueryId the named query id
* @param globalCustomerId the global customer id
- * @param serviceType the service type
- * @param serviceInstance the service instance
+ * @param serviceType the service type
+ * @param serviceInstance the service instance
* @return ResponseEntity The response entity
*/
- @RequestMapping(value="/aai_sub_viewedit/{namedQueryId}/{globalCustomerId}/{serviceType}/{serviceInstance}", method = RequestMethod.GET)
+ @RequestMapping(value = "/aai_sub_viewedit/{namedQueryId}/{globalCustomerId}/{serviceType}/{serviceInstance}", method = RequestMethod.GET)
public ResponseEntity<String> viewEditGetComponentList(
@PathVariable("namedQueryId") String namedQueryId,
@PathVariable("globalCustomerId") String globalCustomerId,
@PathVariable("serviceType") String serviceType,
- @PathVariable("serviceInstance") String serviceInstance) {
+ @PathVariable("serviceInstance") String serviceInstance) {
String componentListPayload = getComponentListPutPayload(namedQueryId, globalCustomerId, serviceType, serviceInstance);
File certiPath = GetCertificatesPath();
- Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
- return convertResponseToResponseEntity(resp);
+ Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
+ return convertResponseToResponseEntity(resp);
}
+
+ // @RequestMapping(value="/aai_get_tenants/{global-customer-id}", method = RequestMethod.GET)
+ // public ResponseEntity<String> viewEditGetComponentList(
+ // @PathVariable("global-customer-id") String globalCustomerId) {
+ // return new ResponseEntity<String>(getTenants(globalCustomerId), HttpStatus.OK);
+ // }
+
/**
* Issue a named query to a&ai.
*
- * @param namedQueryId the named query id
+ * @param namedQueryId the named query id
* @param globalCustomerId the global customer id
- * @param serviceType the service type
+ * @param serviceType the service type
* @return ResponseEntity The response entity
*/
- @RequestMapping(value="/aai_get_models_by_service_type/{namedQueryId}/{globalCustomerId}/{serviceType}", method = RequestMethod.GET)
+ @RequestMapping(value = "/aai_get_models_by_service_type/{namedQueryId}/{globalCustomerId}/{serviceType}", method = RequestMethod.GET)
public ResponseEntity<String> viewEditGetComponentList(
@PathVariable("namedQueryId") String namedQueryId,
@PathVariable("globalCustomerId") String globalCustomerId,
- @PathVariable("serviceType") String serviceType) {
+ @PathVariable("serviceType") String serviceType) {
String componentListPayload = getModelsByServiceTypePayload(namedQueryId, globalCustomerId, serviceType);
File certiPath = GetCertificatesPath();
- Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
- return convertResponseToResponseEntity(resp);
+ Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
+ return convertResponseToResponseEntity(resp);
}
-
+
/**
* Parses the for tenants.
*
* @param resp the resp
* @return the string
*/
- private String parseForTenants(String resp)
- {
+ private String parseForTenants(String resp) {
String tenantList = "";
- try
- {
+ try {
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(resp);
- return parseCustomerObjectForTenants(jsonObject);
- }
- catch (Exception ex) {
+ return parseCustomerObjectForTenants(jsonObject);
+ } catch (Exception ex) {
}
@@ -348,51 +644,59 @@ public class AaiController extends RestrictedBaseController{
* @param resp the resp
* @return the string
*/
- private String parseForTenantsByServiceSubscription(String resp)
- {
+ private String parseForTenantsByServiceSubscription(String resp) {
String tenantList = "";
- try
- {
+ try {
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(resp);
- return parseServiceSubscriptionObjectForTenants(jsonObject);
- }
- catch (Exception ex) {
+ return parseServiceSubscriptionObjectForTenants(jsonObject);
+ } catch (Exception ex) {
}
return tenantList;
}
-
- // @RequestMapping(value="/aai_get_tenants/{global-customer-id}", method = RequestMethod.GET)
- // public ResponseEntity<String> viewEditGetComponentList(
- // @PathVariable("global-customer-id") String globalCustomerId) {
- // return new ResponseEntity<String>(getTenants(globalCustomerId), HttpStatus.OK);
- // }
-
/**
* Obtain tenants for a given service type.
*
* @param globalCustomerId the global customer id
- * @param serviceType the service type
+ * @param serviceType the service type
* @return ResponseEntity The response entity
*/
- @RequestMapping(value="/aai_get_tenants/{global-customer-id}/{service-type}", method = RequestMethod.GET)
- public ResponseEntity<String> viewEditGetTenantsFromServiceType(
+ @RequestMapping(value = "/aai_get_tenants/{global-customer-id}/{service-type}", method = RequestMethod.GET)
+ public ResponseEntity<String> viewEditGetTenantsFromServiceType(HttpServletRequest request,
@PathVariable("global-customer-id") String globalCustomerId, @PathVariable("service-type") String serviceType) {
- return getTenantsFromServiceType(globalCustomerId, serviceType);
+
+ ResponseEntity responseEntity;
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ List<Role> roles = new RoleProvider().getUserRoles(request);
+ RoleValidator roleValidator = new RoleValidator(roles);
+ AaiResponse<GetTenantsResponse[]> response = aaiService.getTenants(globalCustomerId, serviceType, roleValidator);
+ if (response.getHttpCode() == 200) {
+ responseEntity = new ResponseEntity<String>(objectMapper.writeValueAsString(response.getT()), HttpStatus.OK);
+ } else {
+ responseEntity = new ResponseEntity<String>(response.getErrorMessage(), HttpStatus.valueOf(response.getHttpCode()));
+ }
+ }
+ catch (Exception e){
+ responseEntity = new ResponseEntity<String>("Unable to proccess getTenants reponse", HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ return responseEntity;
}
- private ResponseEntity<String> convertResponseToResponseEntity(Response resp) {
+
+ private ResponseEntity<String> convertResponseToResponseEntity(Response resp) {
ResponseEntity<String> respEnt;
- if (resp == null) {
+ ObjectMapper objectMapper = new ObjectMapper();
+ if (resp == null) {
respEnt = new ResponseEntity<String>("Failed to fetch data from A&AI, check server logs for details.", HttpStatus.INTERNAL_SERVER_ERROR);
- } else {
- respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
+ } else {
+ respEnt = new ResponseEntity<String>(resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
}
return respEnt;
}
@@ -403,18 +707,17 @@ public class AaiController extends RestrictedBaseController{
* @param globalCustomerId the global customer id
* @return the tenants
*/
- private ResponseEntity<String> getTenants(String globalCustomerId)
- {
+ private ResponseEntity<String> getTenants(String globalCustomerId) {
File certiPath = GetCertificatesPath();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId, false);
-
- ResponseEntity<String> respEnt;
- if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
- respEnt = new ResponseEntity<String>(parseForTenants((String)resp.readEntity(String.class)), HttpStatus.OK);
- } else {
- respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
- }
- return respEnt;
+ Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId, false);
+
+ ResponseEntity<String> respEnt;
+ if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
+ respEnt = new ResponseEntity<String>(parseForTenants((String) resp.readEntity(String.class)), HttpStatus.OK);
+ } else {
+ respEnt = new ResponseEntity<String>((String) resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
+ }
+ return respEnt;
}
@@ -422,23 +725,27 @@ public class AaiController extends RestrictedBaseController{
* Gets the tenants from service type.
*
* @param globalCustomerId the global customer id
- * @param serviceType the service type
+ * @param serviceType the service type
* @return the tenants from service type
*/
- private ResponseEntity<String> getTenantsFromServiceType(String globalCustomerId, String serviceType)
- {
+ private ResponseEntity<String> getTenantsFromServiceType(String globalCustomerId, String serviceType) {
+
+
+
+
+
File certiPath = GetCertificatesPath();
- String url = "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + serviceType;
+ String url = "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + serviceType;
+
+ Response resp = doAaiGet(certiPath.getAbsolutePath(), url, false);
- Response resp = doAaiGet(certiPath.getAbsolutePath(), url, false);
-
- ResponseEntity<String> respEnt;
- if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
- respEnt = new ResponseEntity<String>(parseForTenantsByServiceSubscription((String)resp.readEntity(String.class)), HttpStatus.OK);
- } else {
- respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
- }
- return respEnt;
+ ResponseEntity<String> respEnt;
+ if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
+ respEnt = new ResponseEntity<String>(parseForTenantsByServiceSubscription((String) resp.readEntity(String.class)), HttpStatus.OK);
+ } else {
+ respEnt = new ResponseEntity<String>((String) resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
+ }
+ return respEnt;
}
@@ -447,45 +754,40 @@ public class AaiController extends RestrictedBaseController{
*
* @return the services
*/
- private Response getServices()
- {
+ private Response getServices() {
File certiPath = GetCertificatesPath();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/services", false);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getServices() resp=" + resp.getStatusInfo());
+ Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/services", false);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getServices() resp=" + resp.getStatusInfo());
//model.put("aai_get_services", resp);
return resp;
}
-
/**
* Gets the subscribers.
*
* @param isFullSet the is full set
* @return the subscribers
*/
- private Response getSubscribers(boolean isFullSet)
- {
+ private Response getSubscribers(boolean isFullSet) {
+
File certiPath = GetCertificatesPath();
String depth = "0";
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers?subscriber-type=INFRA&depth=" + depth, false);
- if (resp != null) {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString());
- }
+ Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers?subscriber-type=INFRA&depth=" + depth, false);
+ if (resp != null) {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString());
+ }
return resp;
}
-
-
/**
* Gets the subscriber details.
*
* @param subscriberId the subscriber id
* @return the subscriber details
*/
- private Response getSubscriberDetails(String subscriberId)
- {
+ private Response getSubscriberDetails(String subscriberId) {
File certiPath = GetCertificatesPath();
Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId + "?depth=2", false);
//String resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId, false);
@@ -498,10 +800,9 @@ public class AaiController extends RestrictedBaseController{
*
* @return the file
*/
- private File GetCertificatesPath()
- {
+ private File GetCertificatesPath() {
if (servletContext != null)
- return new File( servletContext.getRealPath("/WEB-INF/cert/") );
+ return new File(servletContext.getRealPath("/WEB-INF/cert/"));
return null;
}
@@ -509,12 +810,12 @@ public class AaiController extends RestrictedBaseController{
* Send a GET request to a&ai.
*
* @param certiPath the certi path
- * @param uri the uri
- * @param xml the xml
+ * @param uri the uri
+ * @param xml the xml
* @return String The response
*/
protected Response doAaiGet(String certiPath, String uri, boolean xml) {
- String methodName = "getSubscriberList";
+ String methodName = "getSubscriberList";
String transId = UUID.randomUUID().toString();
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
@@ -526,11 +827,11 @@ public class AaiController extends RestrictedBaseController{
} catch (WebApplicationException e) {
final String message = ((BadRequestException) e).getResponse().readEntity(String.class);
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
} catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
}
return resp;
@@ -540,13 +841,13 @@ public class AaiController extends RestrictedBaseController{
* Send a POST request to a&ai.
*
* @param certiPath the certi path
- * @param uri the uri
- * @param payload the payload
- * @param xml the xml
+ * @param uri the uri
+ * @param payload the payload
+ * @param xml the xml
* @return String The response
*/
protected Response doAaiPost(String certiPath, String uri, String payload, boolean xml) {
- String methodName = "getSubscriberList";
+ String methodName = "getSubscriberList";
String transId = UUID.randomUUID().toString();
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
@@ -557,8 +858,8 @@ public class AaiController extends RestrictedBaseController{
resp = restContrller.RestPost(fromAppId, transId, uri, payload, xml);
} catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
}
return resp;
@@ -567,14 +868,14 @@ public class AaiController extends RestrictedBaseController{
/**
* Gets the component list put payload.
*
- * @param namedQueryId the named query id
+ * @param namedQueryId the named query id
* @param globalCustomerId the global customer id
- * @param serviceType the service type
- * @param serviceInstance the service instance
+ * @param serviceType the service type
+ * @param serviceInstance the service instance
* @return the component list put payload
*/
private String getComponentListPutPayload(String namedQueryId, String globalCustomerId, String serviceType, String serviceInstance) {
- return
+ return
" {" +
" \"instance-filters\": {" +
" \"instance-filter\": [" +
@@ -599,9 +900,10 @@ public class AaiController extends RestrictedBaseController{
"}";
}
+
private String getModelsByServiceTypePayload(String namedQueryId, String globalCustomerId, String serviceType) {
// TODO Auto-generated method stub
- return " {" +
+ return " {" +
" \"instance-filters\": {" +
" \"instance-filter\": [" +
" {" +
@@ -620,246 +922,6 @@ public class AaiController extends RestrictedBaseController{
" }" +
" }" +
"}";
-
- }
-
- /**
- * Return tenant details.
- *
- * @param jsonObject the json object
- * @return String The parsing results
- */
- public static String parseCustomerObjectForTenants(JSONObject jsonObject) {
-
- JSONArray tenantArray = new JSONArray();
- boolean bconvert = false;
-
- try {
-
- JSONObject serviceSubsObj = (JSONObject) jsonObject.get("service-subscriptions");
-
- if (serviceSubsObj != null)
- {
- JSONArray srvcSubArray = (JSONArray) serviceSubsObj.get("service-subscription");
-
- if (srvcSubArray != null)
- {
- Iterator i = srvcSubArray.iterator();
-
- while (i.hasNext()) {
-
- JSONObject innerObj = (JSONObject) i.next();
-
- if (innerObj == null)
- continue;
-
- JSONObject relationShipListsObj = (JSONObject) innerObj.get("relationship-list");
- if (relationShipListsObj != null)
- {
- JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
- if (rShipArray != null)
- {
- Iterator i1 = rShipArray.iterator();
-
- while (i1.hasNext()) {
-
- JSONObject inner1Obj = (JSONObject) i1.next();
-
- if (inner1Obj == null)
- continue;
-
- String relatedTo = checkForNull((String)inner1Obj.get("related-to"));
- if (relatedTo.equalsIgnoreCase("tenant"))
- {
- JSONObject tenantNewObj = new JSONObject();
-
- String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
- tenantNewObj.put("link", relatedLink);
-
- JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
- if (rDataArray != null)
- {
- Iterator i2 = rDataArray.iterator();
-
- while (i2.hasNext()) {
- JSONObject inner2Obj = (JSONObject) i2.next();
-
- if (inner2Obj == null)
- continue;
-
- String rShipKey = checkForNull((String)inner2Obj.get("relationship-key"));
- String rShipVal = checkForNull((String)inner2Obj.get("relationship-value"));
- if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner"))
- {
- tenantNewObj.put("cloudOwner", rShipVal);
- }
- else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id"))
- {
- tenantNewObj.put("cloudRegionID", rShipVal);
- }
-
- if (rShipKey.equalsIgnoreCase("tenant.tenant-id"))
- {
- tenantNewObj.put("tenantID", rShipVal);
- }
- }
- }
-
- JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
- if (relatedTPropArray != null)
- {
- Iterator i3 = relatedTPropArray.iterator();
-
- while (i3.hasNext()) {
- JSONObject inner3Obj = (JSONObject) i3.next();
-
- if (inner3Obj == null)
- continue;
-
- String propKey = checkForNull((String)inner3Obj.get("property-key"));
- String propVal = checkForNull((String)inner3Obj.get("property-value"));
- if (propKey.equalsIgnoreCase("tenant.tenant-name"))
- {
- tenantNewObj.put("tenantName", propVal);
- }
- }
- }
- bconvert = true;
- tenantArray.add(tenantNewObj);
- }
- }
- }
- }
- }
- }
- }
- } catch (NullPointerException ex) {
-
-
- }
-
- if (bconvert)
- return tenantArray.toJSONString();
- else
- return "";
-
- }
-
-
- /**
- * Retrieve the service subscription from the jsonObject.
- *
- * @param jsonObject the json object
- * @return String
- */
- public static String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) {
-
- JSONArray tenantArray = new JSONArray();
- boolean bconvert = false;
-
- try {
- JSONObject relationShipListsObj = (JSONObject) jsonObject.get("relationship-list");
- if (relationShipListsObj != null)
- {
- JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
- if (rShipArray != null)
- {
- Iterator i1 = rShipArray.iterator();
-
- while (i1.hasNext()) {
-
- JSONObject inner1Obj = (JSONObject) i1.next();
-
- if (inner1Obj == null)
- continue;
-
- String relatedTo = checkForNull((String)inner1Obj.get("related-to"));
- if (relatedTo.equalsIgnoreCase("tenant"))
- {
- JSONObject tenantNewObj = new JSONObject();
-
- String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
- tenantNewObj.put("link", relatedLink);
-
- JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
- if (rDataArray != null)
- {
- Iterator i2 = rDataArray.iterator();
-
- while (i2.hasNext()) {
- JSONObject inner2Obj = (JSONObject) i2.next();
-
- if (inner2Obj == null)
- continue;
-
- String rShipKey = checkForNull((String)inner2Obj.get("relationship-key"));
- String rShipVal = checkForNull((String)inner2Obj.get("relationship-value"));
- if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner"))
- {
- tenantNewObj.put("cloudOwner", rShipVal);
- }
- else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id"))
- {
- tenantNewObj.put("cloudRegionID", rShipVal);
- }
-
- if (rShipKey.equalsIgnoreCase("tenant.tenant-id"))
- {
- tenantNewObj.put("tenantID", rShipVal);
- }
- }
- }
-
- JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
- if (relatedTPropArray != null)
- {
- Iterator i3 = relatedTPropArray.iterator();
-
- while (i3.hasNext()) {
- JSONObject inner3Obj = (JSONObject) i3.next();
-
- if (inner3Obj == null)
- continue;
-
- String propKey = checkForNull((String)inner3Obj.get("property-key"));
- String propVal = checkForNull((String)inner3Obj.get("property-value"));
- if (propKey.equalsIgnoreCase("tenant.tenant-name"))
- {
- tenantNewObj.put("tenantName", propVal);
- }
- }
- }
- bconvert = true;
- tenantArray.add(tenantNewObj);
- }
- }
-
- }
- }
- } catch (NullPointerException ex) {
-
-
- }
-
- if (bconvert)
- return tenantArray.toJSONString();
- else
- return "";
-
- }
-
- /**
- * Check for null.
- *
- * @param local the local
- * @return the string
- */
- private static String checkForNull(String local)
- {
- if (local != null)
- return local;
- else
- return "";
}
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/controller/MsoController.java b/vid-app-common/src/main/java/org/openecomp/vid/controller/MsoController.java
index f051ed38..56fbd4cb 100755
--- a/vid-app-common/src/main/java/org/openecomp/vid/controller/MsoController.java
+++ b/vid-app-common/src/main/java/org/openecomp/vid/controller/MsoController.java
@@ -21,106 +21,80 @@
package org.openecomp.vid.controller;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-//import java.util.UUID;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Scanner;
-import java.util.stream.Collectors;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.codehaus.jackson.JsonEncoding;
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.JsonToken;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.glassfish.jersey.client.ClientResponse;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
-import org.openecomp.vid.domain.mso.CloudConfiguration;
-import org.openecomp.vid.domain.mso.ModelInfo;
-import org.openecomp.vid.domain.mso.ModelInfo.ModelType;
-import org.openecomp.vid.domain.mso.RequestInfo;
-import org.openecomp.vid.domain.mso.RequestParameters;
+import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.util.SystemProperties;
import org.openecomp.vid.model.ExceptionResponse;
-import org.openecomp.vid.mso.MsoProperties;
-import org.openecomp.vid.mso.MsoResponseWrapper;
-import org.openecomp.vid.mso.MsoRestInterfaceFactory;
-import org.openecomp.vid.mso.MsoRestInterfaceIfc;
-import org.openecomp.vid.mso.MsoUtil;
-import org.openecomp.vid.mso.RestObject;
-import org.openecomp.vid.mso.rest.RelatedModel;
+import org.openecomp.vid.mso.*;
import org.openecomp.vid.mso.rest.RequestDetails;
+import org.openecomp.vid.roles.RoleProvider;
+import org.openecomp.vid.roles.RoleValidator;
import org.springframework.http.HttpStatus;
-//import org.springframework.http.ResponseEntity;
-//import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-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.servlet.ModelAndView;
+import org.springframework.web.bind.annotation.*;
-import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.openecomp.portalsdk.core.util.SystemProperties;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectReader;
-import com.fasterxml.jackson.databind.DeserializationFeature;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
/**
* The Class MsoController.
*/
@RestController
@RequestMapping("mso")
-public class MsoController extends RestrictedBaseController{
-
- /** The view name. */
- String viewName;
-
- /** The logger. */
- EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoController.class);
-
- /** The Constant dateFormat. */
- final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
-
- /** The Constant SVC_INSTANCE_ID. */
- public final static String SVC_INSTANCE_ID = "<service_instance_id>";
-
- /** The Constant VNF_INSTANCE_ID. */
- public final static String VNF_INSTANCE_ID = "<vnf_instance_id>";
-
- /**
- * Welcome.
- *
- * @param request the request
- * @return the model and view
-
- public ModelAndView welcome(HttpServletRequest request) {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== MsoController welcome start");
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " MSO_SERVER_URL=" +
- SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) );
- return new ModelAndView(getViewName());
- }
- */
+public class MsoController extends RestrictedBaseController {
+
+ /**
+ * The Constant SVC_INSTANCE_ID.
+ */
+ public final static String SVC_INSTANCE_ID = "<service_instance_id>";
+ /**
+ * The Constant VNF_INSTANCE_ID.
+ */
+ public final static String VNF_INSTANCE_ID = "<vnf_instance_id>";
+ /**
+ * The Constant dateFormat.
+ */
+ final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
+ /**
+ * The view name.
+ */
+ String viewName;
+ /**
+ * The logger.
+ */
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoController.class);
+
+ /**
+ * Welcome.
+ *
+ * @param request the request
+ * @return the model and view
+
+ public ModelAndView welcome(HttpServletRequest request) {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== MsoController welcome start");
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " MSO_SERVER_URL=" +
+ SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) );
+ return new ModelAndView(getViewName());
+ }
+ */
/* (non-Javadoc)
- * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
+ * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
public String getViewName() {
return viewName;
@@ -128,504 +102,538 @@ public class MsoController extends RestrictedBaseController{
*/
/* (non-Javadoc)
- * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
+ * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
public void setViewName(String viewName) {
this.viewName = viewName;
}
*/
- /**
- * Creates the svc instance.
- *
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST)
- public ResponseEntity<String> createSvcInstance(HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
- String methodName = "createSvcInstance";
-
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start" );
-
+ /**
+ * Creates the svc instance.
+ *
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST)
+ public ResponseEntity<String> createSvcInstance(HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+
+
+ String methodName = "createSvcInstance";
+
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+
+ if (!userIsPermmited(request, mso_request)) {
+ return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
+ }
// mso_request = retrieveRequestObject (request, mso_request);
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
-
- MsoResponseWrapper w = createInstance(mso_request, p);
- // always return OK, the MSO status code is embedded in the body
-
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
-
- }
-
- /**
- * Creates the vnf.
- *
- * @param serviceInstanceId the service instance id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value="/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST)
- public ResponseEntity<String> createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
-
- String methodName = "createVnf";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
-
- //RequestDetails mso_request = retrieveRequestObject (request);
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
-
- if ( p == null || p.isEmpty()) {
- throw new Exception ( "Vnf instance path is not defined");
- }
- // /serviceInstances/v2/<service_instance_id>/vnfs
- String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
- MsoResponseWrapper w = createInstance(mso_request, vnf_path);
-
- // always return OK, the MSO status code is embedded in the body
-
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
-
- }
-
- /**
- * Creates the nw instance.
- *
- * @param serviceInstanceId the service instance id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST)
- public ResponseEntity<String> createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
-
- String methodName = "createNwInstance";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId );
-
- //RequestDetails mso_request = retrieveRequestObject (request);
-
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
-
- if ( p == null || p.isEmpty()) {
- throw new Exception ( "Network instance path is not defined");
- }
- // /serviceInstances/v2/<serviceInstanceId>/networks/
-
- String nw_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
- MsoResponseWrapper w = createInstance(mso_request, nw_path);
-
- // always return OK, the MSO status code is embedded in the body
-
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
-
- }
-
- /**
- * Creates the volume group instance.
- *
- * @param serviceInstanceId the service instance id
- * @param vnfInstanceId the vnf instance id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
- public ResponseEntity<String> createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
- HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
- String methodName = "createVolumeGroupInstance";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
-
- //RequestDetails mso_request = retrieveRequestObject (request);
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
-
- if ( p == null || p.isEmpty()) {
- throw new Exception ( "Volume group instance path is not defined");
- }
- String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
- path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
-
- MsoResponseWrapper w = createInstance(mso_request, path);
-
- // always return OK, the MSO status code is embedded in the body
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
- }
-
- /**
- * Creates the vf module instance.
- *
- * @param serviceInstanceId the service instance id
- * @param vnfInstanceId the vnf instance id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
- public ResponseEntity<String> createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
- @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
- String methodName = "createVfModuleInstance";
-
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
- //RequestDetails mso_request = retrieveRequestObject (request);
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
-
- if ( p == null || p.isEmpty()) {
- throw new Exception ( "VF module instance path is not defined");
- }
- // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
- String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
- path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
-
- MsoResponseWrapper w = createInstance(mso_request, path);
-
- // always return OK, the MSO status code is embedded in the body
-
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
- }
-
- /**
- * Creates the instance.
- *
- * @param request the request
- * @param path the path
- * @return the mso response wrapper
- * @throws ClientHandlerException the client handler exception
- * @throws Exception the exception
- */
- protected MsoResponseWrapper createInstance(RequestDetails request, String path) throws Exception {
- String methodName = "createInstance";
- logger.debug(dateFormat.format(new Date()) + "<== " + methodName + " start");
-
- try {
- MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Post, request = (" + request + ")");
-
- RestObject<String> restObjStr = new RestObject<String>();
- String str = new String();
- restObjStr.set(str);
- restController.<String>Post(str, request, "", path, restObjStr );
- MsoResponseWrapper w = MsoUtil.wrapResponse (restObjStr);
-
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
- return w;
- } catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- throw e;
- }
- }
-
- /**
- * Delete svc instance.
- *
- * @param serviceInstanceId the service instance id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST)
- public ResponseEntity<String> deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
- HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
-
- String methodName = "deleteSvcInstance";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
-
- //RequestDetails mso_request = retrieveRequestObject (request);
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
- String path = p + "/" + serviceInstanceId;
- MsoResponseWrapper w = deleteInstance ( mso_request, path );
-
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
- // always return OK, the MSO status code is embedded in the body
-
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
-
- }
-
- /**
- * Delete vnf.
- *
- * @param serviceInstanceId the service instance id
- * @param vnfInstanceId the vnf instance id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
-
- public ResponseEntity<String> deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
- HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
- String methodName = "deleteVnf";
-
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
-
- //RequestDetails mso_request = retrieveRequestObject (request);
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
- if ( p == null || p.isEmpty()) {
- throw new Exception ( "Vnf instance path is not defined");
- }
- // /serviceInstances/v2/<service_instance_id>/vnfs/
- String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId );
- MsoResponseWrapper w = deleteInstance ( mso_request, vnf_path + "/" + vnfInstanceId );
-
- // always return OK, the MSO status code is embedded in the body
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
-
- }
-
- /**
- * Delete vf module.
- *
- * @param serviceInstanceId the service instance id
- * @param vnfInstanceId the vnf instance id
- * @param vfModuleId the vf module id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee
- @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST)
- public ResponseEntity<String> deleteVfModule (
- @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
- @PathVariable("vfModuleId") String vfModuleId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
-
- String methodName = "deleteVfModule";
-
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
-
- //RequestDetails mso_request = new RequestDetails();
- //mso_request = retrieveRequestObject (request);
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
- if ( p == null || p.isEmpty()) {
- throw new Exception ( "VF Module instance path is not defined");
- }
- // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
- String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
- path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId );
- MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + vfModuleId);
-
- // always return OK, the MSO status code is embedded in the body
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
+ String userId = "";
+ HttpSession session = request.getSession();
+ System.out.println((new ObjectMapper().writeValueAsString(session.getAttribute("roles"))));
+ MsoResponseWrapper w = createInstance(mso_request, p);
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+ // always return OK, the MSO status code is embedded in the body
- }
- /**
- * Delete volume group instance.
- *
- * @param serviceInstanceId the service instance id
- * @param vnfInstanceId the vnf instance id
- * @param volumeGroupId the volume group id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupId}", method = RequestMethod.POST)
- public ResponseEntity<String> deleteVolumeGroupInstance (
- @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, @PathVariable("volumeGroupId") String volumeGroupId,
- HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
-
- String methodName = "deleteVolumeGroupInstance";
-
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
- //RequestDetails mso_request = retrieveRequestObject (request);
-
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
- if ( p == null || p.isEmpty()) {
- throw new Exception ( "Volume group instance path is not defined");
- }
- // /serviceInstances/v2/{serviceInstanceId}/volumeGroups
- String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
- path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId );
- MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + volumeGroupId);
-
- // always return OK, the MSO status code is embedded in the body
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
- }
-
- /**
- * Delete nw instance.
- *
- * @param serviceInstanceId the service instance id
- * @param networkInstanceId the network instance id
- * @param request the request
- * @return the response entity
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST)
- public ResponseEntity<String> deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
- @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
-
- String methodName = "deleteNwInstance";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
-
- //RequestDetails mso_request = retrieveRequestObject (request);
-
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
- if ( p == null || p.isEmpty()) {
- throw new Exception ( "Network instance path is not defined");
- }
- // /serviceInstances/v2/<service_instance_id>/networks
- String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId );
- MsoResponseWrapper w = deleteInstance ( mso_request, path + "/" + networkInstanceId);
-
- // always return OK, the MSO status code is embedded in the body
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
-
- }
-
- /**
- * Delete instance.
- *
- * @param request the request
- * @param path the path
- * @return the mso response wrapper
- * @throws Exception the exception
- */
- protected MsoResponseWrapper deleteInstance(RequestDetails request, String path) throws Exception {
- String methodName = "deleteInstance";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
-
- try {
- MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]");
-
- RestObject<String> restObjStr = new RestObject<String>();
- String str = new String();
- restObjStr.set(str);
- restController.<String>Delete(str, request, "", path, restObjStr );
- MsoResponseWrapper w = MsoUtil.wrapResponse (restObjStr);
-
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
- return w;
-
- } catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- throw e;
- }
-
- }
-
- /**
- * Gets the orchestration request.
- *
- * @param requestId the request id
- * @param request the request
- * @return the orchestration request
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET)
- public ResponseEntity<String> getOrchestrationRequest(@PathVariable("requestId") String requestId,
- HttpServletRequest request) throws Exception {
-
- String methodName = "getOrchestrationRequest";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
- MsoResponseWrapper w = null;
- try {
- MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
- String path = p + "/" + requestId;
-
- RestObject<String> restObjStr = new RestObject<String>();
- String str = new String();
- restObjStr.set(str);
-
- restController.<String>Get(str, "", path, restObjStr);
-
- w = MsoUtil.wrapResponse (restObjStr);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
- // always return OK, the MSO status code is embedded in the body
-
- } catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- throw e;
- }
- // always return OK, the MSO status code is embedded in the body
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
- }
-
-
- /**
- * Gets the orchestration requests.
- *
- * @param filterString the filter string
- * @param request the request
- * @return the orchestration requests
- * @throws Exception the exception
- */
- @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET)
- public ResponseEntity<String> getOrchestrationRequests(@PathVariable("filterString") String filterString,
- HttpServletRequest request) throws Exception {
-
- String methodName = "getOrchestrationRequests";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
- MsoResponseWrapper w = null;
- try {
- MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
- String path = p + filterString;
-
- RestObject<String> restObjStr = new RestObject<String>();
- String str = new String();
- restObjStr.set(str);
-
- restController.<String>Get(str, "", path, restObjStr);
-
- w = MsoUtil.wrapResponse (restObjStr);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
- } catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- throw e;
- }
- // always return OK, the MSO status code is embedded in the body
- return ( new ResponseEntity<String>(w.getResponse(), HttpStatus.OK) );
- }
-
- /**
- * Gets the orchestration requests for svc instance.
- *
- * @param svc_instance_id the svc instance id
- * @return the orchestration requests for svc instance
- * @throws Exception the exception
- */
- public MsoResponseWrapper getOrchestrationRequestsForSvcInstance (String svc_instance_id) throws Exception {
-
- String methodName = "getOrchestrationRequestsForSvcInstance";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
- MsoResponseWrapper w = null;
-
- try {
- MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
- String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
- String path = p + svc_instance_id;
-
- RestObject<String> restObjStr = new RestObject<String>();
- String str = new String();
- restObjStr.set(str);
-
- restController.<String>Get(str, "", path, restObjStr);
- w = MsoUtil.wrapResponse (restObjStr);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
-
- } catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- throw e;
- }
- return w;
- }
-
- /**
- * Exception handler.
- *
- * @param e the e
- * @param response the response
- * @throws IOException Signals that an I/O exception has occurred.
- */
- @ExceptionHandler(Exception.class)
- private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException {
+ }
+
+ private boolean userIsPermmited(HttpServletRequest request, RequestDetails mso_request) {
+
+ RoleValidator roleValidator = new RoleValidator(new RoleProvider().getUserRoles(request));
+ boolean isPermitted = roleValidator.isMsoRequestValid(mso_request);
+ if (!isPermitted) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Creates the vnf.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST)
+ public ResponseEntity<String> createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+// if (!userIsPermmited(request, mso_request)) {
+ String instanceId = (String) ((Map)((Map)((ArrayList)((Map) mso_request.getAdditionalProperties().get("requestDetails")).get("relatedInstanceList")).get(0)).get("relatedInstance")).get("instanceId");
+ ResponseEntity<String> a = new AaiController(request.getServletContext()).doGetServiceInstance(instanceId,"Service Instance id");
+// return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
+// }
+ String methodName = "createVnf";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+
+ //RequestDetails mso_request = retrieveRequestObject (request);
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+
+ if (p == null || p.isEmpty()) {
+ throw new Exception("Vnf instance path is not defined");
+ }
+ // /serviceInstances/v2/<service_instance_id>/vnfs
+ String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ MsoResponseWrapper w = createInstance(mso_request, vnf_path);
+
+ // always return OK, the MSO status code is embedded in the body
+
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+
+ }
+
+ /**
+ * Creates the nw instance.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST)
+ public ResponseEntity<String> createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+
+ String methodName = "createNwInstance";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId);
+
+ //RequestDetails mso_request = retrieveRequestObject (request);
+
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
+
+ if (p == null || p.isEmpty()) {
+ throw new Exception("Network instance path is not defined");
+ }
+ // /serviceInstances/v2/<serviceInstanceId>/networks/
+
+ String nw_path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ MsoResponseWrapper w = createInstance(mso_request, nw_path);
+
+ // always return OK, the MSO status code is embedded in the body
+
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+
+ }
+
+ /**
+ * Creates the volume group instance.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param vnfInstanceId the vnf instance id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
+ public ResponseEntity<String> createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
+ HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+ String methodName = "createVolumeGroupInstance";
+ if (!userIsPermmited(request, mso_request)) {
+ return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
+ }
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+
+ //RequestDetails mso_request = retrieveRequestObject (request);
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
+
+ if (p == null || p.isEmpty()) {
+ throw new Exception("Volume group instance path is not defined");
+ }
+ String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
+
+ MsoResponseWrapper w = createInstance(mso_request, path);
+
+ // always return OK, the MSO status code is embedded in the body
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+ }
+
+ /**
+ * Creates the vf module instance.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param vnfInstanceId the vnf instance id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
+ public ResponseEntity<String> createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
+ @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+ String methodName = "createVfModuleInstance";
+
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+ if (!userIsPermmited(request, mso_request)) {
+ return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
+ }
+ //RequestDetails mso_request = retrieveRequestObject (request);
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
+
+ if (p == null || p.isEmpty()) {
+ throw new Exception("VF module instance path is not defined");
+ }
+ // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
+ String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
+
+ MsoResponseWrapper w = createInstance(mso_request, path);
+
+ // always return OK, the MSO status code is embedded in the body
+
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+ }
+
+ /**
+ * Creates the instance.
+ *
+ * @param request the request
+ * @param path the path
+ * @return the mso response wrapper
+ * @throws Exception the exception
+ */
+ protected MsoResponseWrapper createInstance(RequestDetails request, String path) throws Exception {
+ String methodName = "createInstance";
+ logger.debug(dateFormat.format(new Date()) + "<== " + methodName + " start");
+
+ try {
+ MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Post, request = (" + request + ")");
+
+ RestObject<String> restObjStr = new RestObject<String>();
+ String str = new String();
+ restObjStr.set(str);
+ restController.<String>Post(str, request, "", path, restObjStr);
+ MsoResponseWrapper w = MsoUtil.wrapResponse(restObjStr);
+
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
+ return w;
+ } catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ throw e;
+ }
+ }
+
+ /**
+ * Delete svc instance.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST)
+ public ResponseEntity<String> deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
+ HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+
+ String methodName = "deleteSvcInstance";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+
+ //RequestDetails mso_request = retrieveRequestObject (request);
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
+ String path = p + "/" + serviceInstanceId;
+ MsoResponseWrapper w = deleteInstance(mso_request, path);
+
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
+ // always return OK, the MSO status code is embedded in the body
+
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+
+ }
+
+ /**
+ * Delete vnf.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param vnfInstanceId the vnf instance id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST)
+
+ public ResponseEntity<String> deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
+ HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+ String methodName = "deleteVnf";
+
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+ if (!userIsPermmited(request, mso_request)) {
+ return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
+ }
+ //RequestDetails mso_request = retrieveRequestObject (request);
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VNF_INSTANCE);
+ if (p == null || p.isEmpty()) {
+ throw new Exception("Vnf instance path is not defined");
+ }
+ // /serviceInstances/v2/<service_instance_id>/vnfs/
+ String vnf_path = p.replaceFirst(SVC_INSTANCE_ID, vnfInstanceId);
+ MsoResponseWrapper w = deleteInstance(mso_request, vnf_path + "/" + vnfInstanceId);
+
+ // always return OK, the MSO status code is embedded in the body
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+
+ }
+
+ /**
+ * Delete vf module.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param vnfInstanceId the vnf instance id
+ * @param vfModuleId the vf module id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee
+ @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST)
+ public ResponseEntity<String> deleteVfModule(
+ @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId,
+ @PathVariable("vfModuleId") String vfModuleId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+
+ String methodName = "deleteVfModule";
+
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+ if (!userIsPermmited(request, mso_request)) {
+ return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
+ }
+ //RequestDetails mso_request = new RequestDetails();
+ //mso_request = retrieveRequestObject (request);
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
+ if (p == null || p.isEmpty()) {
+ throw new Exception("VF Module instance path is not defined");
+ }
+ // /serviceInstances/v2/<serviceInstanceId>/vnfs/<vnfInstanceId>/vfmodules
+ String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
+ MsoResponseWrapper w = deleteInstance(mso_request, path + "/" + vfModuleId);
+
+ // always return OK, the MSO status code is embedded in the body
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+
+ }
+
+ /**
+ * Delete volume group instance.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param vnfInstanceId the vnf instance id
+ * @param volumeGroupId the volume group id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupId}", method = RequestMethod.POST)
+ public ResponseEntity<String> deleteVolumeGroupInstance(
+ @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, @PathVariable("volumeGroupId") String volumeGroupId,
+ HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+
+ String methodName = "deleteVolumeGroupInstance";
+
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+ if (!userIsPermmited(request, mso_request)) {
+ return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
+ }
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
+ if (p == null || p.isEmpty()) {
+ throw new Exception("Volume group instance path is not defined");
+ }
+ // /serviceInstances/v2/{serviceInstanceId}/volumeGroups
+ String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
+ MsoResponseWrapper w = deleteInstance(mso_request, path + "/" + volumeGroupId);
+
+ // always return OK, the MSO status code is embedded in the body
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+ }
+
+ /**
+ * Delete nw instance.
+ *
+ * @param serviceInstanceId the service instance id
+ * @param networkInstanceId the network instance id
+ * @param request the request
+ * @return the response entity
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST)
+ public ResponseEntity<String> deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId,
+ @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+
+ String methodName = "deleteNwInstance";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+
+ //RequestDetails mso_request = retrieveRequestObject (request);
+ if (!userIsPermmited(request, mso_request)) {
+ return new ResponseEntity<String>(HttpStatus.FORBIDDEN);
+ }
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
+ if (p == null || p.isEmpty()) {
+ throw new Exception("Network instance path is not defined");
+ }
+ // /serviceInstances/v2/<service_instance_id>/networks
+ String path = p.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
+ MsoResponseWrapper w = deleteInstance(mso_request, path + "/" + networkInstanceId);
+
+ // always return OK, the MSO status code is embedded in the body
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+
+ }
+
+ /**
+ * Delete instance.
+ *
+ * @param request the request
+ * @param path the path
+ * @return the mso response wrapper
+ * @throws Exception the exception
+ */
+ protected MsoResponseWrapper deleteInstance(RequestDetails request, String path) throws Exception {
+ String methodName = "deleteInstance";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+
+ try {
+ MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]");
+
+ RestObject<String> restObjStr = new RestObject<String>();
+ String str = new String();
+ restObjStr.set(str);
+ restController.<String>Delete(str, request, "", path, restObjStr);
+ MsoResponseWrapper w = MsoUtil.wrapResponse(restObjStr);
+
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
+ return w;
+
+ } catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ throw e;
+ }
+
+ }
+
+ /**
+ * Gets the orchestration request.
+ *
+ * @param requestId the request id
+ * @param request the request
+ * @return the orchestration request
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET)
+ public ResponseEntity<String> getOrchestrationRequest(@PathVariable("requestId") String requestId,
+ HttpServletRequest request) throws Exception {
+
+ String methodName = "getOrchestrationRequest";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+ MsoResponseWrapper w = null;
+ try {
+ MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
+ String path = p + "/" + requestId;
+
+ RestObject<String> restObjStr = new RestObject<String>();
+ String str = new String();
+ restObjStr.set(str);
+
+ restController.<String>Get(str, "", path, restObjStr);
+
+ w = MsoUtil.wrapResponse(restObjStr);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
+ // always return OK, the MSO status code is embedded in the body
+
+ } catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ throw e;
+ }
+ // always return OK, the MSO status code is embedded in the body
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+ }
+
+
+ /**
+ * Gets the orchestration requests.
+ *
+ * @param filterString the filter string
+ * @param request the request
+ * @return the orchestration requests
+ * @throws Exception the exception
+ */
+ @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET)
+ public ResponseEntity<String> getOrchestrationRequests(@PathVariable("filterString") String filterString,
+ HttpServletRequest request) throws Exception {
+
+ String methodName = "getOrchestrationRequests";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+ MsoResponseWrapper w = null;
+ try {
+ MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
+ String path = p + filterString;
+
+ RestObject<String> restObjStr = new RestObject<String>();
+ String str = new String();
+ restObjStr.set(str);
+
+ restController.<String>Get(str, "", path, restObjStr);
+
+ w = MsoUtil.wrapResponse(restObjStr);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
+ } catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ throw e;
+ }
+ // always return OK, the MSO status code is embedded in the body
+ return (new ResponseEntity<String>(w.getResponse(), HttpStatus.OK));
+ }
+
+ /**
+ * Gets the orchestration requests for svc instance.
+ *
+ * @param svc_instance_id the svc instance id
+ * @return the orchestration requests for svc instance
+ * @throws Exception the exception
+ */
+ public MsoResponseWrapper getOrchestrationRequestsForSvcInstance(String svc_instance_id) throws Exception {
+
+ String methodName = "getOrchestrationRequestsForSvcInstance";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+ MsoResponseWrapper w = null;
+
+ try {
+ MsoRestInterfaceIfc restController = MsoRestInterfaceFactory.getInstance();
+ String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
+ String path = p + svc_instance_id;
+
+ RestObject<String> restObjStr = new RestObject<String>();
+ String str = new String();
+ restObjStr.set(str);
+
+ restController.<String>Get(str, "", path, restObjStr);
+ w = MsoUtil.wrapResponse(restObjStr);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse());
+
+ } catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ throw e;
+ }
+ return w;
+ }
+
+ /**
+ * Exception handler.
+ *
+ * @param e the e
+ * @param response the response
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ @ExceptionHandler(Exception.class)
+ private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException {
/*
* The following "logger.error" lines "should" be sufficient for logging the exception.
@@ -633,129 +641,126 @@ public class MsoController extends RestrictedBaseController{
* logger statements in this class. Thus the temporary "e.printStackTrace" statement
* is also included.
*/
-
- String methodName = "exceptionHandler";
- logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- StringWriter sw = new StringWriter();
- e.printStackTrace(new PrintWriter(sw));
- logger.error(EELFLoggerDelegate.errorLogger, sw.toString());
+
+ String methodName = "exceptionHandler";
+ logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ logger.error(EELFLoggerDelegate.errorLogger, sw.toString());
/*
* Temporary - IF the above mentioned "logger.error" glitch is resolved ...
* this statement could be removed since it would then likely result in duplicate
* trace output.
*/
- e.printStackTrace(System.err);
+ e.printStackTrace(System.err);
- response.setContentType("application/json; charset=UTF-8");
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ response.setContentType("application/json; charset=UTF-8");
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- ExceptionResponse exceptionResponse = new ExceptionResponse();
- exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
- exceptionResponse.setMessage(e.getMessage());
+ ExceptionResponse exceptionResponse = new ExceptionResponse();
+ exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
+ exceptionResponse.setMessage(e.getMessage());
- response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
+ response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
- response.flushBuffer();
+ response.flushBuffer();
- }
+ }
- /**
- * Parses the orchestration requests for svc instance.
- *
- * @param resp the resp
- * @return the list
- * @throws ParseException the parse exception
- * @throws Exception the exception
- */
- @SuppressWarnings("unchecked")
- public List<JSONObject> parseOrchestrationRequestsForSvcInstance ( ClientResponse resp ) throws org.json.simple.parser.ParseException, Exception {
-
- String methodName = "parseOrchestrationRequestsForSvcInstance";
-
- ArrayList<JSONObject> json_list = new ArrayList<JSONObject>();
-
- String rlist_str = resp.readEntity (String.class);
- logger.debug (EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Response string: " + rlist_str);
-
- JSONParser parser = new JSONParser();
- try {
- Object obj = parser.parse(rlist_str);
-
- JSONObject jsonObject = (JSONObject) obj;
-
- JSONArray requestList = (JSONArray) jsonObject.get("requestList");
-
- if ( requestList != null && ! (requestList.isEmpty()) )
- for ( Object container : requestList) {
-
- JSONObject containerJsonObj = (JSONObject) container;
- //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj: " + containerJsonObj.toJSONString());
- JSONObject reqJsonObj = (JSONObject) containerJsonObj.get("request");
-
- //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj.requestId: " +
- // reqJsonObj.get("requestId") );
- JSONObject result = new JSONObject();
-
- result.put("requestId", reqJsonObj.get ("requestId"));
- if ( reqJsonObj.get("requestType") != null ) {
- result.put("requestType", (reqJsonObj.get("requestType").toString()));
- }
- JSONObject req_status = (JSONObject)reqJsonObj.get("requestStatus");
- if ( req_status != null ) {
- result.put("timestamp", (req_status.get("timestamp")));
- result.put("requestState", (req_status.get("requestState")));
- result.put("statusMessage", (req_status.get("statusMessage")));
- result.put("percentProgress", (req_status.get("percentProgress")));
- }
- json_list.add (result);
- }
- } catch (org.json.simple.parser.ParseException pe) {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Parse exception: " + pe.toString());
- throw pe;
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Exception: " + e.toString());
- throw e;
- }
- return ( json_list );
- }
-
- /**
- * Retrieve request object.
- *
- * @param request the request
- * @return the request details
- * @throws Exception the exception
- */
- public RequestDetails retrieveRequestObject ( HttpServletRequest request, @RequestBody RequestDetails mso_request ) throws Exception {
-
- String methodName = "retrieveRequestObject";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start" );
-
- ObjectMapper mapper = new ObjectMapper();
- //JSON from String to Object
- //RequestDetails mso_request;
-
- try {
- //mso_request = new RequestDetails();
- //mso_request = mapper.readValue(request.getInputStream(), RequestDetails.class);
- }
- catch ( Exception e ) {
- logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to read json object RequestDetails e=" + e.getMessage());
- throw e;
- }
- if ( mso_request == null) {
- logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " mso_request is null");
- throw new Exception ("RequestDetails is missing");
- }
- try {
- String json_req = mapper.writeValueAsString(mso_request);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " request=[" + json_req + "]");
- }
- catch ( Exception e ) {
- logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to convert RequestDetails to json string e=" + e.getMessage());
- throw e;
- }
- return (mso_request);
- }
+ /**
+ * Parses the orchestration requests for svc instance.
+ *
+ * @param resp the resp
+ * @return the list
+ * @throws Exception the exception
+ */
+ @SuppressWarnings("unchecked")
+ public List<JSONObject> parseOrchestrationRequestsForSvcInstance(ClientResponse resp) throws org.json.simple.parser.ParseException, Exception {
+
+ String methodName = "parseOrchestrationRequestsForSvcInstance";
+
+ ArrayList<JSONObject> json_list = new ArrayList<JSONObject>();
+
+ String rlist_str = resp.readEntity(String.class);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Response string: " + rlist_str);
+
+ JSONParser parser = new JSONParser();
+ try {
+ Object obj = parser.parse(rlist_str);
+
+ JSONObject jsonObject = (JSONObject) obj;
+
+ JSONArray requestList = (JSONArray) jsonObject.get("requestList");
+
+ if (requestList != null && !(requestList.isEmpty()))
+ for (Object container : requestList) {
+
+ JSONObject containerJsonObj = (JSONObject) container;
+ //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj: " + containerJsonObj.toJSONString());
+ JSONObject reqJsonObj = (JSONObject) containerJsonObj.get("request");
+
+ //logger.debug(dateFormat.format(new Date()) + "<== " + "." + methodName + " reqJsonObj.requestId: " +
+ // reqJsonObj.get("requestId") );
+ JSONObject result = new JSONObject();
+
+ result.put("requestId", reqJsonObj.get("requestId"));
+ if (reqJsonObj.get("requestType") != null) {
+ result.put("requestType", (reqJsonObj.get("requestType").toString()));
+ }
+ JSONObject req_status = (JSONObject) reqJsonObj.get("requestStatus");
+ if (req_status != null) {
+ result.put("timestamp", (req_status.get("timestamp")));
+ result.put("requestState", (req_status.get("requestState")));
+ result.put("statusMessage", (req_status.get("statusMessage")));
+ result.put("percentProgress", (req_status.get("percentProgress")));
+ }
+ json_list.add(result);
+ }
+ } catch (org.json.simple.parser.ParseException pe) {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Parse exception: " + pe.toString());
+ throw pe;
+ } catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + " Exception: " + e.toString());
+ throw e;
+ }
+ return (json_list);
+ }
+
+ /**
+ * Retrieve request object.
+ *
+ * @param request the request
+ * @return the request details
+ * @throws Exception the exception
+ */
+ public RequestDetails retrieveRequestObject(HttpServletRequest request, @RequestBody RequestDetails mso_request) throws Exception {
+
+ String methodName = "retrieveRequestObject";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+
+ ObjectMapper mapper = new ObjectMapper();
+ //JSON from String to Object
+ //RequestDetails mso_request;
+
+ try {
+ //mso_request = new RequestDetails();
+ //mso_request = mapper.readValue(request.getInputStream(), RequestDetails.class);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to read json object RequestDetails e=" + e.getMessage());
+ throw e;
+ }
+ if (mso_request == null) {
+ logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " mso_request is null");
+ throw new Exception("RequestDetails is missing");
+ }
+ try {
+ String json_req = mapper.writeValueAsString(mso_request);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " request=[" + json_req + "]");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + " Unable to convert RequestDetails to json string e=" + e.getMessage());
+ throw e;
+ }
+ return (mso_request);
+ }
}
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java b/vid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java
index 9972ae5d..838793a7 100755
--- a/vid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java
+++ b/vid-app-common/src/main/java/org/openecomp/vid/controller/VidController.java
@@ -24,18 +24,22 @@ import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.openecomp.vid.asdc.AsdcCatalogException;
+import org.openecomp.vid.asdc.beans.SecureServices;
import org.openecomp.vid.exceptions.VidServiceUnavailableException;
import org.openecomp.vid.model.ServiceModel;
+import org.openecomp.vid.roles.Role;
+import org.openecomp.vid.roles.RoleProvider;
+import org.openecomp.vid.roles.RoleValidator;
+import org.openecomp.vid.services.VidService;
import org.springframework.beans.factory.annotation.Autowired;
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.servlet.ModelAndView;
-import org.openecomp.vid.services.*;
import javax.servlet.http.HttpServletRequest;
-import java.util.Collection;
+import java.util.List;
import java.util.Map;
//import org.openecomp.vid.model.Service;
@@ -61,10 +65,15 @@ public class VidController extends RestrictedBaseController {
* @throws VidServiceUnavailableException the vid service unavailable exception
*/
@RequestMapping(value={"/rest/models/services"}, method = RequestMethod.GET)
- public Collection<org.openecomp.vid.asdc.beans.Service> getServices(HttpServletRequest request) throws VidServiceUnavailableException {
+ public SecureServices getServices(HttpServletRequest request) throws VidServiceUnavailableException {
try {
+ SecureServices secureServices = new SecureServices();
+ RoleProvider roleProvider = new RoleProvider();
Map<String, String[]> requestParams = request.getParameterMap();
- return service.getServices(requestParams);
+ List<Role> roles = new RoleProvider().getUserRoles(request);
+ secureServices.setServices(service.getServices(requestParams));
+ secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
+ return secureServices;
} catch (AsdcCatalogException e) {
LOG.error("Failed to retrieve service definitions from SDC", e);
throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e);
@@ -83,8 +92,9 @@ public class VidController extends RestrictedBaseController {
* @throws VidServiceUnavailableException the vid service unavailable exception
*/
@RequestMapping(value={"/rest/models/services/{uuid}"}, method = RequestMethod.GET)
- public ServiceModel getServices(@PathVariable("uuid") String uuid) throws VidServiceUnavailableException {
+ public ServiceModel getServices(@PathVariable("uuid") String uuid, HttpServletRequest request) throws VidServiceUnavailableException {
try {
+// RoleValidator roleValidator = new RoleValidator(new RoleProvider().getUserRoles(request));
return service.getService(uuid);
} catch (AsdcCatalogException e) {
LOG.error("Failed to retrieve service definitions from SDC", e);
diff --git a/vid-app-common/src/main/java/org/openecomp/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/openecomp/vid/controller/WebConfig.java
index 9a258a10..1e13d0eb 100644
--- a/vid-app-common/src/main/java/org/openecomp/vid/controller/WebConfig.java
+++ b/vid-app-common/src/main/java/org/openecomp/vid/controller/WebConfig.java
@@ -4,13 +4,17 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.json.JSONTokener;
+import org.openecomp.vid.aai.AaiClient;
+import org.openecomp.vid.aai.AaiClientInterface;
import org.openecomp.vid.asdc.AsdcClient;
import org.openecomp.vid.asdc.local.LocalAsdcClient;
import org.openecomp.vid.asdc.memory.InMemoryAsdcClient;
-import org.openecomp.vid.asdc.rest.RestfulAsdcClient;
import org.openecomp.vid.asdc.parser.ToscaParserImpl2;
+import org.openecomp.vid.asdc.rest.RestfulAsdcClient;
import org.openecomp.vid.properties.AsdcClientConfiguration;
import org.openecomp.vid.properties.AsdcClientConfiguration.AsdcClientType;
+import org.openecomp.vid.services.AaiService;
+import org.openecomp.vid.services.AaiServiceImpl;
import org.openecomp.vid.services.VidService;
import org.openecomp.vid.services.VidServiceImpl;
import org.springframework.context.annotation.Bean;
@@ -40,12 +44,24 @@ public class WebConfig {
return new ObjectMapper();
}
+
+
@Bean
public VidService vidService(AsdcClient asdcClient) {
return new VidServiceImpl(asdcClient);
}
@Bean
+ public AaiService getAaiService(){
+ return new AaiServiceImpl();
+ }
+
+ @Bean
+ public AaiClientInterface getAaiClientInterface(){
+ return new AaiClient();
+ }
+
+ @Bean
public AsdcClient asdcClient(AsdcClientConfiguration asdcClientConfig) throws IOException {
switch (asdcClientConfig.getAsdcClientType()) {
case IN_MEMORY: