Search in sources :

Example 6 with CollectRecord

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

the class DataReportGeneratorIntegrationTest method testSimpleErrorReport.

@Test
public void testSimpleErrorReport() {
    EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
    NumberAttributeDefinition dbhDef = (NumberAttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
    DataQuery query = dataQuery().title("Find trees with invalid DBH").entity(treeDef).attribute(dbhDef).conditions("dbh > 20").type(invalidAttributeErrorType).severity(ErrorSeverity.ERROR).build();
    dataQueryManager.save(query, adminUser);
    DataQueryGroup queryGroup = new DataQueryGroup(survey);
    queryGroup.setTitle("Simple query group");
    queryGroup.addQuery(query);
    dataQueryGroupManager.save(queryGroup, adminUser);
    DataReportGeneratorJob job = jobManager.createJob(DataReportGeneratorJob.class);
    job.setQueryGroup(queryGroup);
    job.setRecordStep(Step.ENTRY);
    job.setActiveUser(adminUser);
    jobManager.start(job, false);
    DataReport report = job.getReport();
    DataReport reloadedReport = dataReportManager.loadById(survey, report.getId());
    List<DataReportItem> items = dataReportManager.loadItems(reloadedReport, 0, 100);
    assertFalse(items.isEmpty());
    assertEquals(1, items.size());
    DataReportItem item = items.get(0);
    CollectRecord record = recordManager.load(survey, item.getRecordId());
    assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
    assertEquals(new RealValue(30.0d, dbhDef.getDefaultUnit()), item.extractAttributeValue());
}
Also used : RealValue(org.openforis.idm.model.RealValue) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) Test(org.junit.Test)

Example 7 with CollectRecord

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

the class QueryExecutorIntegrationTest method testSimpleQuery.

@Test
public void testSimpleQuery() {
    // select region from tree where dbh > 20
    DataQuery query = new DataQuery(survey);
    EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
    AttributeDefinition dbhDef = (AttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
    query.setEntityDefinition(treeDef);
    query.setAttributeDefinition(dbhDef);
    query.setConditions("dbh > 20");
    final List<Node<?>> nodes = new ArrayList<Node<?>>();
    DataQueryExecutorJob job = jobManager.createJob(DataQueryExecutorJob.class);
    DataQueryExecutorJobInput input = new DataQueryExecutorJobInput(query, Step.ENTRY, new NodeProcessor() {

        public void process(Node<?> node) {
            nodes.add(node);
        }
    });
    job.setInput(input);
    jobManager.start(job, false);
    assertFalse(nodes.isEmpty());
    // first result
    Node<?> node = nodes.get(0);
    assertTrue(node instanceof Attribute);
    CollectRecord record = (CollectRecord) node.getRecord();
    assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
}
Also used : DataQueryExecutorJobInput(org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) NodeProcessor(org.openforis.collect.model.NodeProcessor) Attribute(org.openforis.idm.model.Attribute) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 8 with CollectRecord

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

the class DataCleansingChainExectutorTask method execute.

@Override
@Transactional
protected void execute() throws Throwable {
    CollectSurvey survey = input.chain.getSurvey();
    RecordFilter filter = createRecordsFilter();
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    datasetSize = recordSummaries.size();
    lastRecordModifiedDate = null;
    // Delete records in bulk if needed
    Set<Integer> recordIdsToBeDeleted = new TreeSet<Integer>();
    Iterator<CollectRecordSummary> it = recordSummaries.iterator();
    while (it.hasNext() && isRunning()) {
        CollectRecordSummary recordSummary = (CollectRecordSummary) it.next();
        udpateLastRecordModifiedDate(recordSummary);
        CollectRecord record = recordManager.load(survey, recordSummary.getId(), input.step, false);
        boolean recordCleansed = false;
        for (DataCleansingStep step : input.chain.getSteps()) {
            DataCleansingStepExecutionResult stepExecutionResult = executeStep(record, step);
            if (stepExecutionResult != null) {
                recordCleansed = true;
                if (stepExecutionResult == DataCleansingStepExecutionResult.RECORD_TO_BE_DELETED) {
                    recordIdsToBeDeleted.add(record.getId());
                    break;
                }
            }
        }
        if (recordCleansed) {
            cleansedRecords++;
        }
        incrementProcessedItems();
    }
    recordManager.deleteByIds(recordIdsToBeDeleted);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) TreeSet(java.util.TreeSet) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with CollectRecord

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

the class DataService method loadRecord.

@Secured(USER)
public RecordProxy loadRecord(int id, Integer stepNumber) {
    SessionState sessionState = sessionManager.getSessionState();
    final CollectSurvey survey = sessionState.getActiveSurvey();
    Step step = stepNumber == null ? null : Step.valueOf(stepNumber);
    CollectRecord record = step == null ? recordManager.load(survey, id) : recordManager.load(survey, id, step);
    sessionManager.setActiveRecord(record);
    return toProxy(record);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

Example 10 with CollectRecord

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

the class DataService method updateActiveRecord.

@Transactional
@Secured(ENTRY_LIMITED)
public NodeChangeSetProxy updateActiveRecord(NodeUpdateRequestSetProxy requestSet) throws RecordPersistenceException, RecordIndexException {
    sessionManager.checkIsActiveRecordLocked();
    CollectRecord activeRecord = getActiveRecord();
    NodeUpdateRequestSet reqSet = requestSet.toNodeUpdateRequestSet(codeListManager, sessionManager, activeRecord);
    NodeChangeSet changeSet = updateRecord(activeRecord, reqSet);
    if (!changeSet.isEmpty() && isCurrentRecordIndexable()) {
        recordIndexService.temporaryIndex(activeRecord);
    }
    String userName = sessionManager.getSessionState().getUser().getUsername();
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, userName);
    sessionManager.onEvents(events);
    NodeChangeSetProxy result = new NodeChangeSetProxy(activeRecord, changeSet, getProxyContext());
    if (requestSet.isAutoSave()) {
        try {
            saveActiveRecord();
            result.setRecordSaved(true);
        } catch (Exception e) {
            result.setRecordSaved(false);
        }
    }
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent) NodeChangeSetProxy(org.openforis.collect.model.proxy.NodeChangeSetProxy) RecordPromoteException(org.openforis.collect.manager.RecordPromoteException) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException) RecordIndexException(org.openforis.collect.manager.RecordIndexException) RecordLockedException(org.openforis.collect.persistence.RecordLockedException) MultipleEditException(org.openforis.collect.persistence.MultipleEditException) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) Secured(org.springframework.security.access.annotation.Secured) Transactional(org.springframework.transaction.annotation.Transactional)

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