Skip to content

Commit

Permalink
add folder hierarchy to html export. close #1253
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Oct 23, 2024
1 parent 7e1ae3b commit f0df521
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@
import java.nio.file.attribute.FileTime;
import java.text.NumberFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -725,7 +727,7 @@ public File getExportFolderName(ArchiveFileBean dto) {
afs = dto.getId();
}
afs = ServerStringUtils.removeSonderzeichen(afs);
File newDir = new File(this.targetDirectory.getAbsolutePath() + System.getProperty("file.separator") + afs);
File newDir = new File(this.targetDirectory.getAbsolutePath() + File.separator + afs);
return newDir;
}

Expand All @@ -743,7 +745,7 @@ public String exportReviews() throws Exception {
this.targetDirectory.mkdirs();
}

File revCsv = new File(this.targetDirectory.getAbsolutePath() + System.getProperty("file.separator") + "wiedervorlagen-fristen.csv");
File revCsv = new File(this.targetDirectory.getAbsolutePath() + File.separator + "wiedervorlagen-fristen.csv");
if (revCsv.exists()) {
revCsv.delete();
}
Expand Down Expand Up @@ -831,7 +833,7 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception {
copyToLocal("templates/exporthtml/index.html", "index.html", newDir, "");
copyToLocal("templates/exporthtml/j-lawyer_style.css", "j-lawyer_style.css", newDir, "");

File newDir2 = new File(newDir.getAbsolutePath() + System.getProperty("file.separator") + "images");
File newDir2 = new File(newDir.getAbsolutePath() + File.separator + "images");
newDir2.mkdirs();

copyToLocal("templates/exporthtml/images/j-lawyer_body.jpg", "j-lawyer_body.jpg", newDir, "images/");
Expand All @@ -842,10 +844,7 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception {
copyToLocal("templates/exporthtml/images/j-lawyer_menu_hover.jpg", "j-lawyer_menu_hover.jpg", newDir, "images/");
copyToLocal("templates/exporthtml/images/j-lawyer_sidebar_section_bottom.jpg", "j-lawyer_sidebar_section_bottom.jpg", newDir, "images/");

File newDir3 = new File(newDir.getAbsolutePath() + System.getProperty("file.separator") + "documents");
newDir3.mkdirs();

File indexFile = new File(newDir.getAbsolutePath() + System.getProperty("file.separator") + "index.html");
File indexFile = new File(newDir.getAbsolutePath() + File.separator + "index.html");
byte[] content = ServerFileUtils.readFile(indexFile);
String sContent = new String(content, "UTF-8");
sContent = sContent.replaceAll("\\{\\{filenumber\\}\\}", dto.getFileNumber());
Expand Down Expand Up @@ -912,42 +911,38 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception {
ArrayList docList = new ArrayList(documents);
Collections.sort(docList, new DocumentsComparator());
sb = new StringBuffer();
HashMap<String,List<CaseFolder>> folderHierarchies=new HashMap<>();
for (Object d : docList) {
if (d instanceof ArchiveFileDocumentsBean) {
ArchiveFileDocumentsBean db = (ArchiveFileDocumentsBean) d;

String dbNewName = removeSonderzeichen(db.getName());

dbNewName = dbNewName.replace(",", "");
dbNewName = dbNewName.replace("\"", "");
dbNewName = dbNewName.replace("§", "");
dbNewName = dbNewName.replace("%", "");
dbNewName = dbNewName.replace("&", "");
dbNewName = dbNewName.replace("/", "");
dbNewName = dbNewName.replace("=", "");
dbNewName = dbNewName.replace("\\?", "");
dbNewName = dbNewName.replace("\\{", "");
dbNewName = dbNewName.replace("\\}", "");
dbNewName = dbNewName.replace("\\[", "");
dbNewName = dbNewName.replace("\\]", "");
dbNewName = dbNewName.replace("\\\\", "");
dbNewName = dbNewName.replace("\\*", "");
dbNewName = dbNewName.replace("#", "");
dbNewName = dbNewName.replace("'", "");
dbNewName = dbNewName.replace(":", "");
dbNewName = dbNewName.replace(";", "");
dbNewName=ServerFileUtils.sanitizeFileName(dbNewName);

if(dbNewName.length()==0) {
log.warn("invalid file name: " + dbNewName);
dbNewName=""+System.currentTimeMillis();
}


List<CaseFolder> hierarchy = new ArrayList<>();
if (db.getFolder() != null) {
if(!folderHierarchies.containsKey(db.getFolder().getId())) {
hierarchy=caseFacade.getFolderHierarchy(db.getFolder().getId());
folderHierarchies.put(db.getFolder().getId(), hierarchy);
}
hierarchy=folderHierarchies.get(db.getFolder().getId());
}

String subPath=toFilePath(hierarchy);
try {
byte[] docContent = caseFacade.getDocumentContentUnrestricted(db.getId());
try (FileOutputStream docOut = new FileOutputStream(newDir3.getAbsolutePath() + System.getProperty("file.separator") + dbNewName)) {
File docFolders=new File(newDir.getAbsolutePath() + subPath);
docFolders.mkdirs();
try (FileOutputStream docOut = new FileOutputStream(newDir.getAbsolutePath() + subPath + File.separator + dbNewName)) {
docOut.write(docContent);
}
File docOutFile = new File(newDir3.getAbsolutePath() + System.getProperty("file.separator") + dbNewName);
File docOutFile = new File(newDir.getAbsolutePath() + subPath + File.separator + dbNewName);
if (db.getChangeDate() != null) {
docOutFile.setLastModified(db.getChangeDate().getTime());
}
Expand All @@ -957,24 +952,27 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception {
}

// <tr><td><p class="post_info">01.01.2013</p></td><td><p class="post_info">dings</p></td></tr>


sb.append("<tr valign=\"top\"><td><p class=\"post_info\">");
sb.append(toDate(df, db.getChangeDate()));
sb.append("</p></td><td><p class=\"post_info\"><a href=\"documents/");
subPath=subPath.replace(File.separator, "/");
if(subPath.startsWith("/") && subPath.length()>1)
subPath=subPath.substring(1);
sb.append("</p></td><td><p class=\"post_info\"><a href=\"").append(subPath);
if(!subPath.isEmpty())
sb.append(File.separator);
sb.append(dbNewName);
sb.append("\">");
sb.append(dbNewName);
sb.append("</a></p></td><td><p class=\"post_info\">");
if (db.getDictateSign() != null) {
sb.append(db.getDictateSign());
}
sb.append("</p></td>");
sb.append("<td><p class=\"post_info\">");
if (db.getFolder() != null) {
sb.append("Ordner: ").append(removeSonderzeichen(db.getFolder().getName()));
} else {
sb.append("");
}
sb.append("</p></td>");
sb.append("</p></td></tr><tr>");
sb.append("<td></td><td><p class=\"folder_info\"><nobr>");
sb.append(toFolderPath(hierarchy));
sb.append("</nobr></p></td>");
sb.append("</tr>");
}
}
Expand All @@ -993,6 +991,28 @@ public String export(ArchiveFileBean dto, Date lastModified) throws Exception {
return newDir.getAbsolutePath();

}

private String toFolderPath(List<CaseFolder> hierarchy) {
StringBuilder sb=new StringBuilder();
for(CaseFolder f: hierarchy) {
sb.append(" > ").append(f.getName());
}
String path=sb.toString().trim();
if(path.isEmpty())
path=">";
return path;
}

private String toFilePath(List<CaseFolder> hierarchy) {
StringBuilder sb=new StringBuilder();
for(CaseFolder f: hierarchy) {
String fName=ServerFileUtils.sanitizeFileName(f.getName());
if(fName.isEmpty())
fName="---";
sb.append(File.separator).append(fName);
}
return sb.toString();
}

private String toDate(SimpleDateFormat dateFormat, Date d) {
if (d == null) {
Expand Down Expand Up @@ -1078,7 +1098,7 @@ private String getPartiesList(Collection parties) {
}

private void copyToLocal(String resource, String name, File dir, String subDir) throws Exception {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(resource); FileOutputStream fOut = new FileOutputStream(dir.getAbsolutePath() + System.getProperty("file.separator") + subDir + name);) {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(resource); FileOutputStream fOut = new FileOutputStream(dir.getAbsolutePath() + File.separator + subDir + name);) {
byte[] buffer = new byte[256];
int len = 0;
while ((len = is.read(buffer)) > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4559,6 +4559,31 @@ public CaseFolder applyFolderTemplateById(String caseId, String templateId) thro
public DocumentFolderTemplate getFolderTemplateById(String id) {
return this.folderTemplateFacade.find(id);
}

/**
* Returns a list of folder representing a hierarchy. First element in the list is the root folder.
* @param folderId
* @return
*/
@Override
@RolesAllowed({"loginRole"})
public List<CaseFolder> getFolderHierarchy(String folderId) {
List<CaseFolder> hierarchy=new ArrayList<>();
if(folderId==null)
return hierarchy;

CaseFolder cf=this.caseFolderFacade.find(folderId);
if(cf!=null) {
hierarchy.add(cf);
while(!cf.isRoot()) {
cf=this.caseFolderFacade.find(cf.getParentId());
hierarchy.add(cf);

}
}
Collections.reverse(hierarchy);
return hierarchy;
}

@Override
@RolesAllowed({"readArchiveFileRole"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ public interface ArchiveFileServiceLocal {
CaseFolder applyFolderTemplateById(String id, String templateId) throws Exception;

DocumentFolderTemplate getFolderTemplateById(String id);

List<CaseFolder> getFolderHierarchy(String folderId);

void purgeDocumentBin() throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ h3 {
font-weight: normal;
}

.content_box .folder_info {
font-size: 9px;
color: #666666;
font-weight: bold;
}

.news_box a{
color: #000000;
font-weight: normal;
Expand Down

0 comments on commit f0df521

Please sign in to comment.