use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataService method deleteRecord.
@Transactional
@Secured(ENTRY)
public void deleteRecord(int id) throws RecordPersistenceException {
SessionState sessionState = sessionManager.getSessionState();
CollectSurvey survey = sessionState.getActiveSurvey();
String userName = sessionState.getUser().getUsername();
CollectRecord record = recordManager.load(survey, id);
if (record.getStep() != Step.ENTRY) {
throw new IllegalStateException("Cannot delete a record not in ENTRY phase");
}
fileManager.deleteAllFiles(record);
recordManager.delete(id);
publishRecordDeletedEvent(record, record.getStep().toRecordStep(), userName);
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class SpeciesService method findByVernacularName.
@Secured("ROLE_ENTRY")
public List<TaxonOccurrenceProxy> findByVernacularName(String taxonomyName, int nodeId, String searchString, int maxResults, TaxonSearchParameters parameters) {
CollectTaxonomy taxonomy = loadTaxonomyByActiveSurvey(taxonomyName);
CollectRecord activeRecord = sessionManager.getActiveRecord();
Node<? extends NodeDefinition> attr = activeRecord.getNodeByInternalId(nodeId);
if (attr instanceof TaxonAttribute) {
List<TaxonOccurrence> list = speciesManager.findByVernacularName(taxonomy, (TaxonAttribute) attr, searchString, maxResults, parameters);
return Proxies.fromList(list, TaxonOccurrenceProxy.class);
} else {
throw new IllegalArgumentException("TaxonAttribute expected, found: " + attr.getClass().getName());
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportProcess method loadRecord.
private CollectRecord loadRecord(Integer recordId, Step step) {
CollectRecord record = recordManager.load(survey, recordId, step, settings.isRecordValidationEnabled());
// delete existing entities
RecordStepKey recordStepKey = new RecordStepKey(record.getId(), step);
if (settings.isDeleteExistingEntities() && !deletedEntitiesRecordKeys.contains(recordStepKey) && !getParentEntityDefinition().isRoot()) {
deleteAllParentEntities(record);
deletedEntitiesRecordKeys.add(recordStepKey);
}
return record;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class DataBackupTask method backup.
private void backup(CollectRecordSummary summary, Step step) {
Integer id = summary.getId();
try {
CollectRecord record = recordManager.load(survey, id, step, false);
BackupRecordEntry recordEntry = new BackupRecordEntry(step, id);
ZipEntry entry = new ZipEntry(recordEntry.getName());
zipOutputStream.putNextEntry(entry);
OutputStreamWriter writer = new OutputStreamWriter(zipOutputStream);
dataMarshaller.write(record, writer);
zipOutputStream.closeEntry();
} catch (Exception e) {
DataBackupError error = new DataBackupError(summary.getId(), summary.getRootEntityKeyValues(), summary.getStep(), e.getMessage());
errors.add(error);
log().error(error.toString(), e);
}
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class XMLDataExportProcess method backup.
private void backup(ZipOutputStream zipOutputStream, CollectRecordSummary summary, Step step) {
Integer id = summary.getId();
try {
CollectRecord record = recordManager.load(survey, id, step, false);
RecordEntry recordEntry = new RecordEntry(step, id);
String entryName = recordEntry.getName();
ZipEntry entry = new ZipEntry(entryName);
zipOutputStream.putNextEntry(entry);
OutputStreamWriter writer = new OutputStreamWriter(zipOutputStream);
dataMarshaller.write(record, writer);
zipOutputStream.closeEntry();
zipOutputStream.flush();
backupRecordFiles(zipOutputStream, record);
} catch (Exception e) {
String message = "Error while backing up " + id + " " + e.getMessage();
if (LOG.isErrorEnabled()) {
LOG.error(message, e);
}
// throw new RuntimeException(message, e);
}
}
Aggregations