2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.interfaces.service.executor;
27 import java.util.ArrayList;
28 import java.util.List;
30 import org.onap.appc.interfaces.service.utils.ServiceConstants;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import com.fasterxml.jackson.databind.JsonNode;
35 import com.fasterxml.jackson.databind.ObjectMapper;
37 public class RequestValidator {
39 private static final Logger log = LoggerFactory.getLogger(RequestValidator.class);
41 public static void validate(String action, String requestData, String requestDataType) throws Exception {
42 log.debug("Received validation for action= " + action + " Data :" + requestData);
44 if (requestData.isEmpty()) {
45 throw new Exception("Request Data is Empty");
47 ObjectMapper objectMapper = new ObjectMapper();
48 JsonNode payloadObject = objectMapper.readTree(requestData);
49 log.info("payloadObject" + payloadObject);
50 if (payloadObject.get(ServiceConstants.VNF) == null)
51 throw new Exception("VNF-ID is null");
52 String vnfId = payloadObject.get(ServiceConstants.VNF).toString();
54 throw new Exception("VNF-ID is blank");
55 if (payloadObject.get(ServiceConstants.CURRENTREQUEST) == null)
56 throw new Exception("Current request is null");
57 String cRequest = payloadObject.get(ServiceConstants.CURRENTREQUEST).toString();
58 if (cRequest.isEmpty())
59 throw new Exception("Current Request is blank");
60 JsonNode currentRequest = payloadObject.get(ServiceConstants.CURRENTREQUEST);
61 if (currentRequest.get(ServiceConstants.ACTION) == null)
62 throw new Exception("Action is null in Current Request");
63 String cRequestAction = currentRequest.get(ServiceConstants.ACTION).toString();
64 if (cRequestAction.isEmpty())
65 throw new Exception("Action is blank in Current Request");
66 if (currentRequest.get(ServiceConstants.ACTIONIDENTIFIER) == null)
67 throw new Exception("Action Identifier is null in Current Request");
68 String cRequestActionIdentifier = currentRequest.get(ServiceConstants.ACTIONIDENTIFIER).toString();
69 if (cRequestActionIdentifier.isEmpty())
70 throw new Exception("Action Identifier is blank in Current Request");
71 } catch (Exception e) {
73 log.debug("Error while validating: " + e.getMessage());