Bug in the Advanced Search for Log Entries

Hi,

There seems to be a bug in the log entries advanced search. When value (valid / invalid) is entered for source / generatedBy and any of the other search parameters have been specified, the log entries are not filtered by either of them. However, the search works quite fine when only the source or only the generatedBy fields are specified

LogEntry Search handler

@Component public class LogEntrySearchHandler implements SearchHandler {

private final SearchConfig searchConfig = new SearchConfig("default", RestConstants.VERSION_1 + IdgenRestController.IDGEN_NAMESPACE + "/logentry",
        Arrays.asList("1.8.*", "1.9.*", "1.10.*", "1.11.*", "1.12.*", "2.0.*", "2.1.*"),
        Arrays.asList(new SearchQuery.Builder(
                "Allows you to find log of ID Generation Activities by Source Name, Identifier contents,Generated Date Range,Comment contents and User who generated the log entry")
                        .withOptionalParameters("source", "identifier", "fromDate", "toDate", "comment",
                                "generatedBy")
                        .build()));

@Override
public PageableResult search(RequestContext context) throws ResponseException {
    IdentifierSourceService identifierSourceService = Context.getService(IdentifierSourceService.class);
    UserService service = Context.getUserService();

    String source = context.getRequest().getParameter("source");
    String fromDate = context.getRequest().getParameter("fromDate");
    String toDate = context.getRequest().getParameter("toDate");
    String identifier = context.getRequest().getParameter("identifier");
    String comment = context.getRequest().getParameter("comment");
    String generatedBy = context.getRequest().getParameter("generatedBy");

    IdentifierSource logSource = source != null ? identifierSourceService.getIdentifierSourceByUuid(source) : null;
    Date dateFrom = fromDate != null ? (Date) ConversionUtil.convert(fromDate, Date.class) : null;
    Date dateTo = toDate != null ? (Date) ConversionUtil.convert(toDate, Date.class) : null;
    User user = generatedBy != null ? service.getUserByUuid(generatedBy): null;
    if (logSource == null && identifier == null && comment == null && dateFrom == null && dateTo == null
            && user == null) {
        return new EmptySearchResult();
    }
    List<LogEntry> logEntries = identifierSourceService.getLogEntries(logSource, dateFrom, dateTo, identifier, user, comment);

    return new NeedsPaging<LogEntry>(logEntries, context);
}
@Override
public SearchConfig getSearchConfig() {
    return searchConfig;
}

}

Forexample:

curl -X GET --header ‘Accept: application/json’ ‘https://modules-refapp.openmrs.org/openmrs/ws/rest/v1/idgen/logentry?identifier=1002&v=full&source=invalid

will return all log entries whose identifier contains the value 1002 despite passing an invalid value for source. However

curl -X GET --header ‘Accept: application/json’ ‘https://modules-refapp.openmrs.org/openmrs/ws/rest/v1/idgen/logentry?v=full&source=invalid

will return an empty results array since no source with value invalid exists.

For more details checkout:

  1. Modifications that were made to the log entries end points in the api in this PR
  2. The idgen_logentry endpoints via the api documentation

Any assistance offered will be highly appreciated

Can you give detailed step by step instructions on how to reproduce? Just like @joelakwes did here: How do I format query request when querying for observations in Cohort Builder's Concept/Observation

Editted this and I am yet to get assistance

Do you think you can create unit tests to reproduce this problem?

Doing that right away.