Removed MsoLogger from UUIDChecker
[so.git] / common / src / main / java / org / onap / so / utils / UUIDChecker.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.so.utils;
25
26 import java.util.UUID;
27
28 import org.onap.so.logger.MessageEnum;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  */
34 public class UUIDChecker {
35
36     private static final Logger logger = LoggerFactory.getLogger(UUIDChecker.class);
37
38     private UUIDChecker() {
39     }
40
41     public static boolean isValidUUID (String id) {
42         try {
43             if (null == id) {
44                 return false;
45             }
46             UUID uuid = UUID.fromString(id);
47             return uuid.toString().equalsIgnoreCase(id);
48         } catch (IllegalArgumentException iae) {
49             logger.debug("IllegalArgumentException", iae);
50             return false;
51         }
52     }
53
54     public static String getUUID () {
55         String result = UUID.randomUUID().toString();
56         logger.info("{} {}", MessageEnum.APIH_GENERATED_REQUEST_ID, result);
57         return result;
58     }
59 }