use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class CSVDataImportProcess method validateRecordKey.
private boolean validateRecordKey(DataLine line) {
long currentRowNumber = line.getLineNumber();
EntityDefinition parentEntityDefn = getParentEntityDefinition();
EntityDefinition rootEntityDefn = parentEntityDefn.getRootEntity();
Value[] recordKeyValues = line.getRecordKeyValues(rootEntityDefn);
String[] recordKeyStringValues = Values.toStringValues(recordKeyValues);
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(rootEntityDefn.getId());
filter.setKeyValues(recordKeyStringValues);
List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
String[] recordKeyColumnNames = DataCSVReader.getKeyAttributeColumnNames(parentEntityDefn, rootEntityDefn.getKeyAttributeDefinitions());
String errorMessageKey = null;
if (settings.isInsertNewRecords()) {
if (!recordSummaries.isEmpty()) {
errorMessageKey = ONLY_NEW_RECORDS_ALLOWED_MESSAGE_KEY;
}
} else if (recordSummaries.isEmpty() && settings.isReportNoRecordFoundErrors()) {
errorMessageKey = NO_RECORD_FOUND_ERROR_MESSAGE_KEY;
} else if (recordSummaries.size() > 1) {
errorMessageKey = MULTIPLE_RECORDS_FOUND_ERROR_MESSAGE_KEY;
}
if (errorMessageKey == null) {
return true;
} else {
ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, currentRowNumber, recordKeyColumnNames, errorMessageKey);
parsingError.setMessageArgs(new String[] { StringUtils.join(recordKeyStringValues) });
status.addParsingError(currentRowNumber, parsingError);
return false;
}
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class XMLDataImportProcess method findAlreadyExistingRecordSummary.
private CollectRecordSummary findAlreadyExistingRecordSummary(CollectRecord parsedRecord) {
CollectSurvey survey = (CollectSurvey) parsedRecord.getSurvey();
List<String> keyValues = parsedRecord.getRootEntityKeyValues();
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(parsedRecord.getRootEntityDefinitionId());
filter.setKeyValues(keyValues);
List<CollectRecordSummary> oldRecords = recordManager.loadFullSummaries(filter);
if (oldRecords == null || oldRecords.isEmpty()) {
return null;
} else if (oldRecords.size() == 1) {
return oldRecords.get(0);
} else {
throw new IllegalStateException(String.format("Multiple records found in survey %s with key(s): %s", survey.getName(), keyValues));
}
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class DataRestoreJob method initializeTask.
@Override
protected void initializeTask(Worker task) {
if (task instanceof SurveyBackupJob) {
SurveyBackupJob t = (SurveyBackupJob) task;
t.setFull(true);
t.setIncludeData(true);
t.setIncludeRecordFiles(true);
t.setOutputFormat(OutputFormat.DESKTOP_FULL);
t.setRecordFilter(new RecordFilter(publishedSurvey));
t.setSurvey(publishedSurvey);
} else if (task instanceof DataRestoreTask) {
DataRestoreTask t = (DataRestoreTask) task;
t.setRecordManager(recordManager);
t.setUserManager(userManager);
t.setUserGroupManager(userGroupManager);
t.setRecordProvider(recordProvider);
t.setTargetSurvey(publishedSurvey);
t.setUser(user);
t.setOverwriteStrategy(recordOverwriteStrategy);
t.setEntryIdsToImport(entryIdsToImport);
t.setIncludeRecordPredicate(includeRecordPredicate);
} else if (task instanceof RecordFileRestoreTask) {
RecordFileRestoreTask t = (RecordFileRestoreTask) task;
t.setRecordManager(recordManager);
t.setRecordFileManager(recordFileManager);
t.setBackupFileExtractor(backupFileExtractor);
t.setRecordProvider(recordProvider);
t.setOverwriteStrategy(recordOverwriteStrategy);
t.setEntryIdsToImport(entryIdsToImport);
t.setSurvey(publishedSurvey);
}
super.initializeTask(task);
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class DataRestoreJob method isBackupNeeded.
private boolean isBackupNeeded() {
if (newSurvey) {
return false;
}
Date lastBackupDate = backupStorageManager.getLastBackupDate(surveyName);
RecordFilter recordFilter = new RecordFilter(publishedSurvey);
recordFilter.setModifiedSince(lastBackupDate);
return recordManager.countRecords(recordFilter) > 0 || (lastBackupDate != null && publishedSurvey.getModifiedDate().after(lastBackupDate));
}
use of org.openforis.collect.model.RecordFilter in project collect by openforis.
the class RecordFileBackupTask method execute.
@Override
protected void execute() throws Throwable {
if (!hasFileAttributeDefinitions()) {
return;
}
RecordFilter filter = new RecordFilter(survey);
filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntityName).getId());
recordManager.visitSummaries(filter, new Visitor<CollectRecordSummary>() {
public void visit(CollectRecordSummary summary) {
try {
backup(summary);
incrementProcessedItems();
} catch (Exception e) {
addSkippedRecord(summary);
log.error(String.format("Error backing up record files for record with id %d and keys %s", summary.getId(), summary.getRootEntityKeyValues().toString()));
}
}
}, new Predicate<CollectRecordSummary>() {
public boolean evaluate(CollectRecordSummary s) {
return !isRunning();
}
});
}
Aggregations