blob: 24537c47a561fb43687a889a704ab0db697e5400 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*-
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ============LICENSE_END=========================================================
*/
package org.onap.appc.interfaces.service.executor;
import java.util.ArrayList;
import java.util.List;
import org.onap.appc.interfaces.service.utils.ServiceConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class RequestValidator {
private static final Logger log = LoggerFactory.getLogger(RequestValidator.class);
public static void validate(String action, String requestData, String requestDataType) throws Exception {
log.debug("Received validation for action= " + action + " Data :" + requestData);
try {
if (requestData.isEmpty()) {
throw new Exception("Request Data is Empty");
}
ObjectMapper objectMapper = new ObjectMapper();
JsonNode payloadObject = objectMapper.readTree(requestData);
log.info("payloadObject" + payloadObject);
if (payloadObject.get(ServiceConstants.VNF) == null)
throw new Exception("VNF-ID is null");
String vnfId = payloadObject.get(ServiceConstants.VNF).toString();
if (vnfId.isEmpty())
throw new Exception("VNF-ID is blank");
if (payloadObject.get(ServiceConstants.CURRENTREQUEST) == null)
throw new Exception("Current request is null");
String cRequest = payloadObject.get(ServiceConstants.CURRENTREQUEST).toString();
if (cRequest.isEmpty())
throw new Exception("Current Request is blank");
JsonNode currentRequest = payloadObject.get(ServiceConstants.CURRENTREQUEST);
if (currentRequest.get(ServiceConstants.ACTION) == null)
throw new Exception("Action is null in Current Request");
String cRequestAction = currentRequest.get(ServiceConstants.ACTION).toString();
if (cRequestAction.isEmpty())
throw new Exception("Action is blank in Current Request");
if (currentRequest.get(ServiceConstants.ACTIONIDENTIFIER) == null)
throw new Exception("Action Identifier is null in Current Request");
String cRequestActionIdentifier = currentRequest.get(ServiceConstants.ACTIONIDENTIFIER).toString();
if (cRequestActionIdentifier.isEmpty())
throw new Exception("Action Identifier is blank in Current Request");
} catch (Exception e) {
e.printStackTrace();
log.debug("Error while validating: " + e.getMessage());
throw e;
}
}
}
|