Skip to content

Commit

Permalink
reworked e-post status updates (moved from timertask to container man…
Browse files Browse the repository at this point in the history
…aged @scheduled). close #2554
  • Loading branch information
j-dimension committed Aug 27, 2024
1 parent 4230cd7 commit e7eb67c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 793 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ file.reference.poi-excelant-4.1.2.jar=lib/poi/poi-excelant-4.1.2.jar
file.reference.poi-ooxml-4.1.2.jar=lib/poi/poi-ooxml-4.1.2.jar
file.reference.poi-ooxml-schemas-4.1.2.jar=lib/poi/poi-ooxml-schemas-4.1.2.jar
file.reference.poi-scratchpad-4.1.2.jar=lib/poi/poi-scratchpad-4.1.2.jar
j2ee.platform.classpath=${j2ee.server.home}/modules/system/layers/base/javax/activation/api/main/activation-1.1.1.jar:${j2ee.server.home}/modules/system/layers/base/javax/annotation/api/main/jboss-annotations-api_1.3_spec-1.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/batch/api/main/jboss-batch-api_1.0_spec-1.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/ejb/api/main/jboss-ejb-api_3.2_spec-1.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/el/api/main/jboss-el-api_3.0_spec-1.0.13.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/enterprise/api/main/cdi-api-2.0.SP1.jar:${j2ee.server.home}/modules/system/layers/base/javax/enterprise/concurrent/api/main/jboss-concurrency-api_1.0_spec-1.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/faces/api/main/jboss-jsf-api_2.3_spec-2.3.9.SP01.jar:${j2ee.server.home}/modules/system/layers/base/javax/inject/api/main/javax.inject-1.jar:${j2ee.server.home}/modules/system/layers/base/javax/interceptor/api/main/jboss-interceptors-api_1.2_spec-1.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/jms/api/main/jboss-jms-api_2.0_spec-1.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/json/api/main/javax.json-api-1.1.2.jar:${j2ee.server.home}/modules/system/layers/base/javax/json/bind/api/main/javax.json.bind-api-1.0.jar:${j2ee.server.home}/modules/system/layers/base/javax/jws/api/main/jsr181-api-1.0-MR1.jar:${j2ee.server.home}/modules/system/layers/base/javax/mail/api/main/javax.mail-1.6.2.jar:${j2ee.server.home}/modules/system/layers/base/javax/management/j2ee/api/main/jboss-j2eemgmt-api_1.1_spec-1.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/orb/api/main/openjdk-orb-8.1.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/persistence/api/main/javax.persistence-api-2.2.jar:${j2ee.server.home}/modules/system/layers/base/javax/resource/api/main/jboss-connector-api_1.7_spec-1.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/security/auth/message/api/main/jboss-jaspi-api_1.1_spec-1.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/security/enterprise/api/main/javax.security.enterprise-api-1.0.jar:${j2ee.server.home}/modules/system/layers/base/javax/security/jacc/api/main/jboss-jacc-api_1.5_spec-1.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/api/main/jboss-servlet-api_4.0_spec-1.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/jsp/api/main/jboss-jsp-api_2.3_spec-1.0.3.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/jstl/api/main/taglibs-standard-compat-1.2.6-RC1.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/jstl/api/main/taglibs-standard-impl-1.2.6-RC1.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/jstl/api/main/taglibs-standard-spec-1.2.6-RC1.jar:${j2ee.server.home}/modules/system/layers/base/javax/transaction/api/main/jboss-transaction-api_1.2_spec-1.1.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/validation/api/main/validation-api-2.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/websocket/api/main/jboss-websocket-api_1.1_spec-1.1.3.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/ws/rs/api/main/jboss-jaxrs-api_2.1_spec-1.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/wsdl4j/api/main/wsdl4j-1.6.3.jar:${j2ee.server.home}/modules/system/layers/base/javax/xml/bind/api/main/jboss-jaxb-api_2.3_spec-1.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/xml/rpc/api/main/jboss-jaxrpc-api_1.1_spec-1.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/xml/soap/api/main/jboss-saaj-api_1.3_spec-1.0.6.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/xml/ws/api/main/jboss-jaxws-api_2.3_spec-1.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/org/glassfish/javax/el/main/javax.el-impl-3.0.1-b08-jbossorg-1.jar:${j2ee.server.home}/modules/system/layers/base/org/glassfish/javax/enterprise/concurrent/main/javax.enterprise.concurrent-1.0.jar:${j2ee.server.home}/modules/system/layers/base/org/glassfish/javax/json/main/javax.json-1.1.2.jar
j2ee.platform.classpath=${j2ee.server.home}/modules/system/layers/base/javax/activation/api/main/jakarta.activation-1.2.2.jar:${j2ee.server.home}/modules/system/layers/base/javax/annotation/api/main/jboss-annotations-api_1.3_spec-2.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/batch/api/main/jboss-batch-api_1.0_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/ejb/api/main/jboss-ejb-api_3.2_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/el/api/main/jboss-el-api_3.0_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/enterprise/api/main/jakarta.enterprise.cdi-api-2.0.2.jar:${j2ee.server.home}/modules/system/layers/base/javax/enterprise/concurrent/api/main/jboss-concurrency-api_1.0_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/faces/api/main/jboss-jsf-api_2.3_spec-3.1.0.SP01.jar:${j2ee.server.home}/modules/system/layers/base/javax/inject/api/main/jakarta.inject-api-1.0.5.jar:${j2ee.server.home}/modules/system/layers/base/javax/interceptor/api/main/jboss-interceptors-api_1.2_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/jms/api/main/jboss-jms-api_2.0_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/json/api/main/jakarta.json-api-1.1.6.jar:${j2ee.server.home}/modules/system/layers/base/javax/json/bind/api/main/jakarta.json.bind-api-1.0.2.jar:${j2ee.server.home}/modules/system/layers/base/javax/jws/api/main/jsr181-api-1.0-MR1.jar:${j2ee.server.home}/modules/system/layers/base/javax/mail/api/main/jakarta.mail-1.6.7.jar:${j2ee.server.home}/modules/system/layers/base/javax/management/j2ee/api/main/jboss-j2eemgmt-api_1.1_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/orb/api/main/openjdk-orb-8.1.7.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/persistence/api/main/jakarta.persistence-api-2.2.3.jar:${j2ee.server.home}/modules/system/layers/base/javax/resource/api/main/jboss-connector-api_1.7_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/security/auth/message/api/main/jboss-jaspi-api_1.1_spec-2.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/security/enterprise/api/main/jakarta.security.enterprise-api-1.0.2.jar:${j2ee.server.home}/modules/system/layers/base/javax/security/jacc/api/main/jboss-jacc-api_1.5_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/api/main/jboss-servlet-api_4.0_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/jsp/api/main/jboss-jsp-api_2.3_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/jstl/api/main/taglibs-standard-compat-1.2.6-RC1.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/jstl/api/main/taglibs-standard-impl-1.2.6-RC1.jar:${j2ee.server.home}/modules/system/layers/base/javax/servlet/jstl/api/main/taglibs-standard-spec-1.2.6-RC1.jar:${j2ee.server.home}/modules/system/layers/base/javax/transaction/api/main/jboss-transaction-api_1.3_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/validation/api/main/jakarta.validation-api-2.0.2.jar:${j2ee.server.home}/modules/system/layers/base/javax/websocket/api/main/jboss-websocket-api_1.1_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/ws/rs/api/main/jboss-jaxrs-api_2.1_spec-2.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/wsdl4j/api/main/wsdl4j-1.6.3.jar:${j2ee.server.home}/modules/system/layers/base/javax/xml/bind/api/main/jboss-jaxb-api_2.3_spec-2.0.1.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/xml/rpc/api/main/jboss-jaxrpc-api_1.1_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/xml/soap/api/main/jboss-saaj-api_1.4_spec-1.0.2.Final.jar:${j2ee.server.home}/modules/system/layers/base/javax/xml/ws/api/main/jboss-jaxws-api_2.3_spec-2.0.0.Final.jar:${j2ee.server.home}/modules/system/layers/base/org/glassfish/javax/enterprise/concurrent/main/jakarta.enterprise.concurrent-1.1.1.jar
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,20 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.annotation.security.RunAs;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.ejb.Schedule;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import org.apache.log4j.Logger;
import org.jboss.ejb3.annotation.TransactionTimeout;

