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.provider.lcm.util;
25 import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.Action;
26 import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.CommonHeader;
27 import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.status.Status;
28 import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.status.StatusBuilder;
29 import org.openecomp.appc.Constants;
30 import org.openecomp.appc.configuration.Configuration;
31 import org.openecomp.appc.configuration.ConfigurationFactory;
32 import org.openecomp.appc.executor.objects.LCMCommandStatus;
33 import org.openecomp.appc.executor.objects.Params;
34 import org.openecomp.appc.i18n.Msg;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
37 import com.att.eelf.i18n.EELFResourceManager;
43 public class ValidationService {
45 private static class ValidationServiceHolder {
46 private static final ValidationService INSTANCE = new ValidationService();
49 private final EELFLogger logger = EELFManager.getInstance().getLogger(ValidationService.class);
51 private Configuration configuration = ConfigurationFactory.getConfiguration();
53 public static ValidationService getInstance(){
54 return ValidationServiceHolder.INSTANCE;
57 public Status validateInput (CommonHeader commonHeader, Action action , String rpcName) {
58 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
60 StringBuilder paramName = new StringBuilder("");
61 if (!isEmpty(commonHeader) && !isEmpty(commonHeader.getApiVer())&& !isEmpty(commonHeader.getTimestamp()) && !isEmpty(commonHeader.getRequestId()) && !isEmpty(action) && !isEmpty(commonHeader.getOriginatorId())){
62 if(!action.toString().equalsIgnoreCase(rpcName)) logger.warn("action in input request '" + action.toString() + "' is different from endpoint '" + rpcName + "'");
65 if(isEmpty(commonHeader)){
66 paramName.append("common-header");
68 if (isEmpty(commonHeader.getApiVer())) paramName.append("api-ver");
69 if (isEmpty(commonHeader.getTimestamp())) paramName.append(isEmpty(paramName) ? "timestamp" : " , timestamp" );
70 if (isEmpty(commonHeader.getRequestId())) paramName.append(isEmpty(paramName) ? "request-id" : " , request-id" );
71 if (isEmpty(commonHeader.getOriginatorId())) paramName.append(isEmpty(paramName) ? "originator-id" : " , originator-id" );
73 if (isEmpty(action)) paramName.append(isEmpty(paramName) ? "action" : " , action" );
78 reason = EELFResourceManager.format(Msg.NULL_OR_INVALID_ARGUMENT, appName, rpcName, paramName.toString() , "");
79 logger.info("Mandatory parameter/s" + paramName.toString() + " is/are missing");
81 LCMCommandStatus lcmCommandStatus = LCMCommandStatus.MISSING_MANDATORY_PARAMETER;
82 Params params = new Params().addParam("paramName", paramName.toString());
83 StatusBuilder status = new StatusBuilder();
84 status.setCode(lcmCommandStatus.getResponseCode());
85 status.setMessage(lcmCommandStatus.getFormattedMessage(params));
86 return status.build();
89 private boolean isEmpty (Object object){
90 return (null == object || "".equalsIgnoreCase(object.toString()));