diff --git a/src/main/java/info/bukova/isspst/DateTimeUtils.java b/src/main/java/info/bukova/isspst/DateTimeUtils.java index eb57b0b9..5a672440 100644 --- a/src/main/java/info/bukova/isspst/DateTimeUtils.java +++ b/src/main/java/info/bukova/isspst/DateTimeUtils.java @@ -1,85 +1,135 @@ package info.bukova.isspst; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import org.apache.commons.lang.time.DateUtils; -public class DateTimeUtils -{ - public static Date getDate(Date value) - { - if (value == null) - { - return value; - } - - // Keep date - truncate time - return DateUtils.truncate(value, Calendar.DAY_OF_MONTH); - } - - public static boolean isEqualByDate(Date d1, Date d2) - { - if (d1 != null && d2 != null) - { - d1 = DateTimeUtils.getDate(d1); - d2 = DateTimeUtils.getDate(d2); - boolean equals = (d1.compareTo(d2) == 0); - return equals; - } - - return false; - } - - public static boolean isEqualByDateForFilter(Date value, Date search) - { - if (search == null) - { - return true; - } - else if (value != null) - { - return DateTimeUtils.isEqualByDate(value, search); - } - - return false; - } - - public static Date getCurrDateTime() - { - return new Date(); - } - - public static Date getCurrDate() - { - return DateTimeUtils.getDate(DateTimeUtils.getCurrDateTime()); - } - - public static Calendar getCalendarDelta(Date value, int calendarType, int delta) { - if (value == null) { - value = DateTimeUtils.getCurrDate(); - } - - Calendar calendar = new GregorianCalendar(); - calendar.setTime(value); - int deltaValue = calendar.get(calendarType); - calendar.set(calendarType, deltaValue + delta); - return calendar; - } - - public static Calendar getCalendar(Date value) { - if (value == null) { - value = DateTimeUtils.getCurrDate(); - } - - Calendar calendar = new GregorianCalendar(); - calendar.setTime(value); - return calendar; - } - - public static Date getDateDelta(Date value, int calendarType, int delta) { - Calendar calendar = DateTimeUtils.getCalendarDelta(value, calendarType, delta); - return calendar.getTime(); - } +public class DateTimeUtils { + public static Date getDate(Date value) { + if (value == null) { + return value; + } + + // Keep date - truncate time + return DateUtils.truncate(value, Calendar.DAY_OF_MONTH); + } + + public static int getYear(Date value) { + if (value == null) { + return 0; + } + + Calendar cal =Calendar.getInstance(); + cal.setTime(value); + return cal.get(Calendar.YEAR); + } + + public static boolean isEqualByDate(Date d1, Date d2) { + if (d1 != null && d2 != null) { + d1 = DateTimeUtils.getDate(d1); + d2 = DateTimeUtils.getDate(d2); + boolean equals = (d1.compareTo(d2) == 0); + return equals; + } + + return false; + } + + public static boolean isEqualByYear(Date d1, Date d2) { + if (d1 != null && d2 != null) { + int year1 = DateTimeUtils.getYear(d1); + int year2 = DateTimeUtils.getYear(d2); + boolean equals = (year1 == year2); + return equals; + } + + return false; + } + public static boolean isEqualByDateForFilter(Date value, Date search) { + if (search == null) { + return true; + } else if (value != null) { + return DateTimeUtils.isEqualByDate(value, search); + } + + return false; + } + + public static String getFormatedDate(Date value) { + if (value == null) { + return ""; + } + + SimpleDateFormat sdf = new SimpleDateFormat(StringUtils.localize("DateFormat")); + String result = sdf.format(value); + return result; + } + + public static String getFormatedDirDate(Date value) { + if (value == null) { + return ""; + } + + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + String result = sdf.format(value); + return result; + } + + public static String getFormatedDirDateDDMM(Date value) { + if (value == null) { + return ""; + } + + SimpleDateFormat sdf = new SimpleDateFormat("MMdd"); + String result = sdf.format(value); + return result; + } + + public static String getFormatedYear(Date value) { + if (value == null) { + return ""; + } + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); + String result = sdf.format(value); + return result; + } + + public static Date getCurrDateTime() { + return new Date(); + } + + public static Date getCurrDate() { + return DateTimeUtils.getDate(DateTimeUtils.getCurrDateTime()); + } + + public static Calendar getCalendarDelta(Date value, int calendarType, int delta) { + if (value == null) { + value = DateTimeUtils.getCurrDate(); + } + + Calendar calendar = new GregorianCalendar(); + calendar.setTime(value); + int deltaValue = calendar.get(calendarType); + calendar.set(calendarType, deltaValue + delta); + return calendar; + } + + public static Calendar getCalendar(Date value) { + if (value == null) { + value = DateTimeUtils.getCurrDate(); + } + + Calendar calendar = new GregorianCalendar(); + calendar.setTime(value); + return calendar; + } + + public static Date getDateDelta(Date value, int calendarType, int delta) { + Calendar calendar = DateTimeUtils.getCalendarDelta(value, calendarType, delta); + return calendar.getTime(); + } } diff --git a/src/main/java/info/bukova/isspst/data/SignedDocument.java b/src/main/java/info/bukova/isspst/data/SignedDocument.java index 608aae43..9b75093c 100644 --- a/src/main/java/info/bukova/isspst/data/SignedDocument.java +++ b/src/main/java/info/bukova/isspst/data/SignedDocument.java @@ -7,11 +7,7 @@ import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; import org.hibernate.search.annotations.IndexedEmbedded; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.OneToMany; -import javax.persistence.Table; +import javax.persistence.*; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -20,6 +16,9 @@ import java.util.List; @Table(name = "SIGNED_DOCUMENTS") public class SignedDocument extends BaseData { + @Transient + private String agendaName; + @Column(name = "MODULE_NAME", length = Constants.LEN_TEXT) private String moduleName; @@ -40,7 +39,10 @@ public class SignedDocument extends BaseData { @IndexedEmbedded private List items; - public String getModuleName() { + public SignedDocument() { + } + + public String getModuleName() { return moduleName; } @@ -81,6 +83,9 @@ public class SignedDocument extends BaseData { } public String getAgendaName() { + if (!StringUtils.isNullOrEmpty(this.agendaName)) { + return this.agendaName; + } if (StringUtils.isNullOrEmpty(this.moduleName)) { return ""; @@ -95,7 +100,11 @@ public class SignedDocument extends BaseData { return ""; } - public List getItems() { + public void setAgendaName(String agendaName) { + this.agendaName = agendaName; + } + + public List getItems() { return items; } diff --git a/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentService.java b/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentService.java index fc992b08..a4534772 100644 --- a/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentService.java +++ b/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentService.java @@ -1,9 +1,13 @@ package info.bukova.isspst.services.signeddocs; import info.bukova.isspst.data.DataModel; +import info.bukova.isspst.data.Member; import info.bukova.isspst.data.SignedDocument; import info.bukova.isspst.data.SignedDocumentItem; import info.bukova.isspst.services.Service; +import info.bukova.isspst.ui.signeddocs.SignedDocsTreeNode; +import org.zkoss.zul.TreeModel; +import org.zkoss.zul.TreeNode; import java.util.List; @@ -17,4 +21,5 @@ public interface SignedDocumentService extends Service { public List getActualList(); public List getArchiveList(); + public TreeModel> getTree(); } diff --git a/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java b/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java index 22803b2d..98029423 100644 --- a/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/signeddocs/SignedDocumentServiceImpl.java @@ -4,126 +4,239 @@ import info.bukova.isspst.DateTimeUtils; import info.bukova.isspst.Module; import info.bukova.isspst.ModuleUtils; import info.bukova.isspst.data.DataModel; +import info.bukova.isspst.data.Member; import info.bukova.isspst.data.SignedDocument; import info.bukova.isspst.data.SignedDocumentItem; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.storage.ReportFileStorage; -import java.util.Calendar; -import java.util.Date; -import java.util.List; +import java.util.*; import javax.servlet.ServletContext; +import info.bukova.isspst.ui.signeddocs.SignedDocsTreeNode; import org.hibernate.Hibernate; import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import org.zkoss.zul.DefaultTreeModel; +import org.zkoss.zul.DefaultTreeNode; +import org.zkoss.zul.TreeModel; +import org.zkoss.zul.TreeNode; public class SignedDocumentServiceImpl extends AbstractOwnedService implements SignedDocumentService { - @Autowired - private ServletContext servletContext; - @Autowired - private ReportFileStorage signedDocStorage; - - @LazyLoader("grid") - @Transactional - public void lazyLoadItems(SignedDocument signedDocument) { - if (signedDocument == null) { - return; - } - - SignedDocument sd = dao.getById(signedDocument.getId()); - Hibernate.initialize(sd.getItems()); - signedDocument.setItems(sd.getItems()); - } - - @Override - @Transactional - public SignedDocument getForEntity(DataModel entity) { - Module module = ModuleUtils.getModule(entity, servletContext); - - if (module == null) { - return null; - } - - Query q = dao.getQuery("from SignedDocument where moduleName = :module and recordId = :record"); - q.setParameter("module", module.getId()); - q.setParameter("record", entity.getId()); - - return (SignedDocument) q.uniqueResult(); - } - - @Override - @Transactional - public SignedDocumentItem getItem(DataModel entity, long reportId) { - SignedDocument doc = getForEntity(entity); - - if (doc == null) { - return null; - } - - for (SignedDocumentItem item : doc.getItems()) { - if (item.getReportId() == reportId) { - return item; - } - } - - return null; - } - - @Override - public void addFromApprove(SignedDocument document) { - super.add(document); - } - - @Override - public void delFromApprove(SignedDocument document) { - if (document == null) { - return; - } - - super.delete(document); - - for (SignedDocumentItem item : document.getItems()) { - signedDocStorage.removeFile(item); - } - } - - @Override - @Transactional - public void deleteForEntity(DataModel entity) { - SignedDocument doc = getForEntity(entity); - if (doc != null) { - delFromApprove(doc); - } - } - - private Date getTresholdDate() { - Date date = DateTimeUtils.getDateDelta(DateTimeUtils.getCurrDate(), Calendar.YEAR, -1); - return date; - } - - @SuppressWarnings("unchecked") - @Override - @Transactional - @PreAuthorize("hasPermission(this, 'PERM_READ')") - public List getActualList() { - Query q = dao.getQuery("from SignedDocument where signDate >= :refDate"); - q.setParameter("refDate", this.getTresholdDate()); - return q.list(); - } - - @SuppressWarnings("unchecked") - @Override - @Transactional - @PreAuthorize("hasPermission(this, 'PERM_READ')") - public List getArchiveList() { - Query q = dao.getQuery("from SignedDocument where signDate < :refDate"); - q.setParameter("refDate", this.getTresholdDate()); - return q.list(); - } + @Autowired + private ServletContext servletContext; + @Autowired + private ReportFileStorage signedDocStorage; + + @LazyLoader("grid") + @Transactional + public void lazyLoadItems(SignedDocument signedDocument) { + if (signedDocument == null) { + return; + } + + SignedDocument sd = dao.getById(signedDocument.getId()); + Hibernate.initialize(sd.getItems()); + signedDocument.setItems(sd.getItems()); + } + + @Override + @Transactional + public SignedDocument getForEntity(DataModel entity) { + Module module = ModuleUtils.getModule(entity, servletContext); + + if (module == null) { + return null; + } + + Query q = dao.getQuery("from SignedDocument where moduleName = :module and recordId = :record"); + q.setParameter("module", module.getId()); + q.setParameter("record", entity.getId()); + + return (SignedDocument) q.uniqueResult(); + } + + @Override + @Transactional + public SignedDocumentItem getItem(DataModel entity, long reportId) { + SignedDocument doc = getForEntity(entity); + + if (doc == null) { + return null; + } + + for (SignedDocumentItem item : doc.getItems()) { + if (item.getReportId() == reportId) { + return item; + } + } + + return null; + } + + @Override + public void addFromApprove(SignedDocument document) { + super.add(document); + } + + @Override + public void delFromApprove(SignedDocument document) { + if (document == null) { + return; + } + + super.delete(document); + + for (SignedDocumentItem item : document.getItems()) { + signedDocStorage.removeFile(item); + } + } + + @Override + @Transactional + public void deleteForEntity(DataModel entity) { + SignedDocument doc = getForEntity(entity); + if (doc != null) { + delFromApprove(doc); + } + } + + private Date getTresholdDate() { + Date date = DateTimeUtils.getDateDelta(DateTimeUtils.getCurrDate(), Calendar.MONTH, -6); + return date; + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_READ')") + public List getActualList() { + Query q = dao.getQuery("from SignedDocument where signDate >= :refDate"); + q.setParameter("refDate", this.getTresholdDate()); + return q.list(); + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_READ')") + public List getArchiveList() { + Query q = dao.getQuery("from SignedDocument where signDate < :refDate"); + q.setParameter("refDate", this.getTresholdDate()); + return q.list(); + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_READ')") + public TreeModel> getTree() { + Query q = queryDao.getQuery("select item " + + "from SignedDocumentItem as item left join item.signedDocument as rec " + + "order by rec.moduleName, rec.signDate desc, item.reportName, item.fileName " + ); + List list = q.list(); + + SignedDocumentItem lastItem = null; + SignedDocument lastRec = null; + List agendaNameList = new LinkedList(); + List signYearList = new LinkedList(); + List signDateList = new LinkedList(); + List filesList = null; + + int documentsCount = list.size() - 1; + + for (int i = 0; i <= documentsCount; i++) { + SignedDocumentItem item = list.get(i); + SignedDocument rec = item.getSignedDocument(); + SignedDocsTreeNode itemNode = new SignedDocsTreeNode(item); + + boolean isChangedAgendaName = ((i == 0) + || (i == documentsCount) + || !lastRec.getAgendaName().equals(rec.getAgendaName()) + ); + boolean isChangedSignYear = ((i == 0) + || (i == documentsCount) + || isChangedAgendaName + || !DateTimeUtils.isEqualByYear(lastRec.getSignDate(), rec.getSignDate()) + ); + boolean isChangedSignDate = ((i == 0) + || (i == documentsCount) + || isChangedSignYear + || !DateTimeUtils.isEqualByDate(lastRec.getSignDate(), rec.getSignDate()) + ); + + if (isChangedAgendaName || isChangedSignYear || isChangedSignDate) { + + if (isChangedSignDate) { + if (i > 0) { + SignedDocsTreeNode signDateNode = new SignedDocsTreeNode((i == documentsCount ? item : lastItem), filesList); + signDateList.add(signDateNode); + } + + filesList = new LinkedList(); + filesList.add(itemNode); + } + + if (isChangedSignYear) { + if (i > 0) { + SignedDocsTreeNode signYearNode = new SignedDocsTreeNode((i == documentsCount ? item : lastItem), signDateList); + signYearList.add(signYearNode); + } + + signDateList = new LinkedList(); + } + + if (isChangedAgendaName) { + if (i > 0) { + SignedDocsTreeNode agendaNode = new SignedDocsTreeNode((i == documentsCount ? item : lastItem), signYearList); + agendaNameList.add(agendaNode); + } + + signYearList = new LinkedList(); + } + } else { + filesList.add(itemNode); + } + + lastItem = item; + lastRec = lastItem.getSignedDocument(); + } + + Collections.sort(agendaNameList, new Comparator() { + @Override + public int compare(SignedDocsTreeNode nodeL, SignedDocsTreeNode nodeR) { + if ((nodeL != null) && (nodeR != null)) { + SignedDocumentItem itemL = nodeL.getData(); + SignedDocumentItem itemR = nodeR.getData(); + + if ((itemL != null) && (itemR != null)) { + SignedDocument recL = itemL.getSignedDocument(); + SignedDocument recR = itemR.getSignedDocument(); + + if ((recL != null) && (recR != null)) { + String nameL = recL.getAgendaName(); + String nameR = recR.getAgendaName(); + + if ((nameL != null) && (nameR != null)) { + return nameL.compareTo(nameR); + } + } + } + } + + return 0; + } + } + ); + + SignedDocsTreeNode root = new SignedDocsTreeNode(null, agendaNameList); + TreeModel> tree = new DefaultTreeModel(root); + return tree; + } } diff --git a/src/main/java/info/bukova/isspst/storage/DocumentFileStorageImpl.java b/src/main/java/info/bukova/isspst/storage/DocumentFileStorageImpl.java index 4ff84e90..bb5bf8d8 100644 --- a/src/main/java/info/bukova/isspst/storage/DocumentFileStorageImpl.java +++ b/src/main/java/info/bukova/isspst/storage/DocumentFileStorageImpl.java @@ -44,6 +44,11 @@ public class DocumentFileStorageImpl extends AbstractFileStorage i this.rootPath = rootPath; } + @Override + public String getRootPath() { + return this.rootPath; + } + @Override public void saveFile(byte[] data, FileMetainfo fileID) { String fileName = generateFileName(fileID.getFileName()); diff --git a/src/main/java/info/bukova/isspst/storage/FileStorage.java b/src/main/java/info/bukova/isspst/storage/FileStorage.java index 90a0eea2..9f384b58 100644 --- a/src/main/java/info/bukova/isspst/storage/FileStorage.java +++ b/src/main/java/info/bukova/isspst/storage/FileStorage.java @@ -9,7 +9,7 @@ import java.io.File; */ public interface FileStorage { -// public String getRootPath(); + public String getRootPath(); public void saveFile(byte[] data, T fileID); public void saveFile(File file, T fileId); public void removeFile(T fileID); diff --git a/src/main/java/info/bukova/isspst/storage/LocalFileStorage.java b/src/main/java/info/bukova/isspst/storage/LocalFileStorage.java index 00d86515..f1bc3ea0 100644 --- a/src/main/java/info/bukova/isspst/storage/LocalFileStorage.java +++ b/src/main/java/info/bukova/isspst/storage/LocalFileStorage.java @@ -12,6 +12,11 @@ public class LocalFileStorage extends AbstractFileStorage { this.rootPath = rootPath; } + @Override + public String getRootPath() { + return this.rootPath; + } + public void setContext(ServletContext ctx) { this.context = ctx; } diff --git a/src/main/java/info/bukova/isspst/storage/ReportFileStorageImpl.java b/src/main/java/info/bukova/isspst/storage/ReportFileStorageImpl.java index 93f59998..470e6026 100644 --- a/src/main/java/info/bukova/isspst/storage/ReportFileStorageImpl.java +++ b/src/main/java/info/bukova/isspst/storage/ReportFileStorageImpl.java @@ -16,6 +16,11 @@ public class ReportFileStorageImpl extends AbstractFileStorage> getTreeBackup() { + try { + return signedDocumentService.getTree(); + } catch (AccessDeniedException e) { + // BindUtils.postGlobalCommand(null, null, "disableCentre", null); + // e.printStackTrace(); + return new DefaultTreeModel(null); + } + } + + public static void addToZipFile(String filePath, String zipPath, ZipOutputStream zos) throws FileNotFoundException, IOException { + + //System.out.println("Writing '" + filePath + "' to zip file"); + + File file = new File(filePath); + FileInputStream fis = new FileInputStream(file); + ZipEntry zipEntry = new ZipEntry(zipPath); + zos.putNextEntry(zipEntry); + + byte[] bytes = new byte[1024]; + int length; + while ((length = fis.read(bytes)) >= 0) { + zos.write(bytes, 0, length); + } + + zos.closeEntry(); + fis.close(); + } + + public static String getNormalizedPath(String path) { + String result = path.replaceAll("[ ]", "_"); + result = Normalizer.normalize(result, Normalizer.Form.NFD); + result = result.replaceAll("[^-a-zA-Z0-9_./]", ""); + return result; + } + + public static String getCheckedString(String str, int maxLength) { + String result = ""; + + if (str != null) { + + int len = str.length(); + + if (len > 0) { + result = str.substring(0, len > maxLength ? maxLength - 1 : len); + result += "-"; + } + } + + return result; + } + + public static String getCheckedString(String str) { + return SignedDocsTreeList.getCheckedString(str, 50); + } + + @Command + public void onCreateZipArchive() { + if (this.selectedNodeItem == null) { + return; + } + + List leafs = this.selectedNodeItem.getLeafs(); + + if (leafs.size() > 0) { + int deep = this.selectedNodeItem.getDeep(); + + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ZipOutputStream zos = new ZipOutputStream(bos); + + for (SignedDocsTreeNode node : leafs) { + SignedDocumentItem item = node.getData(); + String pdfFileName = item.getFileName(); + + SignedDocument doc = item.getSignedDocument(); + String zipDirs = ""; + + + String zipFileName = ""; + + if (deep == 3 || deep == 4) { + zipFileName += SignedDocsTreeList.getCheckedString(DateTimeUtils.getFormatedDirDate(doc.getSignDate())); + } + + zipFileName += SignedDocsTreeList.getCheckedString(item.getReportName()); + zipFileName += SignedDocsTreeList.getCheckedString(doc.getNumser()); + zipFileName += SignedDocsTreeList.getCheckedString(doc.getDescription()); + zipFileName += SignedDocsTreeList.getCheckedString(pdfFileName); + + if (deep == 1 || deep == 2 || deep == 3) { + zipDirs += doc.getAgendaName(); + zipDirs += "/"; + } + + if (deep == 1) { + zipDirs += DateTimeUtils.getFormatedYear(doc.getSignDate()); + zipDirs += "/"; + } + + if (deep == 1) { + zipDirs += DateTimeUtils.getFormatedDirDateDDMM(doc.getSignDate()); + zipDirs += "/"; + } + if (deep == 2) { + zipDirs += DateTimeUtils.getFormatedDirDate(doc.getSignDate()); + zipDirs += "/"; + } + String rootPath = signedDocStorage.getRootPath(); + + String diskPath = rootPath + "/" + pdfFileName; + String zipPath = zipDirs + zipFileName; + + zipPath = SignedDocsTreeList.getNormalizedPath(zipPath); + + if (new File(diskPath).isFile()) { + SignedDocsTreeList.addToZipFile(diskPath, zipPath, zos); + } else { + log.warn("Missing file '" + diskPath + "' !!!"); + log.warn(doc.getAgendaName()); + log.warn(doc.getDescription()); + log.warn(item.getReportName()); + } + } + + zos.close(); + bos.close(); + + Filedownload.save(bos.toByteArray(), "application/zip", "temp" + Long.toString(System.nanoTime()) + ".zip"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsTreeNode.java b/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsTreeNode.java new file mode 100644 index 00000000..1d8e5f1f --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsTreeNode.java @@ -0,0 +1,79 @@ +package info.bukova.isspst.ui.signeddocs; + +import info.bukova.isspst.data.SignedDocumentItem; +import org.zkoss.zul.DefaultTreeNode; +import org.zkoss.zul.TreeNode; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +public class SignedDocsTreeNode extends DefaultTreeNode { + public SignedDocsTreeNode(SignedDocumentItem data) { + super(data); + } + + public SignedDocsTreeNode(SignedDocumentItem data, Collection> children) { + super(data, children); + } + + public SignedDocsTreeNode getParentNode() { + return (SignedDocsTreeNode) this.getParent(); + } + + public int getDeep() { + int iDeep = 0; + SignedDocsTreeNode node = this.getParentNode(); + + while (node != null) { + node = node.getParentNode(); + iDeep++; + } + + return iDeep; + } + + public List getLeafs() { + List list = new LinkedList(); + + if (!this.isLeaf()) { + List> children = this.getChildren(); + + for (TreeNode item : children) { + SignedDocsTreeNode node = (SignedDocsTreeNode) item; + + if (node != null) { + if (node.isLeaf()) { + list.add(node); + } else { + list.addAll(node.getLeafs()); + } + } + } + } + + return list; + } + + public int getLeafsCount() { + int count = 0; + + if (!this.isLeaf()) { + List> children = this.getChildren(); + + for (TreeNode item : children) { + SignedDocsTreeNode node = (SignedDocsTreeNode) item; + + if (node != null) { + if (node.isLeaf()) { + count += 1; + } else { + count += node.getLeafsCount(); + } + } + } + } + + return count; + } +} diff --git a/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsTreeRenderer.java b/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsTreeRenderer.java new file mode 100644 index 00000000..3ec299fd --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/signeddocs/SignedDocsTreeRenderer.java @@ -0,0 +1,41 @@ +package info.bukova.isspst.ui.signeddocs; + +import info.bukova.isspst.DateTimeUtils; +import info.bukova.isspst.StringUtils; +import info.bukova.isspst.data.SignedDocument; +import info.bukova.isspst.data.SignedDocumentItem; +import org.zkoss.zul.*; + +public class SignedDocsTreeRenderer implements TreeitemRenderer { + public void render(Treeitem item, SignedDocsTreeNode data, int index) throws Exception { + + int deep = data.getDeep(); + + boolean node1 = (deep == 1);//data.getParent().getParent() == null; + boolean node3 = (deep == 3);//data.isLeaf(); + boolean node2 = (deep == 2);//!node1 && !node3; + boolean node4 = (deep == 4);//!node1 && !node3; + + SignedDocumentItem signedDocumentItem = data.getData(); + SignedDocument signedDocument = signedDocumentItem.getSignedDocument(); + + Treerow tr = new Treerow(); + tr.setContext("popupMenu"); + + item.appendChild(tr); + tr.appendChild(new Treecell(node1 ? signedDocument.getAgendaName() : "")); + tr.appendChild(new Treecell(node2 ? DateTimeUtils.getFormatedYear(signedDocument.getSignDate()) : "")); + tr.appendChild(new Treecell(node3 ? DateTimeUtils.getFormatedDate(signedDocument.getSignDate()) : "")); + tr.appendChild(new Treecell(node4 ? signedDocument.getNumser() : "")); + tr.appendChild(new Treecell(node4 ? signedDocument.getDescription() : "")); + tr.appendChild(new Treecell(node4 ? signedDocumentItem.getReportName() : data.getLeafsCount() + " souborů")); +// tr.appendChild(new Treecell(node3 ? signedDocumentItem.getFileName() : "")); + + switch (deep) { + case 1 : tr.setSclass("signed-doc-agenda"); break; + case 2 : tr.setSclass("signed-doc-year"); break; + case 3 : tr.setSclass("signed-doc-date"); break; + case 4 : tr.setSclass(""); break; + } + } +} diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index d0f131bd..5e5c5dab 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -415,6 +415,9 @@ Search=Hledat Pending = Nevyřízené Archive = Archiv Completed = Vyřízeno +Backup = Zálohování +SigningYear = Rok podepsání +DownloadZipArchive = Stáhnout ZIP archiv... GenerateBillingForPassengers = Generovat společný požadavek a vyúčtování Passenger = Pasažér diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index 8e325a1d..cc08388d 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -183,7 +183,7 @@ - + diff --git a/src/main/webapp/css/zk-modify.css b/src/main/webapp/css/zk-modify.css index a6039d62..2c9142f2 100644 --- a/src/main/webapp/css/zk-modify.css +++ b/src/main/webapp/css/zk-modify.css @@ -93,3 +93,15 @@ .user-disabled { background-color: #fff2dd !important; } + +.signed-doc-agenda { + background-color: #d0d0d0 !important; +} + +.signed-doc-year { + background-color: #e0e0e0 !important; +} + +.signed-doc-date { + background-color: #f0f0f0 !important; +} \ No newline at end of file diff --git a/src/main/webapp/img/zip-016.png b/src/main/webapp/img/zip-016.png new file mode 100644 index 00000000..57fa131d Binary files /dev/null and b/src/main/webapp/img/zip-016.png differ diff --git a/src/main/webapp/img/zip-032.png b/src/main/webapp/img/zip-032.png new file mode 100644 index 00000000..bbaa5cae Binary files /dev/null and b/src/main/webapp/img/zip-032.png differ diff --git a/src/main/webapp/lists/signeddocs/grid.zul b/src/main/webapp/lists/signeddocs/grid.zul index 52aa0453..aa1fa4d1 100644 --- a/src/main/webapp/lists/signeddocs/grid.zul +++ b/src/main/webapp/lists/signeddocs/grid.zul @@ -3,6 +3,9 @@ diff --git a/src/main/webapp/lists/signeddocs/headListBackup.zul b/src/main/webapp/lists/signeddocs/headListBackup.zul new file mode 100644 index 00000000..54ca730d --- /dev/null +++ b/src/main/webapp/lists/signeddocs/headListBackup.zul @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/src/main/webapp/lists/signeddocs/setup.zul b/src/main/webapp/lists/signeddocs/setup.zul index 2432fd12..fe181283 100644 --- a/src/main/webapp/lists/signeddocs/setup.zul +++ b/src/main/webapp/lists/signeddocs/setup.zul @@ -4,6 +4,7 @@ String gridActual = "/lists/signeddocs/headListActual.zul"; String gridArchive = "/lists/signeddocs/headListArchive.zul"; + String treeBackup = "/lists/signeddocs/headListBackup.zul"; + @@ -13,5 +14,8 @@ + + + diff --git a/src/main/webapp/lists/signeddocs/treeBackup.zul b/src/main/webapp/lists/signeddocs/treeBackup.zul new file mode 100644 index 00000000..b8f3e23f --- /dev/null +++ b/src/main/webapp/lists/signeddocs/treeBackup.zul @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + +