Search in sources :

Example 1 with MissingRecordKeyException

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();
                }
            }
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) MissingRecordKeyException(org.openforis.collect.persistence.MissingRecordKeyException) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Aggregations

MissingRecordKeyException (org.openforis.collect.persistence.MissingRecordKeyException)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 Entity (org.openforis.idm.model.Entity)1