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