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 * @return ResponseEntity The response entity
\r
307 @RequestMapping(value="/aai_get_models_by_service_type/{namedQueryId}/{globalCustomerId}/{serviceType}", method = RequestMethod.GET)
\r
308 public ResponseEntity<String> viewEditGetComponentList(
\r
309 @PathVariable("namedQueryId") String namedQueryId,
\r
310 @PathVariable("globalCustomerId") String globalCustomerId,
\r
311 @PathVariable("serviceType") String serviceType) {
\r
313 String componentListPayload = getModelsByServiceTypePayload(namedQueryId, globalCustomerId, serviceType);
\r
314 File certiPath = GetCertificatesPath();
\r
316 Response resp = doAaiPost(certiPath.getAbsolutePath(), "search/named-query", componentListPayload, false);
\r
317 return convertResponseToResponseEntity(resp);
\r
321 * Parses the for tenants.
\r
323 * @param resp the resp
\r
324 * @return the string
\r
326 private String parseForTenants(String resp)
\r
328 String tenantList = "";
\r
332 JSONParser jsonParser = new JSONParser();
\r
334 JSONObject jsonObject = (JSONObject) jsonParser.parse(resp);
\r
336 return parseCustomerObjectForTenants(jsonObject);
\r
338 catch (Exception ex) {
\r
346 * Parses the for tenants by service subscription.
\r
348 * @param resp the resp
\r
349 * @return the string
\r
351 private String parseForTenantsByServiceSubscription(String resp)
\r
353 String tenantList = "";
\r
357 JSONParser jsonParser = new JSONParser();
\r
359 JSONObject jsonObject = (JSONObject) jsonParser.parse(resp);
\r
361 return parseServiceSubscriptionObjectForTenants(jsonObject);
\r
363 catch (Exception ex) {
\r
371 // @RequestMapping(value="/aai_get_tenants/{global-customer-id}", method = RequestMethod.GET)
\r
372 // public ResponseEntity<String> viewEditGetComponentList(
\r
373 // @PathVariable("global-customer-id") String globalCustomerId) {
\r
374 // return new ResponseEntity<String>(getTenants(globalCustomerId), HttpStatus.OK);
\r
378 * Obtain tenants for a given service type.
\r
380 * @param globalCustomerId the global customer id
\r
381 * @param serviceType the service type
\r
382 * @return ResponseEntity The response entity
\r
384 @RequestMapping(value="/aai_get_tenants/{global-customer-id}/{service-type}", method = RequestMethod.GET)
\r
385 public ResponseEntity<String> viewEditGetTenantsFromServiceType(
\r
386 @PathVariable("global-customer-id") String globalCustomerId, @PathVariable("service-type") String serviceType) {
\r
387 return getTenantsFromServiceType(globalCustomerId, serviceType);
\r
390 private ResponseEntity<String> convertResponseToResponseEntity(Response resp) {
\r
391 ResponseEntity<String> respEnt;
\r
392 if (resp == null) {
\r
393 respEnt = new ResponseEntity<String>("Failed to fetch data from A&AI, check server logs for details.", HttpStatus.INTERNAL_SERVER_ERROR);
\r
395 respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
401 * Gets the tenants.
\r
403 * @param globalCustomerId the global customer id
\r
404 * @return the tenants
\r
406 private ResponseEntity<String> getTenants(String globalCustomerId)
\r
408 File certiPath = GetCertificatesPath();
\r
409 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + globalCustomerId, false);
\r
411 ResponseEntity<String> respEnt;
\r
412 if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
\r
413 respEnt = new ResponseEntity<String>(parseForTenants((String)resp.readEntity(String.class)), HttpStatus.OK);
\r
415 respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
422 * Gets the tenants from service type.
\r
424 * @param globalCustomerId the global customer id
\r
425 * @param serviceType the service type
\r
426 * @return the tenants from service type
\r
428 private ResponseEntity<String> getTenantsFromServiceType(String globalCustomerId, String serviceType)
\r
430 File certiPath = GetCertificatesPath();
\r
431 String url = "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + serviceType;
\r
433 Response resp = doAaiGet(certiPath.getAbsolutePath(), url, false);
\r
435 ResponseEntity<String> respEnt;
\r
436 if (resp.getStatus() >= 200 && resp.getStatus() <= 299) {
\r
437 respEnt = new ResponseEntity<String>(parseForTenantsByServiceSubscription((String)resp.readEntity(String.class)), HttpStatus.OK);
\r
439 respEnt = new ResponseEntity<String>((String)resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus()));
\r
446 * Gets the services.
\r
448 * @return the services
\r
450 private Response getServices()
\r
452 File certiPath = GetCertificatesPath();
\r
453 Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/services", false);
\r
454 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getServices() resp=" + resp.getStatusInfo());
\r
456 //model.put("aai_get_services", resp);
\r
462 * Gets the subscribers.
\r
464 * @param isFullSet the is full set
\r
465 * @return the subscribers
\r
467 private Response getSubscribers(boolean isFullSet)
\r
469 File certiPath = GetCertificatesPath();
\r
470 String depth = "0";
\r
472 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers?subscriber-type=INFRA&depth=" + depth, false);
\r
473 if (resp != null) {
\r
474 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString());
\r
482 * Gets the subscriber details.
\r
484 * @param subscriberId the subscriber id
\r
485 * @return the subscriber details
\r
487 private Response getSubscriberDetails(String subscriberId)
\r
489 File certiPath = GetCertificatesPath();
\r
490 Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId + "?depth=2", false);
\r
491 //String resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId, false);
\r
492 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscriberDetails() resp=" + resp.getStatusInfo().toString());
\r
497 * Gets the certificates path.
\r
501 private File GetCertificatesPath()
\r
503 if (servletContext != null)
\r
504 return new File( servletContext.getRealPath("/WEB-INF/cert/") );
\r
509 * Send a GET request to a&ai.
\r
511 * @param certiPath the certi path
\r
512 * @param uri the uri
\r
513 * @param xml the xml
\r
514 * @return String The response
\r
516 protected Response doAaiGet(String certiPath, String uri, boolean xml) {
\r
517 String methodName = "getSubscriberList";
\r
518 String transId = UUID.randomUUID().toString();
\r
519 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
521 Response resp = null;
\r
524 AAIRestInterface restContrller = new AAIRestInterface(certiPath);
\r
525 resp = restContrller.RestGet(fromAppId, transId, uri, xml);
\r
527 } catch (WebApplicationException e) {
\r
528 final String message = ((BadRequestException) e).getResponse().readEntity(String.class);
\r
529 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
\r
530 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
\r
531 } catch (Exception e) {
\r
532 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
533 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
540 * Send a POST request to a&ai.
\r
542 * @param certiPath the certi path
\r
543 * @param uri the uri
\r
544 * @param payload the payload
\r
545 * @param xml the xml
\r
546 * @return String The response
\r
548 protected Response doAaiPost(String certiPath, String uri, String payload, boolean xml) {
\r
549 String methodName = "getSubscriberList";
\r
550 String transId = UUID.randomUUID().toString();
\r
551 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
\r
553 Response resp = null;
\r
556 AAIRestInterface restContrller = new AAIRestInterface(certiPath);
\r
557 resp = restContrller.RestPost(fromAppId, transId, uri, payload, xml);
\r
559 } catch (Exception e) {
\r
560 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
561 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
\r
568 * Gets the component list put payload.
\r
570 * @param namedQueryId the named query id
\r
571 * @param globalCustomerId the global customer id
\r
572 * @param serviceType the service type
\r
573 * @param serviceInstance the service instance
\r
574 * @return the component list put payload
\r
576 private String getComponentListPutPayload(String namedQueryId, String globalCustomerId, String serviceType, String serviceInstance) {
\r
579 " \"instance-filters\": {" +
\r
580 " \"instance-filter\": [" +
\r
582 " \"customer\": {" +
\r
583 " \"global-customer-id\": \"" + globalCustomerId + "\"" +
\r
585 " \"service-instance\": {" +
\r
586 " \"service-instance-id\": \"" + serviceInstance + "\"" +
\r
588 " \"service-subscription\": {" +
\r
589 " \"service-type\": \"" + serviceType + "\"" +
\r
594 " \"query-parameters\": {" +
\r
595 " \"named-query\": {" +
\r
596 " \"named-query-uuid\": \"" + namedQueryId + "\"" +
\r
602 private String getModelsByServiceTypePayload(String namedQueryId, String globalCustomerId, String serviceType) {
\r
603 // TODO Auto-generated method stub
\r
605 " \"instance-filters\": {" +
\r
606 " \"instance-filter\": [" +
\r
608 " \"customer\": {" +
\r
609 " \"global-customer-id\": \"" + globalCustomerId + "\"" +
\r
611 " \"service-subscription\": {" +
\r
612 " \"service-type\": \"" + serviceType + "\"" +
\r
617 " \"query-parameters\": {" +
\r
618 " \"named-query\": {" +
\r
619 " \"named-query-uuid\": \"" + namedQueryId + "\"" +
\r
627 * Return tenant details.
\r
629 * @param jsonObject the json object
\r
630 * @return String The parsing results
\r
632 public static String parseCustomerObjectForTenants(JSONObject jsonObject) {
\r
634 JSONArray tenantArray = new JSONArray();
\r
635 boolean bconvert = false;
\r
639 JSONObject serviceSubsObj = (JSONObject) jsonObject.get("service-subscriptions");
\r
641 if (serviceSubsObj != null)
\r
643 JSONArray srvcSubArray = (JSONArray) serviceSubsObj.get("service-subscription");
\r
645 if (srvcSubArray != null)
\r
647 Iterator i = srvcSubArray.iterator();
\r
649 while (i.hasNext()) {
\r
651 JSONObject innerObj = (JSONObject) i.next();
\r
653 if (innerObj == null)
\r
656 JSONObject relationShipListsObj = (JSONObject) innerObj.get("relationship-list");
\r
657 if (relationShipListsObj != null)
\r
659 JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
\r
660 if (rShipArray != null)
\r
662 Iterator i1 = rShipArray.iterator();
\r
664 while (i1.hasNext()) {
\r
666 JSONObject inner1Obj = (JSONObject) i1.next();
\r
668 if (inner1Obj == null)
\r
671 String relatedTo = checkForNull((String)inner1Obj.get("related-to"));
\r
672 if (relatedTo.equalsIgnoreCase("tenant"))
\r
674 JSONObject tenantNewObj = new JSONObject();
\r
676 String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
\r
677 tenantNewObj.put("link", relatedLink);
\r
679 JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
\r
680 if (rDataArray != null)
\r
682 Iterator i2 = rDataArray.iterator();
\r
684 while (i2.hasNext()) {
\r
685 JSONObject inner2Obj = (JSONObject) i2.next();
\r
687 if (inner2Obj == null)
\r
690 String rShipKey = checkForNull((String)inner2Obj.get("relationship-key"));
\r
691 String rShipVal = checkForNull((String)inner2Obj.get("relationship-value"));
\r
692 if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner"))
\r
694 tenantNewObj.put("cloudOwner", rShipVal);
\r
696 else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id"))
\r
698 tenantNewObj.put("cloudRegionID", rShipVal);
\r
701 if (rShipKey.equalsIgnoreCase("tenant.tenant-id"))
\r
703 tenantNewObj.put("tenantID", rShipVal);
\r
708 JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
\r
709 if (relatedTPropArray != null)
\r
711 Iterator i3 = relatedTPropArray.iterator();
\r
713 while (i3.hasNext()) {
\r
714 JSONObject inner3Obj = (JSONObject) i3.next();
\r
716 if (inner3Obj == null)
\r
719 String propKey = checkForNull((String)inner3Obj.get("property-key"));
\r
720 String propVal = checkForNull((String)inner3Obj.get("property-value"));
\r
721 if (propKey.equalsIgnoreCase("tenant.tenant-name"))
\r
723 tenantNewObj.put("tenantName", propVal);
\r
728 tenantArray.add(tenantNewObj);
\r
736 } catch (NullPointerException ex) {
\r
742 return tenantArray.toJSONString();
\r
750 * Retrieve the service subscription from the jsonObject.
\r
752 * @param jsonObject the json object
\r
755 public static String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) {
\r
757 JSONArray tenantArray = new JSONArray();
\r
758 boolean bconvert = false;
\r
761 JSONObject relationShipListsObj = (JSONObject) jsonObject.get("relationship-list");
\r
762 if (relationShipListsObj != null)
\r
764 JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
\r
765 if (rShipArray != null)
\r
767 Iterator i1 = rShipArray.iterator();
\r
769 while (i1.hasNext()) {
\r
771 JSONObject inner1Obj = (JSONObject) i1.next();
\r
773 if (inner1Obj == null)
\r
776 String relatedTo = checkForNull((String)inner1Obj.get("related-to"));
\r
777 if (relatedTo.equalsIgnoreCase("tenant"))
\r
779 JSONObject tenantNewObj = new JSONObject();
\r
781 String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
\r
782 tenantNewObj.put("link", relatedLink);
\r
784 JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
\r
785 if (rDataArray != null)
\r
787 Iterator i2 = rDataArray.iterator();
\r
789 while (i2.hasNext()) {
\r
790 JSONObject inner2Obj = (JSONObject) i2.next();
\r
792 if (inner2Obj == null)
\r
795 String rShipKey = checkForNull((String)inner2Obj.get("relationship-key"));
\r
796 String rShipVal = checkForNull((String)inner2Obj.get("relationship-value"));
\r
797 if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner"))
\r
799 tenantNewObj.put("cloudOwner", rShipVal);
\r
801 else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id"))
\r
803 tenantNewObj.put("cloudRegionID", rShipVal);
\r
806 if (rShipKey.equalsIgnoreCase("tenant.tenant-id"))
\r
808 tenantNewObj.put("tenantID", rShipVal);
\r
813 JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
\r
814 if (relatedTPropArray != null)
\r
816 Iterator i3 = relatedTPropArray.iterator();
\r
818 while (i3.hasNext()) {
\r
819 JSONObject inner3Obj = (JSONObject) i3.next();
\r
821 if (inner3Obj == null)
\r
824 String propKey = checkForNull((String)inner3Obj.get("property-key"));
\r
825 String propVal = checkForNull((String)inner3Obj.get("property-value"));
\r
826 if (propKey.equalsIgnoreCase("tenant.tenant-name"))
\r
828 tenantNewObj.put("tenantName", propVal);
\r
833 tenantArray.add(tenantNewObj);
\r
839 } catch (NullPointerException ex) {
\r
845 return tenantArray.toJSONString();
\r
854 * @param local the local
\r
855 * @return the string
\r
857 private static String checkForNull(String local)
\r