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 java.io.File;
\r
24 import java.io.IOException;
\r
25 import java.text.DateFormat;
\r
26 import java.text.SimpleDateFormat;
\r
27 import java.util.Date;
\r
28 import java.util.HashMap;
\r
29 import java.util.Iterator;
\r
30 import java.util.Map;
\r
31 import java.util.UUID;
\r
33 import javax.servlet.ServletContext;
\r
34 import javax.servlet.http.HttpServletRequest;
\r
35 import javax.servlet.http.HttpSession;
\r
36 import javax.ws.rs.BadRequestException;
\r
37 import javax.ws.rs.DefaultValue;
\r
38 import javax.ws.rs.QueryParam;
\r
39 import javax.ws.rs.WebApplicationException;
\r
40 import javax.ws.rs.core.Response;
\r
42 import org.json.simple.JSONArray;
\r
43 import org.json.simple.JSONObject;
\r
44 import org.json.simple.parser.JSONParser;
\r
45 import org.openecomp.aai.util.AAIRestInterface;
\r
46 import org.springframework.beans.factory.annotation.Autowired;
\r
47 import org.springframework.http.HttpStatus;
\r
48 import org.springframework.http.MediaType;
\r
49 import org.springframework.http.ResponseEntity;
\r
50 import org.springframework.web.bind.annotation.PathVariable;
\r
51 import org.springframework.web.bind.annotation.RequestMapping;
\r
52 import org.springframework.web.bind.annotation.RequestMethod;
\r
53 import org.springframework.web.bind.annotation.RestController;
\r
54 import org.springframework.web.servlet.ModelAndView;
\r
56 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
\r
57 import org.openecomp.portalsdk.core.domain.User;
\r
58 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
59 import org.openecomp.portalsdk.core.util.SystemProperties;
\r
62 * Controller to handle a&ai requests.
\r
66 public class AaiController extends RestrictedBaseController{
\r
68 /** The view name. */
\r
72 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiController.class);
\r
74 /** The Constant dateFormat. */
\r
75 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
\r
77 /** The from app id. */
\r
78 protected String fromAppId = "VidAaiController";
\r
81 private Map<String,Object> model = new HashMap<String,Object>();
\r
83 /** The servlet context. */
\r
84 private @Autowired ServletContext servletContext;
\r
89 * @param request the request
\r
90 * @return ModelAndView The view
\r
92 @RequestMapping(value = {"/subscriberSearch" }, method = RequestMethod.GET)
\r
93 public ModelAndView welcome(HttpServletRequest request) {
\r
94 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== AaiController welcome start");
\r
95 return new ModelAndView(getViewName());
\r
99 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
\r
101 public String getViewName() {
\r
106 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
\r
108 public void setViewName(String viewName) {
\r
109 this.viewName = viewName;
\r
113 * Get services from a&ai.
\r
115 * @return ResponseEntity<String> The response entity with the logged in user uuid.
\r
116 * @throws IOException Signals that an I/O exception has occurred.
\r
117 * @throws InterruptedException the interrupted exception
\r
119 @RequestMapping(value = {"/getuserID" }, method = RequestMethod.GET)
\r
120 public ResponseEntity<String> getUserID(HttpServletRequest request) throws IOException, InterruptedException {
\r
122 String userId = "";
\r
123 HttpSession session = request.getSession();
\r
124 if (session != null)
\r
126 User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME));
\r
129 //userId = user.getHrid();
\r
130 userId = user.getLoginId();
\r
131 if (userId == null)
\r
132 userId = user.getOrgUserId();
\r
136 return new ResponseEntity<String>( userId, HttpStatus.OK);
\r
141 * Get services from a&ai.
\r
143 * @return ResponseEntity<String> The response entity
\r
144 * @throws IOException Signals that an I/O exception has occurred.
\r
145 * @throws InterruptedException the interrupted exception
\r
147 @RequestMapping(value="/aai_get_services",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
148 public ResponseEntity<String> doGetServices() throws IOException, InterruptedException {
\r
149 File certiPath = GetCertificatesPath();
\r
150 Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/services", false);
\r
152 return convertResponseToResponseEntity(resp);
\r
156 * Lookup single service instance in a&ai. Get the service-subscription and customer, too, i guess?
\r
158 * @param serviceInstanceId the service instance Id
\r
159 * @return ResponseEntity The response entity
\r
160 * @throws IOException Signals that an I/O exception has occurred.
\r
161 * @throws InterruptedException the interrupted exception
\r
163 @RequestMapping(value="/aai_get_service_instance/{service-instance-id}/{service-instance-type}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
164 public ResponseEntity<String> doGetServiceInstance(@PathVariable("service-instance-id") String serviceInstanceId,@PathVariable("service-instance-type") String serviceInstanceType) throws IOException, InterruptedException {
\r
165 File certiPath = GetCertificatesPath();
\r
166 Response resp=null;
\r
168 if(serviceInstanceType.equalsIgnoreCase("Service Instance Id")){
\r
169 resp = doAaiGet( certiPath.getAbsolutePath(),
\r
170 "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:"
\r
171 + serviceInstanceId, false);
\r
173 resp = doAaiGet( certiPath.getAbsolutePath(),
\r
174 "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:"
\r
175 + serviceInstanceId, false);
\r
177 return convertResponseToResponseEntity(resp);
\r
182 * Get services from a&ai.
\r
184 * @param globalCustomerId the global customer id
\r
185 * @param serviceSubscriptionId the service subscription id
\r
186 * @return ResponseEntity The response entity
\r
187 * @throws IOException Signals that an I/O exception has occurred.
\r
188 * @throws InterruptedException the interrupted exception
\r
190 @RequestMapping(value="/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
191 public ResponseEntity<String> doGetServices(@PathVariable("global-customer-id") String globalCustomerId,
\r
192 @PathVariable("service-subscription-id") String serviceSubscriptionId) throws IOException, InterruptedException {
\r
193 File certiPath = GetCertificatesPath();
\r
194 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId
\r
195 + "/service-subscriptions/service-subscription/" + serviceSubscriptionId + "?depth=0", false);
\r
196 return convertResponseToResponseEntity(resp);
\r
200 * Obtain the subscriber list from a&ai.
\r
202 * @param fullSet the full set
\r
203 * @return ResponseEntity The response entity
\r
204 * @throws IOException Signals that an I/O exception has occurred.
\r
205 * @throws InterruptedException the interrupted exception
\r
207 @RequestMapping(value="/aai_get_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
208 public ResponseEntity<String> doGetSubscriberList(@DefaultValue("n") @QueryParam("fullSet") String fullSet) throws IOException, InterruptedException {
\r
209 Response resp = getSubscribers(false);
\r
210 return convertResponseToResponseEntity(resp);
\r
214 * Obtain the Target Prov Status from the System.Properties file.
\r
216 * @return ResponseEntity The response entity
\r
217 * @throws IOException Signals that an I/O exception has occurred.
\r
218 * @throws InterruptedException the interrupted exception
\r
220 @RequestMapping(value="/get_system_prop_vnf_prov_status",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
221 public ResponseEntity<String> getTargetProvStatus() throws IOException, InterruptedException {
\r
222 String p = SystemProperties.getProperty("aai.vnf.provstatus");
\r
223 return new ResponseEntity<String>(p, HttpStatus.OK);
\r
227 * Obtain the full subscriber list from a&ai.
\r
229 * @return ResponseEntity The response entity
\r
230 * @throws IOException Signals that an I/O exception has occurred.
\r
231 * @throws InterruptedException the interrupted exception
\r
233 @RequestMapping(value="/aai_get_full_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
234 public ResponseEntity<String> getFullSubscriberList() throws IOException, InterruptedException {
\r
235 Response resp = getSubscribers(true);
\r
236 return convertResponseToResponseEntity(resp);
\r
241 * Refresh the subscriber list from a&ai.
\r
243 * @return ResponseEntity The response entity
\r
244 * @throws IOException Signals that an I/O exception has occurred.
\r
246 @RequestMapping(value="/aai_refresh_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
247 public ResponseEntity<String> doRefreshSubscriberList() throws IOException {
\r
248 Response resp = getSubscribers(false);
\r
249 return convertResponseToResponseEntity(resp);
\r
253 * Refresh the full subscriber list from a&ai.
\r
255 * @return ResponseEntity The response entity
\r
256 * @throws IOException Signals that an I/O exception has occurred.
\r
258 @RequestMapping(value="/aai_refresh_full_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
\r
259 public ResponseEntity<String> doRefreshFullSubscriberList() throws IOException {
\r
260 Response resp = getSubscribers(false);
\r
261 return convertResponseToResponseEntity(resp);
\r
265 * Get subscriber details from a&ai.
\r
267 * @param subscriberId the subscriber id
\r
268 * @return ResponseEntity The response entity
\r
270 @RequestMapping(value="/aai_sub_details/{subscriberId}", method = RequestMethod.GET)
\r
271 public ResponseEntity<String> GetSubscriber(@PathVariable("subscriberId") String subscriberId) {
\r
272 Response resp = getSubscriberDetails(subscriberId);
\r
273 return convertResponseToResponseEntity(resp);
\r
277 * Issue a named query to a&ai.
\r
279 * @param namedQueryId the named query id
\r
280 * @param globalCustomerId the global customer id
\r
281 * @param serviceType the service type
\r
282 * @param serviceInstance the service instance
\r
283 * @return ResponseEntity The response entity
\r
285 @RequestMapping(value="/aai_sub_viewedit/{namedQueryId}/{globalCustomerId}/{serviceType}/{serviceInstance}", method = RequestMethod.GET)
\r
286 public ResponseEntity<String> viewEditGetComponentList(
\r
287 @PathVariable("namedQueryId") String namedQueryId,
\r
288 @PathVariable("globalCustomerId") String globalCustomerId,
\r
289 @PathVariable("serviceType") String serviceType,
\r
290 @PathVariable("serviceInstance") String serviceInstance) {
\r
292 String componentListPayload = getComponentListPutPayload(namedQueryId, globalCustomerId, serviceType, serviceInstance);
\r
293 File certiPath = GetCertificatesPath();
\r
295 Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
\r
296 return convertResponseToResponseEntity(resp);
\r
300 * Issue a named query to a&ai.
\r
302 * @param namedQueryId the named query id
\r
303 * @param globalCustomerId the global customer id
\r
304 * @param serviceType the service type
\r
305 * @param serviceInstance the service instance
\r
306 * @return ResponseEntity The response entity
\r
308 @RequestMapping(value="/aai_get_models_by_service_type/{namedQueryId}/{globalCustomerId}/{serviceType}", method = RequestMethod.GET)
\r
309 public ResponseEntity<String> viewEditGetComponentList(
\r
310 @PathVariable("namedQueryId") String namedQueryId,
\r
311 @PathVariable("globalCustomerId") String globalCustomerId,
\r
312 @PathVariable("serviceType") String serviceType) {
\r
314 String componentListPayload = getModelsByServiceTypePayload(namedQueryId, globalCustomerId, serviceType);
\r
315 File certiPath = GetCertificatesPath();
\r
317 Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
\r
318 return convertResponseToResponseEntity(resp);
\r
322 * Parses the for tenants.
\r
324 * @param resp the resp
\r
325 * @return the string
\r
327 private String parseForTenants(String resp)
\r
329 String tenantList = "";
\r
333 JSONParser jsonParser = new JSONParser();
\r
335 JSONObject jsonObject = (JSONObject) jsonParser.parse(resp);
\r
337 return parseCustomerObjectForTenants(jsonObject);
\r
339 catch (Exception ex) {
\r
347 * Parses the for tenants by service subscription.
\r
349 * @param resp the resp
\r
350 * @return the string
\r
352 private String parseForTenantsByServiceSubscription(String resp)
\r
354 String tenantList = "";
\r
358 JSONParser jsonParser = new JSONParser();
\r
360 JSONObject jsonObject = (JSONObject) jsonParser.parse(resp);
\r
362 return parseServiceSubscriptionObjectForTenants(jsonObject);
\r
364 catch (Exception ex) {
\r
372 // @RequestMapping(value="/aai_get_tenants/{global-customer-id}", method = RequestMethod.GET)
\r
373 // public ResponseEntity<String> viewEditGetComponentList(
\r
374 // @PathVariable("global-customer-id") String globalCustomerId) {
\r
375 // return new ResponseEntity<String>(getTenants(globalCustomerId), HttpStatus.OK);
\r
379 * Obtain tenants for a given service type.
\r
381 * @param globalCustomerId the global customer id
\r
382 * @param serviceType the service type
\r
383 * @return ResponseEntity The response entity
\r
385 @RequestMapping(value="/aai_get_tenants/{global-customer-id}/{service-type}", method = RequestMethod.GET)
\r
386 public ResponseEntity<String> viewEditGetTenantsFromServiceType(
\r
387 @PathVariable("global-customer-id") String globalCustomerId, @PathVariable("service-type") String serviceType) {
\r
388 return getTenantsFromServiceType(globalCustomerId, serviceType);
\r
391 private ResponseEntity<String> convertResponseToResponseEntity(Response resp) {
\r
392 ResponseEntity<String> respEnt;
\r
393 if (resp == null) {
\r
394 respEnt = new ResponseEntity<String>("Failed to fetch data from A&AI, check server logs for details.", HttpStatus.INTERNAL_SERVER_ERROR);
\r
396 respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
402 * Gets the tenants.
\r
404 * @param globalCustomerId the global customer id
\r
405 * @return the tenants
\r
407 private ResponseEntity<String> getTenants(String globalCustomerId)
\r
409 File certiPath = GetCertificatesPath();
\r
410 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId, false);
\r
412 ResponseEntity<String> respEnt;
\r
413 if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
\r
414 respEnt = new ResponseEntity<String>(parseForTenants((String)resp.readEntity(String.class)), HttpStatus.OK);
\r
416 respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
423 * Gets the tenants from service type.
\r
425 * @param globalCustomerId the global customer id
\r
426 * @param serviceType the service type
\r
427 * @return the tenants from service type
\r
429 private ResponseEntity<String> getTenantsFromServiceType(String globalCustomerId, String serviceType)
\r
431 File certiPath = GetCertificatesPath();
\r
432 String url = "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + serviceType;
\r
434 Response resp = doAaiGet(certiPath.getAbsolutePath(), url, false);
\r
436 ResponseEntity<String> respEnt;
\r
437 if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
\r
438 respEnt = new ResponseEntity<String>(parseForTenantsByServiceSubscription((String)resp.readEntity(String.class)), HttpStatus.OK);
\r
440 respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
447 * Gets the services.
\r
449 * @return the services
\r
451 private Response getServices()
\r
453 File certiPath = GetCertificatesPath();
\r
454 Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/services", false);
\r
455 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getServices() resp=" + resp.getStatusInfo());
\r
457 //model.put("aai_get_services", resp);
\r
463 * Gets the subscribers.
\r
465 * @param isFullSet the is full set
\r
466 * @return the subscribers
\r
468 private Response getSubscribers(boolean isFullSet)
\r
470 File certiPath = GetCertificatesPath();
\r
471 String depth = "0";
\r
473 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers?subscriber-type=INFRA&depth=" + depth, false);
\r
474 if (resp != null) {
\r
475 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString());
\r
483 * Gets the subscriber details.
\r
485 * @param subscriberId the subscriber id
\r
486 * @return the subscriber details
\r
488 private Response getSubscriberDetails(String subscriberId)
\r
490 File certiPath = GetCertificatesPath();
\r
491 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId + "?depth=2", false);
\r
492 //String resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId, false);
\r
493 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscriberDetails() resp=" + resp.getStatusInfo().toString());
\r
498 * Gets the certificates path.
\r
502 private File GetCertificatesPath()
\r
504 if (servletContext != null)
\r
505 return new File( servletContext.getRealPath("/WEB-INF/cert/") );
\r
510 * Send a GET request to a&ai.
\r
512 * @param certiPath the certi path
\r
513 * @param uri the uri
\r
514 * @param xml the xml
\r
515 * @return String The response
\r
517 protected Response doAaiGet(String certiPath, String uri, boolean xml) {
\r
518 String methodName = "getSubscriberList";
\r
519 String transId = UUID.randomUUID().toString();
\r
520 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
522 Response resp = null;
\r
525 AAIRestInterface restContrller = new AAIRestInterface(certiPath);
\r
526 resp = restContrller.RestGet(fromAppId, transId, uri, xml);
\r
528 } catch (WebApplicationException e) {
\r
529 final String message = ((BadRequestException) e).getResponse().readEntity(String.class);
\r
530 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
\r
531 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
\r
532 } catch (Exception e) {
\r
533 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
534 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
541 * Send a POST request to a&ai.
\r
543 * @param certiPath the certi path
\r
544 * @param uri the uri
\r
545 * @param payload the payload
\r
546 * @param xml the xml
\r
547 * @return String The response
\r
549 protected Response doAaiPost(String certiPath, String uri, String payload, boolean xml) {
\r
550 String methodName = "getSubscriberList";
\r
551 String transId = UUID.randomUUID().toString();
\r
552 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
554 Response resp = null;
\r
557 AAIRestInterface restContrller = new AAIRestInterface(certiPath);
\r
558 resp = restContrller.RestPost(fromAppId, transId, uri, payload, xml);
\r
560 } catch (Exception e) {
\r
561 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
562 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
569 * Gets the component list put payload.
\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 the component list put payload
\r
577 private String getComponentListPutPayload(String namedQueryId, String globalCustomerId, String serviceType, String serviceInstance) {
\r
580 " \"instance-filters\": {" +
\r
581 " \"instance-filter\": [" +
\r
583 " \"customer\": {" +
\r
584 " \"global-customer-id\": \"" + globalCustomerId + "\"" +
\r
586 " \"service-instance\": {" +
\r
587 " \"service-instance-id\": \"" + serviceInstance + "\"" +
\r
589 " \"service-subscription\": {" +
\r
590 " \"service-type\": \"" + serviceType + "\"" +
\r
595 " \"query-parameters\": {" +
\r
596 " \"named-query\": {" +
\r
597 " \"named-query-uuid\": \"" + namedQueryId + "\"" +
\r
603 private String getModelsByServiceTypePayload(String namedQueryId, String globalCustomerId, String serviceType) {
\r
604 // TODO Auto-generated method stub
\r
606 " \"instance-filters\": {" +
\r
607 " \"instance-filter\": [" +
\r
609 " \"customer\": {" +
\r
610 " \"global-customer-id\": \"" + globalCustomerId + "\"" +
\r
612 " \"service-subscription\": {" +
\r
613 " \"service-type\": \"" + serviceType + "\"" +
\r
618 " \"query-parameters\": {" +
\r
619 " \"named-query\": {" +
\r
620 " \"named-query-uuid\": \"" + namedQueryId + "\"" +
\r
628 * Return tenant details.
\r
630 * @param jsonObject the json object
\r
631 * @return String The parsing results
\r
633 public static String parseCustomerObjectForTenants(JSONObject jsonObject) {
\r
635 JSONArray tenantArray = new JSONArray();
\r
636 boolean bconvert = false;
\r
640 JSONObject serviceSubsObj = (JSONObject) jsonObject.get("service-subscriptions");
\r
642 if (serviceSubsObj != null)
\r
644 JSONArray srvcSubArray = (JSONArray) serviceSubsObj.get("service-subscription");
\r
646 if (srvcSubArray != null)
\r
648 Iterator i = srvcSubArray.iterator();
\r
650 while (i.hasNext()) {
\r
652 JSONObject innerObj = (JSONObject) i.next();
\r
654 if (innerObj == null)
\r
657 JSONObject relationShipListsObj = (JSONObject) innerObj.get("relationship-list");
\r
658 if (relationShipListsObj != null)
\r
660 JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
\r
661 if (rShipArray != null)
\r
663 Iterator i1 = rShipArray.iterator();
\r
665 while (i1.hasNext()) {
\r
667 JSONObject inner1Obj = (JSONObject) i1.next();
\r
669 if (inner1Obj == null)
\r
672 String relatedTo = checkForNull((String)inner1Obj.get("related-to"));
\r
673 if (relatedTo.equalsIgnoreCase("tenant"))
\r
675 JSONObject tenantNewObj = new JSONObject();
\r
677 String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
\r
678 tenantNewObj.put("link", relatedLink);
\r
680 JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
\r
681 if (rDataArray != null)
\r
683 Iterator i2 = rDataArray.iterator();
\r
685 while (i2.hasNext()) {
\r
686 JSONObject inner2Obj = (JSONObject) i2.next();
\r
688 if (inner2Obj == null)
\r
691 String rShipKey = checkForNull((String)inner2Obj.get("relationship-key"));
\r
692 String rShipVal = checkForNull((String)inner2Obj.get("relationship-value"));
\r
693 if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner"))
\r
695 tenantNewObj.put("cloudOwner", rShipVal);
\r
697 else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id"))
\r
699 tenantNewObj.put("cloudRegionID", rShipVal);
\r
702 if (rShipKey.equalsIgnoreCase("tenant.tenant-id"))
\r
704 tenantNewObj.put("tenantID", rShipVal);
\r
709 JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
\r
710 if (relatedTPropArray != null)
\r
712 Iterator i3 = relatedTPropArray.iterator();
\r
714 while (i3.hasNext()) {
\r
715 JSONObject inner3Obj = (JSONObject) i3.next();
\r
717 if (inner3Obj == null)
\r
720 String propKey = checkForNull((String)inner3Obj.get("property-key"));
\r
721 String propVal = checkForNull((String)inner3Obj.get("property-value"));
\r
722 if (propKey.equalsIgnoreCase("tenant.tenant-name"))
\r
724 tenantNewObj.put("tenantName", propVal);
\r
729 tenantArray.add(tenantNewObj);
\r
737 } catch (NullPointerException ex) {
\r
743 return tenantArray.toJSONString();
\r
751 * Retrieve the service subscription from the jsonObject.
\r
753 * @param jsonObject the json object
\r
756 public static String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) {
\r
758 JSONArray tenantArray = new JSONArray();
\r
759 boolean bconvert = false;
\r
762 JSONObject relationShipListsObj = (JSONObject) jsonObject.get("relationship-list");
\r
763 if (relationShipListsObj != null)
\r
765 JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
\r
766 if (rShipArray != null)
\r
768 Iterator i1 = rShipArray.iterator();
\r
770 while (i1.hasNext()) {
\r
772 JSONObject inner1Obj = (JSONObject) i1.next();
\r
774 if (inner1Obj == null)
\r
777 String relatedTo = checkForNull((String)inner1Obj.get("related-to"));
\r
778 if (relatedTo.equalsIgnoreCase("tenant"))
\r
780 JSONObject tenantNewObj = new JSONObject();
\r
782 String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
\r
783 tenantNewObj.put("link", relatedLink);
\r
785 JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
\r
786 if (rDataArray != null)
\r
788 Iterator i2 = rDataArray.iterator();
\r
790 while (i2.hasNext()) {
\r
791 JSONObject inner2Obj = (JSONObject) i2.next();
\r
793 if (inner2Obj == null)
\r
796 String rShipKey = checkForNull((String)inner2Obj.get("relationship-key"));
\r
797 String rShipVal = checkForNull((String)inner2Obj.get("relationship-value"));
\r
798 if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner"))
\r
800 tenantNewObj.put("cloudOwner", rShipVal);
\r
802 else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id"))
\r
804 tenantNewObj.put("cloudRegionID", rShipVal);
\r
807 if (rShipKey.equalsIgnoreCase("tenant.tenant-id"))
\r
809 tenantNewObj.put("tenantID", rShipVal);
\r
814 JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
\r
815 if (relatedTPropArray != null)
\r
817 Iterator i3 = relatedTPropArray.iterator();
\r
819 while (i3.hasNext()) {
\r
820 JSONObject inner3Obj = (JSONObject) i3.next();
\r
822 if (inner3Obj == null)
\r
825 String propKey = checkForNull((String)inner3Obj.get("property-key"));
\r
826 String propVal = checkForNull((String)inner3Obj.get("property-value"));
\r
827 if (propKey.equalsIgnoreCase("tenant.tenant-name"))
\r
829 tenantNewObj.put("tenantName", propVal);
\r
834 tenantArray.add(tenantNewObj);
\r
840 } catch (NullPointerException ex) {
\r
846 return tenantArray.toJSONString();
\r
855 * @param local the local
\r
856 * @return the string
\r
858 private static String checkForNull(String local)
\r