Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTWS-953: Support setting values of type "Location" #618

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -185,8 +186,4 @@ public PageableResult search(RequestContext context) throws ResponseException {
return new NeedsPaging<Concept>(conceptsByMapping, context);
}
}

private static boolean isValidUuid(String uuid) {
return uuid != null && (uuid.length() == 36 || uuid.length() == 38 || uuid.indexOf(' ') < 0 || uuid.indexOf('.') < 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Loading