2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.utils;
25 import java.util.UUID;
27 import org.onap.so.logger.MessageEnum;
28 import org.onap.so.logger.MsoLogger;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
34 public class UUIDChecker {
36 private static final Logger logger = LoggerFactory.getLogger(UUIDChecker.class);
39 private UUIDChecker() {
43 public static boolean isValidUUID (String id) {
48 UUID uuid = UUID.fromString(id);
49 return uuid.toString().equalsIgnoreCase(id);
50 } catch (IllegalArgumentException iae) {
51 logger.debug("IllegalArgumentException", iae);
56 public static String getUUID () {
57 return UUID.randomUUID().toString();
60 public static String verifyOldUUID (String oldId, MsoLogger msoLogger) {
61 if (!UUIDChecker.isValidUUID(oldId)) {
62 String newId = UUIDChecker.getUUID();
63 MsoLogger.setLogContext(newId, null);
64 msoLogger.info(MessageEnum.APIH_REPLACE_REQUEST_ID, oldId, "", "");
67 MsoLogger.setLogContext(oldId, null);
71 public static String generateUUID (MsoLogger msoLogger) {
72 String newId = UUIDChecker.getUUID();
73 MsoLogger.setLogContext(newId, null);
74 msoLogger.info(MessageEnum.APIH_GENERATED_REQUEST_ID, newId, "", "");
78 public static String generateServiceInstanceID (MsoLogger msoLogger) {
79 String newId = UUIDChecker.getUUID();
80 MsoLogger.setLogContext(null, newId);
81 msoLogger.info(MessageEnum.APIH_GENERATED_SERVICE_INSTANCE_ID, newId, "", "");