Need

Take a web page that has a list of files and introduce sorts for various aspects of those files such as by name, by size, and by date.

Background

I have a page where I display a collection of files that belong to an html document. The data for the page that lists the files is obtained using the following definition


#############################################
# Data definition for the page
#GFIA: GetFileItemWithAttachments(reportId)
#############################################
request.GFIA.className=com.ai.htmlgen.DBHashTableFormHandler1

#Issue multiple SQL calls to retrieve data that is outside
#of any loops.
request.GFIA.maindatarequest.className=com.ai.db.DBPreTranslateArgsMultiRequestExecutor
request.GFIA.maindatarequest.db=reportsDB
request.GFIA.maindatarequest.request.1=GFIA.getAttachments
request.GFIA.maindatarequest.request.2=GFIA.getAttachmentsCount

#Call  1
request.GFIA.getAttachmentsCount.classname=com.ai.db.DBRequestExecutor2
request.GFIA.getAttachmentsCount.stmt=\
select count(*) as numberOfFiles from file_attachments \
where file_id={reportId}

#Call  2
request.GFIA.getAttachments.className=com.ai.db.DBRequestExecutor2
request.GFIA.getAttachments.db=reportsDB
request.GFIA.getAttachments.stmt=\
\
select * \
from reports r, sql_statements st, filed_items fi, folders f \
where 1=1 \
and r.report_content_id = st.statement_id \
and r.report_id = {reportId} \
and r.report_id = fi.item_id \
and fi.folder_id = f.folder_id

#Dynamic call that retreives a loop of data
request.GFIA.attachmentsloop.class_request.className=com.ai.htmlgen.GenericTableHandler6
request.GFIA.attachmentsloop.query_request.className=com.ai.db.DBRequestExecutor2
request.GFIA.attachmentsloop.query_request.db=reportsDB
request.GFIA.attachmentsloop.query_request.stmt=\
select * from file_attachments \
where file_id={reportId} \
order by last_updated_on desc

With this definition I can see my data as xml whose file listings are sorted by last updated date.

How do I introduce new sorts now?

I am going to introduce a argument filter like this


request.GFIA.GetOrderByClause.classname=com.ai.parts.ValueDecoderPart1
request.GFIA.GetOrderByClause.decodeKeyName=order_by_format
request.GFIA.GetOrderByClause.defaultValue=order by last_updated_on desc
request.GFIA.GetOrderByClause.translate.name=order by filename
request.GFIA.GetOrderByClause.translate.size=order by filesize desc
request.GFIA.GetOrderByClause.resultName=server_orderByClause

This is using a predefined part that transforms/introduces based on an incoming argument and reedefines the order by clause. The transformed order by clause is available in a new server side variable called "server_orderByClause".

I can use this to restructure my get files as follows


request.GFIA.attachmentsloop.class_request.className=com.ai.htmlgen.GenericTableHandler6
request.GFIA.attachmentsloop.query_request.className=com.ai.db.DBRequestExecutor2
request.GFIA.attachmentsloop.query_request.db=reportsDB
request.GFIA.attachmentsloop.query_request.stmt=\
select * from file_attachments \
where file_id={reportId} \
{server_orderByClause.empty}
#order by last_updated_on desc

With these two in place I define the GFIA.GetOrderByClause as the third call of the main data request as follows


request.GFIA.maindatarequest.className=com.ai.db.DBPreTranslateArgsMultiRequestExecutor
request.GFIA.maindatarequest.db=reportsDB
request.GFIA.maindatarequest.request.1=GFIA.getAttachments
request.GFIA.maindatarequest.request.2=GFIA.getAttachmentsCount
request.GFIA.maindatarequest.request.3=GFIA.GetOrderByClause

Now I can sort my data

Now I can attach my sort definitions to the incoming URL


someurl?order_by_format=name
someurl?order_by_format=size

No order_by_format defaults to by date.

Ummmm

There are number of ways this idea can be significantly improved upon but even at this level it seem to delude me to thinking that it is ncie.