setParent method

  1. @override
bool setParent(
  1. String name,
  2. dynamic entity
)
override

Implementation

@override
bool setParent(String name, entity) {
  if (_concept == null) {
    throw new ConceptException('Entity concept is not defined.');
  }

  Parent? parent = _concept!.parents.singleWhereCode(name) as Parent?;
  if (parent == null) {
    String msg =
        '${_concept!.code!}.$name is not correct parent entity name.';
    throw UpdateException(msg);
  }

  if (entity != null && getParent(name) == null) {
    var reference = Reference(entity.oid.toString(), entity.concept.code!,
        entity.concept.entryConcept.code!);
    _parentMap[name] = entity;
    _referenceMap[name] = reference;
    return true;
  } else if (entity != null && parent.update) {
    var reference = Reference(entity.oid.toString(), entity.concept.code!,
        entity.concept.entryConcept.code!);
    _parentMap[name] = entity;
    _referenceMap[name] = reference;
    return true;
  } else {
    String msg = '${_concept!.code!}.${parent.code!} is not updatable.';
    throw UpdateException(msg);
  }
}