2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.client.sniro;
24 import static org.apache.commons.lang.StringUtils.*;
26 import java.util.LinkedHashMap;
28 import org.json.JSONObject;
29 import org.onap.so.client.exception.BadResponseException;
31 import org.onap.so.logger.MsoLogger;
32 import org.springframework.stereotype.Component;
37 public class SniroValidator {
39 private static final MsoLogger log = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SniroValidator.class);
42 * Validates the synchronous homing response from sniro manager
44 * @throws BadResponseException
46 public void validateDemandsResponse(LinkedHashMap<?, ?> response) throws BadResponseException {
47 log.debug("Validating Sniro Managers synchronous response");
48 if(!response.isEmpty()){
49 JSONObject jsonResponse = new JSONObject(response);
50 if(jsonResponse.has("requestStatus")){
51 String status = jsonResponse.getString("requestStatus");
52 if(status.equals("accepted")){
53 log.debug("Sniro Managers synchronous response indicates accepted");
55 String message = jsonResponse.getString("statusMessage");
56 if(isNotBlank(message)){
57 log.debug("Sniro Managers response indicates failed: " + message);
59 log.debug("Sniro Managers response indicates failed: no status message provided");
60 message = "error message not provided";
62 throw new BadResponseException("Sniro Managers synchronous response indicates failed: " + message);
65 log.debug("Sniro Managers synchronous response does not contain: request status");
66 throw new BadResponseException("Sniro Managers synchronous response does not contain: request status");
69 log.debug("Sniro Managers synchronous response is empty");
70 throw new BadResponseException("Sniro Managers synchronous response i is empty");
75 * Validates the asynchronous/callback response from sniro manager which
76 * contains the homing and licensing solutions
78 * @throws BadResponseException
80 public static void validateSolution(String response) throws BadResponseException{
81 log.debug("Validating Sniro Managers asynchronous callback response");
82 if(isNotBlank(response)) {
83 JSONObject jsonResponse = new JSONObject(response);
84 if(!jsonResponse.has("serviceException")){
85 log.debug("Sniro Managers asynchronous response is valid");
87 String message = jsonResponse.getJSONObject("serviceException").getString("text");
88 if(isNotBlank(message)){
89 log.debug("Sniro Managers response contains a service exception: " + message);
91 log.debug("Sniro Managers response contains a service exception: no service exception text provided");
92 message = "error message not provided";
94 throw new BadResponseException("Sniro Managers asynchronous response contains a service exception: " + message);
97 log.debug("Sniro Managers asynchronous response is empty");
98 throw new BadResponseException("Sniro Managers asynchronous response is empty");
104 * Validates the release response from sniro conductor
106 * @throws BadResponseException
108 public void validateReleaseResponse(LinkedHashMap<?, ?> response) throws BadResponseException {
109 log.debug("Validating Sniro Conductors response");
110 if(!response.isEmpty()){
111 String status = (String) response.get("status");
112 if(isNotBlank(status)){
113 if(status.equals("success")){
114 log.debug("Sniro Conductors synchronous response indicates success");
116 String message = (String) response.get("message");
117 if(isNotBlank(message)){
118 log.debug("Sniro Conductors response indicates failed: " + message);
120 log.debug("Sniro Conductors response indicates failed: error message not provided");
121 message = "error message not provided";
123 throw new BadResponseException("Sniro Conductors synchronous response indicates failed: " + message);
126 log.debug("Sniro Managers Conductors response does not contain: status");
127 throw new BadResponseException("Sniro Conductors synchronous response does not contain: status");
130 log.debug("Sniro Conductors response is empty");
131 throw new BadResponseException("Sniro Conductors response is empty");