4141import sif3 .common .persist .common .BasicTransaction ;
4242import sif3 .common .persist .model .SIF3Job ;
4343import sif3 .common .persist .model .SIF3JobEvent ;
44+ import sif3 .common .persist .model .SIF3JobEvent .JobEventType ;
4445
4546/**
4647 * @author Joerg Huber
@@ -605,6 +606,7 @@ public List<SIF3JobEvent> getJobEventsByUUID(BasicTransaction tx, String uuid, A
605606 *
606607 * A few values will be defaulted if they are not set.<br/>
607608 * - toFingerPrintOnly defaults to TRUE: Only the consumer with that fingerprint will receive the event.
609+ * - consumerRequested defaults to TRUE: Event was caused by consumer requested operation on job.
608610 * - fullUpdate defaults to TRUE: it is assumed that the entire Job Object is provided in case of an update event.<br/><br/>
609611 *
610612 * The following values will be ignored and defaulted. The returned object will have them populated as followed:<br/>
@@ -712,14 +714,15 @@ else if ("U".equalsIgnoreCase(jobEvent.getEventType()))
712714 * @param job The job based on which an event shall be created. If null then no event is created and null is returned.
713715 * @param eventType The event type (CREATE, UPDATE, DELETE).
714716 * @param fingerprintOnly Indicating if the event is for the 'fingerprint' consumer only.
717+ * @param consumerRequested Indicating if the event is caused by consumer requested operation on job.
715718 *
716719 * @return The newly created job event. This has now the internalID and the event date and published populated.
717720 * The published will be set to FALSE and the event date will be set to current datetime.
718721 *
719722 * @throws IllegalArgumentException If the tx is null or any of the rules listed above are not met.
720723 * @throws PersistenceException Could not access underlying data store.
721724 */
722- public SIF3JobEvent createJobEvent (BasicTransaction tx , SIF3Job job , EventAction eventType , boolean fingerprintOnly ) throws IllegalArgumentException , PersistenceException
725+ public SIF3JobEvent createJobEvent (BasicTransaction tx , SIF3Job job , EventAction eventType , boolean fingerprintOnly , boolean consumerRequested ) throws IllegalArgumentException , PersistenceException
723726 {
724727 if (tx == null )
725728 {
@@ -728,7 +731,7 @@ public SIF3JobEvent createJobEvent(BasicTransaction tx, SIF3Job job, EventAction
728731
729732 if (job != null )
730733 {
731- return createJobEvent (tx , new SIF3JobEvent (job , eventType , fingerprintOnly ));
734+ return createJobEvent (tx , new SIF3JobEvent (job , eventType , fingerprintOnly , consumerRequested ));
732735 }
733736 else
734737 {
@@ -875,22 +878,91 @@ public List<SIF3JobEvent> retrieveJobEventsSince(BasicTransaction tx, Date chang
875878 criteria .addOrder (Order .asc ("eventDate" ));
876879
877880 @ SuppressWarnings ("unchecked" )
878- List <SIF3JobEvent > jobEventss = criteria .list ();
881+ List <SIF3JobEvent > jobEvents = criteria .list ();
879882
880883 // Just in case test for null....
881- if (jobEventss == null )
884+ if (jobEvents == null )
882885 {
883- jobEventss = new ArrayList <SIF3JobEvent >();
886+ jobEvents = new ArrayList <SIF3JobEvent >();
884887 }
885888
886- return jobEventss ;
889+ return jobEvents ;
887890 }
888891 catch (HibernateException e )
889892 {
890893 throw new PersistenceException ("Unable to retrieve Job Events since " +DateUtils .dateToString (changesSince , DateUtils .DISP_DATE_TIME_SEC )+" for fingerprint = '" + fingerprint + ", zoneID = " + zoneID + ", contextID = " + contextID + ", adapterType = '" + adapterType + "' and pagingInfo = " +pagingInfo +"." , e );
891894 }
892-
893895 }
894896
895-
897+ /*
898+ *
899+ */
900+ public List <SIF3JobEvent > retrieveJobEvents (BasicTransaction tx ,
901+ Date eventsBefore ,
902+ String serviceName ,
903+ AdapterType adapterType ,
904+ JobEventType eventType ,
905+ boolean includeConsumeRequested ) throws IllegalArgumentException , PersistenceException
906+ {
907+ if (tx == null )
908+ {
909+ throw new IllegalArgumentException ("Current transaction is null." );
910+ }
911+ if (adapterType == null )
912+ {
913+ throw new IllegalArgumentException ("adapterType is null." );
914+ }
915+ if (StringUtils .isEmpty (serviceName ))
916+ {
917+ throw new IllegalArgumentException ("serviceName is null or empty." );
918+ }
919+ if (eventsBefore == null )
920+ {
921+ throw new IllegalArgumentException ("eventsBefore is null." );
922+ }
923+ if (eventType == null )
924+ {
925+ throw new IllegalArgumentException ("eventType is null." );
926+ }
927+
928+ try
929+ {
930+ Criteria criteria = tx .getSession ().createCriteria (SIF3JobEvent .class );
931+
932+ criteria = criteria .add (Restrictions .le ("eventDate" , eventsBefore ));
933+ criteria = criteria .add (Restrictions .eq ("adapterType" , adapterType .name ()));
934+ criteria = criteria .add (Restrictions .eq ("serviceName" , serviceName ));
935+ criteria = criteria .add (Restrictions .eq ("eventType" , eventType .name ()));
936+
937+ if (!includeConsumeRequested ) // only get provider initiated events
938+ {
939+ criteria = criteria .add (Restrictions .eq ("consumerRequested" , false ));
940+ }
941+
942+ criteria = criteria .add (Restrictions .eq ("published" , false ));
943+
944+
945+ //Add orderBy to ensure consistent results
946+ criteria .addOrder (Order .asc ("zoneID" )).addOrder (Order .asc ("contextID" )).addOrder (Order .asc ("fingerprint" )).addOrder (Order .asc ("internalID" ));
947+
948+ @ SuppressWarnings ("unchecked" )
949+ List <SIF3JobEvent > jobEvents = criteria .list ();
950+
951+ // Just in case test for null....
952+ if (jobEvents == null )
953+ {
954+ jobEvents = new ArrayList <SIF3JobEvent >();
955+ }
956+
957+ return jobEvents ;
958+ }
959+ catch (HibernateException e )
960+ {
961+ throw new PersistenceException ("Unable to retrieve Job Events for events before " +
962+ DateUtils .dateToString (eventsBefore , DateUtils .DISP_DATE_TIME_SEC )+
963+ " for adapterType = '" + adapterType +
964+ "', serviceName = '" + serviceName +
965+ "', eventType = '" + eventType + "'." , e );
966+ }
967+ }
896968}
0 commit comments