2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.dg.util.impl;
25 import java.util.HashMap;
28 import java.util.regex.Pattern;
30 import org.openecomp.appc.dg.util.InputParameterValidation;
31 import org.openecomp.appc.exceptions.APPCException;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import org.openecomp.sdnc.sli.SvcLogicContext;
38 public class InputParameterValidationImpl implements InputParameterValidation
40 private static final char NL = '\n';
41 private static final EELFLogger logger = EELFManager.getInstance().getLogger(InputParameterValidationImpl.class);
43 public InputParameterValidationImpl() {
47 @SuppressWarnings("nls")
49 public void validateAttribute(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
50 Map<String, String> contextParams=getValueFromContext(ctx);
51 boolean isSuccess = true;
53 for (String k : params.keySet()) {
54 logger.info("validating attribute " + k);
55 if (!contextParams.containsKey(k)) {
56 logger.info("missing attribute " + k);
59 if(contextParams.get(k)==null){
60 logger.info("mandatory attribute " + k+ "is null");
64 }catch (NullPointerException np) {
67 ctx.setAttribute("validateAttribute", String.valueOf(isSuccess));
70 @SuppressWarnings("nls")
72 public void validateAttributeLength(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
73 Map<String, String> contextParams=getValueFromContext(ctx);
74 boolean isSuccess =true;
76 int maxLength = Integer.parseInt(params.get("maximum_length_param"));
77 params.remove("maximum_length_param");
79 for (String k : params.keySet()) {
80 logger.info("validating attribute " + k);
81 if(contextParams.get(k).length() > maxLength){
82 logger.info("attribute " + k+ "'s length is exceeding Maximum limit of " + maxLength +" character");
86 }catch (NullPointerException np) {
89 ctx.setAttribute("validateAttributeLength", String.valueOf(isSuccess));
92 @SuppressWarnings("nls")
94 public void validateAttributeCharacter(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
95 Map<String, String> contextParams=getValueFromContext(ctx);
96 boolean isSuccess =true;
98 String specialCharacter = params.get("special_characters");
99 String pattern = ".*[" + Pattern.quote(specialCharacter) + "].*";
100 params.remove("special_characters");
102 for (String k : params.keySet()) {
103 logger.info("validating attribute " + k);
104 if(contextParams.get(k).matches(pattern)){
105 logger.info("attribute " + k + " contains any of these " + specialCharacter + " special character ");
110 }catch (NullPointerException np) {
113 ctx.setAttribute("validateAttributeCharacter", String.valueOf(isSuccess));
117 private Map<String, String> getValueFromContext(SvcLogicContext context) {
118 Set<String> keys = context.getAttributeKeySet();
119 Map<String, String> params = new HashMap<String, String>();
120 StringBuilder builder = new StringBuilder();
121 if (keys != null && !keys.isEmpty()) {
123 for (String key : keys) {
124 String value = context.getAttribute(key);
125 params.put(key,value);