Search in sources :

Example 26 with CollectTaxonomy

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

the class SpeciesDaoIntegrationTest method testCRUD.

// Disabled because SQLite does not provide Unicode case support by default
// TODO implement it
// @Test
// public void testFindUnicode() throws Exception {
// testFindVernacularName("Орех", 100, 1);
// }
// 
// @Test
// public void testFindUnicodeCaseInsensitive() throws Exception {
// testFindVernacularName("орех", 100, 1);
// }
@Test
public void testCRUD() throws Exception {
    // Create taxonomy
    CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
    testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
    // Create taxa
    Stack<Taxon> taxa = new Stack<Taxon>();
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -1, "JUG", "Juglandaceaex", FAMILY, 9, null));
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -2, "JUG2", "sJuglans sp.", GENUS, 0, null));
    taxa.push(testUpdateAndLoadTaxon(taxonomy1, taxa.pop(), "Juglans sp.", GENUS, 9, taxa.get(0)));
    taxa.push(testInsertAndLoadTaxon(taxonomy1, -4, "JUG3", "Juglans regia", SPECIES, 9, taxa.get(1)));
    // Create vernacular names
    Stack<TaxonVernacularName> names = new Stack<TaxonVernacularName>();
    names.push(testInsertAndLoadVernacularName(taxa.get(0), "Walnut family", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(0), "Walnuts", "en", "Cockney", 0));
    names.push(testUpdateAndLoadVernacularName(names.pop(), taxa.get(1), "Walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(1), "Noce", "ita", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Persian walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "English walnut", "eng", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Noce bianco", "ita", "", 9));
    names.push(testInsertAndLoadVernacularName(taxa.get(2), "Орех грецкий", "rus", "", 9));
    // Remove names
    while (!names.isEmpty()) {
        testDeleteAndLoadVernacularName(names.pop());
    }
    // Remove taxa
    while (!taxa.isEmpty()) {
        testDeleteAndLoadTaxon(taxa.pop());
    }
    // Remove taxonomy
    testDeleteAndLoadTaxonomy(taxonomy1);
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) Stack(java.util.Stack) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 27 with CollectTaxonomy

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

the class SpeciesDaoIntegrationTest method testFindScientificName.

private void testFindScientificName(String match, int maxResults, int expectedResults) {
    // Create taxonomy
    CollectTaxonomy taxonomy1 = testInsertAndLoadTaxonomy("it_bamboo");
    testUpdateAndLoadTaxonomy(taxonomy1, "it_trees");
    Taxon family1 = testInsertAndLoadTaxon(taxonomy1, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
    Taxon genus1 = testInsertAndLoadTaxon(taxonomy1, -2, "JUG", "Juglans sp.", GENUS, 9, family1);
    testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
    List<Taxon> results = taxonDao.findByScientificName(taxonomy1, FAMILY, match, maxResults);
    assertEquals(expectedResults, results.size());
    match = match.toUpperCase();
    for (Taxon taxon : results) {
        String name = taxon.getScientificName();
        name = name.toUpperCase();
        assertTrue(name.startsWith(match));
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 28 with CollectTaxonomy

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

the class SpeciesManager method moveTaxonomies.

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void moveTaxonomies(CollectSurvey fromSurvey, CollectSurvey toSurvey) {
    deleteTaxonomiesBySurvey(toSurvey);
    List<CollectTaxonomy> taxonomies = taxonomyDao.loadAllBySurvey(fromSurvey);
    for (CollectTaxonomy taxonomy : taxonomies) {
        taxonomy.setSurvey(toSurvey);
        taxonomyDao.update(taxonomy);
    }
}
Also used : CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with CollectTaxonomy

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

the class SpeciesBackupExportTask method initializeInternalVariables.

@Override
protected void initializeInternalVariables() throws Throwable {
    super.initializeInternalVariables();
    CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
    this.taxonomyName = taxonomy.getName();
    this.infoAttributeNames = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName).getAttributeNames();
}
Also used : CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 30 with CollectTaxonomy

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

the class SpeciesBackupExportTask method execute.

@Override
protected void execute() throws Throwable {
    CsvWriter writer = new CsvWriter(outputStream);
    CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
    TaxonSummaries summaries = speciesManager.loadFullTaxonSummaries(taxonomy);
    List<String> vernacularNamesLangCodes = getNotEmptyValues(summaries.getVernacularNamesLanguageCodes());
    // consider Latin vernacular name as synonym
    vernacularNamesLangCodes.remove(LATIN_LANG_CODE);
    this.vernacularNamesLangCodes = vernacularNamesLangCodes;
    // write headers
    writeHeaders(writer);
    for (TaxonSummary item : summaries.getItems()) {
        writeTaxonSummary(writer, item);
    }
    writer.flush();
}
Also used : CsvWriter(org.openforis.commons.io.csv.CsvWriter) TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries)

Aggregations

CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)43 Taxon (org.openforis.idm.model.species.Taxon)13 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)8 Secured (org.springframework.security.access.annotation.Secured)8 Test (org.junit.Test)7 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)7 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 ArrayList (java.util.ArrayList)5 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)5 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)5 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)4 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)3 CsvWriter (org.openforis.commons.io.csv.CsvWriter)3 File (java.io.File)2 List (java.util.List)2 SpeciesBackupImportJob (org.openforis.collect.io.metadata.species.SpeciesBackupImportJob)2 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1