use of fi.otavanopisto.pyramus.dao.reports.ReportDAO 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.dao.reports.ReportDAO 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.dao.reports.ReportDAO 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());
}
use of fi.otavanopisto.pyramus.dao.reports.ReportDAO in project pyramus by otavanopisto.
the class ViewReportViewController 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();
Long reportId = pageRequestContext.getLong("reportId");
Report report = reportDAO.findById(reportId);
handleContextParameters(pageRequestContext, report);
pageRequestContext.getRequest().setAttribute("report", report);
pageRequestContext.setIncludeJSP("/templates/reports/viewreport.jsp");
}
use of fi.otavanopisto.pyramus.dao.reports.ReportDAO in project pyramus by otavanopisto.
the class DownloadReportBinaryRequestController method process.
/**
* Processes a binary request for a report in binary format.
* The request should contain the following parameters:
* <dl>
* <dt><code>reportId</code></dt>
* <dd>The ID of the report to download.</dd>
* <dt><code>format</code></dt>
* <dd>The file format of the report. Possible values:
* <ul>
* <li><code>html</code></li>
* <li><code>pdf</code></li>
* <li><code>rtf</code></li>
* <li><code>doc</code></li>
* <li><code>xml</code></li>
* </ul>
* </dd>
* </dl>
*
* @param binaryRequestContext The context of the binary request.
*/
public void process(BinaryRequestContext binaryRequestContext) {
ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
MagicKeyDAO magicKeyDAO = DAOFactory.getInstance().getMagicKeyDAO();
Long reportId = binaryRequestContext.getLong("reportId");
String formatParameter = binaryRequestContext.getString("format");
ReportOutputFormat outputFormat = Enum.valueOf(ReportOutputFormat.class, formatParameter);
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);
Report report = reportDAO.findById(reportId);
String reportName = report.getName().toLowerCase().replaceAll("[^a-z0-9\\.]", "_");
String localeAdd = "";
Locale locale = binaryRequestContext.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(binaryRequestContext.getRequest())).append("/preview").append("?magicKey=").append(magicKey.getName()).append(localeAdd).append("&__report=reports/").append(reportId).append(".rptdesign").append("&__format=").append(outputFormat.name());
Map<String, String[]> parameterMap = binaryRequestContext.getRequest().getParameterMap();
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
if (!reservedParameters.contains(entry.getKey())) {
String[] values = entry.getValue();
for (String value : values) {
// TODO ISO-8859-1 should be UTF-8, once Birt's parameter dialog form has its accept-charset="UTF-8" set
try {
urlBuilder.append('&').append(entry.getKey()).append('=').append(URLEncoder.encode(value, "ISO-8859-1"));
} catch (UnsupportedEncodingException e) {
throw new SmvcRuntimeException(e);
}
}
}
}
binaryRequestContext.setFileName(reportName + '.' + outputFormat.getExt());
binaryRequestContext.setContentUrl(urlBuilder.toString());
}
Aggregations