/**
*
Expand Down Expand Up @@ -1335,5 +1341,91 @@ public void saveEpostReport(int letterId, String fileName) throws EpostException
list.add(letterId);
this.deleteEpostQueueEntries(list);
}

@Schedule(hour = "*", minute = "*/4", persistent = false)
@TransactionTimeout(value = 3, unit = TimeUnit.MINUTES)
public void updateEpostStatus() {
performUpdateEpostStatus();
}

@Asynchronous
public void performUpdateEpostStatus() {

try {
List<EpostQueueBean> entries = this.epostFacade.findAll();

// need to request grouped by sender id, because they might have different credentials
HashMap<String, List<Integer>> unfinishedLetterIds = new HashMap<>();
HashMap<Integer, EpostQueueBean> updateCandidates=new HashMap<>();

int failed = 0;
for (EpostQueueBean eqb : entries) {
updateCandidates.put(eqb.getLetterId(), eqb);

int currentStatus = eqb.getLastStatusId();
if (!EpostUtils.isFinalStatus(currentStatus)) {
if (!unfinishedLetterIds.containsKey(eqb.getSentBy())) {
unfinishedLetterIds.put(eqb.getSentBy(), new ArrayList<>());
}
unfinishedLetterIds.get(eqb.getSentBy()).add(eqb.getLetterId());
}

}

List<EpostLetterStatus> newStatuus = new ArrayList<>();
try {
for (String principal : unfinishedLetterIds.keySet()) {
// different principals might use the same epost credentials and we may run into the rate limit of 5s --> add delay
List<EpostLetterStatus> allForUser = getLetterStatus(unfinishedLetterIds.get(principal), principal);
newStatuus.addAll(allForUser);
try {
Thread.sleep(5500);
} catch (Throwable threadEx) {
log.error("Could not delay next EPOST status query", threadEx);
}
}
} catch (Throwable t) {
log.error("Could not update status for multiple letters, skipping...", t);
}

for (EpostLetterStatus newStatus : newStatuus) {
EpostQueueBean eqb=updateCandidates.get(newStatus.getLetterId());
int currentStatus=eqb.getLastStatusId();
if (newStatus.getStatusId() != currentStatus) {
// update entry
eqb.setCreatedDate(newStatus.getCreatedDate());
eqb.setLastStatusId(newStatus.getStatusId());
eqb.setDestinationAreaStatus(newStatus.getDestinationAreaStatus());
eqb.setDestinationAreaStatusDate(newStatus.getDestinationAreaStatusDate());
eqb.setFileName(newStatus.getFileName());
eqb.setLastStatusDetails(newStatus.getStatusDetails());
eqb.setNoOfPages(newStatus.getNoOfPages());
eqb.setPrintFeedbackDate(newStatus.getPrintFeedbackDate());
eqb.setPrintUploadDate(newStatus.getPrintUploadDate());
eqb.setProcessedDate(newStatus.getProcessedDate());
eqb.setRegisteredLetterStatus(newStatus.getRegisteredLetterStatus());
eqb.setRegisteredLetterStatusDate(newStatus.getRegisteredLetterStatusDate());
eqb.setRegisteredLetterId(newStatus.getRegisteredLetterId());
this.epostFacade.edit(eqb);

if (EpostUtils.isFailStatus(newStatus.getStatusId())) {
failed = failed + 1;
singleton.setFailedLetter(eqb);
}
}
}

if (failed == 0) {
singleton.setFailedLetter(null);
}

ArrayList<EpostQueueBean> list = new ArrayList<>();
list.addAll(this.epostFacade.findAll());
singleton.setEpostQueue(list);

} catch (Throwable ex) {
log.error("Error checking ePost letter statuses", ex);
}
}

}
Loading

0 comments on commit e7eb67c

Please sign in to comment.