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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations