Search in sources :

Example 11 with CollectTaxonomy

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

the class SpeciesDaoIntegrationTest method testDeleteTaxonByTaxonomy.

@Test
public void testDeleteTaxonByTaxonomy() {
    CollectSurvey survey = createAndStoreSurvey();
    // Create taxonomy
    CollectTaxonomy t = new CollectTaxonomy();
    t.setSurvey(survey);
    t.setName("it_trees");
    taxonomyDao.insert(t);
    CollectTaxonomy t2 = new CollectTaxonomy();
    t2.setSurvey(survey);
    t2.setName("it_bamboos");
    taxonomyDao.insert(t2);
    Taxon family1 = testInsertAndLoadTaxon(t, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
    Taxon genus1 = testInsertAndLoadTaxon(t, -2, "JUG", "Juglans sp.", GENUS, 9, family1);
    testInsertAndLoadTaxon(t, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
    Taxon family2 = testInsertAndLoadTaxon(t2, -1, "JUGLANDACAE", "Juglandaceae", FAMILY, 9, null);
    Taxon genus2 = testInsertAndLoadTaxon(t2, -2, "JUG", "Juglans sp.", GENUS, 9, family2);
    testInsertAndLoadTaxon(t2, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus2);
    // verify taxon records present
    List<Taxon> results = taxonDao.findByCode(t, FAMILY, "%", 10);
    assertEquals(3, results.size());
    taxonDao.deleteByTaxonomy(t);
    // verify all taxon records deleted for taxonomy 1
    List<Taxon> results2 = taxonDao.findByCode(t, FAMILY, "%", 10);
    assertTrue(results2 == null || results2.size() == 0);
    // verify all taxon records NOT deleted for taxonomy 2
    List<Taxon> results3 = taxonDao.findByCode(t2, FAMILY, "%", 10);
    assertEquals(3, results3.size());
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 12 with CollectTaxonomy

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

the class SpeciesDaoIntegrationTest method testInsertAndLoadTaxon.

private Taxon testInsertAndLoadTaxon(CollectTaxonomy taxonomy, int taxonId, String code, String scientificName, TaxonRank rank, int step, Taxon parent) {
    Integer parentId = parent == null ? null : parent.getSystemId();
    // Insert
    Taxon t = new Taxon();
    t.setTaxonId(taxonId);
    t.setCode(code);
    t.setScientificName(scientificName);
    t.setTaxonRank(rank);
    t.setStep(step);
    t.setTaxonomyId(taxonomy.getId());
    t.setParentId(parentId);
    taxonDao.insert(t);
    // Confirm saved
    t = taxonDao.loadById((CollectTaxonomy) taxonomy, t.getSystemId());
    assertNotNull(t);
    assertEquals((Integer) taxonId, t.getTaxonId());
    assertEquals(scientificName, t.getScientificName());
    assertEquals(rank, t.getTaxonRank());
    assertEquals(taxonomy.getId(), t.getTaxonomyId());
    assertEquals(step, t.getStep());
    assertEquals(parentId, t.getParentId());
    return t;
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 13 with CollectTaxonomy

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

the class SpeciesDaoIntegrationTest method testFindVernacularName.

private void testFindVernacularName(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);
    Taxon species1 = testInsertAndLoadTaxon(taxonomy1, -3, "JUG/REG", "Juglans regia", SPECIES, 9, genus1);
    testInsertAndLoadVernacularName(family1, "Walnut family", "eng", "", 9);
    testInsertAndLoadVernacularName(genus1, "Walnut", "eng", "", 0);
    testInsertAndLoadVernacularName(genus1, "Noce", "ita", "", 9);
    testInsertAndLoadVernacularName(species1, "Noce bianco", "ita", "", 9);
    testInsertAndLoadVernacularName(species1, "Persian walnut", "eng", "", 9);
    testInsertAndLoadVernacularName(species1, "Орех грецкий", "rus", "", 9);
    List<TaxonVernacularName> results = taxonVernacularNameDao.findByVernacularName(taxonomy1.getId(), match, maxResults);
    assertEquals(expectedResults, results.size());
    match = match.toUpperCase();
    for (TaxonVernacularName tvn : results) {
        String name = tvn.getVernacularName();
        name = name.toUpperCase();
        assertTrue(name.contains(match));
    }
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 14 with CollectTaxonomy

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

the class SpeciesBackupImportTask method persistTaxa.

private void persistTaxa() throws SurveyStoreException {
    CollectTaxonomy taxonomy = loadTaxonomy();
    if (taxonomy == null) {
        if (overwriteAll) {
            // create and store taxonomy taxonomy
            taxonomy = new CollectTaxonomy();
            taxonomy.setName(taxonomyName);
            taxonomy.setSurvey(survey);
            speciesManager.save(taxonomy);
        } else {
            throw new RuntimeException("Cannot insert new taxonomy: overwriteAll parameter not specified");
        }
    }
    // taxonomy definition changed
    saveSurvey();
    speciesManager.insertTaxons(taxonomy, taxonTree, overwriteAll);
}
Also used : CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 15 with CollectTaxonomy

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

the class SpeciesManager method loadTaxonSummaries.

public TaxonSummaries loadTaxonSummaries(CollectSurvey survey, int taxonomyId, int offset, int maxRecords) {
    CollectTaxonomy taxonomy = loadTaxonomyById(survey, taxonomyId);
    String taxonomyName = taxonomy.getName();
    int totalCount = taxonDao.countTaxons(taxonomy);
    Set<String> vernacularNamesLanguageCodes = new HashSet<String>();
    List<TaxonSummary> items = new ArrayList<TaxonSummary>();
    TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
    if (totalCount > 0) {
        List<Taxon> taxons = taxonDao.loadTaxons(taxonomy, offset, maxRecords);
        for (Taxon taxon : taxons) {
            List<TaxonVernacularName> vernacularNames = taxonVernacularNameDao.findByTaxon(taxon.getSystemId());
            TaxonSummary summary = new TaxonSummary(taxonDefinition, taxon, vernacularNames, null);
            List<String> itemVernLangCodes = summary.getVernacularLanguages();
            vernacularNamesLanguageCodes.addAll(itemVernLangCodes);
            items.add(summary);
        }
    }
    List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(vernacularNamesLanguageCodes);
    Collections.sort(sortedVernacularNamesLanguageCodes);
    List<String> infoAttributeNames = taxonDefinition.getAttributeNames();
    return new TaxonSummaries(totalCount, items, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) ArrayList(java.util.ArrayList) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) HashSet(java.util.HashSet)

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