Search in sources :

Example 36 with EntityDefinition

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));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) ArrayList(java.util.ArrayList)

Example 37 with EntityDefinition

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));
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) ArrayList(java.util.ArrayList) List(java.util.List)

Example 38 with EntityDefinition

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Date(java.sql.Date) RecordSummary(org.openforis.collect.model.RecordSummary) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Record(org.jooq.Record)

Example 39 with EntityDefinition

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);
                }
            }
        }
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SchemaPathExpression(org.openforis.idm.metamodel.expression.SchemaPathExpression) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException)

Example 40 with EntityDefinition

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("}}");
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9