461163eaa372bad344588b12e1715c5bb52a7308
[vnfsdk/refrepo.git] /
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openo.gso.gui.servicegateway.util.validate;
18
19 import org.openo.baseservice.remoteservice.exception.ServiceException;
20 import org.openo.gso.gui.servicegateway.exception.ErrorCode;
21 import org.openo.gso.gui.servicegateway.exception.HttpCode;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.springframework.util.StringUtils;
25
26 /**
27  * Validate Util <br/>
28  * <p>
29  * </p>
30  * 
31  * @author
32  * @version GSO 0.5 2016/8/19
33  */
34 public class ValidateUtil {
35
36     /**
37      * Log server.
38      */
39     private static final Logger LOGGER = LoggerFactory.getLogger(ValidateUtil.class);
40
41     /**
42      * Constructor<br/>
43      * <p>
44      * </p>
45      * 
46      * @since GSO 0.5
47      */
48     private ValidateUtil() {
49
50     }
51
52     /**
53      * Assert String parameter.<br/>
54      * 
55      * @param param parameter data
56      * @throws ServiceException when parameter is null or empty.
57      * @since GSO 0.5
58      */
59     public static void assertStringNotNull(String param) throws ServiceException {
60         if(StringUtils.hasLength(param)) {
61             return;
62         }
63
64         LOGGER.error("Parameter is null or empty.");
65         throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, HttpCode.BAD_REQUEST);
66     }
67
68     /**
69      * Assert object is null.<br/>
70      * 
71      * @param object data object
72      * @throws ServiceException when object is null.
73      * @since GSO 0.5
74      */
75     public static void assertObjectNotNull(Object object) throws ServiceException {
76         if(null == object) {
77             LOGGER.error("Object is null.");
78             throw new ServiceException(ErrorCode.SVCMGR_SERVICEMGR_BAD_PARAM, "Object is null.");
79         }
80
81     }
82
83 }