Skip to content

Commit

Permalink
Various minor improvements to Nahima export
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Jan 31, 2024
1 parent 41ba32c commit fe320bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

public class NahimaExportJob implements RunnableJob, Runnable {
private static final Logger log = LoggerFactory.getLogger(NahimaExportJob.class);
Expand All @@ -37,15 +38,15 @@ public class NahimaExportJob implements RunnableJob, Runnable {
private int status = STATUS_RUNNING_FINE;
private Exception lastError = null;
private String oneSpecimenBarcode = null;
private List<Specimen> specimenToExport = null;
private List<Long> specimenToExport = null;
private boolean anon = false;

public void setOneSpecimenToExportBarcode(String oneSpecimenBarcode) {
this.oneSpecimenBarcode = oneSpecimenBarcode;
}

public void setSpecimenToExport(List<Specimen> specimenToExport) {
this.specimenToExport = specimenToExport;
this.specimenToExport = specimenToExport.stream().map(spec -> spec.getSpecimenId()).collect(Collectors.toList());
}

public void goAnon() {
Expand All @@ -66,9 +67,9 @@ public void start() {
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("nahimaExported", false);
queryParams.put("barcode", this.oneSpecimenBarcode);
specimenToExport = sls.findBy(queryParams);
specimenToExport = sls.findBy(queryParams).stream().map(spec -> spec.getSpecimenId()).collect(Collectors.toList());
} else {
specimenToExport = sls.findToExport();
specimenToExport = sls.findIdsToExport();
}
}
Collections.shuffle(specimenToExport);
Expand All @@ -94,8 +95,14 @@ public void start() {

Specimen2JSONSerializer serializer = new Specimen2JSONSerializer(manager);

for (Specimen specimen : specimenToExport) {
for (Long specimenId : specimenToExport) {
Specimen specimen = sls.findById(specimenId);
currentIndex = currentIndex + 1;
// check if it hasn't been exported by another instance already
if (specimen.getDateLastNahimaUpdated() != null && specimen.getDateLastNahimaUpdated().after(specimen.getDateLastUpdated())) {
continue;
}

log.debug("Exporting specimen " + currentIndex + "/" + nrOfSpecimenToProcess + " with id " + specimen.getSpecimenId() + " and barcode " + specimen.getBarcode());
notifyWorkStatusChanged("Exporting specimen " + currentIndex + "/" + nrOfSpecimenToProcess + " with id " + specimen.getSpecimenId() + " and barcode " + specimen.getBarcode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public List<Specimen> findAllPage(int startAt, int fetchSize) {
*
* @return
*/
public List<Specimen> findToExport() {
public List<Long> findIdsToExport() {
try {
Session session = this.getSession();
try {
Expand All @@ -480,7 +480,7 @@ public List<Specimen> findToExport() {
Query q = session.createQuery(cr);
List<Long> ids = q.list();
session.getTransaction().commit();
return this.findByIds(ids);
return ids;
} catch (HibernateException e) {
session.getTransaction().rollback();
log.error("find images failed", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ protected JSONObject dateToNahima(String date, boolean allowInvalid) throws Pars
if (date == null || date.equals("")) {
return null;
}
date = date.trim();
try {
Date parsedDate = DateUtils.parseDate(date);
return dateToNahima(parsedDate);
Expand Down

0 comments on commit fe320bc

Please sign in to comment.