Search in sources :

Example 6 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class DataQueryGenerator method generateValidationCheckQueries.

public List<DataQuery> generateValidationCheckQueries(CollectSurvey survey) {
    final List<DataQuery> result = new ArrayList<DataQuery>();
    survey.getSchema().traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition def) {
            if (def instanceof AttributeDefinition) {
                for (Check<?> check : ((AttributeDefinition) def).getChecks()) {
                    DataQuery query = createQuery(def, check);
                    result.add(query);
                }
            }
        }
    });
    return result;
}
Also used : ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Check(org.openforis.idm.metamodel.validation.Check) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 7 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class DataQueryResultItem method extractNodePath.

public String extractNodePath() {
    Survey survey = record.getSurvey();
    NodeDefinition attrDefn = survey.getSchema().getDefinitionById(query.getAttributeDefinitionId());
    Entity parentEntity = (Entity) record.getNodeByInternalId(parentEntityId);
    String path;
    if (attrDefn.isMultiple()) {
        path = String.format("%s/%s[%d]", parentEntity.getPath(), attrDefn.getName(), nodeIndex + 1);
    } else {
        path = String.format("%s/%s", parentEntity.getPath(), attrDefn.getName());
    }
    return path;
}
Also used : Entity(org.openforis.idm.model.Entity) Survey(org.openforis.idm.metamodel.Survey) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 8 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class JooqDatabaseExporter method deleteAttribute.

@Override
public void deleteAttribute(int recordId, int attributeId, int definitionId) {
    DataTable tableToDeleteFor = schema.getDataTableByDefinitionId(definitionId);
    NodeDefinition defToDeleteFor = tableToDeleteFor.getNodeDefinition();
    BigInteger pkValue = getTableArtificialPK(recordId, defToDeleteFor, attributeId);
    batchExecutor.addDelete(tableToDeleteFor, tableToDeleteFor.getPrimaryKeyColumn(), pkValue);
}
Also used : DataTable(org.openforis.collect.relational.model.DataTable) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) BigInteger(java.math.BigInteger)

Example 9 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class DataCSVReader method extractFieldDefinition.

private FieldDefinition<?> extractFieldDefinition(EntityDefinition parentEntityDefn, String colName) {
    String absoluteColName = getAbsoluteColName(colName);
    List<NodeDefinition> childDefns = parentEntityDefn.getChildDefinitions();
    for (NodeDefinition childDefn : childDefns) {
        String childName = childDefn.getName();
        if (absoluteColName.equals(childName)) {
            if (childDefn instanceof AttributeDefinition) {
                AttributeDefinition attrDefn = (AttributeDefinition) childDefn;
                if (attrDefn.hasMainField()) {
                    String mainFieldName = attrDefn.getMainFieldName();
                    return attrDefn.getFieldDefinition(mainFieldName);
                } else {
                    // it is a composite attribute without a "main" field (date, time, coordinate, taxon)
                    return null;
                }
            } else {
                // column name matches an entity name: error
                return null;
            }
        } else if (absoluteColName.startsWith(childName + ATTRIBUTE_FIELD_SEPARATOR)) {
            if (childDefn instanceof EntityDefinition) {
                if (childDefn.isMultiple()) {
                // ignore it
                } else {
                    String colNamePart = absoluteColName.substring(childName.length() + ATTRIBUTE_FIELD_SEPARATOR.length());
                    FieldDefinition<?> nestedFieldDefn = extractFieldDefinition((EntityDefinition) childDefn, colNamePart);
                    if (nestedFieldDefn != null) {
                        return nestedFieldDefn;
                    }
                }
            } else {
                for (FieldDefinition<?> fieldDefn : ((AttributeDefinition) childDefn).getFieldDefinitions()) {
                    if (absoluteColName.equals(childName + ATTRIBUTE_FIELD_SEPARATOR + fieldDefn.getName())) {
                        return fieldDefn;
                    }
                }
            }
        }
    }
    return null;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) FieldDefinition(org.openforis.idm.metamodel.FieldDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 10 with NodeDefinition

use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.

the class AddNodeCommandHandler method execute.

@Override
public List<RecordEvent> execute(C command) {
    CollectRecord record = findRecord(command);
    Entity parentEntity = record.findNodeByPath(command.getParentEntityPath());
    NodeDefinition nodeDef = parentEntity.getDefinition().getChildDefinition(command.getNodeDefId());
    NodeChangeSet changeSet = recordUpdater.addNode(parentEntity, nodeDef);
    recordManager.save(record);
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, command.getUsername());
    return events;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent)

Aggregations

NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)173 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)70 ArrayList (java.util.ArrayList)42 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)27 Schema (org.openforis.idm.metamodel.Schema)24 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)22 CollectSurvey (org.openforis.collect.model.CollectSurvey)20 Entity (org.openforis.idm.model.Entity)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)16 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)14 UITab (org.openforis.collect.metamodel.ui.UITab)12 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)11 Survey (org.openforis.idm.metamodel.Survey)11 Test (org.junit.Test)10 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)9 ModelVersion (org.openforis.idm.metamodel.ModelVersion)9 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)8 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)8 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)8 Node (org.openforis.idm.model.Node)8