Search in sources :

Example 31 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step) RecordOperations(org.openforis.collect.manager.RecordManager.RecordOperations)

Example 32 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent)

Example 33 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 34 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) BooleanValue(org.openforis.idm.model.BooleanValue) Value(org.openforis.idm.model.Value) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent)

Example 35 with CollectRecord

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

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9