class ServiceResourceService {

    @EventListener
    public synchronized void handleLocationDeleted(AfterLocationDeleted event) {
        // Remove the location in every service that referenced it
        GetMultipleDataResult<ServiceResource> serviceResourceResult = alienDAO.buildQuery(ServiceResource.class)
                .setFilters(singleKeyFilter("locationIds", event.getLocationId())).prepareSearch().search(0, Integer.MAX_VALUE);
        if (serviceResourceResult.getData() == null) {
            return;
        }
        for (ServiceResource serviceResource : serviceResourceResult.getData()) {
            Set<String> locations = CollectionUtils.safeNewHashSet(serviceResource.getLocationIds());
            locations.remove(event.getLocationId());
            serviceResource.setLocationIds(locations.toArray(new String[locations.size()]));
        }
        // bulk update
        alienDAO.save(serviceResourceResult.getData());
    }

}