2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.interfaces.service.executor;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.onap.appc.interfaces.service.utils.ServiceConstants;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import com.fasterxml.jackson.databind.JsonNode;
34 import com.fasterxml.jackson.databind.ObjectMapper;
36 public class RequestValidator {
38 private static final Logger log = LoggerFactory.getLogger(RequestValidator.class);
40 public static void validate(String action, String requestData, String requestDataType) throws Exception {
41 log.debug("Received validation for action= " + action + " Data :" + requestData);
43 if (requestData.isEmpty()) {
44 throw new Exception("Request Data is Empty");
46 ObjectMapper objectMapper = new ObjectMapper();
47 JsonNode payloadObject = objectMapper.readTree(requestData);
48 log.info("payloadObject" + payloadObject);
49 if (payloadObject.get(ServiceConstants.VNF) == null)
50 throw new Exception("VNF-ID is null");
51 String vnfId = payloadObject.get(ServiceConstants.VNF).toString();
53 throw new Exception("VNF-ID is blank");
54 if (payloadObject.get(ServiceConstants.CURRENTREQUEST) == null)
55 throw new Exception("Current request is null");
56 String cRequest = payloadObject.get(ServiceConstants.CURRENTREQUEST).toString();
57 if (cRequest.isEmpty())
58 throw new Exception("Current Request is blank");
59 JsonNode currentRequest = payloadObject.get(ServiceConstants.CURRENTREQUEST);
60 if (currentRequest.get(ServiceConstants.ACTION) == null)
61 throw new Exception("Action is null in Current Request");
62 String cRequestAction = currentRequest.get(ServiceConstants.ACTION).toString();
63 if (cRequestAction.isEmpty())
64 throw new Exception("Action is blank in Current Request");
65 if (currentRequest.get(ServiceConstants.ACTIONIDENTIFIER) == null)
66 throw new Exception("Action Identifier is null in Current Request");
67 String cRequestActionIdentifier = currentRequest.get(ServiceConstants.ACTIONIDENTIFIER).toString();
68 if (cRequestActionIdentifier.isEmpty())
69 throw new Exception("Action Identifier is blank in Current Request");
70 } catch (Exception e) {
72 log.debug("Error while validating: " + e.getMessage());