use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class RecordDaoTest method testLoadRecordSummariesOrderedByClusterId.
// @Test
public void testLoadRecordSummariesOrderedByClusterId() throws IOException, SurveyImportException, DataInconsistencyException, InvalidIdmlException, NonexistentIdException {
EntityDefinition rootEntity = survey.getSchema().getRootEntityDefinitions().get(0);
String rootEntityName = rootEntity.getName();
// load record summaries
int offset = 0;
int maxNumberOfRecords = 5;
String orderByFieldName = "key_id";
String filter = null;
List<EntityDefinition> countInSummaryListEntityDefinitions = new ArrayList<EntityDefinition>();
EntityDefinition plotEntity = (EntityDefinition) rootEntity.getChildDefinition("plot");
countInSummaryListEntityDefinitions.add(plotEntity);
List<CollectRecord> list = this.recordDao.loadSummaries(survey, recordManager, rootEntityName, offset, maxNumberOfRecords, orderByFieldName, filter);
assertNotNull(list);
assertEquals(maxNumberOfRecords, list.size());
// test first record of the page
CollectRecord sampleRecordSummary;
List<String> rootEntityKeys;
sampleRecordSummary = list.get(0);
rootEntityKeys = sampleRecordSummary.getRootEntityKeys();
assertEquals("1", rootEntityKeys.get(0));
// test last record of the page
sampleRecordSummary = list.get(4);
rootEntityKeys = sampleRecordSummary.getRootEntityKeys();
assertEquals("5", rootEntityKeys.get(0));
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class RecordDaoTest method testLoadRecordSummariesOrderedByPlotCount.
// @Test
public void testLoadRecordSummariesOrderedByPlotCount() throws IOException, SurveyImportException, DataInconsistencyException, InvalidIdmlException, NonexistentIdException {
EntityDefinition rootEntity = survey.getSchema().getRootEntityDefinitions().get(0);
String rootEntityName = rootEntity.getName();
// load record summaries
int offset = 0;
int maxNumberOfRecords = 5;
String orderByFieldName = "count_plot";
String filter = null;
List<CollectRecord> list = this.recordDao.loadSummaries(survey, recordManager, rootEntityName, offset, maxNumberOfRecords, orderByFieldName, filter);
assertNotNull(list);
assertEquals(maxNumberOfRecords, list.size());
// test first record of the page
{
CollectRecord sampleRecordSummary = list.get(0);
List<Integer> entityCounts = sampleRecordSummary.getEntityCounts();
assertEquals(new Integer(1), entityCounts.get(0));
}
// test last record of the page
{
CollectRecord sampleRecordSummary = list.get(4);
List<Integer> entityCounts = sampleRecordSummary.getEntityCounts();
assertEquals(new Integer(5), entityCounts.get(0));
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class RecordSummaryDao method mapRecordsToSummaries.
private List<RecordSummary> mapRecordsToSummaries(List<Record> records, List<AttributeDefinition> keyDefs, List<EntityDefinition> countable) {
List<RecordSummary> result = new ArrayList<RecordSummary>();
for (Record record : records) {
Integer id = record.getValueAsInteger(RECORD.ID);
// String createdBy = r.getValueAsString(USER_MODIFIED_BY_ALIAS);
String createdBy = null;
Date dateCreated = record.getValueAsDate(DATE_CREATED_ALIAS);
// String modifiedBy = r.getValueAsString(USER_CREATED_BY_ALIAS);
String modifiedBy = null;
Date modifiedDate = record.getValueAsDate(DATE_MODIFIED_ALIAS);
Integer step = record.getValueAsInteger(RECORD.STEP);
Integer warnings = record.getValueAsInteger(RECORD.WARNINGS);
Integer errors = record.getValueAsInteger(RECORD.ERRORS);
Integer skipped = record.getValueAsInteger(RECORD.SKIPPED);
Integer missing = record.getValueAsInteger(RECORD.MISSING);
// create count map
Map<String, Integer> entityCounts = new HashMap<String, Integer>();
for (EntityDefinition def : countable) {
String alias = COUNT_ALIAS_PREFIX + def.getName();
String key = def.getName();
Integer value = record.getValueAsInteger(alias);
entityCounts.put(key, value);
}
// create key attributes map
Map<String, String> keyAttributes = new HashMap<String, String>();
for (AttributeDefinition attributeDefinition : keyDefs) {
String projectionAlias = KEY_ALIAS_PREFIX + attributeDefinition.getName();
String key = attributeDefinition.getName();
Object value = record.getValue(projectionAlias);
String valueStr = value != null ? value.toString() : "";
keyAttributes.put(key, valueStr);
}
RecordSummary recordSummary = new RecordSummary(id, keyAttributes, entityCounts, createdBy, dateCreated, modifiedBy, modifiedDate, step, skipped, missing, errors, warnings);
result.add(recordSummary);
}
return result;
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class StateDependencyMap method registerDependencies.
private void registerDependencies(NodeDefinition nodeDefinition, String expression, Map<Integer, Map<String, String>> dependencies) {
if (StringUtils.isNotBlank(expression)) {
List<String> referencedPaths = getReferencedPaths(expression);
for (String path : referencedPaths) {
try {
String normalizedPath = getNormalizedPath(path);
SchemaPathExpression schemaExpression = new SchemaPathExpression(normalizedPath);
EntityDefinition parentDefinition = nodeDefinition.getParentDefinition();
NodeDefinition dependantNode = schemaExpression.evaluate(parentDefinition);
String sourcePath = dependantNode.getPath();
String destinationPath = nodeDefinition.getPath();
String relativePath = getRelativePath(sourcePath, destinationPath);
Integer surveyId = nodeDefinition.getSurvey().getId();
Map<String, String> dependenciesMap = getDependenciesMap(dependencies, surveyId);
dependenciesMap.put(sourcePath, relativePath);
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("Unable to register dependency for node " + nodeDefinition.getPath() + " with expression " + path, e);
}
}
}
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class DataMarshaller method writeEntity.
private void writeEntity(Entity entity, Writer out) throws IOException {
out.write("{");
out.write("\"");
out.write(entity.getName());
out.write("\":{");
EntityDefinition defn = entity.getDefinition();
List<NodeDefinition> childDefns = defn.getChildDefinitions();
for (int j = 0; j < childDefns.size(); j++) {
if (j > 0) {
out.write(",");
}
NodeDefinition childDef = childDefns.get(j);
String name = childDef.getName();
int childCount = entity.getCount(name);
if (childCount > 0) {
if (childDef.isMultiple()) {
out.write("[");
for (int i = 0; i < childCount; i++) {
if (i > 0) {
out.write(",");
}
Node<?> child = entity.get(name, i);
write(child, i, out);
}
out.write("]");
} else {
Node<?> child = entity.get(name, 0);
write(child, 0, out);
}
}
}
out.write("}}");
}
Aggregations