diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java index 45ca8a132..a4b1e4de0 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java @@ -452,7 +452,7 @@ public static void setValue(Obs obs, Object value) throws ParseException, Conver } // if there is a potential uuid, see if there is a matching location, and,if so, set the value text as the primary key - if (RestUtil.isUuid(potentialLocationUuid)) { + if (RestUtil.isValidUuid(potentialLocationUuid)) { Location location = Context.getLocationService().getLocationByUuid(potentialLocationUuid); if (location != null) { obs.setValueText(location.getLocationId().toString()); diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs1_8/ConceptSearchHandler1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs1_8/ConceptSearchHandler1_8.java index 1da7ab0fc..668c9128b 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs1_8/ConceptSearchHandler1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs1_8/ConceptSearchHandler1_8.java @@ -20,6 +20,7 @@ import org.openmrs.api.ConceptService; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.RestUtil; import org.openmrs.module.webservices.rest.web.resource.api.PageableResult; import org.openmrs.module.webservices.rest.web.resource.api.SearchConfig; import org.openmrs.module.webservices.rest.web.resource.api.SearchHandler; @@ -89,7 +90,7 @@ public PageableResult search(RequestContext context) throws ResponseException { continue; } // handle UUIDs - if (isValidUuid(conceptReference)) { + if (RestUtil.isValidUuid(conceptReference)) { Concept concept = conceptService.getConceptByUuid(conceptReference); if (concept != null) { concepts.add(concept); @@ -185,8 +186,4 @@ public PageableResult search(RequestContext context) throws ResponseException { return new NeedsPaging(conceptsByMapping, context); } } - - private static boolean isValidUuid(String uuid) { - return uuid != null && (uuid.length() == 36 || uuid.length() == 38 || uuid.indexOf(' ') < 0 || uuid.indexOf('.') < 0); - } } diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceController1_9.java index 7fd10f9c2..c35ea9cd9 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceController1_9.java @@ -61,7 +61,7 @@ public Object search(HttpServletRequest request, HttpServletResponse response) { continue; } // handle UUIDs - if (isValidUuid(conceptReference)) { + if (RestUtil.isValidUuid(conceptReference)) { Concept concept = conceptService.getConceptByUuid(conceptReference); if (concept != null) { addResult(results, conceptReference, concept, requestContext.getRepresentation()); @@ -95,8 +95,5 @@ private void addResult(SimpleObject results, String conceptReference, Concept co ConversionUtil.convertToRepresentation(concept, rep == null ? new DefaultRepresentation() : rep)); } - private static boolean isValidUuid(String uuid) { - return uuid != null && (uuid.length() == 36 || uuid.length() == 38 || uuid.indexOf(' ') < 0 - || uuid.indexOf('.') < 0); - } + } diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestUtil.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestUtil.java index 5b43e48c4..552442c83 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestUtil.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestUtil.java @@ -65,9 +65,6 @@ public class RestUtil implements GlobalPropertyListener { private static Log log = LogFactory.getLog(RestUtil.class); private static boolean contextEnabled = true; - - private static final Pattern UUID_REGEX = - Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); /** * Looks up the admin defined global property for the system limit @@ -941,7 +938,7 @@ public static Class getSupportedClass(Resource resource) { } } - public static boolean isUuid(String str) { - return StringUtils.isNotBlank(str) && UUID_REGEX.matcher(str).matches(); + public static boolean isValidUuid(String uuid) { + return uuid != null && (uuid.length() == 36 || uuid.length() == 38 || uuid.indexOf(' ') < 0 || uuid.indexOf('.') < 0); } }