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