Search in sources :

Example 11 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem in project collect by openforis.

the class RandomRecordGenerator method calculateRecordMeasurementsByKey.

private Map<RecordKey, Integer> calculateRecordMeasurementsByKey(CollectSurvey survey, final User user) {
    final List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
    final Map<RecordKey, Integer> measurementsByRecordKey = new HashMap<RecordKey, Integer>();
    recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary summary) {
            if (summary.getCreatedBy().getId() != user.getId()) {
                List<String> keys = summary.getCurrentStepSummary().getRootEntityKeyValues();
                RecordKey nonMeasurementKey = new RecordKey(nonMeasurementKeyDefs, keys);
                Integer measurements = measurementsByRecordKey.get(nonMeasurementKey);
                if (measurements == null) {
                    measurements = 1;
                } else {
                    measurements += 1;
                }
                measurementsByRecordKey.put(nonMeasurementKey, measurements);
            }
        }
    });
    samplingDesignManager.visitItems(survey.getId(), 1, new Visitor<SamplingDesignItem>() {

        public void visit(SamplingDesignItem item) {
            RecordKey key = new RecordKey(nonMeasurementKeyDefs, item.getLevelCodes());
            Integer measurements = measurementsByRecordKey.get(key);
            if (measurements == null) {
                measurementsByRecordKey.put(key, 0);
            }
        }
    });
    return measurementsByRecordKey;
}
Also used : HashMap(java.util.HashMap) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ArrayList(java.util.ArrayList) List(java.util.List) RecordFilter(org.openforis.collect.model.RecordFilter) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 12 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem in project collect by openforis.

the class RecordGenerator method addSecondLevelEntities.

private void addSecondLevelEntities(CollectRecord record, RecordKey recordKey) {
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    List<AttributeDefinition> nonMeasurementKeyDefs = getNonMeasurementKeyDefs(survey);
    List<String> keyValues = recordKey.getValues(nonMeasurementKeyDefs);
    List<SamplingDesignItem> secondLevelSamplingPointItems = samplingDesignManager.loadChildItems(survey.getId(), keyValues);
    List<CodeAttributeDefinition> samplingPointDataCodeAttributeDefs = findSamplingPointCodeAttributes(survey);
    if (!secondLevelSamplingPointItems.isEmpty() && samplingPointDataCodeAttributeDefs.size() > 1) {
        int levelIndex = 1;
        for (SamplingDesignItem samplingDesignItem : secondLevelSamplingPointItems) {
            CodeAttributeDefinition levelKeyDef = samplingPointDataCodeAttributeDefs.get(levelIndex);
            EntityDefinition levelEntityDef = levelKeyDef.getParentEntityDefinition();
            Entity parentLevelEntity = record.getRootEntity();
            NodeChangeSet addEntityChangeSet = recordUpdater.addEntity(parentLevelEntity, levelEntityDef);
            Entity entity = getAddedEntity(addEntityChangeSet);
            CodeAttribute keyAttr = entity.getChild(levelKeyDef);
            recordUpdater.updateAttribute(keyAttr, new Code(samplingDesignItem.getLevelCode(levelIndex + 1)));
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Code(org.openforis.idm.model.Code) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 13 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem in project collect by openforis.

the class SamplingDesignImportProcess method createItemsFromLines.

protected List<SamplingDesignItem> createItemsFromLines() {
    List<SamplingDesignItem> items = new ArrayList<SamplingDesignItem>();
    for (List<SamplingDesignLine> lines : linesByKey.values()) {
        for (SamplingDesignLine line : lines) {
            SamplingDesignItem item = line.toSamplingDesignItem(survey, reader.getInfoColumnNames());
            items.add(item);
        }
    }
    return items;
}
Also used : ArrayList(java.util.ArrayList) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 14 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem in project collect by openforis.

the class SamplingDesignImportProcess method persistSamplingDesign.

protected void persistSamplingDesign() throws SurveyStoreException {
    List<String> infoColumnNames = reader.getInfoColumnNames();
    List<ReferenceDataDefinition.Attribute> attributes = ReferenceDataDefinition.Attribute.fromNames(infoColumnNames);
    SamplingPointDefinition samplingPoint;
    if (attributes.isEmpty()) {
        samplingPoint = null;
    } else {
        samplingPoint = new SamplingPointDefinition();
        samplingPoint.setAttributes(attributes);
    }
    ReferenceDataSchema referenceDataSchema = survey.getReferenceDataSchema();
    if (referenceDataSchema == null) {
        referenceDataSchema = new ReferenceDataSchema();
        survey.setReferenceDataSchema(referenceDataSchema);
    }
    referenceDataSchema.setSamplingPointDefinition(samplingPoint);
    saveSurvey();
    List<SamplingDesignItem> items = createItemsFromLines();
    samplingDesignManager.insert(survey, items, overwriteAll);
}
Also used : SamplingPointDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.SamplingPointDefinition) ReferenceDataSchema(org.openforis.idm.metamodel.ReferenceDataSchema) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Example 15 with SamplingDesignItem

use of org.openforis.collect.model.SamplingDesignItem in project collect by openforis.

the class SamplingDesignImportTask method createItemsFromLines.

protected List<SamplingDesignItem> createItemsFromLines() {
    List<SamplingDesignItem> items = new ArrayList<SamplingDesignItem>();
    for (List<SamplingDesignLine> lines : linesByKey.values()) {
        for (SamplingDesignLine line : lines) {
            SamplingDesignItem item = line.toSamplingDesignItem(survey, reader.getInfoColumnNames());
            items.add(item);
        }
    }
    return items;
}
Also used : ArrayList(java.util.ArrayList) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem)

Aggregations

SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)26 ArrayList (java.util.ArrayList)9 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)8 Coordinate (org.openforis.idm.model.Coordinate)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)6 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 SamplingPointDataGenerator (org.openforis.collect.io.metadata.samplingpointdata.SamplingPointDataGenerator)3 SamplingPointGenerationSettings (org.openforis.collect.metamodel.samplingdesign.SamplingPointGenerationSettings)3 SamplingDesignImportProcess (org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess)2 SamplingDesignImportStatus (org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus)2 SamplingPointLevelGenerationSettings (org.openforis.collect.metamodel.samplingdesign.SamplingPointLevelGenerationSettings)2 OfcSamplingDesignRecord (org.openforis.collect.persistence.jooq.tables.records.OfcSamplingDesignRecord)2 CsvWriter (org.openforis.commons.io.csv.CsvWriter)2 CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)2 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 ReferenceDataSchema (org.openforis.idm.metamodel.ReferenceDataSchema)2 SamplingPointDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.SamplingPointDefinition)2 Document (de.micromata.opengis.kml.v_2_2_0.Document)1 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)1