use of org.openforis.idm.metamodel.TaxonAttributeDefinition in project collect by openforis.
the class DataCleansingChainIntegrationTest method testUpdateFieldChain.
@Test
public void testUpdateFieldChain() {
DataCleansingChain chain = new DataCleansingChain(survey);
chain.setTitle("Test chain");
chain.setDescription("This is just a test");
DataQuery query = new DataQuery(survey);
EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
TaxonAttributeDefinition speciesDef = (TaxonAttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/species");
query.setTitle("Find trees with unlisted species");
query.setEntityDefinition(treeDef);
query.setAttributeDefinition(speciesDef);
query.setConditions("species/@code = 'UNL'");
dataQueryManager.save(query, user);
int initialCount = countResults(query);
assertEquals(1, initialCount);
DataCleansingStep step = new DataCleansingStep(survey);
step.setTitle("Step 1");
step.setDescription("This is the step 1");
step.setQuery(query);
{
DataCleansingStepValue updateValue = new DataCleansingStepValue();
updateValue.setUpdateType(UpdateType.FIELD);
updateValue.setCondition("idm:blank(species/@code)");
updateValue.setFieldFixExpressions(Arrays.asList("'UNL'", "'Will not be applied'"));
step.addUpdateValue(updateValue);
}
{
DataCleansingStepValue updateValue = new DataCleansingStepValue();
updateValue.setUpdateType(UpdateType.FIELD);
updateValue.setFieldFixExpressions(Arrays.asList("'PIN'", "'Pinus Sp.'"));
step.addUpdateValue(updateValue);
}
stepManager.save(step, user);
chain.addStep(step);
chainManager.save(chain, user);
DataCleansingChainExecutorJob job = jobManager.createJob(DataCleansingChainExecutorJob.class);
job.setSurvey(survey);
job.setChain(chain);
job.setRecordStep(Step.ENTRY);
jobManager.start(job, false);
int finalCount = countResults(query);
assertEquals(0, finalCount);
}
use of org.openforis.idm.metamodel.TaxonAttributeDefinition in project collect by openforis.
the class SpeciesService method deleteReferencingAttributes.
protected void deleteReferencingAttributes(CollectTaxonomy taxonomy) {
List<TaxonAttributeDefinition> defns = getTaxonAttributeDefinitionsForDesignerSurvey(taxonomy.getName());
if (!defns.isEmpty()) {
for (TaxonAttributeDefinition defn : defns) {
EntityDefinition parent = (EntityDefinition) defn.getParentDefinition();
parent.removeChildDefinition(defn);
}
sessionManager.saveActiveDesignerSurvey();
}
}
use of org.openforis.idm.metamodel.TaxonAttributeDefinition in project collect by openforis.
the class NewMondrianSchemaGenerator method generateLevel.
private Level generateLevel(AttributeDefinition nodeDef) {
DataTable dataTable = rdbSchema.getDataTable(nodeDef.getParentDefinition());
Level level = new Level(determineDimensionName(nodeDef), determineLevelCaption(nodeDef));
level.levelType = "Regular";
if (nodeDef instanceof NumericAttributeDefinition) {
level.type = ((NumericAttributeDefinition) nodeDef).getType() == Type.INTEGER ? INTEGER_DATATYPE : NUMERIC_DATATYPE;
} else if (nodeDef instanceof BooleanAttributeDefinition) {
level.type = BOOLEAN_DATATYPE;
} else if (nodeDef instanceof CodeAttributeDefinition) {
level.type = ((CodeAttributeDefinition) nodeDef).getList().isExternal() ? STRING_DATATYPE : INTEGER_DATATYPE;
} else {
level.type = STRING_DATATYPE;
}
if (nodeDef instanceof CodeAttributeDefinition && !((CodeAttributeDefinition) nodeDef).getList().isExternal()) {
CodeAttributeDefinition codeDef = (CodeAttributeDefinition) nodeDef;
CodeTable codeListTable = rdbSchema.getCodeListTable(codeDef);
level.table = codeListTable.getName();
level.column = codeListTable.getPrimaryKeyConstraint().getPrimaryKeyColumn().getName();
level.nameColumn = CodeListTables.getLabelColumnName(rdbConfig, codeDef.getList(), codeDef.getLevelIndex(), language);
} else if (nodeDef instanceof TaxonAttributeDefinition) {
DataColumn dataColumn = dataTable.getDataColumn(((TaxonAttributeDefinition) nodeDef).getCodeFieldDefinition());
level.column = dataColumn.getName();
} else if (nodeDef.isMultiple()) {
// TODO skip multiple attributes?
level.column = nodeDef.getName();
} else {
DataColumn dataColumn = dataTable.getDataColumn(nodeDef.getMainFieldDefinition());
level.column = dataColumn.getName();
}
return level;
}
use of org.openforis.idm.metamodel.TaxonAttributeDefinition in project collect by openforis.
the class SpeciesManager method extractQualifierValues.
protected String[] extractQualifierValues(TaxonAttribute attr) {
TaxonAttributeDefinition defn = attr.getDefinition();
List<String> qualifiers = defn.getQualifiers();
String[] qualifierValues = null;
if (qualifiers != null && !qualifiers.isEmpty()) {
qualifierValues = new String[qualifiers.size()];
Entity parent = attr.getParent();
for (int i = 0; i < qualifiers.size(); i++) {
String qualifierExpr = qualifiers.get(i);
try {
ModelPathExpression expression = expressionFactory.createModelPathExpression(qualifierExpr);
CodeAttribute code = (CodeAttribute) expression.evaluate(parent, null);
String qualifierValue = code.getValue().getCode();
qualifierValues[i] = qualifierValue;
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Error evaluating taxon qualifiers: ", e);
}
break;
}
}
}
return qualifierValues;
}
use of org.openforis.idm.metamodel.TaxonAttributeDefinition in project collect by openforis.
the class NodeDefinitionProxy method fromList.
static List<NodeDefinitionProxy> fromList(EntityDefinitionProxy parent, List<? extends NodeDefinition> list) {
List<NodeDefinitionProxy> proxies = new ArrayList<NodeDefinitionProxy>();
if (list != null) {
for (NodeDefinition n : list) {
NodeDefinitionProxy p = null;
CollectSurvey survey = (CollectSurvey) n.getSurvey();
UIOptions uiOptions = survey.getUIOptions();
boolean hidden = uiOptions.isHidden(n);
if (!hidden) {
if (n instanceof AttributeDefinition) {
if (n instanceof BooleanAttributeDefinition) {
p = new BooleanAttributeDefinitionProxy(parent, (BooleanAttributeDefinition) n);
} else if (n instanceof CodeAttributeDefinition) {
p = new CodeAttributeDefinitionProxy(parent, (CodeAttributeDefinition) n);
} else if (n instanceof CoordinateAttributeDefinition) {
p = new CoordinateAttributeDefinitionProxy(parent, (CoordinateAttributeDefinition) n);
} else if (n instanceof DateAttributeDefinition) {
p = new DateAttributeDefinitionProxy(parent, (DateAttributeDefinition) n);
} else if (n instanceof FileAttributeDefinition) {
p = new FileAttributeDefinitionProxy(parent, (FileAttributeDefinition) n);
} else if (n instanceof NumberAttributeDefinition) {
p = new NumberAttributeDefinitionProxy(parent, (NumberAttributeDefinition) n);
} else if (n instanceof RangeAttributeDefinition) {
p = new RangeAttributeDefinitionProxy(parent, (RangeAttributeDefinition) n);
} else if (n instanceof TaxonAttributeDefinition) {
p = new TaxonAttributeDefinitionProxy(parent, (TaxonAttributeDefinition) n);
} else if (n instanceof TextAttributeDefinition) {
p = new TextAttributeDefinitionProxy(parent, (TextAttributeDefinition) n);
} else if (n instanceof TimeAttributeDefinition) {
p = new TimeAttributeDefinitionProxy(parent, (TimeAttributeDefinition) n);
} else {
throw new RuntimeException("AttributeDefinition not supported: " + n.getClass().getSimpleName());
}
} else if (n instanceof EntityDefinition) {
p = new EntityDefinitionProxy(parent, (EntityDefinition) n);
}
if (p != null) {
proxies.add(p);
}
}
}
}
return proxies;
}
Aggregations