validate method
Implementation
void validate() {
if (name == null || name.isEmpty) throw Exception('name is not defined');
if (properties == null) throw Exception('properties is null');
if (properties.isEmpty) {
if (lastPropertyId != null) {
throw Exception(
'lastPropertyId is not null although there are no properties');
}
} else {
if (lastPropertyId == null) throw Exception('lastPropertyId is null');
var lastPropertyIdFound = false;
for (final p in properties) {
if (p.entity != this) {
throw Exception(
"property '${p.name}' with id ${p.id.toString()} has incorrect parent entity reference");
}
p.validate();
if (lastPropertyId.id < p.id.id) {
throw Exception(
"lastPropertyId ${lastPropertyId.toString()} is lower than the one of property '${p.name}' with id ${p.id.toString()}");
}
if (lastPropertyId.id == p.id.id) {
if (lastPropertyId.uid != p.id.uid) {
throw Exception(
"lastPropertyId ${lastPropertyId.toString()} does not match property '${p.name}' with id ${p.id.toString()}");
}
lastPropertyIdFound = true;
}
}
if (!lastPropertyIdFound &&
!listContains(model.retiredPropertyUids, lastPropertyId.uid)) {
throw Exception(
'lastPropertyId ${lastPropertyId.toString()} does not match any property');
}
}
}