Search in sources :

Example 1 with ModelPathExpression

use of org.openforis.idm.model.expression.ModelPathExpression in project collect by openforis.

the class SpeciesManager method extractQualifierValues.

protected String[] extractQualifierValues(TaxonAttribute attr) {
    TaxonAttributeDefinition defn = attr.getDefinition();
    List<String> qualifiers = defn.getQualifiers();
    String[] qualifierValues = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
        qualifierValues = new String[qualifiers.size()];
        Entity parent = attr.getParent();
        for (int i = 0; i < qualifiers.size(); i++) {
            String qualifierExpr = qualifiers.get(i);
            try {
                ModelPathExpression expression = expressionFactory.createModelPathExpression(qualifierExpr);
                CodeAttribute code = (CodeAttribute) expression.evaluate(parent, null);
                String qualifierValue = code.getValue().getCode();
                qualifierValues[i] = qualifierValue;
            } catch (Exception e) {
                if (log.isWarnEnabled()) {
                    log.warn("Error evaluating taxon qualifiers: ", e);
                }
                break;
            }
        }
    }
    return qualifierValues;
}
Also used : Entity(org.openforis.idm.model.Entity) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ModelPathExpression(org.openforis.idm.model.expression.ModelPathExpression)

Aggregations

TaxonAttributeDefinition (org.openforis.idm.metamodel.TaxonAttributeDefinition)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1 Entity (org.openforis.idm.model.Entity)1 ModelPathExpression (org.openforis.idm.model.expression.ModelPathExpression)1