use of org.openforis.collect.model.CollectRecordSummary 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.CollectRecordSummary in project collect by openforis.
the class RecordController method loadRecordSummaries.
@RequestMapping(value = "survey/{surveyId}/data/records/summary", method = GET)
@ResponseBody
public Map<String, Object> loadRecordSummaries(@PathVariable("surveyId") int surveyId, @Valid RecordSummarySearchParameters params) {
CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
User user = loadUser(params.getUserId(), params.getUsername());
Map<String, Object> result = new HashMap<String, Object>();
Schema schema = survey.getSchema();
EntityDefinition rootEntityDefinition = params.getRootEntityName() == null ? schema.getFirstRootEntityDefinition() : schema.getRootEntityDefinition(params.getRootEntityName());
RecordFilter filter = createRecordFilter(survey, user, userGroupManager, rootEntityDefinition.getId(), false);
filter.setKeyValues(params.getKeyValues());
filter.setCaseSensitiveKeyValues(params.isCaseSensitiveKeyValues());
if (CollectionUtils.isEmpty(filter.getQualifiers())) {
// filter by qualifiers only if not already done by user group qualifiers
filter.setQualifiers(params.getQualifierValues());
}
filter.setSummaryValues(params.getSummaryValues());
if (filter.getOwnerIds() == null && params.getOwnerIds() != null && params.getOwnerIds().length > 0) {
filter.setOwnerIds(Arrays.asList(params.getOwnerIds()));
}
filter.setOffset(params.getOffset());
filter.setMaxNumberOfRecords(params.getMaxNumberOfRows());
// load summaries
List<CollectRecordSummary> summaries = params.isFullSummary() ? recordManager.loadFullSummaries(filter, params.getSortFields()) : recordManager.loadSummaries(filter, params.getSortFields());
result.put("records", toProxies(summaries));
// count total records
int count = recordManager.countRecords(filter);
result.put("count", count);
if (params.isIncludeOwners()) {
Set<User> owners = recordManager.loadDistinctOwners(createRecordFilter(survey, user, userGroupManager, rootEntityDefinition.getId(), false));
Set<BasicUserProxy> ownerProxies = Proxies.fromSet(owners, BasicUserProxy.class);
result.put("owners", ownerProxies);
}
return result;
}
use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.
the class RecordStatsGenerator method generate.
public RecordsStats generate(int surveyId, Date[] period) {
final RecordsStats stats = new RecordsStats(period);
CollectSurvey survey = surveyManager.getById(surveyId);
recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {
public void visit(CollectRecordSummary s) {
for (Entry<Step, StepSummary> entry : s.getStepSummaries().entrySet()) {
Step step = entry.getKey();
StepSummary stepSummary = entry.getValue();
if (stepSummary.getCreationDate() != null) {
PointStats pointStats = stats.getOrCreateDailyStats(stepSummary.getCreationDate());
switch(step) {
case ENTRY:
pointStats.incrementCreated();
break;
case CLEANSING:
pointStats.incrementEntered();
break;
case ANALYSIS:
pointStats.incrementCleansed();
break;
}
}
}
if (s.getModifiedDate() != null) {
PointStats pointStats = stats.getOrCreateDailyStats(s.getModifiedDate());
pointStats.incrementModified();
}
}
}, true);
stats.finalize();
return stats;
}
use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.
the class ValidationController method validateAllRecords.
@RequestMapping(value = "/validateAllRecords.htm", method = RequestMethod.GET)
public void validateAllRecords(HttpServletRequest request, HttpServletResponse response, @RequestParam String s, @RequestParam String r) throws IOException {
final ServletOutputStream outputStream = response.getOutputStream();
try {
if (s == null || r == null) {
outputStream.println("Wrong parameters: please specify 's' (survey) and 'r' (root entity name).");
return;
}
SessionState sessionState = getSessionState(request);
final User user = sessionState.getUser();
final String sessionId = sessionState.getSessionId();
print(outputStream, "Starting validation of all records: ");
final CollectSurvey survey = surveyManager.get(s);
if (survey == null) {
print(outputStream, "Survey not found");
return;
}
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(r).getId());
final ValidationMessageBuilder validationMessageHelper = ValidationMessageBuilder.createInstance(messageContextHolder);
recordManager.visitSummaries(filter, null, new Visitor<CollectRecordSummary>() {
public void visit(CollectRecordSummary summary) {
try {
String recordKey = validationMessageHelper.getRecordKey(summary);
long start = System.currentTimeMillis();
print(outputStream, "Start validating record: " + recordKey);
Integer id = summary.getId();
Step step = summary.getStep();
recordManager.validateAndSave(survey, user, sessionId, id, step);
long elapsedMillis = System.currentTimeMillis() - start;
print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
} catch (Exception e) {
try {
String message = "ERROR validating record " + summary.getId();
outputStream.println(message);
LOG.error(message);
} catch (IOException e1) {
}
}
}
});
print(outputStream, "End of validation of all records.");
} catch (Exception e) {
outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.openforis.collect.model.CollectRecordSummary in project collect by openforis.
the class GeoDataController method processNodes.
private void processNodes(CollectSurvey survey, Integer recordOffset, Integer maxNumberOfRecords, int attributeId, NodeProcessor nodeProcessor) throws Exception {
NodeDefinition nodeDef = survey.getSchema().getDefinitionById(attributeId);
RecordFilter filter = new RecordFilter(survey);
filter.setOffset(recordOffset);
filter.setMaxNumberOfRecords(maxNumberOfRecords);
List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
for (CollectRecordSummary summary : summaries) {
CollectRecord record = recordManager.load(survey, summary.getId(), summary.getStep(), false);
List<Node<?>> nodes = record.findNodesByPath(nodeDef.getPath());
for (Node<?> node : nodes) {
nodeProcessor.process(node);
}
}
}
Aggregations