13727bdc49a231be6ec2dba994b5b46c9eb16cbf
[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.openecomp.mso.logger.MessageEnum;\r
26 import org.openecomp.mso.logger.MsoLogger;\r
27 \r
28 public class ValidateUtil {\r
29 \r
30   /**\r
31    * Log server.\r
32    */\r
33   private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);\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 paramName parameter name\r
51    * @since ONAP Amsterdam Release 2017-9-6\r
52    */\r
53   public static void assertStringNotNull(String paramValue, String paramName)\r
54       throws ApplicationException {\r
55     if (null != paramValue && !paramValue.isEmpty()) {\r
56       return;\r
57     }\r
58     LOGGER.error(MessageEnum.RA_NS_EXC, "VFC Adapter", "", MsoLogger.ErrorCode.AvailabilityError, paramName + ": Parameter is null or empty.");\r
59 \r
60     throw new ApplicationException(HttpCode.BAD_REQUEST, paramName + ": Invalid parameter.");\r
61   }\r
62 \r
63   /**\r
64    * Assert object is null.<br/>\r
65    * \r
66    * @param object data object\r
67    * @since ONAP Amsterdam Release 2017-9-6\r
68    */\r
69   public static void assertObjectNotNull(Object object) throws ApplicationException {\r
70     if (null == object) {\r
71       LOGGER.error(MessageEnum.RA_NS_EXC, "VFC Adapter", "", MsoLogger.ErrorCode.AvailabilityError, "Object is null.");\r
72 \r
73       throw new ApplicationException(HttpCode.BAD_REQUEST, "Object is null.");\r
74     }\r
75 \r
76   }\r
77 \r
78   /**\r
79    * <br>\r
80    * \r
81    * @param str\r
82    * @return\r
83    * @since ONAP Amsterdam Release\r
84    */\r
85   public static boolean isStrEmpty(String str) {\r
86     return null == str || str.isEmpty();\r
87   }\r
88 }\r