Created
February 25, 2009 04:21
-
-
Save 3gcodes/70002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Criteria crit = getSession().createCriteria(DashboardProject.class); | |
crit.createAlias("templateHistory", "th", CriteriaSpecification.INNER_JOIN); | |
crit.createAlias("health", "h"); | |
crit.add(eq("th.id", report.getTemplate().getId())); | |
for (StoredReportGlobalItem item : report.getStoredReportGlobalItems()) { | |
if ((item.isDisplayOnReport() || item.getValues() != null)) { | |
if (item.getSearchFilter().equals("GT")) { | |
if (item.getQueryProperty().equals("startDate")) { | |
if (item.getValues().size() > 0) { | |
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); | |
try { | |
Date startDate = format.parse(item.getValues().get("0")); | |
crit.add(Expression.gt("startDate", startDate)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} else if (item.getQueryProperty().equals("createdDate")) { | |
if (item.getValues().size() > 0) { | |
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); | |
try { | |
Date startDate = format.parse(item.getValues().get("0")); | |
crit.add(Expression.gt("createdDate", startDate)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} else if (item.getSearchFilter().equals("LT")) { | |
if (item.getQueryProperty().equals("startDate")) { | |
if (item.getValues().size() > 0) { | |
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); | |
try { | |
Date startDate = format.parse(item.getValues().get("0")); | |
crit.add(Expression.lt("startDate", startDate)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} else if (item.getQueryProperty().equals("createdDate")) { | |
if (item.getValues().size() > 0) { | |
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); | |
try { | |
Date startDate = format.parse(item.getValues().get("0")); | |
crit.add(Expression.lt("createdDate", startDate)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} else if (item.getSearchFilter().equals("BETWEEN")) { | |
if (item.getQueryProperty().equals("startDate")) { | |
if (item.getValues().size() > 0) { | |
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); | |
try { | |
Date startDate = format.parse(item.getValues().get("0")); | |
Date endDate = format.parse(item.getValues().get("1")); | |
crit.add(Expression.between("startDate", startDate, endDate)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} else if (item.getQueryProperty().equals("createdDate")) { | |
if (item.getValues().size() > 0) { | |
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); | |
try { | |
Date startDate = format.parse(item.getValues().get("0")); | |
Date endDate = format.parse(item.getValues().get("1")); | |
crit.add(Expression.between("createdDate", startDate, endDate)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} else if (item.getSearchFilter().equals("CONTAINS")) { | |
if (item.getValues() != null && item.getValues().size() > 0) { | |
crit.add(like(item.getQueryProperty(), item.getValues().get("0"), MatchMode.ANYWHERE)); | |
} | |
} else if (item.getSearchFilter().equals("EQUALS")) { | |
if (item.getValues().size() > 0) { | |
if (item.getQueryProperty().equals("startDate")) { | |
if (item.getValues().size() > 0) { | |
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); | |
try { | |
Date startDate = format.parse(item.getValues().get("0")); | |
crit.add(Expression.eq("startDate", startDate)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} else if (item.getQueryProperty().equals("createdDate")) { | |
if (item.getValues().size() > 0) { | |
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); | |
try { | |
Date startDate = format.parse(item.getValues().get("0")); | |
crit.add(Expression.eq("createdDate", startDate)); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
} | |
} else { | |
crit.add(eq(item.getQueryProperty(), item.getValues().get("0"))); | |
} | |
} | |
} else if (item.getSearchFilter().equals("HAS_ANY_VALUE")) { | |
if (item.getQueryProperty().endsWith("_health") && item.getValues().size() > 0) { | |
Disjunction or = Restrictions.disjunction(); | |
for (String key : item.getValues().keySet()) { | |
if (item.getQueryProperty().startsWith("overall")) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq("h.overall", Integer.parseInt(item.getValues().get(key)))); | |
} | |
} else if (item.getQueryProperty().startsWith("scope")) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq("h.scope", Integer.parseInt(item.getValues().get(key)))); | |
} | |
} else if (item.getQueryProperty().startsWith("schedule")) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq("h.schedule", Integer.parseInt(item.getValues().get(key)))); | |
} | |
} else if (item.getQueryProperty().startsWith("budget")) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq("h.cost", Integer.parseInt(item.getValues().get(key)))); | |
} | |
} | |
} | |
if (item.getValues().size() > 0) { | |
crit.add(or); | |
} | |
//System.out.println(crit.toString()); | |
} else if (item.getQueryProperty().equals("project_visibility")) { | |
Disjunction or = Restrictions.disjunction(); | |
for (String key : item.getValues().keySet()) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq("visibility", Integer.parseInt(item.getValues().get(key)))); | |
} | |
} | |
crit.add(or); | |
} else if (item.getQueryProperty().equals("project_category")) { | |
Disjunction or = Restrictions.disjunction(); | |
for (String key : item.getValues().keySet()) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq("category", Integer.parseInt(item.getValues().get(key)))); | |
} | |
} | |
crit.add(or); | |
} else if (item.getQueryProperty().equals("project_status")) { | |
Disjunction or = Restrictions.disjunction(); | |
for (String key : item.getValues().keySet()) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq("status", Integer.parseInt(item.getValues().get(key)))); | |
} | |
} | |
} else if (item.getQueryProperty().equals("project_classification")) { | |
Disjunction or = Restrictions.disjunction(); | |
for (String key : item.getValues().keySet()) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq("classification", Integer.parseInt(item.getValues().get(key)))); | |
} | |
} | |
crit.add(or); | |
} else { | |
Disjunction or = Restrictions.disjunction(); | |
for (String key : item.getValues().keySet()) { | |
if (item.getValues().get(key) != null) { | |
or.add(eq(item.getQueryProperty(), Integer.parseInt(item.getValues().get(key)))); | |
} | |
} | |
crit.add(or); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment