Skip to content

Commit 8764f60

Browse files
authored
RESTWS-953:Support setting values of type "Location" (#618)
(standardize UUID method)
1 parent 4f3e8ec commit 8764f60

File tree

4 files changed

+7
-16
lines changed

4 files changed

+7
-16
lines changed

omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public static void setValue(Obs obs, Object value) throws ParseException, Conver
452452
}
453453

454454
// if there is a potential uuid, see if there is a matching location, and,if so, set the value text as the primary key
455-
if (RestUtil.isUuid(potentialLocationUuid)) {
455+
if (RestUtil.isValidUuid(potentialLocationUuid)) {
456456
Location location = Context.getLocationService().getLocationByUuid(potentialLocationUuid);
457457
if (location != null) {
458458
obs.setValueText(location.getLocationId().toString());

omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs1_8/ConceptSearchHandler1_8.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.openmrs.api.ConceptService;
2121
import org.openmrs.module.webservices.rest.web.RequestContext;
2222
import org.openmrs.module.webservices.rest.web.RestConstants;
23+
import org.openmrs.module.webservices.rest.web.RestUtil;
2324
import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
2425
import org.openmrs.module.webservices.rest.web.resource.api.SearchConfig;
2526
import org.openmrs.module.webservices.rest.web.resource.api.SearchHandler;
@@ -89,7 +90,7 @@ public PageableResult search(RequestContext context) throws ResponseException {
8990
continue;
9091
}
9192
// handle UUIDs
92-
if (isValidUuid(conceptReference)) {
93+
if (RestUtil.isValidUuid(conceptReference)) {
9394
Concept concept = conceptService.getConceptByUuid(conceptReference);
9495
if (concept != null) {
9596
concepts.add(concept);
@@ -185,8 +186,4 @@ public PageableResult search(RequestContext context) throws ResponseException {
185186
return new NeedsPaging<Concept>(conceptsByMapping, context);
186187
}
187188
}
188-
189-
private static boolean isValidUuid(String uuid) {
190-
return uuid != null && (uuid.length() == 36 || uuid.length() == 38 || uuid.indexOf(' ') < 0 || uuid.indexOf('.') < 0);
191-
}
192189
}

omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ConceptReferenceController1_9.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Object search(HttpServletRequest request, HttpServletResponse response) {
6161
continue;
6262
}
6363
// handle UUIDs
64-
if (isValidUuid(conceptReference)) {
64+
if (RestUtil.isValidUuid(conceptReference)) {
6565
Concept concept = conceptService.getConceptByUuid(conceptReference);
6666
if (concept != null) {
6767
addResult(results, conceptReference, concept, requestContext.getRepresentation());
@@ -95,8 +95,5 @@ private void addResult(SimpleObject results, String conceptReference, Concept co
9595
ConversionUtil.convertToRepresentation(concept, rep == null ? new DefaultRepresentation() : rep));
9696
}
9797

98-
private static boolean isValidUuid(String uuid) {
99-
return uuid != null && (uuid.length() == 36 || uuid.length() == 38 || uuid.indexOf(' ') < 0
100-
|| uuid.indexOf('.') < 0);
101-
}
98+
10299
}

omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestUtil.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ public class RestUtil implements GlobalPropertyListener {
6565
private static Log log = LogFactory.getLog(RestUtil.class);
6666

6767
private static boolean contextEnabled = true;
68-
69-
private static final Pattern UUID_REGEX =
70-
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}$");
7168

7269
/**
7370
* Looks up the admin defined global property for the system limit
@@ -941,7 +938,7 @@ public static Class<?> getSupportedClass(Resource resource) {
941938
}
942939
}
943940

944-
public static boolean isUuid(String str) {
945-
return StringUtils.isNotBlank(str) && UUID_REGEX.matcher(str).matches();
941+
public static boolean isValidUuid(String uuid) {
942+
return uuid != null && (uuid.length() == 36 || uuid.length() == 38 || uuid.indexOf(' ') < 0 || uuid.indexOf('.') < 0);
946943
}
947944
}

0 commit comments

Comments
 (0)