Search in sources :

Example 1 with TaxonSummary

use of org.openforis.collect.metamodel.TaxonSummary 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)

Example 2 with TaxonSummary

use of org.openforis.collect.metamodel.TaxonSummary in project collect by openforis.

the class SpeciesManager method loadFullTaxonSummaries.

public TaxonSummaries loadFullTaxonSummaries(CollectTaxonomy taxonomy) {
    TaxonTree tree = loadTaxonTree(taxonomy);
    List<TaxonSummary> summaries = tree.toSummaries(TaxonRank.FAMILY, true);
    List<String> sortedVernacularNamesLanguageCodes = new ArrayList<String>(tree.getVernacularLanguageCodes());
    Collections.sort(sortedVernacularNamesLanguageCodes);
    List<String> infoAttributeNames = taxonomy.getSurvey().getReferenceDataSchema().getTaxonomyDefinition(taxonomy.getName()).getAttributeNames();
    return new TaxonSummaries(summaries.size(), summaries, sortedVernacularNamesLanguageCodes, infoAttributeNames);
}
Also used : TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) ArrayList(java.util.ArrayList) TaxonTree(org.openforis.collect.model.TaxonTree) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries)

Example 3 with TaxonSummary

use of org.openforis.collect.metamodel.TaxonSummary in project collect by openforis.

the class SpeciesExportProcess method exportToCSV.

public void exportToCSV(OutputStream out, CollectSurvey survey, int taxonomyId) {
    CsvWriter writer = null;
    try {
        writer = new CsvWriter(out);
        CollectTaxonomy taxonomy = speciesManager.loadTaxonomyById(survey, taxonomyId);
        taxonomyName = taxonomy.getName();
        TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
        ArrayList<String> colNames = new ArrayList<String>();
        colNames.add(SpeciesFileColumn.NO.getColumnName());
        colNames.add(SpeciesFileColumn.CODE.getColumnName());
        colNames.add(SpeciesFileColumn.FAMILY.getColumnName());
        colNames.add(SpeciesFileColumn.SCIENTIFIC_NAME.getColumnName());
        colNames.add(SpeciesFileColumn.SYNONYMS.getColumnName());
        List<String> vernacularNamesLangCodes = extractVernacularNameLanguageCodes(summaries);
        colNames.addAll(vernacularNamesLangCodes);
        List<String> infoAttributeNames = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName).getAttributeNames();
        colNames.addAll(infoAttributeNames);
        writer.writeHeaders(colNames);
        List<TaxonSummary> items = summaries.getItems();
        for (TaxonSummary item : items) {
            writeTaxonSummary(writer, vernacularNamesLangCodes, infoAttributeNames, item);
        }
    } catch (Exception e) {
        log.error(e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
Also used : CsvWriter(org.openforis.commons.io.csv.CsvWriter) TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) ArrayList(java.util.ArrayList) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries)

Example 4 with TaxonSummary

use of org.openforis.collect.metamodel.TaxonSummary in project collect by openforis.

the class TaxonSummaryProxy method fromList.

public static List<TaxonSummaryProxy> fromList(List<TaxonSummary> list) {
    List<TaxonSummaryProxy> proxies = new ArrayList<TaxonSummaryProxy>();
    if (list != null) {
        for (TaxonSummary item : list) {
            TaxonSummaryProxy proxy = new TaxonSummaryProxy(item);
            proxies.add(proxy);
        }
    }
    return proxies;
}
Also used : TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) ArrayList(java.util.ArrayList)

Example 5 with TaxonSummary

use of org.openforis.collect.metamodel.TaxonSummary in project collect by openforis.

the class SurveyManagerIntegrationTest method publishSurveyTaxonomyTest.

@Test
public void publishSurveyTaxonomyTest() throws SurveyImportException {
    insertTestTaxonomy();
    CollectSurvey temporarySurvey = surveyManager.createTemporarySurveyFromPublished(survey.getUri(), adminUser);
    {
        CollectTaxonomy taxonomy = speciesManager.loadTaxonomyByName(temporarySurvey, "tree");
        assertNotNull(taxonomy);
        TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
        assertEquals(1, summaries.getTotalCount());
        List<TaxonSummary> taxonSummaryList = summaries.getItems();
        {
            TaxonSummary taxonSummary = taxonSummaryList.get(0);
            assertEquals("Albizia glaberrima", taxonSummary.getScientificName());
            List<String> vernacularLanguages = taxonSummary.getVernacularLanguages();
            assertEquals(Arrays.asList("swh"), vernacularLanguages);
            List<String> vernacularNames = taxonSummary.getVernacularNames("swh");
            assertEquals(Arrays.asList("Mgerenge", "Mchani"), vernacularNames);
        }
    }
}
Also used : TaxonSummary(org.openforis.collect.metamodel.TaxonSummary) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)8 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)7 ArrayList (java.util.ArrayList)6 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)5 CsvWriter (org.openforis.commons.io.csv.CsvWriter)3 TaxonTree (org.openforis.collect.model.TaxonTree)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CodeList (org.openforis.idm.metamodel.CodeList)1 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)1 Taxon (org.openforis.idm.model.species.Taxon)1 TaxonVernacularName (org.openforis.idm.model.species.TaxonVernacularName)1