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.provider.lcm.util;
27 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.StatusBuilder;
31 import org.onap.appc.Constants;
32 import org.onap.appc.configuration.Configuration;
33 import org.onap.appc.configuration.ConfigurationFactory;
34 import org.onap.appc.executor.objects.LCMCommandStatus;
35 import org.onap.appc.executor.objects.Params;
36 import org.onap.appc.i18n.Msg;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
39 import com.att.eelf.i18n.EELFResourceManager;
41 public class ValidationService {
43 private static class ValidationServiceHolder {
44 private static final ValidationService INSTANCE = new ValidationService();
47 private final EELFLogger logger = EELFManager.getInstance().getLogger(ValidationService.class);
48 private Configuration configuration = ConfigurationFactory.getConfiguration();
50 public static ValidationService getInstance(){
51 return ValidationServiceHolder.INSTANCE;
54 public Status validateInput(CommonHeader commonHeader, Action action , String rpcName) {
55 if (!isEmpty(commonHeader)
56 && !isEmpty(commonHeader.getApiVer())
57 && !isEmpty(commonHeader.getTimestamp())
58 && !isEmpty(commonHeader.getRequestId())
59 && !isEmpty(commonHeader.getOriginatorId())
60 && !isEmpty(action)) {
64 StringBuilder paramName = new StringBuilder();
65 if(isEmpty(commonHeader)){
66 paramName.append("common-header");
68 if (isEmpty(commonHeader.getApiVer())) {
69 paramName.append("api-ver");
71 if (isEmpty(commonHeader.getTimestamp())) {
72 paramName.append(isEmpty(paramName) ? "timestamp" : " , timestamp");
74 if (isEmpty(commonHeader.getRequestId())) {
75 paramName.append(isEmpty(paramName) ? "request-id" : " , request-id");
77 if (isEmpty(commonHeader.getOriginatorId())) {
78 paramName.append(isEmpty(paramName) ? "originator-id" : " , originator-id");
81 if (isEmpty(action)) {
82 paramName.append(isEmpty(paramName) ? "action" : " , action");
85 logger.info("Mandatory parameter/s" + paramName.toString() + " is/are missing");
86 String reason = EELFResourceManager.format(
87 Msg.NULL_OR_INVALID_ARGUMENT,
88 configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME),
94 LCMCommandStatus lcmCommandStatus = LCMCommandStatus.MISSING_MANDATORY_PARAMETER;
95 Params params = new Params().addParam("paramName", paramName.toString());
97 StatusBuilder status = new StatusBuilder();
98 status.setCode(lcmCommandStatus.getResponseCode());
99 status.setMessage(lcmCommandStatus.getFormattedMessage(params));
100 return status.build();
103 private boolean isEmpty(Object object) {
104 return null == object || "".equalsIgnoreCase(object.toString());