populateEntityReferences method

void populateEntityReferences(
  1. Entities<Entity> entities
)

Implementation

void populateEntityReferences(Entities entities) {
  for (var entity in entities) {
    for (Parent parent in entity.concept.externalParents) {
      Reference? reference = entity.getReference(parent.code!);
      if (reference != null) {
        //String parentOidString = reference.parentOidString;
        //String parentConceptCode = reference.parentConceptCode;
        //String entryConceptCode = reference.entryConceptCode;
        var parentEntity =
            internalSingle(reference.entryConceptCode, reference.oid);
        if (parentEntity == null) {
          throw ParentException('Parent not found for the reference: '
              '${reference.toString()}');
        }
        if (entity.getParent(parent.code!) == null) {
          entity.setParent(parent.code!, parentEntity);
          //print('parent.opposite.code!: ${parent.opposite.code!}');
          var parentChildEntities =
              parentEntity.getChild(parent.opposite?.code!) as Entities?;
          //print('parentChildEntities.length before add: ${parentChildEntities.length}');
          parentChildEntities?.add(entity);
          //print('parentChildEntities.length after add: ${parentChildEntities.length}');
        }
      }
    }
    for (Child internalChild in entity.concept.internalChildren) {
      var childEntities = entity.getChild(internalChild.code!) as Entities?;
      populateEntityReferences(childEntities!);
    }
  }
}