2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.provider.lcm.util;
26 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
27 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.StatusBuilder;
30 import org.onap.appc.Constants;
31 import org.onap.appc.configuration.Configuration;
32 import org.onap.appc.configuration.ConfigurationFactory;
33 import org.onap.appc.executor.objects.LCMCommandStatus;
34 import org.onap.appc.executor.objects.Params;
35 import org.onap.appc.i18n.Msg;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
38 import com.att.eelf.i18n.EELFResourceManager;
40 public class ValidationService {
42 private static class ValidationServiceHolder {
43 private static final ValidationService INSTANCE = new ValidationService();
46 private final EELFLogger logger = EELFManager.getInstance().getLogger(ValidationService.class);
47 private Configuration configuration = ConfigurationFactory.getConfiguration();
49 public static ValidationService getInstance(){
50 return ValidationServiceHolder.INSTANCE;
53 public Status validateInput(CommonHeader commonHeader, Action action , String rpcName) {
54 if (!isEmpty(commonHeader)
55 && !isEmpty(commonHeader.getApiVer())
56 && !isEmpty(commonHeader.getTimestamp())
57 && !isEmpty(commonHeader.getRequestId())
58 && !isEmpty(commonHeader.getOriginatorId())
59 && !isEmpty(action)) {
63 StringBuilder paramName = new StringBuilder();
64 if(isEmpty(commonHeader)){
65 paramName.append("common-header");
67 if (isEmpty(commonHeader.getApiVer())) {
68 paramName.append("api-ver");
70 if (isEmpty(commonHeader.getTimestamp())) {
71 paramName.append(isEmpty(paramName) ? "timestamp" : " , timestamp");
73 if (isEmpty(commonHeader.getRequestId())) {
74 paramName.append(isEmpty(paramName) ? "request-id" : " , request-id");
76 if (isEmpty(commonHeader.getOriginatorId())) {
77 paramName.append(isEmpty(paramName) ? "originator-id" : " , originator-id");
80 if (isEmpty(action)) {
81 paramName.append(isEmpty(paramName) ? "action" : " , action");
84 logger.info("Mandatory parameter/s" + paramName.toString() + " is/are missing");
85 String reason = EELFResourceManager.format(
86 Msg.NULL_OR_INVALID_ARGUMENT,
87 configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME),
93 LCMCommandStatus lcmCommandStatus = LCMCommandStatus.MISSING_MANDATORY_PARAMETER;
94 Params params = new Params().addParam("paramName", paramName.toString());
96 StatusBuilder status = new StatusBuilder();
97 status.setCode(lcmCommandStatus.getResponseCode());
98 status.setMessage(lcmCommandStatus.getFormattedMessage(params));
99 return status.build();
102 private boolean isEmpty(Object object) {
103 return null == object || "".equalsIgnoreCase(object.toString());