@Override public void printReferencesById(List<Long> referenceIds) { for (Long referenceId : referenceIds) { Reference reference = referenceDAO.findById(referenceId); reference.setState(Reference.ReferenceState.PROCESSED); referenceDAO.update(reference); } }
@Override public void readyReferencesById(List<Long> referenceIds) { for (Long referenceId : referenceIds) { Reference reference = referenceDAO.findById(referenceId); reference.setState(Reference.ReferenceState.READY); referenceDAO.update(reference); } }
@Override public Reference makeReference(Reference.ReferenceType type, Long ownerId) { Reference reference = new Reference(); reference.setType(type); reference.setOwnerId(ownerId); reference.setPurpose("по месту требования"); return reference; }
@Override public void issueReferencesById(List<Long> referenceIds) { for (Long referenceId : referenceIds) { Reference reference = referenceDAO.findById(referenceId); reference.setIssuedDate(new Date()); reference.setState(Reference.ReferenceState.ISSUED); referenceDAO.update(reference); } }
@Override public void generatePrintForm(Reference reference, OutputStream outputStream) { ReportXml reportXml = new ReportXml(); if (reference.getPrintTemplate() == null || reference.getPrintTemplate().getFileName() == null) { setDefaultPrintTemplate(reference); } reportXml.setTemplateFileName(reference.getPrintTemplate().getFileName()); build(reportXml, studentDAO.findById(reference.getOwnerId()), reference.getPurpose()); ReportPdfProcessor.getInstance().generate(reportXml, outputStream); }
@Override public void setDefaultPrintTemplate(Reference reference) { String documentName; switch (reference.getType()) { case REFERENCE_1: documentName = "reference-1.xml"; break; case REFERENCE_2: documentName = "reference-2.xml"; break; case REFERENCE_3: documentName = "reference-3.xml"; break; default: throw new RuntimeException( "Unknown template file name for reference type " + reference.getType() + "."); } String templName = ReferenceServiceImpl.class.getResource("/templates/" + documentName).getFile(); templName = templName.replace("%20", " "); reference.setPrintTemplate(new Template(templName)); }
@Override public void generatePrintForm(List<Reference> references, OutputStream outputStream) { List<Report> reports = new ArrayList<Report>(); for (Reference reference : references) { ReportXml reportXml = new ReportXml(); if (reference.getPrintTemplate() == null || reference.getPrintTemplate().getFileName() == null) { setDefaultPrintTemplate(reference); } reportXml.setTemplateFileName(reference.getPrintTemplate().getFileName()); build(reportXml, studentDAO.findById(reference.getOwnerId()), reference.getPurpose()); reports.add(reportXml); } ReportPdfProcessor.getInstance().generate(reports, outputStream); }
@Override public void registrationReference(Reference reference) { reference.setRegisteredDate(new Date()); reference.setState(Reference.ReferenceState.REGISTERED); referenceDAO.saveOrUpdate(reference); }