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 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.so.utils;
24 import java.util.UUID;
26 import org.onap.so.logger.MessageEnum;
27 import org.onap.so.logger.MsoLogger;
31 public class UUIDChecker {
33 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL, UUIDChecker.class);
35 private UUIDChecker() {
39 public static boolean isValidUUID (String id) {
44 UUID uuid = UUID.fromString(id);
45 return uuid.toString().equalsIgnoreCase(id);
46 } catch (IllegalArgumentException iae) {
47 LOGGER.debug("IllegalArgumentException", iae);
52 public static String getUUID () {
53 return UUID.randomUUID().toString();
56 public static String verifyOldUUID (String oldId, MsoLogger msoLogger) {
57 if (!UUIDChecker.isValidUUID(oldId)) {
58 String newId = UUIDChecker.getUUID();
59 MsoLogger.setLogContext(newId, null);
60 msoLogger.info(MessageEnum.APIH_REPLACE_REQUEST_ID, oldId, "", "");
63 MsoLogger.setLogContext(oldId, null);
67 public static String generateUUID (MsoLogger msoLogger) {
68 String newId = UUIDChecker.getUUID();
69 MsoLogger.setLogContext(newId, null);
70 msoLogger.info(MessageEnum.APIH_GENERATED_REQUEST_ID, newId, "", "");
74 public static String generateServiceInstanceID (MsoLogger msoLogger) {
75 String newId = UUIDChecker.getUUID();
76 MsoLogger.setLogContext(null, newId);
77 msoLogger.info(MessageEnum.APIH_GENERATED_SERVICE_INSTANCE_ID, newId, "", "");