Search in sources :

Example 51 with CollectRecordSummary

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

the class DataQueryGroupExectutorTask method execute.

@Override
@Transactional
protected void execute() throws Throwable {
    CollectSurvey survey = input.getSurvey();
    RecordFilter filter = createRecordsFilter();
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    Iterator<CollectRecordSummary> it = recordSummaries.iterator();
    while (it.hasNext() && isRunning()) {
        CollectRecordSummary recordSummary = (CollectRecordSummary) it.next();
        Date modifiedDate = recordSummary.getModifiedDate();
        if (lastRecordModifiedDate == null) {
            lastRecordModifiedDate = modifiedDate;
        } else if (modifiedDate.compareTo(lastRecordModifiedDate) > 0) {
            lastRecordModifiedDate = modifiedDate;
        }
        CollectRecord record = recordManager.load(survey, recordSummary.getId(), input.step, false);
        List<DataQuery> queries = input.getQueries();
        for (DataQuery query : queries) {
            DataQueryEvaluator queryEvaluator = createQueryEvaluator(query);
            List<Node<?>> nodes = queryEvaluator.evaluate(record);
            for (Node<?> node : nodes) {
                processNode(query, node);
            }
        }
        incrementProcessedItems();
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Node(org.openforis.idm.model.Node) Date(java.util.Date) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) XPathDataQueryEvaluator(org.openforis.collect.datacleansing.xpath.XPathDataQueryEvaluator) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with CollectRecordSummary

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

the class RecordController method canDeleteRecords.

private boolean canDeleteRecords(int surveyId, Set<Integer> recordIds) {
    CollectSurvey survey = surveyManager.getById(surveyId);
    RecordFilter filter = new RecordFilter(survey);
    filter.setRecordIds(recordIds);
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    User loggedUser = sessionManager.getLoggedUser();
    RecordAccessControlManager recordAccessControlManager = new RecordAccessControlManager();
    UserInGroup userInSurveyGroup = userGroupManager.findUserInGroupOrDescendants(survey.getUserGroup(), loggedUser);
    boolean canDeleteRecords = userInSurveyGroup != null && recordAccessControlManager.canDeleteRecords(loggedUser, userInSurveyGroup.getRole(), recordSummaries);
    return canDeleteRecords;
}
Also used : User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordAccessControlManager(org.openforis.collect.manager.RecordAccessControlManager) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 53 with CollectRecordSummary

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

the class DataService method loadRecordSummaries.

@Secured(USER)
public Map<String, Object> loadRecordSummaries(RecordFilterProxy filterProxy, List<RecordSummarySortField> sortFields, String localeStr) {
    Map<String, Object> result = new HashMap<String, Object>();
    CollectSurvey survey;
    if (filterProxy.getSurveyId() > 0) {
        survey = surveyManager.getById(filterProxy.getSurveyId());
    } else {
        SessionState sessionState = sessionManager.getSessionState();
        survey = sessionState.getActiveSurvey();
    }
    RecordFilter filter = filterProxy.toFilter(survey);
    // load summaries
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter, sortFields);
    Locale locale = LocaleUtils.toLocale(localeStr);
    ProxyContext proxyContext = new ProxyContext(locale, messageSource, surveyContext);
    List<RecordSummaryProxy> proxies = RecordSummaryProxy.fromList(summaries, proxyContext);
    result.put("records", proxies);
    // count total records
    int count = recordManager.countRecords(filter);
    result.put("count", count);
    return result;
}
Also used : Locale(java.util.Locale) SessionState(org.openforis.collect.web.session.SessionState) ProxyContext(org.openforis.collect.ProxyContext) HashMap(java.util.HashMap) RecordSummaryProxy(org.openforis.collect.model.proxy.RecordSummaryProxy) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) Secured(org.springframework.security.access.annotation.Secured)

Example 54 with CollectRecordSummary

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

the class RDBReportingRepositories method insertRecords.

private void insertRecords(String surveyName, RecordStep recordStep, RelationalSchema targetSchema, Connection targetConn, ProgressListener progressListener) throws CollectRdbException {
    ProcessProgressListener processProgressListener = new ProcessProgressListener(2);
    CollectSurvey survey = surveyManager.get(surveyName);
    DatabaseExporter databaseUpdater = createRDBUpdater(targetSchema, targetConn);
    databaseUpdater.insertReferenceData(new ProcessStepProgressListener(processProgressListener, progressListener));
    processProgressListener.stepCompleted();
    RecordFilter recordFilter = new RecordFilter(survey);
    Step step = Step.fromRecordStep(recordStep);
    recordFilter.setStepGreaterOrEqual(step);
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(recordFilter);
    ProcessStepProgressListener recordInsertProcessListener = new ProcessStepProgressListener(processProgressListener, progressListener);
    recordInsertProcessListener.progressMade(new Progress(0, summaries.size()));
    long processedRecords = 0;
    for (CollectRecordSummary summary : summaries) {
        CollectRecord record = recordManager.load(survey, summary.getId(), step, false);
        databaseUpdater.insertRecordData(record, ProgressListener.NULL_PROGRESS_LISTENER);
        processedRecords++;
        recordInsertProcessListener.progressMade(new Progress(processedRecords, summaries.size()));
    }
    IOUtils.closeQuietly(databaseUpdater);
    processProgressListener.stepCompleted();
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Progress(org.openforis.concurrency.Progress) JooqDatabaseExporter(org.openforis.collect.relational.jooq.JooqDatabaseExporter) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) ProcessStepProgressListener(org.openforis.concurrency.ProcessStepProgressListener) ProcessProgressListener(org.openforis.concurrency.ProcessProgressListener) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 55 with CollectRecordSummary

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

the class ValidationReportProcess method startProcessing.

@Override
public void startProcessing() throws Exception {
    super.startProcessing();
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(recordFilter);
    if (summaries != null) {
        status.setTotal(summaries.size());
        try {
            initWriter();
            writeHeader();
            for (CollectRecordSummary summary : summaries) {
                // print(outputStream, "Start validating record: " + recordKey);
                if (status.isRunning()) {
                    Step step = summary.getStep();
                    Integer recordId = summary.getId();
                    CollectRecord record = recordManager.load(recordFilter.getSurvey(), recordId, step);
                    writeValidationReport(record);
                    status.incrementProcessed();
                // long elapsedMillis = System.currentTimeMillis() - start;
                // print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
                }
            }
            closeWriter();
            if (status.isRunning()) {
                status.complete();
            }
        } catch (IOException e) {
            status.error();
            String message = e.getMessage();
            status.setErrorMessage(message);
            if (LOG.isErrorEnabled()) {
                LOG.error(message, e);
            }
        }
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step) IOException(java.io.IOException)

Aggregations

CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)55 RecordFilter (org.openforis.collect.model.RecordFilter)33 CollectRecord (org.openforis.collect.model.CollectRecord)25 Step (org.openforis.collect.model.CollectRecord.Step)21 CollectSurvey (org.openforis.collect.model.CollectSurvey)15 IOException (java.io.IOException)8 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 User (org.openforis.collect.model.User)5 Transactional (org.springframework.transaction.annotation.Transactional)5 MainStep (org.openforis.collect.io.data.DataImportState.MainStep)4 SubStep (org.openforis.collect.io.data.DataImportState.SubStep)4 StepSummary (org.openforis.collect.model.CollectRecordSummary.StepSummary)4 Schema (org.openforis.idm.metamodel.Schema)4 List (java.util.List)3 Test (org.junit.Test)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2