Search in sources :

Example 41 with AttributeDefinition

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);
    }
}
Also used : Entity(org.openforis.idm.model.Entity) Attribute(org.openforis.idm.model.Attribute) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Example 42 with AttributeDefinition

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();
        }
    }
}
Also used : Field(org.apache.lucene.document.Field) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Record(org.openforis.idm.model.Record) CollectRecord(org.openforis.collect.model.CollectRecord) Document(org.apache.lucene.document.Document) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException)

Example 43 with AttributeDefinition

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;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) ArrayList(java.util.ArrayList) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition)

Example 44 with AttributeDefinition

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);
                    }
                }
            });
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) NodeVisitor(org.openforis.idm.model.NodeVisitor)

Example 45 with AttributeDefinition

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);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8