Nicolas Raoul
Nicolas Raoul

Reputation: 60203

Alfresco audit query: fromTime/toTime seem to have no effect

I want to get all audit entries from an Alfresco audit application.

Following the Alfresco Audit REST API documentation, I wrote this query:

curl -u admin:admin "http://localhost:8080/alfresco/service/api/audit/query/audit-custom?fromId=1&toId=100000&fromTime=2017-02-19T18:46:09.212+09:00&toTime=2017-02-20T18:46:09.212+09:00&user=admin&forward=true&limit=0&verbose=true"

(Note the fromTime={2017-02-19T18:46:09.212+09:00}&toTime={2017-02-20T18:46:09.212+09:00} part)

PROBLEM: This returns the exact same 90 results as the request without the fromTime and toTime parameters. By the way, I installed Alfresco on 2017-02-21 so the query above should actually return zero results.

How to use correctly the fromTime and toTime parameters?

Upvotes: 0

Views: 615

Answers (1)

Nicolas Raoul
Nicolas Raoul

Reputation: 60203

It is not obvious in the documentation, but fromTime and longTime must be entered as long values.

Here is the relevant Alfresco source code:

public static final String PARAM_FROM_TIME = "fromTime";

protected Long getParamFromTime(WebScriptRequest req)
{
    String paramStr = req.getParameter(PARAM_FROM_TIME);
    try
    {
        return Long.parseLong(paramStr);
    }
    catch (NumberFormatException e)
    {
        return DEFAULT_TO_TIME;
    }
}

As you can see, format problems are quietly dropped, and default values used instead, which is what is happening with the requests included in the question above.

With long values, a valid request could be:

curl -u admin:admin "http://localhost:8080/alfresco/service/api/audit/query/audit-custom?fromTime=1485152993728&toTime=1485239393728&verbose=true"

(Note the fromTime=1485152993728&toTime=1485239393728 part)

Here is a convenient Java snippet to convert dates to long values when performing tests:

import java.util.concurrent.TimeUnit;
public class Main {
    public static void main(String[] args) {

        long now = System.currentTimeMillis();
        long lastMonth = now - TimeUnit.DAYS.toMillis(30); 
        long lastMonthPlusOne = now - TimeUnit.DAYS.toMillis(29);

        System.out.println("Now:" + now);
        System.out.println("Last month:" + lastMonth);
        System.out.println("Last month plus one day:" + lastMonthPlusOne);
    }
}

Upvotes: 2

Related Questions