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.design.dbervices;
27 import org.onap.appc.design.services.util.DesignServiceConstants;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 public class RequestValidator {
36 private static final EELFLogger log = EELFManager.getInstance().getLogger(RequestValidator.class);
37 public static void validate(String action, String payload) throws Exception {
38 log.info("payload" + payload);
39 ObjectMapper objectMapper = new ObjectMapper();
40 JsonNode payloadObject = objectMapper.readTree(payload);
41 log.info("payloadObject" + payloadObject.get(DesignServiceConstants.ARTIFACT_CONTENTS));
43 String errorString = null;
45 case DesignServiceConstants.GETDESIGNS:
46 if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty())
47 errorString = DesignServiceConstants.USER_ID;
49 case DesignServiceConstants.GETARTIFACT:
50 if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty())
51 errorString = DesignServiceConstants.VNF_TYPE;
52 else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty())
53 errorString = DesignServiceConstants.ARTIFACT_TYPE;
54 else if(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().isEmpty())
55 errorString = DesignServiceConstants.ARTIFACT_NAME;
57 case DesignServiceConstants.GETSTATUS:
58 if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty())
59 errorString = DesignServiceConstants.USER_ID;
60 else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty())
61 errorString = DesignServiceConstants.VNF_TYPE;
63 case DesignServiceConstants.SETSTATUS:
64 if(payloadObject.get(DesignServiceConstants.USER_ID) == null || payloadObject.get(DesignServiceConstants.USER_ID).textValue().isEmpty())
65 errorString = DesignServiceConstants.USER_ID;
66 else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty())
67 errorString = DesignServiceConstants.VNF_TYPE;
68 else if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty())
69 errorString = DesignServiceConstants.ACTION;
70 else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty())
71 errorString = DesignServiceConstants.ARTIFACT_TYPE;
72 else if(payloadObject.get(DesignServiceConstants.STATUS) == null || payloadObject.get(DesignServiceConstants.STATUS).textValue().isEmpty())
73 errorString = DesignServiceConstants.STATUS;
75 case DesignServiceConstants.UPLOADARTIFACT:
76 if(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().isEmpty())
77 errorString = DesignServiceConstants.ARTIFACT_NAME;
78 else if(! payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue().contains("reference")){
79 if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty())
80 errorString = DesignServiceConstants.ACTION;
82 else if(payloadObject.get(DesignServiceConstants.ARTIFACT_VERSOIN) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_VERSOIN).textValue().isEmpty())
83 errorString = DesignServiceConstants.ARTIFACT_VERSOIN;
84 else if(payloadObject.get(DesignServiceConstants.ARTIFACT_CONTENTS) == null)
85 errorString = DesignServiceConstants.ARTIFACT_CONTENTS;
86 else if(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE) == null || payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue().isEmpty())
87 errorString = DesignServiceConstants.ARTIFACT_TYPE;
89 else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty())
90 errorString = DesignServiceConstants.VNF_TYPE;
94 case DesignServiceConstants.SETPROTOCOLREFERENCE:
95 if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty())
96 errorString = DesignServiceConstants.ACTION;
97 else if(payloadObject.get(DesignServiceConstants.ACTION_LEVEL) == null || payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue().isEmpty())
98 errorString = DesignServiceConstants.ACTION_LEVEL;
99 else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty())
100 errorString = DesignServiceConstants.VNF_TYPE;
101 else if(payloadObject.get(DesignServiceConstants.PROTOCOL) == null || payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty())
102 errorString = DesignServiceConstants.PROTOCOL;
104 case DesignServiceConstants.SETINCART:
105 if(payloadObject.get(DesignServiceConstants.ACTION) == null || payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty())
106 errorString = DesignServiceConstants.ACTION;
107 else if(payloadObject.get(DesignServiceConstants.ACTION_LEVEL) == null || payloadObject.get(DesignServiceConstants.ACTION_LEVEL).textValue().isEmpty())
108 errorString = DesignServiceConstants.ACTION_LEVEL;
109 else if(payloadObject.get(DesignServiceConstants.VNF_TYPE) == null || payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty())
110 errorString = DesignServiceConstants.VNF_TYPE;
111 else if(payloadObject.get(DesignServiceConstants.PROTOCOL) == null || payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty())
112 errorString = DesignServiceConstants.PROTOCOL;
115 throw new Exception(" Action " + action + " not found while processing request ");
118 if(errorString != null)
119 throw new Exception(" Missing input parameter :-" + errorString + " -:");