package au.gov.ga.geodesy.domain.model.event;

import java.time.Instant;
import java.util.Calendar;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

public class EventRepositoryImpl implements EventRepositoryCustom {

    @PersistenceContext(unitName = "geodesy")
    private EntityManager entityManager;

    public List<Event> getPendingEvents() {

        // TODO: try to remove oneMinuteAgo
        String queryString = "select e from Event e "
            + "where e.timeHandled is null and (e.retries is null or e.retries < " + Event.MAX_RETRIES + ") and (e.timePublished is null or e.timePublished < :oneMinuteAgo)";

        TypedQuery<Event> query = entityManager.createQuery(queryString, Event.class);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MINUTE, -1);
        query.setParameter("oneMinuteAgo", c.getTime());
        return query.getResultList();
    }
}

@@ -44,61 +44,8 @@
 t;%0A%0A
-import java.time.Instant;%0Aimport java.util.Calendar;%0A
 impo
@@ -344,16 +344,48 @@
 nager;%0A%0A
+    // TODO: move out of custom%0A
     publ
@@ -425,52 +425,8 @@
  %7B%0A%0A
-        // TODO: try to remove oneMinuteAgo%0A
     
@@ -615,43 +615,8 @@
 null
- or e.timePublished %3C :oneMinuteAgo
 )%22;%0A
@@ -707,146 +707,8 @@
 s);%0A
-        Calendar c = Calendar.getInstance();%0A        c.add(Calendar.MINUTE, -1);%0A        query.setParameter(%22oneMinuteAgo%22, c.getTime());%0A
     

Remove recently published test for pending events