Min - I will take a stab at this. See if this makes sense to you. I haven't 
used them but I think the intention of the code should be this.

If say you want to query events within a time range then you will use these 
parameter. Say at this point of time you want to get all the events that took 
place in the last 2 mins then you will mention entryTime = 120 and duration=0. 
I think the duration should be interpreted as end time and there reference is 
from current system time. So entry time means how many seconds before the 
current time and duration (end time) is how many seconds before the current 
time.
In our example, since we want to query events that happened in the last 120 
secs I mention entry time as 120 and end time as 0
and as is clear the duration or the end time shouldn't exceed the entry time.

Please file documentation bugs and test if these params work as intended.

Thanks,
-Nitin

On 08-Dec-2012, at 5:07 AM, Min Chen wrote:

> Hi there,
> 
> In refactoring ListEventsCmd api, I ran into the following code which is a 
> mystery to me, hope that somebody can explain here:
> 
> 
>        if ((entryTime != null) && (duration != null)) {
> 
>            if (entryTime <= duration) {
> 
>                throw new InvalidParameterValueException("Entry time must be 
> greater than duration");
> 
>            }
> 
>            Calendar calMin = Calendar.getInstance();
> 
>            Calendar calMax = Calendar.getInstance();
> 
>            calMin.add(Calendar.SECOND, -entryTime);
> 
>            calMax.add(Calendar.SECOND, -duration);
> 
>            Date minTime = calMin.getTime();
> 
>            Date maxTime = calMax.getTime();
> 
> 
>            sc.setParameters("state", com.cloud.event.Event.State.Completed);
> 
>            sc.setParameters("startId", 0);
> 
>            sc.setParameters("createDate", minTime, maxTime);
> 
>            List<EventJoinVO> startedEvents = 
> _eventJoinDao.searchAllEvents(sc, searchFilter);
> 
>            List<EventJoinVO> pendingEvents = new ArrayList<EventJoinVO>();
> 
>            for (EventVO event : startedEvents) {
> 
>                EventVO completedEvent = 
> _eventDao.findCompletedEvent(event.getId());
> 
>                if (completedEvent == null) {
> 
>                    pendingEvents.add(event);
> 
>                }
> 
>            }
> 
>            return pendingEvents;
> 
>        }
> 
> 
>   I have several questions here:
> 
> 1. What are entryTime and duration parameters here? Based on API doc, here 
> are description on these two cmd parameters:
> 
>     entryTime:  the time the event is entered
> 
>     duration:   the duration of the event
> 
>    But from code, it seems that they are both Integer type. So not sure how 
> to understand the entryTime and duration here, contradictory to my English 
> understanding.
> 
> 2. In the code above, why must we have "Entry time must be greater than 
> duration"?
> 
> 3. When user provides entryTime and duration parameters in the search, what 
> kind of events are we supposed to return here? I don't quite understand the 
> pendingEvents list we are constructing here.
> 
> 
>   Thanks
> 
>   -min

Reply via email to