2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.utils;
23 import org.openecomp.mso.logger.MessageEnum;
24 import org.openecomp.mso.logger.MsoLogger;
26 import java.util.UUID;
30 public class UUIDChecker {
32 private UUIDChecker() {
36 public static boolean isValidUUID (String id) {
41 UUID uuid = UUID.fromString(id);
42 return uuid.toString().equalsIgnoreCase(id);
43 } catch (IllegalArgumentException iae) {
48 private static String getUUID () {
49 return UUID.randomUUID().toString();
52 public static String verifyOldUUID (String oldId, MsoLogger msoLogger) {
53 if (!UUIDChecker.isValidUUID(oldId)) {
54 String newId = UUIDChecker.getUUID();
55 MsoLogger.setLogContext(newId, null);
56 msoLogger.info(MessageEnum.APIH_REPLACE_REQUEST_ID, oldId, "", "");
59 MsoLogger.setLogContext(oldId, null);
63 public static String generateUUID (MsoLogger msoLogger) {
64 String newId = UUIDChecker.getUUID();
65 MsoLogger.setLogContext(newId, null);
66 msoLogger.info(MessageEnum.APIH_GENERATED_REQUEST_ID, newId, "", "");
70 public static String generateServiceInstanceID (MsoLogger msoLogger) {
71 String newId = UUIDChecker.getUUID();
72 MsoLogger.setLogContext(null, newId);
73 msoLogger.info(MessageEnum.APIH_GENERATED_SERVICE_INSTANCE_ID, newId, "", "");