Correct OpenRosa response to Form List request when No Forms available?

When using Collect's "Get Blank Form" button, I would like to display a friendly message to the user if there are no forms available. Currently, it appears that any response which is not an actual form list results in Collect showing "Nothing available to display". It would be nice to be able to customise this message.
I tried sending this, which AFAICS is an OpenRosa-compliant response:

<?xml version="1.0" encoding="UTF-8"?>
 <OpenRosaResponse xmlns="http://openrosa.org/http/response" items="1">
        <message nature="no_forms">Sorry, there are no forms currently available.  Please try again later.</message>
    </OpenRosaResponse>

But this still results in Collect showing "Nothing available to display", rather than the OpenRosa Message text.
Is there any way to make Collect display a custom message in this context?
And if not, does anyone else think this would be a nice feature to have?
Thanks
Nik

In Collect v1.5.0, @Jon_Nordling added a feature that would use OpenRosa server messages on the form list and in v1.8.0 @Grzesiek2010 improved that feature so it'd work better for multiple languages. I believe both of these are just for submissions, but it seems reasonable that this could be added for form lists as well.

@Blitheringeejit is this functionality you'd be interested in contributing to Collect?

I would be happy to, but I'm afraid that I'm just not competent. I have virtually no real understanding of Android, and very little experience of Java - the customisations I've made to my own Collect forks have been tiny changes, involving a couple of lines of code added here and there, for processing existing data for my own purposes (eg resizing images before upload).
Which makes me a bit of a passenger in these forums - especially as I work entirely with custom LAMP server backends, not with Aggregate, so even my serverside skills are not useful to most. I'm very happy to help folks who are trying to do what I do, but my contributions to the community will be limited to stuff I actually know about. :slight_smile: I might have a go at implementing this functionality, in a bull-in-a-china-shop sort of way, but I'm sure that any Java I came up with would not be up to the standard required for a proper community project.
Nik

Afterthought:
it might be possible for me to contribute funds if that would enable others the community to contribute app features which are beyond my expertise. I recall seeing some mention of this option elsewhere on the board. Any idea what sort of cost we might be talking about to add an option to interpret a FormList response as OpenRosa and display a response message if the FormList isn't a valid in this way?
Nik

It is, as you say, a community project! If you do your best with it and submit what you have, it may inspire somebody else to come and help you shore it up a bit. If you've already played around with the Collect codebase a bit, you're far ahead of many folks!

Clint - thanks for the encouragement! But my main problem is that because I don't speak Java AND I don't understand Android, I usually can't even tell where to begin looking for the bits I might want to change.
As far as I can tell from looking at DownloadFormListTask.java, the app already tries to parse any Form List Request response as OpenRosa:

 if (result.isOpenRosaResponse) {
            // Attempt OpenRosa 1.0 parsing
            Element xformsElement = result.doc.getRootElement();
            if (!xformsElement.getName().equals("xforms")) {
                String error = "root element is not <xforms> : " + xformsElement.getName();
                Timber.e("Parsing OpenRosa reply -- %s", error);
                formList.put(
                        DL_ERROR_MSG,
                        new FormDetails(Collect.getInstance().getString(
                                R.string.parse_openrosa_formlist_failed, error)));
                return formList;
            }
...

This appears to mean that if the root element is not <xforms>, the response should be parsed as OpenRosa - which is what we want. But I can't tell whether that's actually happening or not, because I can't understand the code well enough to see what's being shown to the user. I assume
Timber.e
is some kind of error logging which doesn't appear in the UI, but AFAICS the lines

formList.put(
     DL_ERROR_MSG,
    new FormDetails(Collect.getInstance().getString(
            R.string.parse_openrosa_formlist_failed, error)));
    return formList;

....should result in a UI report to the user, which in my language context resolves to "The server has not provided an available-forms document..." - followed by "root element is not <xforms>".
But nothing like this appears in the app, even when I send (I think) an OpenRosa response as above.
Any thoughts - am I anywhere near the right track?
Thanks
Nik

I think you're totally on the right track! In fact, if nothing appears in the app I'm guessing you've found a bug—what appears instead when Collect gets this response?

But everything you've diagnosed about this code sounds right to me, and once you figure out why the message isn't showing up right now, I think all you have to do is peel apart the OpenRosa message response, check to see if there is a relevant message, and drop it in instead.

1 Like