Skip to content

Commit

Permalink
sending registered letters. issue #54.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Oct 13, 2023
1 parent d7274bb commit 9cf3042
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,8 @@
package com.jdimension.jlawyer.client.launcher;

import com.jdimension.jlawyer.client.editors.EditorsRegistry;
import com.jdimension.jlawyer.persistence.ArchiveFileBean;
import com.jdimension.jlawyer.persistence.ArchiveFileDocumentsBean;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
Expand All @@ -694,49 +691,39 @@ public void launch(boolean autoCloseExistingDocument) throws Exception {

final Launcher thisLauncher = this;

new Thread(new Runnable() {
new Thread(() -> {
ObservedDocument odoc = new ObservedDocument(url, store, thisLauncher);
DocumentObserver observer = DocumentObserver.getInstance();
odoc.setStatus(ObservedDocument.STATUS_LAUNCHING);
odoc.setMonitoringMode(true);
observer.addDocument(odoc);

public void run() {

ObservedDocument odoc = null;
// if (!readOnly) {
odoc = new ObservedDocument(url, store, thisLauncher);
DocumentObserver observer = DocumentObserver.getInstance();
odoc.setStatus(ObservedDocument.STATUS_LAUNCHING);
odoc.setMonitoringMode(true);
observer.addDocument(odoc);

try {
Desktop d = null;
if (Desktop.isDesktopSupported()) {
d = Desktop.getDesktop();

} else {
odoc.setClosed(true);
throw new Exception("Datei kann nicht geöffnet werden: Desktop API wird nicht unterstützt!");
}
odoc.setStatus(ObservedDocument.STATUS_MONITORING);
long launched=System.currentTimeMillis();
d.open(new File(url));
long launchDuration=System.currentTimeMillis()-launched;
if(launchDuration>30000)
odoc.setClosed(true);

} catch (final Exception ex) {
try {
Desktop d = null;
if (Desktop.isDesktopSupported()) {
d = Desktop.getDesktop();

} else {
odoc.setClosed(true);
throw new Exception("Datei kann nicht geöffnet werden: Desktop API wird nicht unterstützt!");
}
odoc.setStatus(ObservedDocument.STATUS_MONITORING);
long launched = System.currentTimeMillis();
d.open(new File(url));
long launchDuration = System.currentTimeMillis() - launched;
if (launchDuration > 30000) {
odoc.setClosed(true);
SwingUtilities.invokeLater(new Runnable() {

public void run() {
JOptionPane.showMessageDialog(EditorsRegistry.getInstance().getMainWindow(), "Fehler beim Öffnen des Dokuments: " + ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE);
}
});

}

//odoc.setClosed(true);
} catch (final Exception ex) {

odoc.setClosed(true);
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(EditorsRegistry.getInstance().getMainWindow(), "Fehler beim Öffnen des Dokuments: " + ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE);
});

}

}).start();
}

Expand Down
32 changes: 28 additions & 4 deletions j-lawyer-fax/src/com/jdimension/jlawyer/epost/EpostAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,6 @@ public class EpostAPI {
private static final String AUTH_HEADERNAME = "Authorization";
private static final String AUTH_HEADERPREFIX = "Bearer ";

//private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");

private String baseUri = "https://api.epost.docuguide.com";
Expand Down Expand Up @@ -822,8 +821,34 @@ public String sendLetter(String token, EpostLetter letter) throws EpostException
return letterId;
}

public String sendRegisteredLetter(EpostLetter letter) throws EpostException {
return null;
public String sendRegisteredLetter(String token, EpostLetter letter, String registeredLetterMode) throws EpostException {
log.info("ePost API registered letter sending");

if(registeredLetterMode==null)
throw new EpostException("Registered letter mode is required");

boolean validType=false;
for(String m: EpostLetter.REGISTEREDLETTER_TYPES) {
if(m.equals(registeredLetterMode)) {
validType=true;
break;
}
}
if(!validType) {
throw new EpostException("Registered letter mode not supported: " + registeredLetterMode);
}

letter.setRegisteredLetter(registeredLetterMode);

this.validateLetterAttributes(letter);

String letterId = this.postLetterToApi(token, letter, false, null);
log.info("ePost API registered letter sending finished, letter ID is " + letterId);
return letterId;




}

public EpostApiStatus healthCheck() throws EpostException {
Expand Down Expand Up @@ -886,7 +911,6 @@ public EpostLetterStatus getLetterStatus(String token, String letterId) throws E
Object jsonOutput = Jsoner.deserialize(returnValue);
if (jsonOutput instanceof JsonObject) {
JsonObject result = (JsonObject) jsonOutput;
//JsonKey levelKey = Jsoner.mintJsonKey("level", null);

s.setLetterId(result.getInteger(Jsoner.mintJsonKey("letterID", null)));
s.setFileName(result.getString(Jsoner.mintJsonKey("fileName", null)));
Expand Down
25 changes: 25 additions & 0 deletions j-lawyer-fax/src/com/jdimension/jlawyer/epost/EpostLetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,15 @@ You should also get your employer (if you work as a programmer) or school,
public class EpostLetter implements Serializable {

protected static long serialVersionUID = 1L;


public static final String EINSCHREIBEN="Einschreiben";
public static final String EINSCHREIBEN_EINWURF="Einwurf Einschreiben";
public static final String EINSCHREIBEN_EIGENHAENDIG="Einschreiben eigenhändig";
public static final String EINSCHREIBEN_RUECKSCHEIN="Einschreiben Rückschein";
public static final String EINSCHREIBEN_EIGENHAENDIG_RUECKSCHEIN="Einschreiben eigenhändig Rückschein";

public static final String[] REGISTEREDLETTER_TYPES={EINSCHREIBEN, EINSCHREIBEN_EINWURF, EINSCHREIBEN_EIGENHAENDIG, EINSCHREIBEN_RUECKSCHEIN, EINSCHREIBEN_EIGENHAENDIG_RUECKSCHEIN};

protected String fileName = null;
protected byte[] data = null;
Expand All @@ -698,6 +707,8 @@ public class EpostLetter implements Serializable {
protected String custom3 = null;
protected String custom4 = null;
protected String custom5 = null;

protected String registeredLetter=null;

public EpostLetter() {

Expand Down Expand Up @@ -1025,4 +1036,18 @@ public void setCoverLetter(boolean coverLetter) {
this.coverLetter = coverLetter;
}

/**
* @return the registeredLetter
*/
public String getRegisteredLetter() {
return registeredLetter;
}

/**
* @param registeredLetter the registeredLetter to set
*/
public void setRegisteredLetter(String registeredLetter) {
this.registeredLetter = registeredLetter;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ You should also get your employer (if you work as a programmer) or school,
* @author jens
*/
public class EpostLetterStatus {

protected static long serialVersionUID = 1L;

protected int letterId = -1;
protected String fileName = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ You should also get your employer (if you work as a programmer) or school,
*
*/
public class EpostLetterStatusError {

protected static long serialVersionUID = 1L;

protected String level = null;
protected String code = null;
Expand Down

0 comments on commit 9cf3042

Please sign in to comment.