use of org.openforis.collect.persistence.MissingRecordKeyException in project collect by openforis.
the class RecordManager method checkAllKeysSpecified.
// END OF RECORD UPDATE METHODS
private void checkAllKeysSpecified(CollectRecord record) throws MissingRecordKeyException {
Entity rootEntity = record.getRootEntity();
List<String> rootEntityKeyValues = record.getRootEntityKeyValues();
List<AttributeDefinition> keyDefns = rootEntity.getDefinition().getKeyAttributeDefinitions();
for (int i = 0; i < keyDefns.size(); i++) {
AttributeDefinition keyDefn = keyDefns.get(i);
EntityDefinition keyParentDefn = keyDefn.getParentEntityDefinition();
Entity keyParent = record.findNodeByPath(keyParentDefn.getPath());
if (keyParent == null) {
throw new MissingRecordKeyException();
}
boolean required = keyParent.isRequired(keyDefn);
if (required) {
Node<?> keyNode = keyParent.getChild(keyDefn);
if (keyNode == null) {
throw new MissingRecordKeyException();
} else {
String keyValue = rootEntityKeyValues.get(i);
if (StringUtils.isBlank(keyValue)) {
throw new MissingRecordKeyException();
}
}
}
}
}
Aggregations