*/
if (resultlist!=null && filter.intervaltime > 0) {
int maxSize = (int) (resultlist.size() * filter.intervaltime / 100);
for (int j = 0; j < resultlist.size();j++) {
YLogIdentifier ylog = (YLogIdentifier) resultlist.get(j);
/*
Calculate intervaltime for this identifier...
if it is not a percentage based interval
*/
ylog.setTime(ylog.getCompleted()-ylog.getCreated());
if (!filter.granularity.equals("Percent")) {
if (filter.LessThan) {
if ((ylog.getCompleted()-ylog.getCreated()) < filter.intervaltime) {
finalresult.add(ylog);
}
} else {
if ((ylog.getCompleted()-ylog.getCreated()) > filter.intervaltime) {
finalresult.add(ylog);
}
}
} else {
/*
If it is a percentage based interval
Compare to the rest of the list to see if it is
within the X percent...if there is room...then ok
*/
System.out.println("MAX SIZE: " + maxSize);
if (finalresult.size() < maxSize) {
finalresult.add(ylog);
} else {
for (int k = 0; k < finalresult.size();k++) {
YLogIdentifier old = (YLogIdentifier) finalresult.get(k);
if (filter.LessThan) {
if (old.getTime() > ylog.getTime()) {
finalresult.remove(old);
finalresult.add(ylog);
}
} else {
if (old.getTime() < ylog.getTime()) {
finalresult.remove(old);
finalresult.add(ylog);
}
}
}
}
}
}
for (int j = 0; j < finalresult.size();j++) {
YLogIdentifier ylog = (YLogIdentifier) finalresult.get(j);
//reallyfinal.add(addCaseParameters(req,ylog));
reallyfinal.add(ylog);
}
} else {
finalresult = resultlist;
for (int j = 0; j < finalresult.size();j++) {
YLogIdentifier ylog = (YLogIdentifier) finalresult.get(j);
ylog.setTime(ylog.getCompleted()-ylog.getCreated());
//reallyfinal.add(addCaseParameters(req,ylog));
System.out.println("YLOG: " + ylog.getCreatedby());
reallyfinal.add(ylog);
}
}
/*
This should be done if there is a grouping
request in the query rather than individual
*/
if (!grouping.equals("No grouping")) {
reallyfinal = calculateCaseAggregation(reallyfinal,grouping);
}
/*
If this is a work item query
*/
} else {
checkWorkItemDisplayParameters(req);
boolean add = false;
String currentid = "";
String exec_query = filter.query;
/*
WHY are they sorted this way??
Actually to keep the grouping of items
So that we know when we are finished with one item
*/
resultlist = _model.executeQueryWorkItems(exec_query+ " order by time");
AggregatedWorkItemRecord witem = new AggregatedWorkItemRecord();
HashMap parent_items = new HashMap();
YWorkItemEvent dummy_event = new YWorkItemEvent();
dummy_event.setIdentifier("");
dummy_event.setTaskid("");
dummy_event.setEvent("dummy");
resultlist.add(dummy_event);
/*
Create WorkItemRecords...
*/
/*
Rewrite into a hashMap Algorithm, which makes it order independent
That should fix it!!!
*/
HashMap eventview = new HashMap();
for (int j = 0; j < resultlist.size();j++) {
YWorkItemEvent event = (YWorkItemEvent) resultlist.get(j);
witem = (AggregatedWorkItemRecord) eventview.get(event.getIdentifier()+event.getTaskid());
if (witem==null) {
witem = new AggregatedWorkItemRecord();
witem.setCaseID(event.getIdentifier());
witem.setTaskID(event.getTaskid());
eventview.put(event.getIdentifier()+event.getTaskid(),witem);
}
if (event.getEvent().equals("Fired")) {
witem.setFiringTime(DateTransform.transform(event.getTime()));
Long parent_enablement = (Long) parent_items.get(event.getIdentifier().
substring(0,event.getIdentifier().
lastIndexOf("."))+
event.getTaskid());
if (parent_enablement!=null) {
long enabled = parent_enablement.longValue();
witem.setEnablementTime(DateTransform.transform(enabled));
witem.setFired2Started(enabled);
}
}
if (event.getEvent().equals("Executing")) {
witem.setStartTime(DateTransform.transform(event.getTime()));
add = true;
long started = event.getTime();
witem.setStarted2Complete(started);
}
if (event.getEvent().equals("Enabled")) {
parent_items.put(event.getIdentifier()+event.getTaskid(),
new Long(event.getTime()));
}
if (event.getEvent().equals("Complete")) {
witem.setCompletionTime(DateTransform.transform(event.getTime()));
long completed = event.getTime();
long enabled = witem.getFired2Started();
long started = witem.getStarted2Complete();
/*
fired to started
*/
witem.setFired2Started(started - enabled);
/*
completion time (fired - complete)
*/
witem.setFired2Complete(completed-enabled);
/*
started to complete
*/
witem.setStarted2Complete(completed-started);
witem.setAssignedTo(event.getResource());
/*
Do not add the parent items and items with missing information
*/
if (parent_items.get(event.getIdentifier()+event.getTaskid())==null) {
if (enabled!=0 && completed!=0 && started!=0) {
checkForAddition(filter,witem,reallyfinal);
}
}
}
witem.setTaskID(event.getTaskid());
witem.setSpecificationID(event.getDescription());
}
if (filter.granularity.equals("Percent")) {
reallyfinal = reduceToPercentage(reallyfinal, filter);
}
/*
calculate the aggregation according to the grouping
*/
if (!grouping.equals("No grouping")) {
reallyfinal = calculateWorkItemAggregation(reallyfinal,grouping);
System.out.println(reallyfinal);
}
}
}
if (action!=null && action.equals("Create chart")) {
String interval_granul = req.getParameter("interval_chart_granularity");
int granul = 0;
if (interval_granul.equals("Seconds")) {
granul = Calendar.SECOND;
}
if (interval_granul.equals("Minutes")) {
granul = Calendar.MINUTE;
}
if (interval_granul.equals("Hours")) {
granul = Calendar.HOUR_OF_DAY;
}
if (interval_granul.equals("Days")) {
granul = Calendar.DATE;
}
if (interval_granul.equals("Months")) {
granul = Calendar.MONTH;
}
if (interval_granul.equals("Years")) {
granul = Calendar.YEAR;
}
String charttype = req.getParameter("graphtype");
System.out.println(charttype);
List chartValues = new LinkedList();
String xaxis = req.getParameter("groupbyvalue");
String yaxis = req.getParameter("chartvalue");
for (int i = 0; i < reallyfinal.size();i++) {
if (querytype.equals("case")) {
YLogIdentifier ylog = (YLogIdentifier) reallyfinal.get(i);
System.out.println(ylog.getTime());
System.out.println(ylog.getSpecification());
Object[] o = new Object[2];
/*
Select time selected
*/
if (yaxis.equals("Started-Completed")) {
o[1] = new Integer((int)DateTransform.getTime(ylog.getTime(),granul));
} else if (yaxis.equals("Count")) {
o[1] = new Integer((int) ylog.getCount());
}
/*
Select group by element
*/
if (grouping.equals("Specification")) {
o[0] = ylog.getSpecification();
} else if (grouping.equals("Resource")) {
o[0] = ylog.getCreatedby();
} else {
o[0] = ylog.getIdentifier();
}
System.out.println("Setting " + grouping + " as " + o[0] + " " + ylog.getCreatedby());
chartValues.add(o);
} else {
AggregatedWorkItemRecord witem = (AggregatedWorkItemRecord) reallyfinal.get(i);
Object[] o = new Object[2];