a6fa2d29e264315ce60c67cbffabf5c7a0d99077
[so.git] / adapters / mso-vfc-adapter / src / main / java / org / openecomp / mso / adapters / vfc / util / ValidateUtil.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.mso.adapters.vfc.util;\r
22 \r
23 import org.openecomp.mso.adapters.vfc.constant.HttpCode;\r
24 import org.openecomp.mso.adapters.vfc.exceptions.ApplicationException;\r
25 import org.slf4j.Logger;\r
26 import org.slf4j.LoggerFactory;\r
27 \r
28 public class ValidateUtil {\r
29 \r
30     /**\r
31      * Log server.\r
32      */\r
33     private static final Logger LOGGER = LoggerFactory.getLogger(ValidateUtil.class);\r
34 \r
35     /**\r
36      * Constructor<br/>\r
37      * <p>\r
38      * </p>\r
39      * \r
40      * @since ONAP Amsterdam Release 2017-9-6\r
41      */\r
42     private ValidateUtil() {\r
43 \r
44     }\r
45 \r
46     /**\r
47      * Assert String parameter.<br/>\r
48      * \r
49      * @param paramValue parameter data\r
50      * @param name of parameter\r
51      * @since ONAP Amsterdam Release 2017-9-6\r
52      */\r
53     public static void assertStringNotNull(String paramValue, String paramName) throws ApplicationException {\r
54         if(null != paramValue && !paramValue.isEmpty()) {\r
55             return;\r
56         }\r
57 \r
58         LOGGER.error(paramName + ": Parameter is null or empty.");\r
59         throw new ApplicationException(HttpCode.BAD_REQUEST, paramName + ": Invalid parameter.");\r
60     }\r
61 \r
62     /**\r
63      * Assert object is null.<br/>\r
64      * \r
65      * @param object data object\r
66      * @since ONAP Amsterdam Release 2017-9-6\r
67      */\r
68     public static void assertObjectNotNull(Object object) throws ApplicationException {\r
69         if(null == object) {\r
70             LOGGER.error("Object is null.");\r
71             throw new ApplicationException(HttpCode.BAD_REQUEST, "Object is null.");\r
72         }\r
73 \r
74     }\r
75 \r
76     /**\r
77      * <br>\r
78      * \r
79      * @param str\r
80      * @return\r
81      * @since ONAP Amsterdam Release\r
82      */\r
83     public static boolean isStrEmpty(String str) {\r
84         return null == str || str.isEmpty();\r
85     }\r
86 }\r