use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class RecordIndexManager method index.
protected void index(final IndexWriter indexWriter, CollectRecord record) throws RecordIndexException {
try {
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
NodeDefinition defn = node.getDefinition();
if (defn instanceof AttributeDefinition) {
index(indexWriter, (Attribute<?, ?>) node);
}
}
});
} catch (Exception e) {
throw new RecordIndexException(e);
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class RecordIndexManager method index.
protected void index(IndexWriter indexWriter, Attribute<?, ?> attr) {
AttributeDefinition defn = attr.getDefinition();
String indexName = defn.getAnnotation(Annotation.AUTOCOMPLETE.getQName());
if (StringUtils.isNotBlank(indexName)) {
try {
Object value = attr.getValue();
if (value != null) {
Document doc = new Document();
Record record = attr.getRecord();
Integer recordId = record.getId();
if (recordId != null) {
Field recordKeyField = createRecordIdField(recordId);
doc.add(recordKeyField);
}
for (org.openforis.idm.model.Field<?> field : attr.getFields()) {
index(doc, indexName, field);
}
indexWriter.addDocument(doc);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class SurveyValidator method validateRootKeyAttributeSpecified.
private List<SurveyValidationResult> validateRootKeyAttributeSpecified(CollectSurvey survey) {
List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
Schema schema = survey.getSchema();
for (EntityDefinition rootEntityDef : schema.getRootEntityDefinitions()) {
List<AttributeDefinition> keyAttributeDefinitions = rootEntityDef.getKeyAttributeDefinitions();
if (keyAttributeDefinitions.isEmpty()) {
SurveyValidationResult validationResult = new SurveyValidationResult(rootEntityDef.getPath(), "survey.validation.error.key_attribute_not_specified");
results.add(validationResult);
} else if (keyAttributeDefinitions.size() > MAX_KEY_ATTRIBUTE_DEFINITION_COUNT) {
SurveyValidationResult validationResult = new SurveyValidationResult(rootEntityDef.getPath(), "survey.validation.error.maximum_key_attribute_definitions_exceeded");
results.add(validationResult);
}
}
return results;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class RecordUpdater method addEmptyNodes.
private void addEmptyNodes(Entity entity) {
Record record = entity.getRecord();
ModelVersion version = record.getVersion();
addEmptyEnumeratedEntities(entity);
EntityDefinition entityDefn = entity.getDefinition();
List<NodeDefinition> childDefinitions = entityDefn.getChildDefinitionsInVersion(version);
for (NodeDefinition childDefn : childDefinitions) {
if (entity.getCount(childDefn) == 0) {
if (addEmptyMultipleEntitiesWhenAddingNewEntities || !(childDefn instanceof EntityDefinition && childDefn.isMultiple())) {
int toBeInserted = entity.getMinCount(childDefn);
if (toBeInserted <= 0 && childDefn instanceof AttributeDefinition || !childDefn.isMultiple()) {
// insert at least one node
toBeInserted = 1;
}
addEmptyChildren(entity, childDefn, toBeInserted);
}
} else {
entity.visitChildren(childDefn, new NodeVisitor() {
public void visit(Node<? extends NodeDefinition> child, int idx) {
if (child instanceof Entity) {
addEmptyNodes((Entity) child);
}
}
});
}
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class UIOptionsMigrator method addFormComponent.
protected void addFormComponent(UIFormContentContainer parent, NodeDefinition nodeDefn, int row) throws UIOptionsMigrationException {
CollectSurvey survey = (CollectSurvey) nodeDefn.getSurvey();
UIOptions oldUIOptions = survey.getUIOptions();
UIFormComponent component;
if (nodeDefn instanceof AttributeDefinition) {
component = createField(parent, nodeDefn);
} else {
EntityDefinition entityDefn = (EntityDefinition) nodeDefn;
if (entityDefn.isMultiple() && oldUIOptions.getLayout(entityDefn) == Layout.TABLE) {
component = createTable(parent, entityDefn);
} else {
component = createFormSection(parent, entityDefn);
}
}
component.setColumn(oldUIOptions.getColumn(nodeDefn));
component.setColumnSpan(oldUIOptions.getColumnSpan(nodeDefn));
component.setRow(row);
parent.addChild(component);
}
Aggregations