mirror of https://github.com/apache/cloudstack.git
Rename validateUUID method to isUuid (#6793)
* Rename validateUUID method to isUuid * adds JavaDoc to isUuid method Co-authored-by: Eduardo Zanetta <eduardo.zanetta@scclouds.com.br>
This commit is contained in:
parent
8d276c0220
commit
5a54dc19b6
|
|
@ -29,7 +29,7 @@ public enum ApiArgValidator {
|
|||
PositiveNumber,
|
||||
|
||||
/**
|
||||
* Validates if the parameter is an UUID with the method {@link UuidUtils#validateUUID(String)}.
|
||||
* Validates if the parameter is an UUID with the method {@link UuidUtils#isUuid(String)}.
|
||||
*/
|
||||
UuidString,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2616,7 +2616,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
throw new InvalidParameterValueException("The VLAN tag for isolated PVLAN " + isolatedPvlan + " is already being used for dynamic vlan allocation for the guest network in zone "
|
||||
+ zone.getName());
|
||||
}
|
||||
if (!UuidUtils.validateUUID(vlanId)) {
|
||||
if (!UuidUtils.isUuid(vlanId)) {
|
||||
// For Isolated and L2 networks, don't allow to create network with vlan that already exists in the zone
|
||||
if (!hasGuestBypassVlanOverlapCheck(bypassVlanOverlapCheck, ntwkOff, isPrivateNetwork)) {
|
||||
if (_networksDao.listByZoneAndUriAndGuestType(zoneId, uri.toString(), null).size() > 0) {
|
||||
|
|
@ -2779,7 +2779,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
if (vlanIdFinal != null) {
|
||||
if (isolatedPvlan == null) {
|
||||
URI uri = null;
|
||||
if (UuidUtils.validateUUID(vlanIdFinal)) {
|
||||
if (UuidUtils.isUuid(vlanIdFinal)) {
|
||||
//Logical router's UUID provided as VLAN_ID
|
||||
userNetwork.setVlanIdAsUUID(vlanIdFinal); //Set transient field
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class InMemoryEventBusTest {
|
|||
assertNotNull(uuid);
|
||||
|
||||
String uuidStr = uuid.toString();
|
||||
assertTrue(UuidUtils.validateUUID(uuidStr));
|
||||
assertTrue(UuidUtils.isUuid(uuidStr));
|
||||
assertTrue(bus.totalSubscribers() == 1);
|
||||
|
||||
bus.unsubscribe(uuid, subscriber);
|
||||
|
|
@ -96,7 +96,7 @@ public class InMemoryEventBusTest {
|
|||
|
||||
String uuidStr = uuid.toString();
|
||||
|
||||
assertTrue(UuidUtils.validateUUID(uuidStr));
|
||||
assertTrue(UuidUtils.isUuid(uuidStr));
|
||||
assertTrue(bus.totalSubscribers() == 1);
|
||||
//
|
||||
bus.unsubscribe(uuid, subscriber);
|
||||
|
|
@ -138,7 +138,7 @@ public class InMemoryEventBusTest {
|
|||
assertNotNull(uuid);
|
||||
|
||||
String uuidStr = uuid.toString();
|
||||
assertTrue(UuidUtils.validateUUID(uuidStr));
|
||||
assertTrue(UuidUtils.isUuid(uuidStr));
|
||||
assertTrue(bus.totalSubscribers() == 1);
|
||||
|
||||
bus.publish(event);
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class VirtualMachineModel extends ModelObjectBase {
|
|||
*
|
||||
* In other fix I added the validate UUID method to the UuidUtil classes.
|
||||
*/
|
||||
if (UuidUtils.validateUUID(serviceUuid)) {
|
||||
if (UuidUtils.isUuid(serviceUuid)) {
|
||||
/* link the object with the service instance */
|
||||
buildServiceInstance(controller, serviceUuid);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class ScaleIOUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (!UuidUtils.validateUUID(result)) {
|
||||
if (!UuidUtils.isUuid(result)) {
|
||||
LOGGER.warn("Invalid SDC guid: " + result);
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||
private void validateUuidString(final Object param, final String argName) {
|
||||
String value = String.valueOf(param);
|
||||
|
||||
if (!UuidUtils.validateUUID(value)) {
|
||||
if (!UuidUtils.isUuid(value)) {
|
||||
throwInvalidParameterValueException(argName);
|
||||
}
|
||||
}
|
||||
|
|
@ -467,7 +467,7 @@ public class ParamProcessWorker implements DispatchWorker {
|
|||
// If annotation's empty, the cmd existed before 3.x try conversion to long
|
||||
final boolean isPre3x = annotation.since().isEmpty();
|
||||
// Match against Java's UUID regex to check if input is uuid string
|
||||
final boolean isUuid = UuidUtils.validateUUID(uuid);
|
||||
final boolean isUuid = UuidUtils.isUuid(uuid);
|
||||
// Enforce that it's uuid for newly added apis from version 3.x
|
||||
if (!isPre3x && !isUuid)
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -357,19 +357,19 @@ public class DomainManagerImplTest {
|
|||
@Test
|
||||
public void createDomainVoTestCreateValidUuidIfEmptyString(){
|
||||
DomainVO domainVo = domainManager.createDomainVo("test",1L,2L,"NetworkTest","");
|
||||
Assert.assertTrue(UuidUtils.validateUUID(domainVo.getUuid()));
|
||||
Assert.assertTrue(UuidUtils.isUuid(domainVo.getUuid()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDomainVoTestCreateValidUuidIfWhiteSpace(){
|
||||
DomainVO domainVo = domainManager.createDomainVo("test",1L,2L,"NetworkTest"," ");
|
||||
Assert.assertTrue(UuidUtils.validateUUID(domainVo.getUuid()));
|
||||
Assert.assertTrue(UuidUtils.isUuid(domainVo.getUuid()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDomainVoTestCreateValidUuidIfNull(){
|
||||
DomainVO domainVo = domainManager.createDomainVo("test",1L,2L,"NetworkTest",null);
|
||||
Assert.assertTrue(UuidUtils.validateUUID(domainVo.getUuid()));
|
||||
Assert.assertTrue(UuidUtils.isUuid(domainVo.getUuid()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -30,7 +30,13 @@ public class UuidUtils {
|
|||
return uuid.substring(0, uuid.indexOf('-'));
|
||||
}
|
||||
|
||||
public static boolean validateUUID(String uuid) {
|
||||
/**
|
||||
* Checks if the parameter is a valid UUID (based on {@link UuidUtils#uuidRegex}).
|
||||
* <br/>
|
||||
* Example: 24abcb8f-4211-374f-a2e1-e5c0b7e88a2d -> true
|
||||
* 24abcb8f4211374fa2e1e5c0b7e88a2dda23 -> false
|
||||
*/
|
||||
public static boolean isUuid(String uuid) {
|
||||
return uuidRegex.matches(uuid);
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +55,7 @@ public class UuidUtils {
|
|||
.append(noHyphen.substring(16, 20)).append("-")
|
||||
.append(noHyphen.substring(20, 32));
|
||||
String uuid = stringBuilder.toString();
|
||||
if (!validateUUID(uuid)) {
|
||||
if (!isUuid(uuid)) {
|
||||
throw new CloudRuntimeException("Error generating UUID");
|
||||
}
|
||||
return uuid;
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ import org.junit.Test;
|
|||
public class UuidUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testValidateUUIDPass() throws Exception {
|
||||
public void isUuidTestPass() throws Exception {
|
||||
String serviceUuid = "f81a9aa3-1f7d-466f-b04b-f2b101486bae";
|
||||
|
||||
assertTrue(UuidUtils.validateUUID(serviceUuid));
|
||||
assertTrue(UuidUtils.isUuid(serviceUuid));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUUIDFail() throws Exception {
|
||||
public void isUuidTestFail() throws Exception {
|
||||
String serviceUuid = "6fc6ce7-d503-4f95-9e68-c9cd281b13df";
|
||||
|
||||
assertFalse(UuidUtils.validateUUID(serviceUuid));
|
||||
assertFalse(UuidUtils.isUuid(serviceUuid));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue