Skip to content

Commit

Permalink
Merge pull request #6538 from davidradl/git6537
Browse files Browse the repository at this point in the history
#6537 add null protection
  • Loading branch information
davidradl authored May 24, 2022
2 parents 7b679ff + a6b8c29 commit 3710383
Showing 1 changed file with 56 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,67 +276,71 @@ private void distributeTypeDefEvent(OMRSTypeDefEvent event)
*/
private void distributeInstanceEvent(OMRSInstanceEvent event)
{
boolean validEvent = false;

if (event.getInstanceEventType() == OMRSInstanceEventType.BATCH_INSTANCES_EVENT)
{
/*
* A batch instance event is valid and should be processed if all
* references and entities in the contained graph are valid to be processed
*/
InstanceGraph eventGraph = event.getInstanceBatch();
List<EntityDetail> eventEntities = eventGraph.getEntities();
List<Relationship> eventRelationships = eventGraph.getRelationships();

List<EntityDetail> validEntities = new ArrayList<>();
List<Relationship> validRelationships = new ArrayList<>();

for (EntityDetail entity: eventEntities)
{
if (exchangeRule.processInstanceEvent(entity))
{
validEntities.add(entity);
}
}


for (Relationship relationship: eventRelationships)
{
if (exchangeRule.processInstanceEvent(relationship))
{
validRelationships.add(relationship);
}
}

if (validEntities.size() > 0 || validRelationships.size() > 0)
{
/*
* Can't just update the instance graph on the event, so we'll
* construct a new event with the updated instances and adjust...
*/
InstanceGraph validInstanceGraph = new InstanceGraph(validEntities, validRelationships);
OMRSInstanceEvent validInstanceEvent = new OMRSInstanceEvent(OMRSInstanceEventType.BATCH_INSTANCES_EVENT,
boolean validEvent = false;

if (event.getInstanceEventType() == OMRSInstanceEventType.BATCH_INSTANCES_EVENT)
{
/*
* A batch instance event is valid and should be processed if all
* references and entities in the contained graph are valid to be processed
*/
InstanceGraph eventGraph = event.getInstanceBatch();
List<EntityDetail> eventEntities = eventGraph.getEntities();
List<Relationship> eventRelationships = eventGraph.getRelationships();

List<EntityDetail> validEntities = new ArrayList<>();
List<Relationship> validRelationships = new ArrayList<>();
if (eventEntities != null)
{
for (EntityDetail entity : eventEntities)
{
if (exchangeRule.processInstanceEvent(entity))
{
validEntities.add(entity);
}
}
}

if (eventRelationships != null)
{
for (Relationship relationship : eventRelationships)
{
if (exchangeRule.processInstanceEvent(relationship))
{
validRelationships.add(relationship);
}
}
}

if (validEntities.size() > 0 || validRelationships.size() > 0)
{
/*
* Can't just update the instance graph on the event, so we'll
* construct a new event with the updated instances and adjust...
*/
InstanceGraph validInstanceGraph = new InstanceGraph(validEntities, validRelationships);
OMRSInstanceEvent validInstanceEvent = new OMRSInstanceEvent(OMRSInstanceEventType.BATCH_INSTANCES_EVENT,
validInstanceGraph);
validInstanceEvent.setEventOriginator(event.getEventOriginator());
event = validInstanceEvent;
validEvent = true;
}
}
else
validInstanceEvent.setEventOriginator(event.getEventOriginator());
event = validInstanceEvent;
validEvent = true;
}

}
else
{
validEvent = exchangeRule.processInstanceEvent(event.getTypeDefGUID(),
validEvent = exchangeRule.processInstanceEvent(event.getTypeDefGUID(),
event.getTypeDefName());
}
if (validEvent)
{

if (validEvent)
{
for (OMRSInstanceEventProcessorInterface consumer : instanceEventConsumers)
{
consumer.sendInstanceEvent(super.eventProcessorName, event);
}

}
}
}


Expand Down

0 comments on commit 3710383

Please sign in to comment.