Merge branch 'master' of https://git.bukova.info/repos/git/isspst
commit
5079d6d55a
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,186 @@
|
||||
package info.bukova.isspst.ui.signeddocs;
|
||||
|
||||
import info.bukova.isspst.DateTimeUtils;
|
||||
import info.bukova.isspst.data.SignedDocument;
|
||||
import info.bukova.isspst.data.SignedDocumentItem;
|
||||
import info.bukova.isspst.storage.ReportFileStorage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.DefaultTreeModel;
|
||||
import org.zkoss.zul.Filedownload;
|
||||
import org.zkoss.zul.TreeModel;
|
||||
import org.zkoss.zul.TreeNode;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.Normalizer;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
||||
public class SignedDocsTreeList extends SignedDocsList {
|
||||
@SuppressWarnings("unused")
|
||||
private final static Logger log = LoggerFactory.getLogger(SignedDocsTreeList.class.getName());
|
||||
|
||||
@WireVariable
|
||||
private ReportFileStorage signedDocStorage;
|
||||
|
||||
public SignedDocsTreeNode getSelectedNodeItem() {
|
||||
return selectedNodeItem;
|
||||
}
|
||||
|
||||
public void setSelectedNodeItem(SignedDocsTreeNode selectedNodeItem) {
|
||||
this.selectedNodeItem = selectedNodeItem;
|
||||
}
|
||||
|
||||
private SignedDocsTreeNode selectedNodeItem;
|
||||
|
||||
public SignedDocsTreeList() {
|
||||
}
|
||||
|
||||
@Init(superclass = true)
|
||||
public void signedDocsTreeListInit() {
|
||||
}
|
||||
|
||||
public TreeModel<TreeNode<SignedDocumentItem>> getTreeBackup() {
|
||||
try {
|
||||
return signedDocumentService.getTree();
|
||||
} catch (AccessDeniedException e) {
|
||||
// BindUtils.postGlobalCommand(null, null, "disableCentre", null);
|
||||
// e.printStackTrace();
|
||||
return new DefaultTreeModel<SignedDocumentItem>(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<SignedDocsTreeNode> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<SignedDocumentItem> {
|
||||
public SignedDocsTreeNode(SignedDocumentItem data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public SignedDocsTreeNode(SignedDocumentItem data, Collection<? extends TreeNode<SignedDocumentItem>> 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<SignedDocsTreeNode> getLeafs() {
|
||||
List<SignedDocsTreeNode> list = new LinkedList<SignedDocsTreeNode>();
|
||||
|
||||
if (!this.isLeaf()) {
|
||||
List<TreeNode<SignedDocumentItem>> children = this.getChildren();
|
||||
|
||||
for (TreeNode<SignedDocumentItem> 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<TreeNode<SignedDocumentItem>> children = this.getChildren();
|
||||
|
||||
for (TreeNode<SignedDocumentItem> item : children) {
|
||||
SignedDocsTreeNode node = (SignedDocsTreeNode) item;
|
||||
|
||||
if (node != null) {
|
||||
if (node.isLeaf()) {
|
||||
count += 1;
|
||||
} else {
|
||||
count += node.getLeafsCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
@ -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<SignedDocsTreeNode> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 950 B |
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,12 @@
|
||||
<zk>
|
||||
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
|
||||
<window
|
||||
vflex="1"
|
||||
border="none"
|
||||
apply="org.zkoss.bind.BindComposer"
|
||||
viewModel="@id('vm') @init('info.bukova.isspst.ui.signeddocs.SignedDocsTreeList')">
|
||||
<include
|
||||
vflex="1"
|
||||
src="/lists/signeddocs/treeBackup.zul" />
|
||||
</window>
|
||||
</zk>
|
@ -0,0 +1,25 @@
|
||||
<hlayout vflex="1" hflex="max">
|
||||
<tree id="tree"
|
||||
vflex="1" hflex="max"
|
||||
model="@load(vm.treeBackup)"
|
||||
selectedItem="@bind(vm.selectedNodeItem)"
|
||||
itemRenderer="info.bukova.isspst.ui.signeddocs.SignedDocsTreeRenderer"
|
||||
sclass="addScrollbar">
|
||||
|
||||
<treecols>
|
||||
<treecol hflex="7" label="${labels.AgendaName}"/>
|
||||
<treecol hflex="4" label="${labels.SigningYear}"/>
|
||||
<treecol hflex="5" label="${labels.SigningDate}"/>
|
||||
<treecol hflex="5" label="${labels.Number}"/>
|
||||
<treecol hflex="15" label="${labels.OrderFormDescription}"/>
|
||||
<treecol hflex="6" label="${labels.ReportReport}"/>
|
||||
</treecols>
|
||||
</tree>
|
||||
<menupopup id="popupMenu">
|
||||
<menuitem
|
||||
image="/img/zip-032.png"
|
||||
label="${labels.DownloadZipArchive}..."
|
||||
onClick="@command('onCreateZipArchive')"
|
||||
/>
|
||||
</menupopup>
|
||||
</hlayout>
|
Loading…
Reference in New Issue