Replaced all tabs with spaces in java and pom.xml
[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 import org.onap.so.logger.MessageEnum;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  */
33 public class UUIDChecker {
34
35     private static final Logger logger = LoggerFactory.getLogger(UUIDChecker.class);
36
37     private UUIDChecker() {}
38
39     public static boolean isValidUUID(String id) {
40         try {
41             if (null == id) {
42                 return false;
43             }
44             UUID uuid = UUID.fromString(id);
45             return uuid.toString().equalsIgnoreCase(id);
46         } catch (IllegalArgumentException iae) {
47             logger.debug("IllegalArgumentException", iae);
48             return false;
49         }
50     }
51
52     public static String getUUID() {
53         String result = UUID.randomUUID().toString();
54         logger.info("{} {}", MessageEnum.APIH_GENERATED_REQUEST_ID, result);
55         return result;
56     }
57 }