Search in sources :

Example 1 with CollectTaxonomy

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

the class CollectSpeciesListService method loadSpeciesListNames.

@Override
public List<String> loadSpeciesListNames(Survey survey) {
    List<CollectTaxonomy> taxonomies = speciesManager.loadTaxonomiesBySurvey((CollectSurvey) survey);
    List<String> result = new ArrayList<String>(taxonomies.size());
    for (CollectTaxonomy taxonomy : taxonomies) {
        result.add(taxonomy.getName());
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 2 with CollectTaxonomy

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

the class CollectSpeciesListService method loadSpeciesListData.

@Override
public Object loadSpeciesListData(Survey survey, String taxonomyName, String attribute, String speciesCode) {
    CollectTaxonomy taxonomy = speciesManager.loadTaxonomyByName((CollectSurvey) survey, taxonomyName);
    TaxonTree taxonTree = speciesManager.loadTaxonTree(taxonomy);
    Taxon taxon = taxonTree.findTaxonByCode(speciesCode);
    if (taxon == null) {
        return null;
    }
    Node taxonNode = taxonTree.getNodeBySystemId(taxon.getSystemId());
    if (FAMILY_ATTRIBUTE.equals(attribute) || FAMILY_NAME_ATTRIBUTE.equals(attribute) || FAMILY_SCIENTIFIC_NAME_ATTRIBUTE.equals(attribute)) {
        // family name
        Node familyNode = taxonNode.getAncestor(TaxonRank.FAMILY);
        return familyNode == null ? null : familyNode.getTaxon().getScientificName();
    } else if (GENUS_ATTRIBUTE.equals(attribute)) {
        Node genusNode = taxonNode.getAncestor(TaxonRank.GENUS);
        return genusNode == null ? null : genusNode.getTaxon().getScientificName();
    } else if (SCIENTIFIC_NAME_ATTRIBUTE.equals(attribute)) {
        return taxon.getScientificName();
    } else if (CODE_ATTRIBUTE.equals(attribute)) {
        return taxon.getCode();
    } else if (Languages.exists(Standard.ISO_639_3, attribute)) {
        TaxonVernacularName vernacularName = taxonNode.getVernacularName(attribute);
        return vernacularName == null ? null : vernacularName.getVernacularName();
    } else {
        // info (extra) attribute
        TaxonomyDefinition taxonDefinition = survey.getReferenceDataSchema().getTaxonomyDefinition(taxonomyName);
        if (taxonDefinition == null) {
            throw new IllegalArgumentException("No reference data schema found for taxonomy: " + taxonomyName);
        } else {
            int attributeIndex = taxonDefinition.getAttributeNames().indexOf(attribute);
            if (attributeIndex < 0) {
                throw new IllegalArgumentException("Unsupported attribute: " + attribute);
            } else {
                return taxon.getInfoAttribute(attributeIndex);
            }
        }
    }
}
Also used : TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) Taxon(org.openforis.idm.model.species.Taxon) Node(org.openforis.collect.model.TaxonTree.Node) TaxonTree(org.openforis.collect.model.TaxonTree) TaxonVernacularName(org.openforis.idm.model.species.TaxonVernacularName) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 3 with CollectTaxonomy

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

the class SpeciesImportProcessIntegrationTest method findTaxonByCode.

protected Taxon findTaxonByCode(String code) {
    CollectTaxonomy taxonomy = taxonomyDao.loadByName(survey, TEST_TAXONOMY_NAME);
    List<Taxon> results = taxonDao.findByCode(taxonomy, FAMILY, code, 10);
    assertNotNull(results);
    assertEquals(1, results.size());
    Taxon taxon = results.get(0);
    return taxon;
}
Also used : Taxon(org.openforis.idm.model.species.Taxon) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy)

Example 4 with CollectTaxonomy

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

the class SpeciesImportProcessIntegrationTest method testExport.

@Test
public void testExport() throws Exception {
    SpeciesImportProcess process = importCSVFile(VALID_TEST_CSV);
    SpeciesImportStatus status = process.getStatus();
    assertTrue(status.isComplete());
    CollectTaxonomy taxonomy = taxonomyDao.loadByName(survey, TEST_TAXONOMY_NAME);
    TaxonSummaries summaries = speciesManager.loadFullTaxonSummariesOld(taxonomy);
    assertNotNull(summaries);
}
Also used : SpeciesImportProcess(org.openforis.collect.manager.speciesimport.SpeciesImportProcess) SpeciesImportStatus(org.openforis.collect.manager.speciesimport.SpeciesImportStatus) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) TaxonSummaries(org.openforis.collect.metamodel.TaxonSummaries) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 5 with CollectTaxonomy

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

the class SpeciesService method loadTaxonomiesBySurvey.

@Secured("ROLE_ENTRY")
public List<TaxonomyProxy> loadTaxonomiesBySurvey(int surveyId, boolean work) {
    CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveyId);
    List<CollectTaxonomy> result = speciesManager.loadTaxonomiesBySurvey(survey);
    return Proxies.fromList(result, TaxonomyProxy.class);
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) CollectTaxonomy(org.openforis.collect.model.CollectTaxonomy) Secured(org.springframework.security.access.annotation.Secured)

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