Search in sources :

Example 31 with CollectSurvey

use of org.openforis.collect.model.CollectSurvey in project collect by openforis.

the class SpeciesService method deleteTaxonomy.

@Secured("ROLE_ADMIN")
public void deleteTaxonomy(TaxonomyProxy proxy) {
    CollectSurvey survey = sessionManager.getActiveDesignerSurvey();
    Integer taxonomyId = proxy.getId();
    CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
    speciesManager.delete(taxonomy);
    deleteReferencingAttributes(taxonomy);
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) Secured(org.springframework.security.access.annotation.Secured)

Example 32 with CollectSurvey

use of org.openforis.collect.model.CollectSurvey in project collect by openforis.

the class DataRestoreServiceImpl method checkValidSurvey.

private void checkValidSurvey(String surveyName, String surveyUri) {
    CollectSurvey expectedSurvey = surveyManager.get(surveyName);
    String expectedSurveyUri = expectedSurvey.getUri();
    if (!surveyUri.equals(expectedSurveyUri)) {
        throw new IllegalArgumentException("The backup file is not related to the specified survey");
    }
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 33 with CollectSurvey

use of org.openforis.collect.model.CollectSurvey in project collect by openforis.

the class DataCSVReader method calculateIgnoredColumns.

private List<String> calculateIgnoredColumns() {
    final CSVDataExportParameters csvExportConfig = new CSVDataExportParameters();
    csvExportConfig.setIncludeCodeItemLabelColumn(true);
    csvExportConfig.setIncludeEnumeratedEntities(false);
    CollectSurvey survey = (CollectSurvey) parentEntityDefinition.getSurvey();
    ColumnProviderChain columnProvider = new CSVDataExportColumnProviderGenerator(survey, csvExportConfig).generateColumnProviderChain(parentEntityDefinition);
    List<String> result = new ArrayList<String>();
    List<String> colNames = getColumnNames();
    for (final String colName : colNames) {
        final MutableBoolean ignored = new MutableBoolean(false);
        columnProvider.traverseProviders(new Visitor<ColumnProvider>() {

            public void visit(ColumnProvider p) {
                if (!(p instanceof ColumnProviderChain) && p instanceof BasicColumnProvider) {
                    List<String> finalColumnHeadings = ((BasicColumnProvider) p).generateFinalColumnHeadings();
                    if (finalColumnHeadings.contains(colName)) {
                        if (p instanceof CodeColumnProvider && colName.endsWith(csvExportConfig.getFieldHeadingSeparator() + CodeColumnProvider.ITEM_LABEL_SUFFIX)) {
                            ignored.setTrue();
                        }
                    }
                }
            }
        });
        if (ignored.booleanValue()) {
            result.add(colName);
        }
    }
    return result;
}
Also used : ColumnProviderChain(org.openforis.collect.io.data.csv.ColumnProviderChain) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) ArrayList(java.util.ArrayList) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CodeColumnProvider(org.openforis.collect.io.data.csv.CodeColumnProvider) BasicColumnProvider(org.openforis.collect.io.data.csv.BasicColumnProvider) CodeColumnProvider(org.openforis.collect.io.data.csv.CodeColumnProvider) ColumnProvider(org.openforis.collect.io.data.csv.ColumnProvider) BasicColumnProvider(org.openforis.collect.io.data.csv.BasicColumnProvider) ArrayList(java.util.ArrayList) List(java.util.List) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 34 with CollectSurvey

use of org.openforis.collect.model.CollectSurvey in project collect by openforis.

the class XMLDataImportProcess method loadExistingSurvey.

protected CollectSurvey loadExistingSurvey() {
    String uri;
    if (surveyUri == null) {
        if (packagedSurvey == null) {
            throw new IllegalStateException("Survey uri not specified and packaged survey not found");
        } else {
            uri = packagedSurvey.getUri();
        }
    } else {
        uri = surveyUri;
    }
    CollectSurvey survey = surveyManager.getByUri(uri);
    if (survey == null && surveyUri != null) {
        throw new IllegalArgumentException("Published survey not found. URI: " + surveyUri);
    } else {
        return survey;
    }
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 35 with CollectSurvey

use of org.openforis.collect.model.CollectSurvey in project collect by openforis.

the class DataRestoreBaseJob method validateInput.

@Override
protected void validateInput() throws Throwable {
    super.validateInput();
    BackupFileExtractor backupFileExtractor = null;
    try {
        backupFileExtractor = new BackupFileExtractor(file);
        if (backupFileExtractor.isOldFormat()) {
            if (publishedSurvey == null) {
                throw new IllegalArgumentException("Please specify a published survey to witch restore data into");
            }
        } else {
            SurveyBackupInfo backupInfo = backupFileExtractor.extractInfo();
            CollectSurvey existingPublishedSurvey = findExistingPublishedSurvey(backupInfo);
            boolean newSurvey = publishedSurvey == null;
            if (newSurvey) {
                if (existingPublishedSurvey != null) {
                    throw new IllegalArgumentException(String.format("The backup file is associated to an already published survey: %s", existingPublishedSurvey.getName()));
                }
            } else {
                String publishedSurveyUri = publishedSurvey.getUri();
                String packagedSurveyUri = backupInfo.getSurveyUri();
                if (!publishedSurveyUri.equals(packagedSurveyUri)) {
                    throw new RuntimeException(String.format("Packaged survey uri (%s) is different from the expected one (%s)", packagedSurveyUri, publishedSurveyUri));
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(backupFileExtractor);
    }
}
Also used : SurveyBackupInfo(org.openforis.collect.io.SurveyBackupInfo) BackupFileExtractor(org.openforis.collect.io.BackupFileExtractor) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

CollectSurvey (org.openforis.collect.model.CollectSurvey)329 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)53 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)40 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)38 CollectRecord (org.openforis.collect.model.CollectRecord)30 RecordFilter (org.openforis.collect.model.RecordFilter)27 Transactional (org.springframework.transaction.annotation.Transactional)26 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)25 ArrayList (java.util.ArrayList)23 File (java.io.File)21 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)21 Secured (org.springframework.security.access.annotation.Secured)20 User (org.openforis.collect.model.User)19 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 SessionState (org.openforis.collect.web.session.SessionState)18 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)17 Test (org.junit.Test)16 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)15 CodeList (org.openforis.idm.metamodel.CodeList)15 Schema (org.openforis.idm.metamodel.Schema)15