use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class RecordGenerator method addSecondLevelEntities.
private void addSecondLevelEntities(CollectRecord record, RecordKey recordKey) {
CollectSurvey survey = (CollectSurvey) record.getSurvey();
List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
List<String> keyValues = recordKey.getValues(nonMeasurementKeyDefs);
List<SamplingDesignItem> secondLevelSamplingPointItems = samplingDesignManager.loadChildItems(survey.getId(), keyValues);
List<CodeAttributeDefinition> samplingPointDataCodeAttributeDefs = findSamplingPointCodeAttributes(survey);
if (!secondLevelSamplingPointItems.isEmpty() && samplingPointDataCodeAttributeDefs.size() > 1) {
int levelIndex = 1;
for (SamplingDesignItem samplingDesignItem : secondLevelSamplingPointItems) {
CodeAttributeDefinition levelKeyDef = samplingPointDataCodeAttributeDefs.get(levelIndex);
EntityDefinition levelEntityDef = levelKeyDef.getParentEntityDefinition();
Entity parentLevelEntity = record.getRootEntity();
NodeChangeSet addEntityChangeSet = recordUpdater.addEntity(parentLevelEntity, levelEntityDef);
Entity entity = getAddedEntity(addEntityChangeSet);
CodeAttribute keyAttr = entity.getChild(levelKeyDef);
recordUpdater.updateAttribute(keyAttr, new Code(samplingDesignItem.getLevelCode(levelIndex + 1)));
}
}
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class CodeListManager method loadParentItem.
protected CodeListItem loadParentItem(CodeAttribute attribute) {
CodeList list = attribute.getDefinition().getList();
boolean persistedSurvey = list.getSurvey().getId() != null;
Record record = attribute.getRecord();
ModelVersion version = record.getVersion();
if (persistedSurvey && list.isExternal()) {
ExternalCodeListItem item = (ExternalCodeListItem) loadItemByAttribute(attribute);
return provider.getParentItem(item);
} else if (persistedSurvey && list.isEmpty()) {
PersistedCodeListItem lastParentItem = null;
List<CodeAttribute> codeAncestors = attribute.getCodeAncestors();
for (int i = 0; i < codeAncestors.size(); i++) {
CodeAttribute ancestor = codeAncestors.get(i);
Integer lastParentItemId = lastParentItem == null ? null : lastParentItem.getSystemId();
Code code = ancestor.getValue();
lastParentItem = codeListItemDao.loadItem(list, lastParentItemId, code.getCode(), version);
if (lastParentItem == null) {
break;
}
}
return lastParentItem;
} else {
CodeAttribute codeParent = attribute.getCodeParent();
if (codeParent == null) {
return null;
} else {
return loadItemByAttribute(codeParent);
}
}
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class CodeColumnProvider method extractValues.
@Override
public List<String> extractValues(Node<?> axis) {
List<String> values = super.extractValues(axis);
if (hasExpandedItems) {
List<Node<?>> attributes = extractNodes(axis);
for (CodeListItem item : expandedItems) {
CodeAttribute attr = findAttributeByCode(attributes, item.getCode());
values.add(Boolean.valueOf(attr != null).toString());
if (item.isQualifiable()) {
values.add(attr == null ? "" : attr.getValue().getQualifier());
}
}
}
return values;
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class CodeColumnProvider method findAttributeByCode.
protected CodeAttribute findAttributeByCode(List<Node<?>> attributes, String code) {
for (Node<?> attr : attributes) {
CodeAttribute codeAttr = (CodeAttribute) attr;
Code val = codeAttr.getValue();
if (val != null && code.equals(val.getCode())) {
return codeAttr;
}
}
return null;
}
use of org.openforis.idm.model.CodeAttribute 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;
}
Aggregations