fromJsonMap method
Internal: loads entity data from a map entityMap, optionally linking to an internalParent.
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');
}
// Temporarily allow OID update.
var beforeUpdateOid = concept.updateOid;
concept.updateOid = true;
oid = Oid.ts(timeStamp);
concept.updateOid = beforeUpdateOid;
// Temporarily allow code update.
var beforeUpdateCode = concept.updateCode;
concept.updateCode = true;
code = entityMap['code'] as String;
concept.updateCode = beforeUpdateCode;
// Temporarily allow when.* updates.
var beforeUpdateWhen = concept.updateWhen;
concept.updateWhen = true;
// Parse timestamps.
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 each attribute, parse the stored string.
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 {
setStringToAttribute(attribute.code, entityMap[attribute.code]);
}
}
// Load neighbors: parent references, child sets.
_neighborsFromJsonMap(entityMap, internalParent);
pre = beforePre;
}