fromJsonMap method

void fromJsonMap(
  1. dynamic entityMap, [
  2. Entity<Entity>? internalParent
])

Loads data from a json map.

Implementation

void fromJsonMap(entityMap, [Entity? internalParent]) {
  int timeStamp = 0;
  try {
    var key = entityMap['oid'];
    if (key != null) {
      timeStamp = int.parse(key.toString());
    }
  } on FormatException catch (e) {
    throw TypeException('${entityMap['oid']} oid is not int: $e');
  }
  var beforeUpdateOid = concept.updateOid;
  concept.updateOid = true;
  oid = Oid.ts(timeStamp);
  concept.updateOid = beforeUpdateOid;

  var beforeUpdateCode = concept.updateCode;
  concept.updateCode = true;
  code = entityMap['code'] as String;
  concept.updateCode = beforeUpdateCode;

  var beforeUpdateWhen = concept.updateWhen;
  concept.updateWhen = true;
  DateTime? whenAddedTime;
  try {
    String? when = entityMap['whenAdded'] as String?;
    if (when != null && when != 'null') {
      whenAddedTime = DateTime.parse(when);
    }
  } on FormatException catch (e) {
    throw TypeException(
        '${entityMap['whenAdded']} whenAdded is not DateTime: $e');
  }
  whenAdded = whenAddedTime;
  DateTime? whenSetTime;
  try {
    String? when = entityMap['whenSet'] as String?;
    if (when != null && when != 'null') {
      whenSetTime = DateTime.parse(when);
    }
  } on FormatException catch (e) {
    throw TypeException(
        '${entityMap['whenSet']} whenSet is not DateTime: $e');
  }
  whenSet = whenSetTime;
  DateTime? whenRemovedTime;
  try {
    String? when = entityMap['whenRemoved'] as String?;
    if (when != null && when != 'null') {
      whenRemovedTime = DateTime.parse(when);
    }
  } on FormatException catch (e) {
    throw TypeException(
        '${entityMap['whenRemoved']} whenRemoved is not DateTime: $e');
  }
  whenRemoved = whenRemovedTime;
  concept.updateWhen = beforeUpdateWhen;

  var beforePre = pre;
  pre = false;
  for (Attribute attribute in concept.attributes.whereType<Attribute>()) {
    if (attribute.identifier) {
      var beforeUpdate = attribute.update;
      attribute.update = true;
      setStringToAttribute(attribute.code!, entityMap[attribute.code!]);
      attribute.update = beforeUpdate;
    } else if (attribute.code != null && entityMap[attribute.code!] != null) {
      setStringToAttribute(attribute.code!, entityMap[attribute.code!]);
    }
  }
  _neighborsFromJsonMap(entityMap, internalParent);
  pre = beforePre;
}