2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.client.sniro;
26 import static org.apache.commons.lang3.StringUtils.*;
27 import java.util.LinkedHashMap;
28 import org.json.JSONObject;
29 import org.onap.so.client.exception.BadResponseException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.stereotype.Component;
37 public class SniroValidator {
39 private static final Logger logger = LoggerFactory.getLogger(SniroValidator.class);
42 * Validates the synchronous homing response from sniro manager
44 * @throws BadResponseException
46 public void validateDemandsResponse(LinkedHashMap<String, Object> response) throws BadResponseException {
47 logger.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 ("accepted".equals(status)) {
53 logger.debug("Sniro Managers synchronous response indicates accepted");
55 String message = jsonResponse.getString("statusMessage");
56 if (isNotBlank(message)) {
57 logger.debug("Sniro Managers response indicates failed: " + message);
59 logger.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 logger.debug("Sniro Managers synchronous response does not contain: request status");
66 throw new BadResponseException("Sniro Managers synchronous response does not contain: request status");
69 logger.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 contains the homing and licensing solutions
77 * @throws BadResponseException
79 public static void validateSolution(String response) throws BadResponseException {
80 logger.debug("Validating Sniro Managers asynchronous callback response");
81 if (isNotBlank(response)) {
82 JSONObject jsonResponse = new JSONObject(response);
83 if (!jsonResponse.has("serviceException")) {
84 logger.debug("Sniro Managers asynchronous response is valid");
86 String message = jsonResponse.getJSONObject("serviceException").getString("text");
87 if (isNotBlank(message)) {
88 logger.debug("Sniro Managers response contains a service exception: " + message);
91 "Sniro Managers response contains a service exception: no service exception text provided");
92 message = "error message not provided";
94 throw new BadResponseException(
95 "Sniro Managers asynchronous response contains a service exception: " + message);
98 logger.debug("Sniro Managers asynchronous response is empty");
99 throw new BadResponseException("Sniro Managers asynchronous response is empty");
105 * Validates the release response from sniro conductor
107 * @throws BadResponseException
109 public void validateReleaseResponse(LinkedHashMap<String, Object> response) throws BadResponseException {
110 logger.debug("Validating Sniro Conductors response");
111 if (!response.isEmpty()) {
112 String status = (String) response.get("status");
113 if (isNotBlank(status)) {
114 if ("success".equals(status)) {
115 logger.debug("Sniro Conductors synchronous response indicates success");
117 String message = (String) response.get("message");
118 if (isNotBlank(message)) {
119 logger.debug("Sniro Conductors response indicates failed: " + message);
121 logger.debug("Sniro Conductors response indicates failed: error message not provided");
122 message = "error message not provided";
124 throw new BadResponseException(
125 "Sniro Conductors synchronous response indicates failed: " + message);
128 logger.debug("Sniro Managers Conductors response does not contain: status");
129 throw new BadResponseException("Sniro Conductors synchronous response does not contain: status");
132 logger.debug("Sniro Conductors response is empty");
133 throw new BadResponseException("Sniro Conductors response is empty");