Criteria critTotals = session.createCriteria(Prozess.class, "proc");
critTotals.add(Restrictions.eq("proc.istTemplate", Boolean.FALSE));
critTotals.add(Restrictions.eq("proc.projekt", project));
ProjectionList proList = Projections.projectionList();
proList.add(Projections.count("proc.id"));
proList.add(Projections.sum("proc.sortHelperImages"));
critTotals.setProjection(proList);
List<Object> list = critTotals.list();
for (Object obj : list) {
Object[] row = (Object[]) obj;
totalNumberOfProc = (Long) row[FieldList.totalProcessCount.fieldLocation];
totalNumberOfImages = (Long) row[FieldList.totalImageCount.fieldLocation];
;
}
proList = null;
list = null;
Criteria critSteps = session.createCriteria(Schritt.class);
critSteps.createCriteria("prozess", "proc");
critSteps.addOrder(Order.asc("reihenfolge"));
critSteps.add(Restrictions.eq("proc.istTemplate", Boolean.FALSE));
critSteps.add(Restrictions.eq("proc.projekt", project));
proList = Projections.projectionList();
proList.add(Projections.groupProperty(("titel")));
proList.add(Projections.count("id"));
proList.add(Projections.avg("reihenfolge"));
critSteps.setProjection(proList);
// now we have to discriminate the hits where the max number of hits doesn't reach numberOfProcs
// and extract a workflow, which is the workflow common for all processes according to its titel
// the position will be calculated by the average of 'reihenfolge' of steps
list = critSteps.list();
String title;
Double averageStepOrder;
Long numberOfSteps;
Long numberOfImages;
List<StepInformation> workFlow = new ArrayList<StepInformation>();
for (Object obj : list) {
Object[] row = (Object[]) obj;
title = (String) (row[FieldList.stepName.fieldLocation]);
numberOfSteps = (Long) (row[FieldList.stepCount.fieldLocation]);
averageStepOrder = (Double) (row[FieldList.stepOrder.fieldLocation]);
// in this step we only take the steps which are present in each of the workflows
if (numberOfSteps.equals(totalNumberOfProc)) {
StepInformation newStep = new StepInformation(title, averageStepOrder);
newStep.setNumberOfTotalImages(totalNumberOfImages.intValue());
newStep.setNumberOfTotalSteps(totalNumberOfProc.intValue());
workFlow.add(newStep);
}
}
Criteria critStepDone = session.createCriteria(Schritt.class, "step");
critStepDone.createCriteria("prozess", "proc");
critStepDone.add(Restrictions.eq("step.bearbeitungsstatus", StepStatus.DONE.getValue()));
critStepDone.add(Restrictions.eq("proc.istTemplate", Boolean.FALSE));
critStepDone.add(Restrictions.eq("proc.projekt", project));
ProjectionList proCount = Projections.projectionList();
proCount.add(Projections.groupProperty(("step.titel")));
proCount.add(Projections.count("proc.id"));
proCount.add(Projections.sum("proc.sortHelperImages"));
critStepDone.setProjection(proCount);
list = critStepDone.list();