use of fi.otavanopisto.pyramus.domainmodel.reports.Report in project pyramus by otavanopisto.
the class EditReportViewController method process.
/**
* Processes the page request by including the corresponding JSP page to the response.
*
* @param pageRequestContext Page request context
*/
public void process(PageRequestContext pageRequestContext) {
ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
ReportCategoryDAO categoryDAO = DAOFactory.getInstance().getReportCategoryDAO();
ReportContextDAO reportContextDAO = DAOFactory.getInstance().getReportContextDAO();
Long reportId = pageRequestContext.getLong("reportId");
Report report = reportDAO.findById(reportId);
List<ReportCategory> categories = categoryDAO.listAll();
List<ReportContext> reportContexts = reportContextDAO.listByReport(report);
Collections.sort(categories, new Comparator<ReportCategory>() {
public int compare(ReportCategory o1, ReportCategory o2) {
if (o1.getIndexColumn() == o2.getIndexColumn() || o1.getIndexColumn().equals(o2.getIndexColumn())) {
return o1.getName() == null ? -1 : o2.getName() == null ? 1 : o1.getName().compareTo(o2.getName());
} else {
return o1.getIndexColumn() == null ? -1 : o2.getIndexColumn() == null ? 1 : o1.getIndexColumn().compareTo(o2.getIndexColumn());
}
}
});
Map<String, Boolean> selectedContexts = new HashMap<>();
for (ReportContext context : reportContexts) selectedContexts.put(context.getContext().toString(), Boolean.TRUE);
List<String> contextTypes = new ArrayList<>();
for (ReportContextType contextType : ReportContextType.values()) contextTypes.add(contextType.toString());
pageRequestContext.getRequest().setAttribute("report", report);
pageRequestContext.getRequest().setAttribute("reportCategories", categories);
pageRequestContext.getRequest().setAttribute("reportContexts", selectedContexts);
pageRequestContext.getRequest().setAttribute("contextTypes", contextTypes);
pageRequestContext.setIncludeJSP("/templates/reports/editreport.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.reports.Report in project pyramus by otavanopisto.
the class ListReportsViewController method process.
/**
* Processes the page request by including the corresponding JSP page to the response.
*
* @param pageRequestContext Page request context
*/
public void process(PageRequestContext pageRequestContext) {
ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
List<Report> reports = reportDAO.listByContextType(ReportContextType.Common);
Collections.sort(reports, new Comparator<Report>() {
@Override
public int compare(Report o1, Report o2) {
String s1 = o1.getCategory() == null ? null : o1.getCategory().getName();
String s2 = o2.getCategory() == null ? null : o2.getCategory().getName();
int cmp = s1 == null ? 1 : s2 == null ? -1 : s1.compareToIgnoreCase(s2);
if (cmp == 0) {
cmp = o1.getName().compareToIgnoreCase(o2.getName());
}
return cmp;
}
});
pageRequestContext.getRequest().setAttribute("reports", reports);
pageRequestContext.setIncludeJSP("/templates/reports/listreports.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.reports.Report in project pyramus by otavanopisto.
the class ReportDAO method create.
public Report create(String name, String data, User creatingUser) {
Date now = new Date(System.currentTimeMillis());
Report report = new Report();
report.setData(data);
report.setName(name);
report.setCreated(now);
report.setCreator(creatingUser);
report.setLastModified(now);
report.setLastModifier(creatingUser);
getEntityManager().persist(report);
return report;
}
use of fi.otavanopisto.pyramus.domainmodel.reports.Report in project pyramus by otavanopisto.
the class ReportDAO method listByContextType.
public List<Report> listByContextType(ReportContextType contextType) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Report> criteria = criteriaBuilder.createQuery(Report.class);
Root<ReportContext> root = criteria.from(ReportContext.class);
criteria.select(root.get(ReportContext_.report));
criteria.where(criteriaBuilder.equal(root.get(ReportContext_.context), contextType));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.reports.Report in project pyramus by otavanopisto.
the class ViewReportParametersViewController method process.
/**
* Processes the page request by including the corresponding JSP page to the response.
*
* @param pageRequestContext Page request context
*/
public void process(PageRequestContext pageRequestContext) {
MagicKeyDAO magicKeyDAO = DAOFactory.getInstance().getMagicKeyDAO();
ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
Long reportId = pageRequestContext.getLong("reportId");
Report report = reportDAO.findById(reportId);
StringBuilder magicKeyBuilder = new StringBuilder().append(Long.toHexString(reportId)).append('-').append(Long.toHexString(System.currentTimeMillis())).append('-').append(Long.toHexString(Thread.currentThread().getId()));
MagicKey magicKey = magicKeyDAO.create(magicKeyBuilder.toString(), MagicKeyScope.REQUEST);
String localeAdd = "";
Locale locale = pageRequestContext.getRequest().getLocale();
if (locale != null) {
localeAdd = "&__locale=";
localeAdd += locale.getLanguage();
if (!StringUtils.isEmpty(locale.getCountry())) {
localeAdd += "_";
localeAdd += locale.getCountry();
}
}
StringBuilder urlBuilder = new StringBuilder().append(ReportUtils.getReportsUrl(pageRequestContext.getRequest())).append("/parameter?magicKey=").append(magicKey.getName()).append(localeAdd).append("&__report=reports/").append(reportId).append(".rptdesign").append("&__masterpage=true&__nocache");
handleContextParameters(pageRequestContext, report, urlBuilder);
pageRequestContext.setIncludeUrl(urlBuilder.toString());
}
Aggregations