diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/HtmlEditorPanel.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/HtmlEditorPanel.java index 60b027199..1311b9e03 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/HtmlEditorPanel.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/HtmlEditorPanel.java @@ -666,10 +666,17 @@ import com.jdimension.jlawyer.server.utils.ContentTypes; import java.awt.Component; import java.awt.Container; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JEditorPane; +import javax.swing.KeyStroke; import org.apache.log4j.Logger; +import javax.swing.undo.UndoManager; /** * @@ -677,6 +684,7 @@ */ public class HtmlEditorPanel extends javax.swing.JPanel implements EditorImplementation { + private final UndoManager undoManager; private static final Logger log=Logger.getLogger(HtmlEditorPanel.class.getName()); /** @@ -684,7 +692,9 @@ public class HtmlEditorPanel extends javax.swing.JPanel implements EditorImpleme */ public HtmlEditorPanel() { initComponents(); - } + + undoManager = new UndoManager(); + setupUndoRedoForEditorPane(htmlPane); } /** * This method is called from within the constructor to initialize the form. @@ -822,5 +832,54 @@ private boolean insertToEditorPane(Container c, String t, int pos) { } return false; } + + private void setupUndoRedoForEditorPane(Container container) { + for (Component comp : container.getComponents()) { + if (comp instanceof JEditorPane) { + JEditorPane editorPane = (JEditorPane) comp; + editorPane.getDocument().addUndoableEditListener(e -> undoManager.addEdit(e.getEdit())); + + // Setup key bindings for undo + KeyStroke undoKeystroke = KeyStroke.getKeyStroke( + KeyEvent.VK_Z, + Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() + ); + + // Setup key bindings for redo + KeyStroke redoKeystroke = KeyStroke.getKeyStroke( + KeyEvent.VK_Y, + Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() + ); + + editorPane.getInputMap(JComponent.WHEN_FOCUSED).put(undoKeystroke, "Undo"); + editorPane.getActionMap().put("Undo", new AbstractAction("Undo") { + @Override + public void actionPerformed(ActionEvent evt) { + if (undoManager.canUndo()) { + undoManager.undo(); + } + } + }); + + editorPane.getInputMap(JComponent.WHEN_FOCUSED).put(redoKeystroke, "Redo"); + editorPane.getActionMap().put("Redo", new AbstractAction("Redo") { + @Override + public void actionPerformed(ActionEvent evt) { + if (undoManager.canRedo()) { + undoManager.redo(); + } + } + }); + + break; // Found the editor pane, no need to continue + } else if (comp instanceof Container) { + setupUndoRedoForEditorPane((Container) comp); + } + } + } + + public UndoManager getUndoManager() { + return undoManager; + } } diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/TextEditorPanel.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/TextEditorPanel.java index c0e8e24da..18c6e0d37 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/TextEditorPanel.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/TextEditorPanel.java @@ -664,20 +664,64 @@ package com.jdimension.jlawyer.client.mail; import com.jdimension.jlawyer.server.utils.ContentTypes; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import javax.swing.AbstractAction; +import javax.swing.JComponent; import javax.swing.KeyStroke; +import javax.swing.undo.UndoManager; /** * * @author Kutschke */ public class TextEditorPanel extends javax.swing.JPanel implements EditorImplementation { - + + private final UndoManager undoManager; + /** * Creates new form TextEditorPanel */ public TextEditorPanel() { initComponents(); + // Initialize UndoManager + undoManager = new UndoManager(); + taText.getDocument().addUndoableEditListener(e -> undoManager.addEdit(e.getEdit())); + + // Setup key bindings for undo + KeyStroke undoKeystroke = KeyStroke.getKeyStroke( + KeyEvent.VK_Z, + Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() + ); + + // Setup key bindings for redo + KeyStroke redoKeystroke = KeyStroke.getKeyStroke( + KeyEvent.VK_Y, + Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() + ); + + taText.getInputMap(JComponent.WHEN_FOCUSED).put(undoKeystroke, "Undo"); + taText.getActionMap().put("Undo", new AbstractAction("Undo") { + @Override + public void actionPerformed(ActionEvent evt) { + if (undoManager.canUndo()) { + undoManager.undo(); + } + } + }); + + taText.getInputMap(JComponent.WHEN_FOCUSED).put(redoKeystroke, "Redo"); + taText.getActionMap().put("Redo", new AbstractAction("Redo") { + @Override + public void actionPerformed(ActionEvent evt) { + if (undoManager.canRedo()) { + undoManager.redo(); + } + } + }); + // this is required because the scroll pane was stealing those key strokes from its jtextarea, making it impossible to scroll using the keys this.jScrollPane2.getInputMap().put(KeyStroke.getKeyStroke("UP"), "none"); this.jScrollPane2.getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "none"); @@ -764,4 +808,9 @@ public String getSelectedText() { public void insert(String t, int pos) { this.taText.insert(t, pos); } + + + public UndoManager getUndoManager() { + return undoManager; + } } diff --git a/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v6/TemplatesEndpointLocalV6.java b/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v6/TemplatesEndpointLocalV6.java index 6ae5a1408..17a042ba8 100644 --- a/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v6/TemplatesEndpointLocalV6.java +++ b/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v6/TemplatesEndpointLocalV6.java @@ -682,5 +682,8 @@ public interface TemplatesEndpointLocalV6 { Response getPlaceHoldersForTemplate(String folder, String template, String caseId); Response addDocumentFromTemplate(String caseId, String fileName, String templateFolder, String template, List placeHolderValues) throws Exception; + + Response listEmailTemplates(); + Response getEmailFromTemplate(String templateName, String caseId); } diff --git a/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v6/TemplatesEndpointV6.java b/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v6/TemplatesEndpointV6.java index 3af11dc7f..1141bed2f 100644 --- a/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v6/TemplatesEndpointV6.java +++ b/j-lawyer-server/j-lawyer-io/src/java/org/jlawyer/io/rest/v6/TemplatesEndpointV6.java @@ -663,18 +663,25 @@ You should also get your employer (if you work as a programmer) or school, */ package org.jlawyer.io.rest.v6; +import com.jdimension.jlawyer.documents.CommonTemplatesUtil; +import com.jdimension.jlawyer.email.EmailTemplate; import com.jdimension.jlawyer.persistence.AppUserBean; import com.jdimension.jlawyer.persistence.ArchiveFileAddressesBean; import com.jdimension.jlawyer.persistence.ArchiveFileBean; import com.jdimension.jlawyer.persistence.ArchiveFileDocumentsBean; +import com.jdimension.jlawyer.persistence.PartyTypeBean; import com.jdimension.jlawyer.services.ArchiveFileServiceLocal; import com.jdimension.jlawyer.services.FormsServiceLocal; import com.jdimension.jlawyer.pojo.PartiesTriplet; +import com.jdimension.jlawyer.services.IntegrationServiceLocal; import com.jdimension.jlawyer.services.SystemManagementLocal; +import java.security.Principal; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import javax.annotation.security.RolesAllowed; import javax.ejb.Stateless; import javax.naming.InitialContext; @@ -690,6 +697,9 @@ You should also get your employer (if you work as a programmer) or school, import org.jlawyer.data.tree.GenericNode; import org.jlawyer.io.rest.v1.pojo.RestfulDocumentV1; import org.jlawyer.io.rest.v6.pojo.RestfulPlaceholderV6; +import java.util.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.SecurityContext; /** * @@ -702,29 +712,33 @@ You should also get your employer (if you work as a programmer) or school, public class TemplatesEndpointV6 implements TemplatesEndpointLocalV6 { private static final Logger log = Logger.getLogger(TemplatesEndpointV6.class.getName()); - private static final String LOOKUP_SYSMAN="java:global/j-lawyer-server/j-lawyer-server-ejb/SystemManagement!com.jdimension.jlawyer.services.SystemManagementLocal"; - private static final String LOOKUP_CASESVC="java:global/j-lawyer-server/j-lawyer-server-ejb/ArchiveFileService!com.jdimension.jlawyer.services.ArchiveFileServiceLocal"; - private static final String LOOKUP_FORMSSVC="java:global/j-lawyer-server/j-lawyer-server-ejb/FormsService!com.jdimension.jlawyer.services.FormsServiceLocal"; - + private static final String LOOKUP_SYSMAN = "java:global/j-lawyer-server/j-lawyer-server-ejb/SystemManagement!com.jdimension.jlawyer.services.SystemManagementLocal"; + private static final String LOOKUP_CASESVC = "java:global/j-lawyer-server/j-lawyer-server-ejb/ArchiveFileService!com.jdimension.jlawyer.services.ArchiveFileServiceLocal"; + private static final String LOOKUP_FORMSSVC = "java:global/j-lawyer-server/j-lawyer-server-ejb/FormsService!com.jdimension.jlawyer.services.FormsServiceLocal"; + private static final String LOOKUP_INTEGRATIONSVC = "java:global/j-lawyer-server/j-lawyer-server-ejb/IntegrationService!com.jdimension.jlawyer.services.IntegrationServiceLocal"; + + @Context + private SecurityContext securityContext; + /** * Returns the folder structure holding document templates. - * + * * @return entire folder structure for document templates * @response 401 User not authorized * @response 403 User not authenticated */ @Override @GET - @Produces(MediaType.APPLICATION_JSON+";charset=utf-8") + @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") @Path("/documents/folders") @RolesAllowed({"loginRole"}) public Response getTemplateFolders() { try { InitialContext ic = new InitialContext(); SystemManagementLocal system = (SystemManagementLocal) ic.lookup(LOOKUP_SYSMAN); - GenericNode rootNode=system.getAllTemplatesTree(SystemManagementLocal.TEMPLATE_TYPE_BODY); - String baseDir=system.getTemplatesBaseDir(SystemManagementLocal.TEMPLATE_TYPE_BODY); - ArrayList nodeIds=new ArrayList<>(); + GenericNode rootNode = system.getAllTemplatesTree(SystemManagementLocal.TEMPLATE_TYPE_BODY); + String baseDir = system.getTemplatesBaseDir(SystemManagementLocal.TEMPLATE_TYPE_BODY); + ArrayList nodeIds = new ArrayList<>(); collectFolders(rootNode, baseDir, nodeIds); Collections.sort(nodeIds, String.CASE_INSENSITIVE_ORDER); return Response.ok(nodeIds).build(); @@ -735,12 +749,13 @@ public Response getTemplateFolders() { } private void collectFolders(Object startNode, String stripPrefix, ArrayList resultList) { - GenericNode node=(GenericNode)startNode; - String id=node.getId(); - if(id.startsWith(stripPrefix)) - id=id.replace(stripPrefix, "/"); + GenericNode node = (GenericNode) startNode; + String id = node.getId(); + if (id.startsWith(stripPrefix)) { + id = id.replace(stripPrefix, "/"); + } resultList.add(id); - for(GenericNode c: node.getChildren()) { + for (GenericNode c : node.getChildren()) { collectFolders(c, stripPrefix, resultList); } } @@ -754,15 +769,15 @@ private void collectFolders(Object startNode, String stripPrefix, ArrayList resultList=system.getTemplatesByPath(SystemManagementLocal.TEMPLATE_TYPE_BODY, folder); + + List resultList = system.getTemplatesByPath(SystemManagementLocal.TEMPLATE_TYPE_BODY, folder); Collections.sort(resultList, String.CASE_INSENSITIVE_ORDER); return Response.ok(resultList).build(); } catch (Exception ex) { @@ -772,7 +787,9 @@ public Response getTemplatesInFolder(@PathParam("folder") String folder) { } /** - * Returns all placeholders keys for a given template in a given folder, using the given case. Case is needed to resolve potential forms placeholders (AKA Falldaten). + * Returns all placeholders keys for a given template in a given folder, + * using the given case. Case is needed to resolve potential forms + * placeholders (AKA Falldaten). * * @param folder the folder hierarchy starting with / * @param template the file name of the template @@ -782,20 +799,20 @@ public Response getTemplatesInFolder(@PathParam("folder") String folder) { */ @Override @GET - @Produces(MediaType.APPLICATION_JSON+";charset=utf-8") + @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") @Path("/documents/{folder}/{template}/{caseId}") @RolesAllowed({"loginRole"}) public Response getPlaceHoldersForTemplate(@PathParam("folder") String folder, @PathParam("template") String template, @PathParam("caseId") String caseId) { try { InitialContext ic = new InitialContext(); SystemManagementLocal system = (SystemManagementLocal) ic.lookup(LOOKUP_SYSMAN); - - List resultList=system.getPlaceHoldersForTemplate(SystemManagementLocal.TEMPLATE_TYPE_BODY, folder, template, caseId); + + List resultList = system.getPlaceHoldersForTemplate(SystemManagementLocal.TEMPLATE_TYPE_BODY, folder, template, caseId); Collections.sort(resultList, String.CASE_INSENSITIVE_ORDER); - Object[] oArray=resultList.stream().filter(ph -> !ph.startsWith("[[")).toArray(); - String[] resultArray=new String[oArray.length]; - for(int i=0;i !ph.startsWith("[[")).toArray(); + String[] resultArray = new String[oArray.length]; + for (int i = 0; i < oArray.length; i++) { + resultArray[i] = oArray[i].toString(); } return Response.ok(resultArray).build(); } catch (Exception ex) { @@ -805,86 +822,92 @@ public Response getPlaceHoldersForTemplate(@PathParam("folder") String folder, @ } /** - * Creates a new document based on a template.Any place holders are automatically populated, but a client may override them. Invoice creation not supported. + * Creates a new document based on a template.Any place holders are + * automatically populated, but a client may override them. Invoice creation + * not supported. * * @param caseId the id of the case - * @param fileName file name of the document to be created, without file extension (server will enforce same extension as template) + * @param fileName file name of the document to be created, without file + * extension (server will enforce same extension as template) * @param folder the template folder hierarchy starting with / * @param template the file name of the template - * @param placeHolderValues key-value pairs holding placeholder values, used for overriding defaults / existing values + * @param placeHolderValues key-value pairs holding placeholder values, used + * for overriding defaults / existing values * @response 401 User not authorized * @response 403 User not authenticated */ @Override @PUT - @Produces(MediaType.APPLICATION_JSON+";charset=utf-8") + @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") @Path("/documents/{folder}/{template}/{caseId}/{fileName}") @RolesAllowed({"loginRole"}) public Response addDocumentFromTemplate(@PathParam("caseId") String caseId, @PathParam("fileName") String fileName, @PathParam("folder") String folder, @PathParam("template") String template, List placeHolderValues) throws Exception { - - if(folder==null || "".equals(folder)) - folder="/"; - - if(!folder.startsWith("/")) - folder="/" + folder; - + + if (folder == null || "".equals(folder)) { + folder = "/"; + } + + if (!folder.startsWith("/")) { + folder = "/" + folder; + } + try { InitialContext ic = new InitialContext(); ArchiveFileServiceLocal casesvc = (ArchiveFileServiceLocal) ic.lookup(LOOKUP_CASESVC); - + SystemManagementLocal system = (SystemManagementLocal) ic.lookup(LOOKUP_SYSMAN); - List placeHoldersInTemplate=system.getPlaceHoldersForTemplate(SystemManagementLocal.TEMPLATE_TYPE_BODY, folder, template, caseId); + List placeHoldersInTemplate = system.getPlaceHoldersForTemplate(SystemManagementLocal.TEMPLATE_TYPE_BODY, folder, template, caseId); Collections.sort(placeHoldersInTemplate, String.CASE_INSENSITIVE_ORDER); - Object[] placeHoldersInTemplateArray=placeHoldersInTemplate.stream().filter(ph -> !ph.startsWith("[[")).toArray(); - HashMap placeHoldersInTemplateMap=new HashMap<>(); - for(Object o: placeHoldersInTemplateArray) { + Object[] placeHoldersInTemplateArray = placeHoldersInTemplate.stream().filter(ph -> !ph.startsWith("[[")).toArray(); + HashMap placeHoldersInTemplateMap = new HashMap<>(); + for (Object o : placeHoldersInTemplateArray) { placeHoldersInTemplateMap.put(o.toString(), ""); } - - ArchiveFileBean aFile=casesvc.getArchiveFile(caseId); - if(aFile==null) { + + ArchiveFileBean aFile = casesvc.getArchiveFile(caseId); + if (aFile == null) { log.error("can not create document with template " + template + " in folder " + folder + " for case " + caseId + " - case does not exist"); return Response.serverError().build(); } - + FormsServiceLocal forms = (FormsServiceLocal) ic.lookup(LOOKUP_FORMSSVC); - HashMap formsPlaceHolders=forms.getPlaceHolderValuesForCase(caseId); - - List parties=new ArrayList<>(); - List aabList=casesvc.getInvolvementDetailsForCase(caseId); - for(ArchiveFileAddressesBean aab: aabList) { - PartiesTriplet pt=new PartiesTriplet(aab.getAddressKey(), aab.getReferenceType(), aab); + HashMap formsPlaceHolders = forms.getPlaceHolderValuesForCase(caseId); + + List parties = new ArrayList<>(); + List aabList = casesvc.getInvolvementDetailsForCase(caseId); + for (ArchiveFileAddressesBean aab : aabList) { + PartiesTriplet pt = new PartiesTriplet(aab.getAddressKey(), aab.getReferenceType(), aab); parties.add(pt); } //placeHoldersInTemplateMap = system.getPlaceHolderValues(placeHoldersInTemplateMap, aFile, parties, "", null, formsPlaceHolders, system.getUser(aFile.getLawyer()), system.getUser(aFile.getAssistant()), system.getUser(context.getCallerPrincipal().getName())); - - AppUserBean userLawyer=null; + + AppUserBean userLawyer = null; try { - userLawyer=system.getUser(aFile.getLawyer()); + userLawyer = system.getUser(aFile.getLawyer()); } catch (Throwable t) { log.warn("Unable to find lawyer " + aFile.getLawyer(), t); } - AppUserBean userAssistant=null; + AppUserBean userAssistant = null; try { - userAssistant=system.getUser(aFile.getAssistant()); + userAssistant = system.getUser(aFile.getAssistant()); } catch (Throwable t) { log.warn("Unable to find assistant " + aFile.getLawyer(), t); } - - + placeHoldersInTemplateMap = system.getPlaceHolderValues(placeHoldersInTemplateMap, aFile, parties, "", null, formsPlaceHolders, userLawyer, userAssistant, null, null, null, null, null, null, null); - - - for(RestfulPlaceholderV6 rph: placeHolderValues) { - String key=rph.getPlaceHolderKey(); - if(!key.startsWith("{{")) - key="{{"+key; - if(!key.endsWith("}}")) - key=key+"}}"; + + for (RestfulPlaceholderV6 rph : placeHolderValues) { + String key = rph.getPlaceHolderKey(); + if (!key.startsWith("{{")) { + key = "{{" + key; + } + if (!key.endsWith("}}")) { + key = key + "}}"; + } placeHoldersInTemplateMap.put(key, rph.getPlaceHolderValue()); } - ArchiveFileDocumentsBean newDoc=casesvc.addDocumentFromTemplate(caseId, fileName, null, folder, template, placeHoldersInTemplateMap, "", null); - RestfulDocumentV1 rdoc=new RestfulDocumentV1(); + ArchiveFileDocumentsBean newDoc = casesvc.addDocumentFromTemplate(caseId, fileName, null, folder, template, placeHoldersInTemplateMap, "", null); + RestfulDocumentV1 rdoc = new RestfulDocumentV1(); rdoc.setCreationDate(newDoc.getCreationDate()); rdoc.setChangeDate(newDoc.getChangeDate()); rdoc.setFavorite(rdoc.isFavorite()); @@ -896,7 +919,7 @@ public Response addDocumentFromTemplate(@PathParam("caseId") String caseId, @Pat rdoc.setSize(newDoc.getSize()); rdoc.setHighlight1(newDoc.getHighlight1()); rdoc.setHighlight2(newDoc.getHighlight2()); - + return Response.ok(rdoc).build(); } catch (Exception ex) { log.error("can not create document with template " + template + " in folder " + folder + " for case " + caseId, ex); @@ -904,4 +927,147 @@ public Response addDocumentFromTemplate(@PathParam("caseId") String caseId, @Pat } } + /** + * Lists all available email templates. + * + * @return List of available email templates with their names + * @response 200 List of templates successfully retrieved + * @response 401 User not authorized + * @response 403 User not authenticated + * @response 500 Server error while retrieving templates + */ + @Override + @GET + @Path("email") + @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") + @RolesAllowed({"loginRole"}) + public Response listEmailTemplates() { + try { + InitialContext ic = new InitialContext(); + IntegrationServiceLocal intSvc = (IntegrationServiceLocal) ic.lookup(LOOKUP_INTEGRATIONSVC); + + Collection templates = intSvc.getAllEmailTemplateNames(); + List> resultList = new ArrayList<>(); + + for (String templateName : templates) { + Map template = new LinkedHashMap<>(); + template.put("name", templateName); + resultList.add(template); + } + + return Response.ok(resultList).build(); + + } catch (Exception ex) { + log.error("Cannot list email templates", ex); + return Response.serverError().build(); + } + } + + /** + * Returns a specific email template with all placeholders filled with case + * data. Default parties will be used. + * + * @param caseId The ID of the case to fill placeholders from + * @param templateName Name of the template to retrieve + * @return Email template with original content, filled content and + * placeholder values + * @response 200 Template successfully retrieved with filled placeholders + * @response 401 User not authorized + * @response 403 User not authenticated + * @response 404 Case or template not found + * @response 500 Server error while processing template + */ + @Override + @GET + @Path("email/{templateName}/{caseId}") + @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") + @RolesAllowed({"loginRole"}) + public Response getEmailFromTemplate(@PathParam("templateName") String templateName, @PathParam("caseId") String caseId) { + try { + InitialContext ic = new InitialContext(); + SystemManagementLocal system = (SystemManagementLocal) ic.lookup(LOOKUP_SYSMAN); + ArchiveFileServiceLocal caseService = (ArchiveFileServiceLocal) ic.lookup(LOOKUP_CASESVC); + IntegrationServiceLocal intSvc = (IntegrationServiceLocal) ic.lookup(LOOKUP_INTEGRATIONSVC); + + Principal principal = securityContext.getUserPrincipal(); + + AppUserBean author = null; + if (principal != null) { + author = system.getUser(principal.getName()); + } + + EmailTemplate tpl = intSvc.getEmailTemplate(templateName); + + ArchiveFileBean aFile = caseService.getArchiveFile(caseId); + if (aFile == null) { + return Response.status(Response.Status.NOT_FOUND) + .entity("Case not found: " + caseId) + .build(); + } + + List allPartyTypes = system.getPartyTypes(); + List allPartyTypesPlaceholders = new ArrayList<>(); + for (PartyTypeBean ptb : allPartyTypes) { + allPartyTypesPlaceholders.add(ptb.getPlaceHolder()); + } + + FormsServiceLocal forms = (FormsServiceLocal) ic.lookup(LOOKUP_FORMSSVC); + Collection formPlaceHolders = forms.getPlaceHoldersForCase(caseId); + HashMap formPlaceHolderValues = forms.getPlaceHolderValuesForCase(caseId); + + // get a list of placeholders + ArrayList placeHolderNames = CommonTemplatesUtil.getPlaceHoldersInTemplate(tpl.getSubject(), allPartyTypesPlaceholders, formPlaceHolders); + HashMap ht = new HashMap<>(); + for (String ph : placeHolderNames) { + ht.put(ph, ""); + } + + // get user objects for this case + AppUserBean caseLawyer = null; + AppUserBean caseAssistant = null; + try { + caseLawyer = system.getUser(aFile.getLawyer()); + } catch (Exception ex) { + log.warn("Unable to load lawyer with id " + aFile.getLawyer()); + } + try { + caseAssistant = system.getUser(aFile.getAssistant()); + } catch (Exception ex) { + log.warn("Unable to load assistant with id " + aFile.getAssistant()); + } + + // Platzhalter sammeln und füllen + List parties = new ArrayList<>(); + List addresses = caseService.getInvolvementDetailsForCase(caseId); + for (ArchiveFileAddressesBean aab : addresses) { + parties.add(new PartiesTriplet(aab.getAddressKey(), aab.getReferenceType(), aab)); + } + + // get all placeholder values for the given set of placeholders + HashMap htValues = system.getPlaceHolderValues(ht, aFile, parties, "", null, formPlaceHolderValues, caseLawyer, caseAssistant, author, null, null, null, null, null, null); + String subject = CommonTemplatesUtil.replacePlaceHolders(tpl.getSubject(), htValues); + + placeHolderNames = CommonTemplatesUtil.getPlaceHoldersInTemplate(tpl.getBody(), allPartyTypesPlaceholders, formPlaceHolders); + ht = new HashMap<>(); + for (String ph : placeHolderNames) { + ht.put(ph, ""); + } + htValues = system.getPlaceHolderValues(ht, aFile, parties, "", null, formPlaceHolderValues, caseLawyer, caseAssistant, author, null, null, null, null, null, null); + + htValues.put("{{CLOUD_LINK}}", ""); + + String body = CommonTemplatesUtil.replacePlaceHolders(tpl.getBody(), htValues); + Map result = new LinkedHashMap<>(); + result.put("subject", subject.trim()); + result.put("body", body); + result.put("mimeType", tpl.getFormat()); + + return Response.ok(result).build(); + + } catch (Exception ex) { + log.error("Cannot get email template " + templateName + " for case " + caseId, ex); + return Response.serverError().build(); + } + } + } diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/AddressService.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/AddressService.java index 96eebd554..41208f70f 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/AddressService.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/AddressService.java @@ -680,7 +680,6 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; -import java.util.Hashtable; import java.util.List; import java.util.Map; import javax.annotation.Resource; diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/IntegrationServiceLocal.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/IntegrationServiceLocal.java index 4d8658b46..bd6038bb2 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/IntegrationServiceLocal.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/IntegrationServiceLocal.java @@ -663,6 +663,8 @@ */ package com.jdimension.jlawyer.services; +import com.jdimension.jlawyer.email.EmailTemplate; +import java.util.Collection; import javax.ejb.Local; /** @@ -672,4 +674,7 @@ @Local public interface IntegrationServiceLocal { + Collection getAllEmailTemplateNames(); + EmailTemplate getEmailTemplate(String fileName) throws Exception; + } diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagement.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagement.java index fc37c96e5..b570debc8 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagement.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagement.java @@ -2548,5 +2548,4 @@ public List importSheets(byte[] odsData, List sheetNames return importer.importSheets(sheetNames, dryRun); } - } diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagementLocal.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagementLocal.java index d2c2c730d..269b197ad 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagementLocal.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/services/SystemManagementLocal.java @@ -734,4 +734,5 @@ public interface SystemManagementLocal { HashMap getPlaceHolderValuesUnrestricted(HashMap placeHolders, ArchiveFileBean aFile, List selectedParties, String dictateSign, GenericCalculationTable calculationTable, HashMap formsPlaceHolderValues, AppUserBean caseLawyer, AppUserBean caseAssistant, AppUserBean author, Invoice invoice, AppUserBean invoiceSender, GenericCalculationTable invoiceTable, GenericCalculationTable timesheetsTable, byte[] giroCode, String ingoText) throws Exception; DocumentNameTemplate getDefaultDocumentNameTemplate() throws Exception; + }