2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.vid.controller;
\r
23 import org.codehaus.jackson.JsonGenerationException;
\r
24 import org.codehaus.jackson.map.JsonMappingException;
\r
25 import org.codehaus.jackson.map.ObjectMapper;
\r
26 import org.json.simple.JSONArray;
\r
27 import org.json.simple.JSONObject;
\r
28 import org.json.simple.parser.JSONParser;
\r
29 import org.openecomp.aai.util.AAIRestInterface;
\r
30 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
\r
31 import org.openecomp.portalsdk.core.domain.User;
\r
32 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
33 import org.openecomp.portalsdk.core.util.SystemProperties;
\r
34 import org.openecomp.vid.aai.AaiResponse;
\r
35 import org.openecomp.vid.aai.SubscriberData;
\r
36 import org.openecomp.vid.aai.SubscriberFilteredResults;
\r
37 import org.openecomp.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
\r
38 import org.openecomp.vid.roles.Role;
\r
39 import org.openecomp.vid.roles.RoleProvider;
\r
40 import org.openecomp.vid.roles.RoleValidator;
\r
41 import org.openecomp.vid.services.AaiService;
\r
42 import org.springframework.beans.factory.annotation.Autowired;
\r
43 import org.springframework.http.HttpStatus;
\r
44 import org.springframework.http.MediaType;
\r
45 import org.springframework.http.ResponseEntity;
\r
46 import org.springframework.web.bind.annotation.PathVariable;
\r
47 import org.springframework.web.bind.annotation.RequestMapping;
\r
48 import org.springframework.web.bind.annotation.RequestMethod;
\r
49 import org.springframework.web.bind.annotation.RestController;
\r
50 import org.springframework.web.servlet.ModelAndView;
\r
53 import javax.servlet.ServletContext;
\r
54 import javax.servlet.http.HttpServletRequest;
\r
55 import javax.servlet.http.HttpSession;
\r
56 import javax.ws.rs.BadRequestException;
\r
57 import javax.ws.rs.DefaultValue;
\r
58 import javax.ws.rs.QueryParam;
\r
59 import javax.ws.rs.WebApplicationException;
\r
60 import javax.ws.rs.core.Response;
\r
61 import java.io.File;
\r
62 import java.io.IOException;
\r
63 import java.text.DateFormat;
\r
64 import java.text.SimpleDateFormat;
\r
68 * Controller to handle a&ai requests.
\r
72 public class AaiController extends RestrictedBaseController {
\r
74 public AaiController() {
\r
77 public AaiController(ServletContext servletContext) {
\r
78 this.servletContext = servletContext;
\r
86 * The Constant dateFormat.
\r
88 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
\r
92 protected String fromAppId = "VidAaiController";
\r
100 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiController.class);
\r
106 private Map<String, Object> model = new HashMap<String, Object>();
\r
108 * The servlet context.
\r
111 private ServletContext servletContext;
\r
117 private AaiService aaiService;
\r
122 * Return tenant details.
\r
124 * @param jsonObject the json object
\r
125 * @return String The parsing results
\r
127 public static String parseCustomerObjectForTenants(JSONObject jsonObject) {
\r
129 JSONArray tenantArray = new JSONArray();
\r
130 boolean bconvert = false;
\r
134 JSONObject serviceSubsObj = (JSONObject) jsonObject.get("service-subscriptions");
\r
136 if (serviceSubsObj != null) {
\r
137 JSONArray srvcSubArray = (JSONArray) serviceSubsObj.get("service-subscription");
\r
139 if (srvcSubArray != null) {
\r
140 Iterator i = srvcSubArray.iterator();
\r
142 while (i.hasNext()) {
\r
144 JSONObject innerObj = (JSONObject) i.next();
\r
146 if (innerObj == null)
\r
149 JSONObject relationShipListsObj = (JSONObject) innerObj.get("relationship-list");
\r
150 if (relationShipListsObj != null) {
\r
151 JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
\r
152 if (rShipArray != null) {
\r
153 Iterator i1 = rShipArray.iterator();
\r
155 while (i1.hasNext()) {
\r
157 JSONObject inner1Obj = (JSONObject) i1.next();
\r
159 if (inner1Obj == null)
\r
162 String relatedTo = checkForNull((String) inner1Obj.get("related-to"));
\r
163 if (relatedTo.equalsIgnoreCase("tenant")) {
\r
164 JSONObject tenantNewObj = new JSONObject();
\r
166 String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
\r
167 tenantNewObj.put("link", relatedLink);
\r
169 JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
\r
170 if (rDataArray != null) {
\r
171 Iterator i2 = rDataArray.iterator();
\r
173 while (i2.hasNext()) {
\r
174 JSONObject inner2Obj = (JSONObject) i2.next();
\r
176 if (inner2Obj == null)
\r
179 String rShipKey = checkForNull((String) inner2Obj.get("relationship-key"));
\r
180 String rShipVal = checkForNull((String) inner2Obj.get("relationship-value"));
\r
181 if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner")) {
\r
182 tenantNewObj.put("cloudOwner", rShipVal);
\r
183 } else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id")) {
\r
184 tenantNewObj.put("cloudRegionID", rShipVal);
\r
187 if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) {
\r
188 tenantNewObj.put("tenantID", rShipVal);
\r
193 JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
\r
194 if (relatedTPropArray != null) {
\r
195 Iterator i3 = relatedTPropArray.iterator();
\r
197 while (i3.hasNext()) {
\r
198 JSONObject inner3Obj = (JSONObject) i3.next();
\r
200 if (inner3Obj == null)
\r
203 String propKey = checkForNull((String) inner3Obj.get("property-key"));
\r
204 String propVal = checkForNull((String) inner3Obj.get("property-value"));
\r
205 if (propKey.equalsIgnoreCase("tenant.tenant-name")) {
\r
206 tenantNewObj.put("tenantName", propVal);
\r
211 tenantArray.add(tenantNewObj);
\r
219 } catch (NullPointerException ex) {
\r
225 return tenantArray.toJSONString();
\r
234 * Retrieve the service subscription from the jsonObject.
\r
236 * @param jsonObject the json object
\r
239 public static String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) {
\r
241 JSONArray tenantArray = new JSONArray();
\r
242 boolean bconvert = false;
\r
245 JSONObject relationShipListsObj = (JSONObject) jsonObject.get("relationship-list");
\r
246 if (relationShipListsObj != null) {
\r
247 JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
\r
248 if (rShipArray != null) {
\r
249 Iterator i1 = rShipArray.iterator();
\r
251 while (i1.hasNext()) {
\r
253 JSONObject inner1Obj = (JSONObject) i1.next();
\r
255 if (inner1Obj == null)
\r
258 String relatedTo = checkForNull((String) inner1Obj.get("related-to"));
\r
259 if (relatedTo.equalsIgnoreCase("tenant")) {
\r
260 JSONObject tenantNewObj = new JSONObject();
\r
262 String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
\r
263 tenantNewObj.put("link", relatedLink);
\r
265 JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
\r
266 if (rDataArray != null) {
\r
267 Iterator i2 = rDataArray.iterator();
\r
269 while (i2.hasNext()) {
\r
270 JSONObject inner2Obj = (JSONObject) i2.next();
\r
272 if (inner2Obj == null)
\r
275 String rShipKey = checkForNull((String) inner2Obj.get("relationship-key"));
\r
276 String rShipVal = checkForNull((String) inner2Obj.get("relationship-value"));
\r
277 if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner")) {
\r
278 tenantNewObj.put("cloudOwner", rShipVal);
\r
279 } else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id")) {
\r
280 tenantNewObj.put("cloudRegionID", rShipVal);
\r
283 if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) {
\r
284 tenantNewObj.put("tenantID", rShipVal);
\r
289 JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
\r
290 if (relatedTPropArray != null) {
\r
291 Iterator i3 = relatedTPropArray.iterator();
\r
293 while (i3.hasNext()) {
\r
294 JSONObject inner3Obj = (JSONObject) i3.next();
\r
296 if (inner3Obj == null)
\r
299 String propKey = checkForNull((String) inner3Obj.get("property-key"));
\r
300 String propVal = checkForNull((String) inner3Obj.get("property-value"));
\r
301 if (propKey.equalsIgnoreCase("tenant.tenant-name")) {
\r
302 tenantNewObj.put("tenantName", propVal);
\r
307 tenantArray.add(tenantNewObj);
\r
313 } catch (NullPointerException ex) {
\r
319 return tenantArray.toJSONString();
\r
328 * @param local the local
\r
329 * @return the string
\r
331 private static String checkForNull(String local) {
\r
342 * @param request the request
\r
343 * @return ModelAndView The view
\r
345 @RequestMapping(value = {"/subscriberSearch"}, method = RequestMethod.GET)
\r
346 public ModelAndView welcome(HttpServletRequest request) {
\r
347 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== AaiController welcome start");
\r
348 return new ModelAndView(getViewName());
\r
351 @RequestMapping(value = {"/aai_get_aic_zones"}, method = RequestMethod.GET)
\r
352 public ResponseEntity<String> getAicZones(HttpServletRequest request) throws JsonGenerationException, JsonMappingException, IOException {
\r
353 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== getAicZones controller start");
\r
354 AaiResponse response = aaiService.getAaiZones();
\r
355 return aaiResponseToResponseEntity(response);
\r
360 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
\r
362 public String getViewName() {
\r
367 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
\r
369 public void setViewName(String viewName) {
\r
370 this.viewName = viewName;
\r
374 * Get services from a&ai.
\r
376 * @return ResponseEntity<String> The response entity with the logged in user uuid.
\r
377 * @throws IOException Signals that an I/O exception has occurred.
\r
378 * @throws InterruptedException the interrupted exception
\r
380 @RequestMapping(value = {"/getuserID"}, method = RequestMethod.GET)
\r
381 public ResponseEntity<String> getUserID(HttpServletRequest request) throws IOException, InterruptedException {
\r
383 String userId = "";
\r
384 HttpSession session = request.getSession();
\r
385 if (session != null) {
\r
386 User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME));
\r
387 if (user != null) {
\r
388 //userId = user.getHrid();
\r
389 userId = user.getLoginId();
\r
390 if (userId == null)
\r
391 userId = user.getOrgUserId();
\r
395 return new ResponseEntity<String>(userId, HttpStatus.OK);
\r
399 * Get services from a&ai.
\r
401 * @return ResponseEntity<String> The response entity
\r
402 * @throws IOException Signals that an I/O exception has occurred.
\r
403 * @throws InterruptedException the interrupted exception
\r
405 @RequestMapping(value = "/aai_get_services", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
406 public ResponseEntity<String> doGetServices(HttpServletRequest request) throws IOException, InterruptedException {
\r
408 RoleValidator roleValidator = new RoleValidator(new RoleProvider().getUserRoles(request));
\r
410 AaiResponse subscriberList = aaiService.getServices(roleValidator);
\r
411 ResponseEntity<String> responseEntity = aaiResponseToResponseEntity( subscriberList);
\r
413 return responseEntity;
\r
418 private ResponseEntity<String> aaiResponseToResponseEntity( AaiResponse aaiResponseData)
\r
419 throws IOException, JsonGenerationException, JsonMappingException {
\r
420 ResponseEntity<String> responseEntity;
\r
421 ObjectMapper objectMapper = new ObjectMapper();
\r
422 if (aaiResponseData.getHttpCode() == 200) {
\r
423 responseEntity = new ResponseEntity<String>(objectMapper.writeValueAsString(aaiResponseData.getT()), HttpStatus.OK);
\r
425 responseEntity = new ResponseEntity<String>(aaiResponseData.getErrorMessage(), HttpStatus.valueOf(aaiResponseData.getHttpCode()));
\r
427 return responseEntity;
\r
431 * Lookup single service instance in a&ai. Get the service-subscription and customer, too, i guess?
\r
433 * @param serviceInstanceId the service instance Id
\r
434 * @return ResponseEntity The response entity
\r
435 * @throws IOException Signals that an I/O exception has occurred.
\r
436 * @throws InterruptedException the interrupted exception
\r
438 @RequestMapping(value = "/aai_get_service_instance/{service-instance-id}/{service-instance-type}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
439 public ResponseEntity<String> doGetServiceInstance(@PathVariable("service-instance-id") String serviceInstanceId, @PathVariable("service-instance-type") String serviceInstanceType) throws IOException, InterruptedException {
\r
440 File certiPath = GetCertificatesPath();
\r
441 Response resp = null;
\r
443 if (serviceInstanceType.equalsIgnoreCase("Service Instance Id")) {
\r
444 resp = doAaiGet(certiPath.getAbsolutePath(),
\r
445 "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:"
\r
446 + serviceInstanceId, false);
\r
448 resp = doAaiGet(certiPath.getAbsolutePath(),
\r
449 "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:"
\r
450 + serviceInstanceId, false);
\r
452 return convertResponseToResponseEntity(resp);
\r
456 * Get services from a&ai.
\r
458 * @param globalCustomerId the global customer id
\r
459 * @param serviceSubscriptionId the service subscription id
\r
460 * @return ResponseEntity The response entity
\r
461 * @throws IOException Signals that an I/O exception has occurred.
\r
462 * @throws InterruptedException the interrupted exception
\r
464 @RequestMapping(value = "/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
465 public ResponseEntity<String> doGetServices(@PathVariable("global-customer-id") String globalCustomerId,
\r
466 @PathVariable("service-subscription-id") String serviceSubscriptionId) throws IOException, InterruptedException {
\r
467 File certiPath = GetCertificatesPath();
\r
468 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId
\r
469 + "/service-subscriptions/service-subscription/" + serviceSubscriptionId + "?depth=0", false);
\r
470 return convertResponseToResponseEntity(resp);
\r
474 * Obtain the subscriber list from a&ai.
\r
476 * @param fullSet the full set
\r
477 * @return ResponseEntity The response entity
\r
478 * @throws IOException Signals that an I/O exception has occurred.
\r
479 * @throws InterruptedException the interrupted exception
\r
481 @RequestMapping(value = "/aai_get_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
482 public ResponseEntity<String> doGetSubscriberList(HttpServletRequest request,@DefaultValue("n") @QueryParam("fullSet") String fullSet) throws IOException, InterruptedException {
\r
483 return getFullSubscriberList(request);
\r
487 * Obtain the Target Prov Status from the System.Properties file.
\r
489 * @return ResponseEntity The response entity
\r
490 * @throws IOException Signals that an I/O exception has occurred.
\r
491 * @throws InterruptedException the interrupted exception
\r
493 @RequestMapping(value = "/get_system_prop_vnf_prov_status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
494 public ResponseEntity<String> getTargetProvStatus() throws IOException, InterruptedException {
\r
495 String p = SystemProperties.getProperty("aai.vnf.provstatus");
\r
496 return new ResponseEntity<String>(p, HttpStatus.OK);
\r
500 * Obtain the full subscriber list from a&ai.
\r
502 * g @return ResponseEntity The response entity
\r
504 * @throws IOException Signals that an I/O exception has occurred.
\r
505 * @throws InterruptedException the interrupted exception
\r
507 @RequestMapping(value = "/aai_get_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
508 public ResponseEntity<String> getFullSubscriberList(HttpServletRequest request) throws IOException, InterruptedException {
\r
509 ObjectMapper objectMapper = new ObjectMapper();
\r
510 ResponseEntity<String> responseEntity;
\r
511 RoleValidator roleValidator = new RoleValidator(new RoleProvider().getUserRoles(request));
\r
512 SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator);
\r
513 if (subscriberList.getHttpCode() == 200) {
\r
514 responseEntity = new ResponseEntity<String>(objectMapper.writeValueAsString(subscriberList.getSubscriberList()), HttpStatus.OK);
\r
516 responseEntity = new ResponseEntity<String>(subscriberList.getErrorMessage(), HttpStatus.valueOf(subscriberList.getHttpCode()));
\r
520 return responseEntity;
\r
524 * Refresh the subscriber list from a&ai.
\r
526 * @return ResponseEntity The response entity
\r
527 * @throws IOException Signals that an I/O exception has occurred.
\r
529 @RequestMapping(value = "/aai_refresh_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
530 public ResponseEntity<String> doRefreshSubscriberList() throws IOException {
\r
531 Response resp = getSubscribers(false);
\r
532 return convertResponseToResponseEntity(resp);
\r
536 * Refresh the full subscriber list from a&ai.
\r
538 * @return ResponseEntity The response entity
\r
539 * @throws IOException Signals that an I/O exception has occurred.
\r
541 @RequestMapping(value = "/aai_refresh_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
542 public ResponseEntity<String> doRefreshFullSubscriberList() throws IOException {
\r
543 Response resp = getSubscribers(false);
\r
544 return convertResponseToResponseEntity(resp);
\r
548 * Get subscriber details from a&ai.
\r
550 * @param subscriberId the subscriber id
\r
551 * @return ResponseEntity The response entity
\r
553 @RequestMapping(value = "/aai_sub_details/{subscriberId}", method = RequestMethod.GET)
\r
554 public ResponseEntity<String> GetSubscriberDetails(HttpServletRequest request,@PathVariable("subscriberId") String subscriberId) throws IOException {
\r
555 ObjectMapper objectMapper = new ObjectMapper();
\r
556 ResponseEntity responseEntity;
\r
557 List<Role> roles = new RoleProvider().getUserRoles(request);
\r
558 RoleValidator roleValidator = new RoleValidator(roles);
\r
559 AaiResponse<SubscriberData> subscriberData = aaiService.getSubscriberData(subscriberId,roleValidator);
\r
560 String httpMessage = subscriberData.getT() != null ?
\r
561 objectMapper.writeValueAsString(subscriberData.getT()) :
\r
562 subscriberData.getErrorMessage();
\r
564 responseEntity = new ResponseEntity<String>(httpMessage, HttpStatus.valueOf(subscriberData.getHttpCode()));
\r
565 return responseEntity;
\r
569 * Issue a named query to a&ai.
\r
571 * @param namedQueryId the named query id
\r
572 * @param globalCustomerId the global customer id
\r
573 * @param serviceType the service type
\r
574 * @param serviceInstance the service instance
\r
575 * @return ResponseEntity The response entity
\r
577 @RequestMapping(value = "/aai_sub_viewedit/{namedQueryId}/{globalCustomerId}/{serviceType}/{serviceInstance}", method = RequestMethod.GET)
\r
578 public ResponseEntity<String> viewEditGetComponentList(
\r
579 @PathVariable("namedQueryId") String namedQueryId,
\r
580 @PathVariable("globalCustomerId") String globalCustomerId,
\r
581 @PathVariable("serviceType") String serviceType,
\r
582 @PathVariable("serviceInstance") String serviceInstance) {
\r
584 String componentListPayload = getComponentListPutPayload(namedQueryId, globalCustomerId, serviceType, serviceInstance);
\r
585 File certiPath = GetCertificatesPath();
\r
587 Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
\r
588 return convertResponseToResponseEntity(resp);
\r
592 // @RequestMapping(value="/aai_get_tenants/{global-customer-id}", method = RequestMethod.GET)
\r
593 // public ResponseEntity<String> viewEditGetComponentList(
\r
594 // @PathVariable("global-customer-id") String globalCustomerId) {
\r
595 // return new ResponseEntity<String>(getTenants(globalCustomerId), HttpStatus.OK);
\r
599 * Issue a named query to a&ai.
\r
601 * @param namedQueryId the named query id
\r
602 * @param globalCustomerId the global customer id
\r
603 * @param serviceType the service type
\r
604 * @return ResponseEntity The response entity
\r
606 @RequestMapping(value = "/aai_get_models_by_service_type/{namedQueryId}/{globalCustomerId}/{serviceType}", method = RequestMethod.GET)
\r
607 public ResponseEntity<String> viewEditGetComponentList(
\r
608 @PathVariable("namedQueryId") String namedQueryId,
\r
609 @PathVariable("globalCustomerId") String globalCustomerId,
\r
610 @PathVariable("serviceType") String serviceType) {
\r
612 String componentListPayload = getModelsByServiceTypePayload(namedQueryId, globalCustomerId, serviceType);
\r
613 File certiPath = GetCertificatesPath();
\r
615 Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
\r
616 return convertResponseToResponseEntity(resp);
\r
620 * Parses the for tenants.
\r
622 * @param resp the resp
\r
623 * @return the string
\r
625 private String parseForTenants(String resp) {
\r
626 String tenantList = "";
\r
629 JSONParser jsonParser = new JSONParser();
\r
631 JSONObject jsonObject = (JSONObject) jsonParser.parse(resp);
\r
633 return parseCustomerObjectForTenants(jsonObject);
\r
634 } catch (Exception ex) {
\r
642 * Parses the for tenants by service subscription.
\r
644 * @param resp the resp
\r
645 * @return the string
\r
647 private String parseForTenantsByServiceSubscription(String resp) {
\r
648 String tenantList = "";
\r
651 JSONParser jsonParser = new JSONParser();
\r
653 JSONObject jsonObject = (JSONObject) jsonParser.parse(resp);
\r
655 return parseServiceSubscriptionObjectForTenants(jsonObject);
\r
656 } catch (Exception ex) {
\r
664 * Obtain tenants for a given service type.
\r
666 * @param globalCustomerId the global customer id
\r
667 * @param serviceType the service type
\r
668 * @return ResponseEntity The response entity
\r
670 @RequestMapping(value = "/aai_get_tenants/{global-customer-id}/{service-type}", method = RequestMethod.GET)
\r
671 public ResponseEntity<String> viewEditGetTenantsFromServiceType(HttpServletRequest request,
\r
672 @PathVariable("global-customer-id") String globalCustomerId, @PathVariable("service-type") String serviceType) {
\r
674 ResponseEntity responseEntity;
\r
676 ObjectMapper objectMapper = new ObjectMapper();
\r
677 List<Role> roles = new RoleProvider().getUserRoles(request);
\r
678 RoleValidator roleValidator = new RoleValidator(roles);
\r
679 AaiResponse<GetTenantsResponse[]> response = aaiService.getTenants(globalCustomerId, serviceType, roleValidator);
\r
680 if (response.getHttpCode() == 200) {
\r
681 responseEntity = new ResponseEntity<String>(objectMapper.writeValueAsString(response.getT()), HttpStatus.OK);
\r
683 responseEntity = new ResponseEntity<String>(response.getErrorMessage(), HttpStatus.valueOf(response.getHttpCode()));
\r
686 catch (Exception e){
\r
687 responseEntity = new ResponseEntity<String>("Unable to proccess getTenants reponse", HttpStatus.INTERNAL_SERVER_ERROR);
\r
689 return responseEntity;
\r
693 private ResponseEntity<String> convertResponseToResponseEntity(Response resp) {
\r
694 ResponseEntity<String> respEnt;
\r
695 ObjectMapper objectMapper = new ObjectMapper();
\r
696 if (resp == null) {
\r
697 respEnt = new ResponseEntity<String>("Failed to fetch data from A&AI, check server logs for details.", HttpStatus.INTERNAL_SERVER_ERROR);
\r
699 respEnt = new ResponseEntity<String>(resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
705 * Gets the tenants.
\r
707 * @param globalCustomerId the global customer id
\r
708 * @return the tenants
\r
710 private ResponseEntity<String> getTenants(String globalCustomerId) {
\r
711 File certiPath = GetCertificatesPath();
\r
712 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId, false);
\r
714 ResponseEntity<String> respEnt;
\r
715 if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
\r
716 respEnt = new ResponseEntity<String>(parseForTenants((String) resp.readEntity(String.class)), HttpStatus.OK);
\r
718 respEnt = new ResponseEntity<String>((String) resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
725 * Gets the tenants from service type.
\r
727 * @param globalCustomerId the global customer id
\r
728 * @param serviceType the service type
\r
729 * @return the tenants from service type
\r
731 private ResponseEntity<String> getTenantsFromServiceType(String globalCustomerId, String serviceType) {
\r
737 File certiPath = GetCertificatesPath();
\r
738 String url = "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + serviceType;
\r
740 Response resp = doAaiGet(certiPath.getAbsolutePath(), url, false);
\r
742 ResponseEntity<String> respEnt;
\r
743 if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
\r
744 respEnt = new ResponseEntity<String>(parseForTenantsByServiceSubscription((String) resp.readEntity(String.class)), HttpStatus.OK);
\r
746 respEnt = new ResponseEntity<String>((String) resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
753 * Gets the services.
\r
755 * @return the services
\r
757 private Response getServices() {
\r
758 File certiPath = GetCertificatesPath();
\r
759 Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/services", false);
\r
760 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getServices() resp=" + resp.getStatusInfo());
\r
762 //model.put("aai_get_services", resp);
\r
767 * Gets the subscribers.
\r
769 * @param isFullSet the is full set
\r
770 * @return the subscribers
\r
772 private Response getSubscribers(boolean isFullSet) {
\r
774 File certiPath = GetCertificatesPath();
\r
775 String depth = "0";
\r
777 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers?subscriber-type=INFRA&depth=" + depth, false);
\r
778 if (resp != null) {
\r
779 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString());
\r
785 * Gets the subscriber details.
\r
787 * @param subscriberId the subscriber id
\r
788 * @return the subscriber details
\r
790 private Response getSubscriberDetails(String subscriberId) {
\r
791 File certiPath = GetCertificatesPath();
\r
792 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId + "?depth=2", false);
\r
793 //String resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId, false);
\r
794 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscriberDetails() resp=" + resp.getStatusInfo().toString());
\r
799 * Gets the certificates path.
\r
803 private File GetCertificatesPath() {
\r
804 if (servletContext != null)
\r
805 return new File(servletContext.getRealPath("/WEB-INF/cert/"));
\r
810 * Send a GET request to a&ai.
\r
812 * @param certiPath the certi path
\r
813 * @param uri the uri
\r
814 * @param xml the xml
\r
815 * @return String The response
\r
817 protected Response doAaiGet(String certiPath, String uri, boolean xml) {
\r
818 String methodName = "getSubscriberList";
\r
819 String transId = UUID.randomUUID().toString();
\r
820 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
822 Response resp = null;
\r
825 AAIRestInterface restContrller = new AAIRestInterface(certiPath);
\r
826 resp = restContrller.RestGet(fromAppId, transId, uri, xml);
\r
828 } catch (WebApplicationException e) {
\r
829 final String message = ((BadRequestException) e).getResponse().readEntity(String.class);
\r
830 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
\r
831 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
\r
832 } catch (Exception e) {
\r
833 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
834 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
841 * Send a POST request to a&ai.
\r
843 * @param certiPath the certi path
\r
844 * @param uri the uri
\r
845 * @param payload the payload
\r
846 * @param xml the xml
\r
847 * @return String The response
\r
849 protected Response doAaiPost(String certiPath, String uri, String payload, boolean xml) {
\r
850 String methodName = "getSubscriberList";
\r
851 String transId = UUID.randomUUID().toString();
\r
852 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
854 Response resp = null;
\r
857 AAIRestInterface restContrller = new AAIRestInterface(certiPath);
\r
858 resp = restContrller.RestPost(fromAppId, transId, uri, payload, xml);
\r
860 } catch (Exception e) {
\r
861 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
862 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
869 * Gets the component list put payload.
\r
871 * @param namedQueryId the named query id
\r
872 * @param globalCustomerId the global customer id
\r
873 * @param serviceType the service type
\r
874 * @param serviceInstance the service instance
\r
875 * @return the component list put payload
\r
877 private String getComponentListPutPayload(String namedQueryId, String globalCustomerId, String serviceType, String serviceInstance) {
\r
880 " \"instance-filters\": {" +
\r
881 " \"instance-filter\": [" +
\r
883 " \"customer\": {" +
\r
884 " \"global-customer-id\": \"" + globalCustomerId + "\"" +
\r
886 " \"service-instance\": {" +
\r
887 " \"service-instance-id\": \"" + serviceInstance + "\"" +
\r
889 " \"service-subscription\": {" +
\r
890 " \"service-type\": \"" + serviceType + "\"" +
\r
895 " \"query-parameters\": {" +
\r
896 " \"named-query\": {" +
\r
897 " \"named-query-uuid\": \"" + namedQueryId + "\"" +
\r
904 private String getModelsByServiceTypePayload(String namedQueryId, String globalCustomerId, String serviceType) {
\r
905 // TODO Auto-generated method stub
\r
907 " \"instance-filters\": {" +
\r
908 " \"instance-filter\": [" +
\r
910 " \"customer\": {" +
\r
911 " \"global-customer-id\": \"" + globalCustomerId + "\"" +
\r
913 " \"service-subscription\": {" +
\r
914 " \"service-type\": \"" + serviceType + "\"" +
\r
919 " \"query-parameters\": {" +
\r
920 " \"named-query\": {" +
\r
921 " \"named-query-uuid\": \"" + namedQueryId + "\"" +
\r