private void saveReceipt(EntityRef notification, EntityRef device, Receipt receipt, boolean hasError) throws Exception {
boolean debug = false;
if(this.notification != null){
debug = this.notification.getDebug();
}
if ( debug || hasError) {
List<EntityRef> entities = Arrays.asList(notification, device);
if (receipt.getUuid() == null) {
Receipt savedReceipt = em.create(receipt);
em.addToCollections(entities, Notification.RECEIPTS_COLLECTION, savedReceipt);
} else {
em.addToCollections(entities, Notification.RECEIPTS_COLLECTION, receipt);
}
if ( logger.isDebugEnabled() ) {
logger.debug( "Notification {} receipt saved for device {}", notification.getUuid(), device.getUuid() );
}
}
}