Search in sources :

Example 1 with ReportCategory

use of fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory in project pyramus by otavanopisto.

the class EditReportJSONRequestController method process.

/**
 * Processes the request to edit a report.
 *
 * @param requestContext The JSON request context
 */
public void process(JSONRequestContext requestContext) {
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    ReportCategoryDAO categoryDAO = DAOFactory.getInstance().getReportCategoryDAO();
    ReportContextDAO reportContextDAO = DAOFactory.getInstance().getReportContextDAO();
    Long reportId = requestContext.getLong("reportId");
    Report report = reportDAO.findById(reportId);
    Long reportCategoryId = requestContext.getLong("category");
    ReportCategory category = reportCategoryId == null ? null : categoryDAO.findById(reportCategoryId);
    String name = requestContext.getString("name");
    reportDAO.update(report, name, category);
    for (ReportContextType contextType : ReportContextType.values()) {
        ReportContext context = reportContextDAO.findByReportAndContextType(report, contextType);
        boolean selected = requestContext.getBoolean("context." + contextType.toString());
        if (selected && context == null)
            reportContextDAO.create(report, contextType);
        else if (!selected && context != null)
            reportContextDAO.delete(context);
    }
    requestContext.setRedirectURL(requestContext.getReferer(true));
}
Also used : ReportCategory(fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) ReportContextDAO(fi.otavanopisto.pyramus.dao.reports.ReportContextDAO) ReportCategoryDAO(fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO) ReportContextType(fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) ReportContext(fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)

Example 2 with ReportCategory

use of fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory in project pyramus by otavanopisto.

the class ImportReportViewController method processForm.

@Override
public void processForm(PageRequestContext requestContext) {
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    ReportCategoryDAO categoryDAO = DAOFactory.getInstance().getReportCategoryDAO();
    ReportContextDAO reportContextDAO = DAOFactory.getInstance().getReportContextDAO();
    List<Report> reports = reportDAO.listAll();
    Collections.sort(reports, new StringAttributeComparator("getName"));
    JSONArray contextTypesJSON = new JSONArray();
    List<String> contextTypes = new ArrayList<>();
    for (ReportContextType contextType : ReportContextType.values()) {
        contextTypes.add(contextType.toString());
        contextTypesJSON.add(contextType.toString());
    }
    JSONArray reportsJSON = new JSONArray();
    for (Report report : reports) {
        JSONObject rObj = new JSONObject();
        List<ReportContext> contexts = reportContextDAO.listByReport(report);
        JSONArray rCtxs = new JSONArray();
        for (ReportContext ctx : contexts) {
            rCtxs.add(ctx.getContext().toString());
        }
        rObj.put("id", report.getId().toString());
        rObj.put("name", report.getName());
        rObj.put("category", report.getCategory() != null ? report.getCategory().getId() : "");
        rObj.put("contexts", rCtxs);
        reportsJSON.add(rObj);
    }
    List<ReportCategory> categories = categoryDAO.listAll();
    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());
            }
        }
    });
    setJsDataVariable(requestContext, "reports", reportsJSON.toString());
    setJsDataVariable(requestContext, "contextTypes", contextTypesJSON.toString());
    requestContext.getRequest().setAttribute("reports", reports);
    requestContext.getRequest().setAttribute("reportCategories", categories);
    requestContext.getRequest().setAttribute("contextTypes", contextTypes);
    requestContext.setIncludeJSP("/templates/system/importreport.jsp");
}
Also used : ReportCategory(fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) ReportCategoryDAO(fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArray(net.sf.json.JSONArray) ArrayList(java.util.ArrayList) ReportContextType(fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType) JSONObject(net.sf.json.JSONObject) ReportContextDAO(fi.otavanopisto.pyramus.dao.reports.ReportContextDAO) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) ReportContext(fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)

Example 3 with ReportCategory

use of fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory in project pyramus by otavanopisto.

the class ReportCategoriesViewController 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) {
    ReportCategoryDAO categoryDAO = DAOFactory.getInstance().getReportCategoryDAO();
    List<ReportCategory> categories = categoryDAO.listAll();
    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());
            }
        }
    });
    String jsonCategories = new JSONArrayExtractor("name", "id").extractString(categories);
    this.setJsDataVariable(pageRequestContext, "reportCategories", jsonCategories);
    pageRequestContext.setIncludeJSP("/templates/settings/reportcategories.jsp");
}
Also used : ReportCategory(fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory) ReportCategoryDAO(fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor)

Example 4 with ReportCategory

use of fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory in project pyramus by otavanopisto.

the class DeleteReportCategoryJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    ReportCategoryDAO categoryDAO = DAOFactory.getInstance().getReportCategoryDAO();
    Long reportCategoryId = requestContext.getLong("reportCategory");
    ReportCategory reportCategory = categoryDAO.findById(reportCategoryId);
    if (categoryDAO.isReportCategoryInUse(reportCategory)) {
        Locale locale = requestContext.getRequest().getLocale();
        String msg = Messages.getInstance().getText(locale, "settings.deleteReportCategory.categoryInUse");
        throw new SmvcRuntimeException(PyramusStatusCode.VALIDATION_FAILURE, msg);
    } else {
        categoryDAO.delete(reportCategory);
    }
}
Also used : Locale(java.util.Locale) ReportCategory(fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory) ReportCategoryDAO(fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException)

Example 5 with ReportCategory

use of fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory 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");
}
Also used : ReportCategory(fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) HashMap(java.util.HashMap) ReportCategoryDAO(fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO) ArrayList(java.util.ArrayList) ReportContextType(fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType) ReportContextDAO(fi.otavanopisto.pyramus.dao.reports.ReportContextDAO) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO) ReportContext(fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)

Aggregations

ReportCategory (fi.otavanopisto.pyramus.domainmodel.reports.ReportCategory)8 ReportCategoryDAO (fi.otavanopisto.pyramus.dao.reports.ReportCategoryDAO)7 ReportDAO (fi.otavanopisto.pyramus.dao.reports.ReportDAO)4 Report (fi.otavanopisto.pyramus.domainmodel.reports.Report)4 ReportContextDAO (fi.otavanopisto.pyramus.dao.reports.ReportContextDAO)3 ReportContext (fi.otavanopisto.pyramus.domainmodel.reports.ReportContext)3 ReportContextType (fi.otavanopisto.pyramus.domainmodel.reports.ReportContextType)3 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)2 ArrayList (java.util.ArrayList)2 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)1 User (fi.otavanopisto.pyramus.domainmodel.users.User)1 JSONArrayExtractor (fi.otavanopisto.pyramus.util.JSONArrayExtractor)1 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 EntityManager (javax.persistence.EntityManager)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1