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