public void delete(int id) { Document d = new Document(); d.setId(id); try { FileManage criteria = new FileManage(); criteria.setSource(ParameterModel.DOCUMENT_ENTITY); criteria.setFkEntityId(id + ""); List<FileManage> files = this.getFileManageService().getByExample(criteria, null); String lastFileName; if (files != null & !files.isEmpty() && files.size() > 0) { lastFileName = files.get(files.size() - 1).getPath(); FileUtils.deleteFile(lastFileName); fileManageService.delete(files.get(files.size() - 1)); } criteria.setSource(ParameterModel.DOCUMENT_THUMB_ENTITY); files = this.getFileManageService().getByExample(criteria, null); if (files != null & !files.isEmpty() && files.size() > 0) { lastFileName = files.get(files.size() - 1).getPath(); FileUtils.deleteFile(lastFileName); fileManageService.delete(files.get(files.size() - 1)); } } catch (Exception e) { } documentService.delete(d); documents = documentService.getAll(); FacesContext.getCurrentInstance() .addMessage( null, new FacesMessage(FacesMessage.SEVERITY_INFO, ParameterModel.STATUS_DELETE_SUCCESS, "")); }
public void init() { if (id != 0) { Document d = documentService.getById(id); title = d.getTitle(); documentType = d.getDocType().getId() + ""; } }
public Map<String, Integer> getDocumentTypesForSelect() { if (documentTypesForSelect == null || documentTypesForSelect.isEmpty()) { documentTypesForSelect = new LinkedHashMap<String, Integer>(); List<DocumentType> l = documentService.getAllType(); documentTypesForSelect.put(ParameterModel.PLEASE_SELECT, null); for (DocumentType c : l) { documentTypesForSelect.put(c.getDocumentType(), c.getId()); } } return documentTypesForSelect; }
public void add() { logger.info("add"); Document model = new Document(); String lastFileName = null; try { model.setTitle(getTitle()); DocumentType docType = new DocumentType(); docType.setId(Integer.parseInt(getDocumentType())); model.setDocType(docType); model.setUpdatedBy(FacesContext.getCurrentInstance().getExternalContext().getRemoteUser()); if (getId() == 0) { documentService.add(model); } else { model.setId(getId()); documentService.update(model); } try { if (file != null) { String f = FileUtils.copyFile(file); List<FileManage> files; FileManage criteria = new FileManage(); criteria.setSource(ParameterModel.DOCUMENT_ENTITY); FileManage fModel = new FileManage(); fModel.setFkEntityId(model.getId() + ""); fModel.setPath(f); fModel.setSource(ParameterModel.DOCUMENT_ENTITY); if (getId() != 0) { // check dup criteria.setFkEntityId(getId() + ""); criteria.setWeight(1); files = this.getFileManageService().getByExample(criteria, null); if (files != null & !files.isEmpty() && files.size() > 0) { fModel.setId(files.get(files.size() - 1).getId()); lastFileName = files.get(files.size() - 1).getPath(); } } fModel.setType(""); fModel.setUpdatedBy( FacesContext.getCurrentInstance().getExternalContext().getRemoteUser()); if (fModel.getId() == 0) fileManageService.add(fModel); else { fileManageService.update(fModel); FileUtils.deleteFile(lastFileName); } } } catch (IOException e) { e.printStackTrace(); } try { if (thumb != null) { String f = FileUtils.copyFile(thumb); List<FileManage> files; FileManage criteria = new FileManage(); criteria.setSource(ParameterModel.DOCUMENT_THUMB_ENTITY); FileManage fModel = new FileManage(); fModel.setFkEntityId(model.getId() + ""); fModel.setPath(f); fModel.setSource(ParameterModel.DOCUMENT_THUMB_ENTITY); if (getId() != 0) { // check dup criteria.setFkEntityId(getId() + ""); criteria.setWeight(2); files = this.getFileManageService().getByExample(criteria, null); if (files != null & !files.isEmpty() && files.size() > 0) { fModel.setId(files.get(files.size() - 1).getId()); lastFileName = files.get(files.size() - 1).getPath(); } } fModel.setType(""); fModel.setUpdatedBy( FacesContext.getCurrentInstance().getExternalContext().getRemoteUser()); if (fModel.getId() == 0) fileManageService.add(fModel); else { fileManageService.update(fModel); FileUtils.deleteFile(lastFileName); } } } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } setId(0); setDocumentType(""); setTitle(""); }
public List<Document> getDocuments() { return documentService.getAll(); }