Search in sources :

Example 16 with CollectRecord

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);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with CollectRecord

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());
    }
}
Also used : TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) CollectRecord(org.openforis.collect.model.CollectRecord) TaxonAttribute(org.openforis.idm.model.TaxonAttribute) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) Secured(org.springframework.security.access.annotation.Secured)

Example 18 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord)

Example 19 with CollectRecord

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);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ZipEntry(java.util.zip.ZipEntry) BackupRecordEntry(org.openforis.collect.io.data.BackupDataExtractor.BackupRecordEntry) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 20 with CollectRecord

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);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) ZipEntry(java.util.zip.ZipEntry) OutputStreamWriter(java.io.OutputStreamWriter) RecordFileException(org.openforis.collect.manager.exception.RecordFileException) IOException(java.io.IOException)

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9