use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordOperationGenerator method generate.
public RecordOperations generate() throws IOException, MissingStepsException, RecordParsingException {
RecordOperations operations = new RecordOperations();
boolean firstStepToBeProcessed = true;
CollectRecordSummary existingRecordSummary = null;
int workflowSequenceNumber = -1;
boolean newRecord = true;
for (Step step : Step.values()) {
CollectRecord parsedRecord = recordProvider.provideRecord(entryId, step);
if (parsedRecord == null || !isToBeProcessed(parsedRecord)) {
continue;
}
setDefaultValues(parsedRecord);
if (firstStepToBeProcessed) {
existingRecordSummary = findAlreadyExistingRecordSummary(parsedRecord);
newRecord = existingRecordSummary == null;
if (newRecord) {
insertRecordDataUntilStep(operations, parsedRecord, step);
workflowSequenceNumber = calculateStepDataSequenceNumber(existingRecordSummary, step);
} else {
Step existingRecordStep = existingRecordSummary.getStep();
operations.initializeRecordId(existingRecordSummary.getId());
operations.setOriginalStep(existingRecordStep);
if (overwriteStrategy == OVERWRITE_OLDER && isNewer(parsedRecord, existingRecordSummary) || overwriteStrategy == ONLY_SPECIFIED || overwriteStrategy == OVERWRITE_ALL) {
// overwrite existing record data
parsedRecord.setId(existingRecordSummary.getId());
boolean insertNewDataStep = step.after(existingRecordStep);
workflowSequenceNumber = calculateStepDataSequenceNumber(existingRecordSummary, step);
operations.addUpdate(parsedRecord, step, insertNewDataStep, workflowSequenceNumber);
}
}
firstStepToBeProcessed = false;
} else {
boolean insertNewDataStep = newRecord ? true : step.after(operations.getOriginalStep());
workflowSequenceNumber = calculateStepDataSequenceNumber(existingRecordSummary, step);
operations.addUpdate(parsedRecord, step, insertNewDataStep, workflowSequenceNumber);
}
}
return operations;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class AddNodeCommandHandler method execute.
@Override
public List<RecordEvent> execute(C command) {
CollectRecord record = findRecord(command);
Entity parentEntity = record.findNodeByPath(command.getParentEntityPath());
NodeDefinition nodeDef = parentEntity.getDefinition().getChildDefinition(command.getNodeDefId());
NodeChangeSet changeSet = recordUpdater.addNode(parentEntity, nodeDef);
recordManager.save(record);
List<RecordEvent> events = new EventProducer().produceFor(changeSet, command.getUsername());
return events;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class NodeCommandHandler method findRecord.
protected CollectRecord findRecord(NodeCommand command) {
CollectSurvey survey = surveyManager.getById(command.getSurveyId());
CollectRecord record = recordProvider.provide(survey, command.getRecordId());
return record;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class UpdateAttributeCommandHandler method execute.
@Override
public List<RecordEvent> execute(UpdateAttributeCommand command) {
CollectRecord record = findRecord(command);
Attribute<?, Value> attribute = findAttribute(command, record);
Value value = extractValue(command);
NodeChangeSet changeSet = recordUpdater.updateAttribute(attribute, value);
recordManager.save(record);
List<RecordEvent> events = new EventProducer().produceFor(changeSet, command.getUsername());
return events;
}
use of org.openforis.collect.model.CollectRecord 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));
}
Aggregations