use of org.openforis.idm.model.Record in project collect by openforis.
the class CollectValidator method isRootEntityKey.
private boolean isRootEntityKey(Attribute<?, ?> attribute) {
AttributeDefinition attrDef = attribute.getDefinition();
if (attrDef.isKey()) {
Record record = attribute.getRecord();
Entity rootEntity = record.getRootEntity();
EntityDefinition rootEntityDef = rootEntity.getDefinition();
List<AttributeDefinition> keyAttributeDefs = rootEntityDef.getKeyAttributeDefinitions();
for (AttributeDefinition keyDef : keyAttributeDefs) {
if (keyDef.getId() == attrDef.getId()) {
return true;
}
}
}
return false;
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class CodeValueFKColumnValueExtractor method extractValue.
private Object extractValue(CodeAttribute valNode) {
CodeListItem item = findCodeListItem(valNode);
if (item == null) {
String defaultCodeValue = column.getDefaultCodeValue();
String codeValue = getCodeValue(valNode);
if (defaultCodeValue == null || (codeValue != null && !codeValue.equals(defaultCodeValue))) {
// no default code value specified or code list item not found (invalid code?)
return null;
} else {
CodeAttributeDefinition definition = valNode.getDefinition();
CodeList list = definition.getList();
Record record = valNode.getRecord();
ModelVersion version = record.getVersion();
return getDefaultCodeItemId(list, version);
}
} else {
return item.getId();
}
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class TestFixture method survey.
public static TestFixture survey(NodeDefinitionBuilder.EntityDefinitionBuilder entityDefinitionBuilder, RecordBuilder... recordBuilders) {
SurveyContext surveyContext = new TestSurveyContext();
Survey survey = surveyContext.createSurvey();
EntityDefinition rootEntityDef = (EntityDefinition) entityDefinitionBuilder.buildInternal(survey);
survey.getSchema().addRootEntityDefinition(rootEntityDef);
survey.refreshSurveyDependencies();
List<Record> records = new ArrayList<Record>();
for (RecordBuilder recordBuilder : recordBuilders) {
Record record = recordBuilder.build(survey);
records.add(record);
}
return new TestFixture(survey, Collections.unmodifiableList(records));
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class AbstractTest method createCluster.
@Before
public void createCluster() {
this.record = new Record(survey, "2.0", "cluster");
this.cluster = record.getRootEntity();
Record record2 = new Record(survey, "2.0", "household");
this.household = record2.getRootEntity();
}
use of org.openforis.idm.model.Record 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);
}
}
}
Aggregations