Skip to content

Commit

Permalink
Merge pull request #279 from b123400/fix-273
Browse files Browse the repository at this point in the history
Print reasons for not dispatching result
  • Loading branch information
zdavatz authored Jul 10, 2024
2 parents 466cbdc + 8916a91 commit 5aa3726
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,21 @@ public ArrayList<ResultDispatch> getResultDispatches() {

public void dispatchResult(String gln, String edifactType, File file, String messageId) {
ArrayList<ResultDispatch> dispatches = this.getResultDispatches();
boolean anySent = false;
int i = 0;
String reasons = "";
for (ResultDispatch dispatch : dispatches) {
dispatch.send(gln, edifactType, file, messageId);
String reasonForNotSending = dispatch.send(gln, edifactType, file, messageId);
if (reasonForNotSending != null) {
reasons += "Dispatch " + i + "\n";
reasons += reasonForNotSending;
} else {
anySent = true;
}
i++;
}
if (!anySent) {
System.out.println("Not sending result, because: \n" + reasons);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,22 @@ class Filter {
}
}

boolean shouldSend(String gln, String edifactType) {
String a = null;
String reasonForNotSending(String gln, String edifactType) {
String reason = "";
if (glns != null) {
if (!glns.contains(gln)) {
return false;
reason = "The gln is " + gln + ", not one of the following: " + glns.toString() + "\n";
}
}
if (edifactTypes != null) {
if (!edifactTypes.contains(edifactType)) {
return false;
reason += "The edifact type is " + edifactType + ", not one of the following: " + edifactTypes.toString() + "\n";
}
}
return true;
if (reason.length() > 0) {
return reason;
}
return null;
}
}

Expand All @@ -121,9 +124,13 @@ boolean shouldSend(String gln, String edifactType) {
}
}

void send(String gln, String edifactType, File file, String messageId) {
if (this.filter != null && !this.filter.shouldSend(gln, edifactType)) {
return;
/**
* @return Null if it sends, otherwise the reason for not sending
*/
String send(String gln, String edifactType, File file, String messageId) {
if (this.filter != null) {
String reasonForNotSending = this.filter.reasonForNotSending(gln, edifactType);
if (reasonForNotSending != null) return reasonForNotSending + "----------\n";
}
if (this.httpPost != null) {
this.sendHTTPPost(file, messageId);
Expand All @@ -134,6 +141,7 @@ void send(String gln, String edifactType, File file, String messageId) {
if (this.emailDest != null) {
this.sendEmail(file);
}
return null;
}

void sendHTTPPost(File file, String messageId) {
Expand Down

0 comments on commit 5aa3726

Please sign in to comment.