3535import sif3 .common .model .ServiceInfo ;
3636import sif3 .common .model .ServiceRights .AccessRight ;
3737import sif3 .common .model .ServiceRights .AccessType ;
38+ import sif3 .common .model .ZoneContextInfo ;
3839import sif3 .common .persist .model .SIF3Session ;
3940import sif3 .common .ws .BaseResponse ;
4041import sif3 .infra .common .env .mgr .BrokeredProviderEnvironmentManager ;
@@ -200,7 +201,8 @@ public void broadcastEvents()
200201 try
201202 {
202203 // Let's get the Event Client
203- EventClient evtClient = new EventClient (getEnvironmentManager (), getRequestMediaType (), getResponseMediaType (), getServiceName (), getMarshaller (), getCompressionEnabled ());
204+ String serviceName = getServiceName ();
205+ EventClient evtClient = new EventClient (getEnvironmentManager (), getRequestMediaType (), getResponseMediaType (), serviceName , getMarshaller (), getCompressionEnabled ());
204206 SIFEventIterator <L > iterator = getSIFEvents ();
205207 if (iterator != null )
206208 {
@@ -210,39 +212,45 @@ public void broadcastEvents()
210212 try
211213 {
212214 sifEvents = iterator .getNextEvents (maxNumObjPerEvent );
213- // This should not return null since the hasNext() returned true, but just in case we check
214- // and exit the loop if it should return null. In this case we assume that there is no more
215- // data. We also log an error to make the coder aware of the issue.
215+ // This should not return null since the hasNext() returned true, but just in case we check and exit the loop if it should return null.
216+ // In this case we assume that there is no more data. We also log an error to make the coder aware of the issue.
216217 if (sifEvents != null )
217218 {
218- logger .debug ("Number of " +getMultiObjectClassInfo ().getObjectName ()+" Objects in this Event: " + sifEvents .getListSize ());
219- for (ServiceInfo service : servicesForProvider )
219+ logger .debug ("Number of " +serviceName +" Objects in this Event: " + sifEvents .getListSize ());
220+
221+ // keep event action. Just in case the developer changes it in modifyBeforePublishing() which would confuse everything.
222+ EventAction eventAction = sifEvents .getEventAction ();
223+
224+ // Do we need to sent to all services or to a limited list of zone & context?
225+ if ((sifEvents .getLimitToZoneCtxList () == null ) || (sifEvents .getLimitToZoneCtxList ().size () == 0 ))
226+ {
227+ for (ServiceInfo service : servicesForProvider )
228+ {
229+ // Check if provider has rights to publish to given zone and context
230+ if (hasAccess (service ))
231+ {
232+ failedRecords = failedRecords + prepareEventAndSend (evtClient , sifEvents , service .getZone (), service .getContext (), eventAction );
233+ }
234+ else
235+ {
236+ logNoAccessRight (service .getZone (), service .getContext ());
237+ }
238+ }
239+ }
240+ else // only sent to limited list
220241 {
221- // keep event action. Just in case the developer changes it in modifyBeforePublishing() which would confuse
222- // everything.
223- EventAction eventAction = sifEvents .getEventAction ();
224- if (hasAccess (service ))
225- {
226- HeaderProperties customHTTPHeaders = new HeaderProperties ();
227- SIFEvent <L > modifiedEvents = modifyBeforePublishing (sifEvents , service .getZone (), service .getContext (), customHTTPHeaders );
228- if (modifiedEvents != null )
229- {
230- //Just in case the developer has changed it. Should not be allowed :-)
231- modifiedEvents .setEventAction (eventAction );
232-
233- if (!sendEvents (evtClient , modifiedEvents , service .getZone (), service .getContext (), customHTTPHeaders ))
234- {
235- //Report back to the caller. This should also give the event back to the caller.
236- onEventError (modifiedEvents , service .getZone (), service .getContext ());
237- failedRecords = failedRecords + ((modifiedEvents != null ) ? modifiedEvents .getListSize () : 0 );
238- }
239- }
240- }
241- else
242- {
243- logger .debug ("The " +getProviderName ()+" does not have the PROVIDE = APPROVED. No events are sent." );
244- failedRecords = failedRecords + ((sifEvents != null ) ? sifEvents .getListSize () : 0 );
245- }
242+ for (ZoneContextInfo zoneCtxInfo : sifEvents .getLimitToZoneCtxList ())
243+ {
244+ // Check if provider has rights to publish to given zone and context
245+ if (sif3Session .hasAccess (AccessRight .PROVIDE , AccessType .APPROVED , serviceName , zoneCtxInfo .getZone (), zoneCtxInfo .getContext ()))
246+ {
247+ failedRecords = failedRecords + prepareEventAndSend (evtClient , sifEvents , zoneCtxInfo .getZone (), zoneCtxInfo .getContext (), eventAction );
248+ }
249+ else
250+ {
251+ logNoAccessRight (zoneCtxInfo .getZone (), zoneCtxInfo .getContext ());
252+ }
253+ }
246254 }
247255
248256 totalRecords = totalRecords + sifEvents .getListSize ();
@@ -275,6 +283,41 @@ public void broadcastEvents()
275283 logger .debug ("================================ Finished broadcastEvents() for provider " +getPrettyName ());
276284 }
277285
286+ /*
287+ * Return the number of failed records. If 0 is return all then the event with its content is sent successfully.
288+ */
289+ protected int prepareEventAndSend (EventClient evtClient , SIFEvent <L > sifEvents , SIFZone zone , SIFContext context , EventAction eventAction )
290+ {
291+ int failedRecords = 0 ;
292+
293+ HeaderProperties customHTTPHeaders = new HeaderProperties ();
294+ SIFEvent <L > modifiedEvents = modifyBeforePublishing (sifEvents , zone , context , customHTTPHeaders );
295+ if (modifiedEvents != null )
296+ {
297+ //Just in case the developer has changed it. Should not be allowed :-)
298+ modifiedEvents .setEventAction (eventAction );
299+
300+ if (!sendEvents (evtClient , modifiedEvents , zone , context , customHTTPHeaders ))
301+ {
302+ //Report back to the caller. This should also give the event back to the caller.
303+ onEventError (modifiedEvents , zone , context );
304+ failedRecords = ((modifiedEvents != null ) ? modifiedEvents .getListSize () : 0 );
305+ }
306+ }
307+
308+ return failedRecords ;
309+ }
310+
311+ private void logNoAccessRight (SIFZone zone , SIFContext context )
312+ {
313+ String zoneID = (zone == null ) ? "Default" : zone .getId ();
314+ String contextID = (context == null ) ? CommonConstants .DEFAULT_CONTEXT_NAME : context .getId ();
315+
316+ logger .debug ("The " +getProviderName ()+" does not have the ACL entry PROVIDE = APPROVED for service = " + getServiceName () + " for the Zone = " + zoneID + " and the Context = " + contextID + ". Events are NOT sent to this zone and context." );
317+ // return ((sifEvents != null) ? sifEvents.getListSize() : 0);
318+ }
319+
320+
278321 /**
279322 * If one doesn't want certain events to be published to a given zone then this method needs to be
280323 * overridden. It allows to test for the event and zone and make the appropriate decision if the event
0 commit comments