Search in sources :

Example 1 with DefinedTermBase

use of eu.etaxonomy.cdm.model.term.DefinedTermBase in project cdmlib by cybertaxonomy.

the class PilotOutputExporter method doInvoke.

/**
 * Retrieves data from a CDM DB and serializes them CDM to XML.
 * Starts with root taxa and traverses the classification to retrieve children taxa, synonyms and relationships.
 * Taxa that are not part of the classification are not found.
 *
 * @param exImpConfig
 * @param dbname
 * @param filename
 */
@Override
protected void doInvoke(PilotOutputExportState state) {
    // protected boolean doInvoke(IExportConfigurator config,
    // Map<String, MapWrapper<? extends CdmBase>> stores) {
    PilotOutputExportConfigurator pilotOutputExpConfig = state.getConfig();
    String dbname = pilotOutputExpConfig.getSource().getName();
    String fileName = pilotOutputExpConfig.getDestinationNameString();
    logger.info("Serializing DB " + dbname + " to file " + fileName);
    logger.debug("DbSchemaValidation = " + pilotOutputExpConfig.getDbSchemaValidation());
    TransactionStatus txStatus = startTransaction(true);
    SDDDataSet dataSet = new SDDDataSet();
    List<Taxon> taxa = null;
    List<DefinedTermBase> terms = null;
    try {
        logger.info("Retrieving data from DB");
        retrieveData(pilotOutputExpConfig, dataSet);
    } catch (Exception e) {
        logger.error("Error retrieving data");
        e.printStackTrace();
    }
    logger.info("All data retrieved");
    try {
        pilotOutputDocumentBuilder = new PilotOutputDocumentBuilder();
        File f = new File(fileName);
        FileOutputStream fos = new FileOutputStream(f);
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, "UTF8"), true);
        pilotOutputDocumentBuilder.marshal(dataSet, fileName);
        // TODO: Split into one file per data set member to see whether performance improves?
        logger.info("XML file written");
        logger.info("Filename is: " + fileName);
    } catch (Exception e) {
        logger.error("Marshalling error");
        e.printStackTrace();
    }
    commitTransaction(txStatus);
    return;
}
Also used : Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TransactionStatus(org.springframework.transaction.TransactionStatus) SDDDataSet(eu.etaxonomy.cdm.io.sdd.out.SDDDataSet) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 2 with DefinedTermBase

use of eu.etaxonomy.cdm.model.term.DefinedTermBase in project cdmlib by cybertaxonomy.

the class TestCdmDbComparator method retrieveAllTables.

private Map<String, List<String>> retrieveAllTables(CdmApplicationController appCtr) {
    Map<String, List<String>> tables = new HashMap<>(table_list.length);
    List<String> agentTableContent = new ArrayList<>(MAX_ROWS);
    List<? extends AgentBase> agents = appCtr.getAgentService().list(null, MAX_ROWS, 0, null, null);
    for (AgentBase agent : agents) {
        // TODO: Want the entire row as string not just toString() of the object.
        agentTableContent.add(agent.toString());
    }
    tables.put("agents", agentTableContent);
    // List<Annotation> annotations = appCtr.getTermService().getAllAnnotations(MAX_ROWS, 0);
    List<String> definedTermBaseTableContent = new ArrayList<>(MAX_ROWS);
    List<DefinedTermBase> definedTermBases = appCtr.getTermService().list(null, MAX_ROWS, 0, null, null);
    for (DefinedTermBase definedTermBase : definedTermBases) {
        definedTermBaseTableContent.add(definedTermBase.toString());
    }
    tables.put("definedTermBases", definedTermBaseTableContent);
    // List<DescriptionBase> descriptionBases = appCtr.getDescriptionService().getAllDescriptionBases(MAX_ROWS, 0);
    // List<DescriptionElementBase> descriptionElementBases = appCtr.getDescriptionService().getAllDescriptionElementBases(MAX_ROWS, 0);
    // List<HomotypicalGroup> homotypicalGroups = appCtr.getNameService().getAllHomotypicalGroups(MAX_ROWS, 0);
    List<LanguageString> languageStrings = appCtr.getTermService().getAllLanguageStrings(MAX_ROWS, 0);
    // List<Marker> markers = appCtr.getTermService().getAllMarkers(MAX_ROWS, 0);
    // List<NameRelationship> nameRelationships = appCtr.getNameService().getAllNameRelationships(MAX_ROWS, 0);
    List<NomenclaturalStatus> nomenclaturalStatus = appCtr.getNameService().getAllNomenclaturalStatus(MAX_ROWS, 0);
    // List<OriginalSource> originalSources = appCtr.getNameService().getAllOriginalSources(MAX_ROWS, 0);
    List<Reference> references = appCtr.getReferenceService().list(null, MAX_ROWS, 0, null, null);
    List<Representation> representations = appCtr.getTermService().getAllRepresentations(MAX_ROWS, 0);
    List<SpecimenOrObservationBase> specimenOrObservationBases = appCtr.getOccurrenceService().list(null, MAX_ROWS, 0, null, null);
    // List<TaxonBase> taxonBases = appCtr.getTaxonService().getAllTaxa(MAX_ROWS, 0);
    // List<TaxonName> taxonNames = appCtr.getNameService().getAllNames(MAX_ROWS, 0);
    // List<TaxonRelationship> taxonRelationships = appCtr.getTaxonService().getAllTaxonRelationships(MAX_ROWS, 0);
    List<TermVocabulary> termVocabularies = appCtr.getVocabularyService().list(null, MAX_ROWS, 0, null, null);
    List<TypeDesignationBase<?>> typeDesignationBases = appCtr.getNameService().getAllTypeDesignations(MAX_ROWS, 0);
    return tables;
}
Also used : HashMap(java.util.HashMap) Reference(eu.etaxonomy.cdm.model.reference.Reference) TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) ArrayList(java.util.ArrayList) TermVocabulary(eu.etaxonomy.cdm.model.term.TermVocabulary) Representation(eu.etaxonomy.cdm.model.term.Representation) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) AgentBase(eu.etaxonomy.cdm.model.agent.AgentBase) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with DefinedTermBase

use of eu.etaxonomy.cdm.model.term.DefinedTermBase in project cdmlib by cybertaxonomy.

the class DefinedTermDaoImplTest method testListByTermType.

@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testListByTermType() {
    TermType termType = TermType.Modifier;
    List<DefinedTermBase> existingList = this.dao.listByTermType(termType, null, null, null, null);
    int nExisting = existingList.size();
    int nExistingTerms = this.dao.list(DefinedTerm.class, null, null, null, null).size();
    // prepare
    @SuppressWarnings("unchecked") TermVocabulary<DefinedTerm> newVoc = TermVocabulary.NewInstance(termType);
    UUID vocUuid = UUID.fromString("6ced4c45-9c1b-4053-9dc3-6b8c51d286ed");
    newVoc.setUuid(vocUuid);
    UUID termUuid = UUID.fromString("2ab69720-c06c-4cfc-8928-d2ae6f1e4a48");
    DefinedTerm newModifier = DefinedTerm.NewModifierInstance("Test Modifier Description", "English Modifier", "TM");
    newModifier.setUuid(termUuid);
    newVoc.addTerm(newModifier);
    vocabularyDao.save(newVoc);
    this.commitAndStartNewTransaction(null);
    // assert 1 more
    int nNow = this.dao.listByTermType(termType, null, null, null, null).size();
    Assert.assertEquals("There should be exactly 1 more term now", nExisting + 1, nNow);
    int nTermsNow = this.dao.list(DefinedTerm.class, null, null, null, null).size();
    Assert.assertEquals("There should be exactly 1 more term now", nExistingTerms + 1, nTermsNow);
    this.commitAndStartNewTransaction(null);
    // Add German representation
    Representation newRepresentation = Representation.NewInstance("Beschreibung", "Deutscher Modifier", "Abk.", Language.GERMAN());
    newModifier.addRepresentation(newRepresentation);
    dao.saveOrUpdate(newModifier);
    this.commitAndStartNewTransaction(null);
    nNow = this.dao.listByTermType(termType, null, null, null, null).size();
    Assert.assertEquals("There should still be only one more term (but with 2 representations)", nExisting + 1, nNow);
    nTermsNow = this.dao.list(DefinedTerm.class, null, null, null, null).size();
    Assert.assertEquals("There should be exactly 1 more term now", nExistingTerms + 1, nTermsNow);
    List<DefinedTerm> languages = this.dao.listByTermType(TermType.Language, null, null, null, null);
    Assert.assertNotNull(languages);
    Assert.assertEquals(485, languages.size());
}
Also used : DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) Representation(eu.etaxonomy.cdm.model.term.Representation) UUID(java.util.UUID) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm) TermType(eu.etaxonomy.cdm.model.term.TermType) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSets(org.unitils.dbunit.annotation.DataSets)

Example 4 with DefinedTermBase

use of eu.etaxonomy.cdm.model.term.DefinedTermBase in project cdmlib by cybertaxonomy.

the class ClassificationServiceImpl method getTaxonInContext.

@Override
public TaxonInContextDTO getTaxonInContext(UUID classificationUuid, UUID taxonBaseUuid, Boolean doChildren, Boolean doSynonyms, boolean includeUnpublished, List<UUID> ancestorMarkers, TaxonNodeSortMode sortMode) {
    TaxonInContextDTO result = new TaxonInContextDTO();
    TaxonBase<?> taxonBase = taxonDao.load(taxonBaseUuid);
    if (taxonBase == null) {
        throw new EntityNotFoundException("Taxon with uuid " + taxonBaseUuid + " not found in datasource");
    }
    boolean isSynonym = false;
    Taxon acceptedTaxon;
    if (taxonBase.isInstanceOf(Synonym.class)) {
        isSynonym = true;
        Synonym synonym = CdmBase.deproxy(taxonBase, Synonym.class);
        acceptedTaxon = synonym.getAcceptedTaxon();
        if (acceptedTaxon == null) {
            throw new EntityNotFoundException("Accepted taxon not found for synonym");
        }
        TaxonStatus taxonStatus = TaxonStatus.Synonym;
        if (synonym.getName() != null && acceptedTaxon.getName() != null && synonym.getName().getHomotypicalGroup().equals(acceptedTaxon.getName().getHomotypicalGroup())) {
            taxonStatus = TaxonStatus.SynonymObjective;
        }
        result.setTaxonStatus(taxonStatus);
    } else {
        acceptedTaxon = CdmBase.deproxy(taxonBase, Taxon.class);
        result.setTaxonStatus(TaxonStatus.Accepted);
    }
    UUID acceptedTaxonUuid = acceptedTaxon.getUuid();
    UUID taxonNodeUuid = getTaxonNodeUuidByTaxonUuid(classificationUuid, acceptedTaxonUuid);
    if (taxonNodeUuid == null) {
        throw new EntityNotFoundException("Taxon not found in classficiation with uuid " + classificationUuid + ". Either classification does not exist or does not contain taxon/synonym with uuid " + taxonBaseUuid);
    }
    result.setTaxonNodeUuid(taxonNodeUuid);
    // TODO make it a dao call
    Taxon parentTaxon = getParentTaxon(classificationUuid, acceptedTaxon);
    if (parentTaxon != null) {
        result.setParentTaxonUuid(parentTaxon.getUuid());
        result.setParentTaxonLabel(parentTaxon.getTitleCache());
        if (parentTaxon.getName() != null) {
            result.setParentNameLabel(parentTaxon.getName().getTitleCache());
        }
    }
    result.setTaxonUuid(taxonBaseUuid);
    result.setClassificationUuid(classificationUuid);
    if (taxonBase.getSec() != null) {
        result.setSecundumUuid(taxonBase.getSec().getUuid());
        result.setSecundumLabel(taxonBase.getSec().getTitleCache());
    }
    result.setTaxonLabel(taxonBase.getTitleCache());
    TaxonName name = taxonBase.getName();
    result.setNameUuid(name.getUuid());
    result.setNameLabel(name.getTitleCache());
    result.setNameWithoutAuthor(name.getNameCache());
    result.setGenusOrUninomial(name.getGenusOrUninomial());
    result.setInfraGenericEpithet(name.getInfraGenericEpithet());
    result.setSpeciesEpithet(name.getSpecificEpithet());
    result.setInfraSpecificEpithet(name.getInfraSpecificEpithet());
    result.setAuthorship(name.getAuthorshipCache());
    Rank rank = name.getRank();
    if (rank != null) {
        result.setRankUuid(rank.getUuid());
        String rankLabel = rank.getAbbreviation();
        if (StringUtils.isBlank(rankLabel)) {
            rankLabel = rank.getLabel();
        }
        result.setRankLabel(rankLabel);
    }
    boolean recursive = false;
    Integer pageSize = null;
    Integer pageIndex = null;
    Pager<TaxonNodeDto> children = taxonNodeService.pageChildNodesDTOs(taxonNodeUuid, recursive, includeUnpublished, doSynonyms, sortMode, pageSize, pageIndex);
    // children
    if (!isSynonym) {
        for (TaxonNodeDto childDto : children.getRecords()) {
            if (doChildren && childDto.getTaxonStatus().equals(TaxonStatus.Accepted)) {
                EntityDTO<Taxon> child = new EntityDTO<Taxon>(childDto.getTaxonUuid(), childDto.getTitleCache());
                result.addChild(child);
            } else if (doSynonyms && childDto.getTaxonStatus().isSynonym()) {
                EntityDTO<Synonym> child = new EntityDTO<>(childDto.getTaxonUuid(), childDto.getTitleCache());
                result.addSynonym(child);
            }
        }
    } else {
        result.setAcceptedTaxonUuid(acceptedTaxonUuid);
        String nameTitel = acceptedTaxon.getName() == null ? null : acceptedTaxon.getName().getTitleCache();
        result.setAcceptedTaxonLabel(acceptedTaxon.getTitleCache());
        result.setAcceptedNameLabel(nameTitel);
    }
    // marked ancestors
    if (ancestorMarkers != null && !ancestorMarkers.isEmpty()) {
        @SuppressWarnings("rawtypes") List<DefinedTermBase> markerTypesTerms = termDao.list(ancestorMarkers, pageSize, null, null, null);
        List<MarkerType> markerTypes = new ArrayList<>();
        for (DefinedTermBase<?> term : markerTypesTerms) {
            if (term.isInstanceOf(MarkerType.class)) {
                markerTypes.add(CdmBase.deproxy(term, MarkerType.class));
            }
        }
        if (!markerTypes.isEmpty()) {
            TaxonNode node = taxonNodeDao.findByUuid(taxonNodeUuid);
            handleAncestorsForMarkersRecursive(result, markerTypes, node);
        }
    }
    return result;
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) ArrayList(java.util.ArrayList) TaxonStatus(eu.etaxonomy.cdm.persistence.dto.TaxonStatus) MarkedEntityDTO(eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO) EntityDTO(eu.etaxonomy.cdm.api.service.dto.EntityDTO) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TaxonInContextDTO(eu.etaxonomy.cdm.api.service.dto.TaxonInContextDTO) UUID(java.util.UUID) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Rank(eu.etaxonomy.cdm.model.name.Rank) EntityNotFoundException(javax.persistence.EntityNotFoundException) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym) TaxonNodeDto(eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto)

Example 5 with DefinedTermBase

use of eu.etaxonomy.cdm.model.term.DefinedTermBase in project cdmlib by cybertaxonomy.

the class TaxonServiceSearchTest method testFindByDescriptionElementFullText_CategoricalData.

@SuppressWarnings("rawtypes")
@Test
@DataSet
public final void testFindByDescriptionElementFullText_CategoricalData() throws IOException, LuceneParseException {
    TaxonNode subtree = null;
    // add CategoricalData
    DescriptionBase d_abies_balsamea = descriptionService.find(DESC_ABIES_BALSAMEA_UUID);
    // Categorical data
    CategoricalData cdata = CategoricalData.NewInstance();
    cdata.setFeature(Feature.DESCRIPTION());
    State state = State.NewInstance("green", "green", "gn");
    StateData statedata = StateData.NewInstance(state);
    statedata.putModifyingText(Language.ENGLISH(), "always, even during winter");
    cdata.addStateData(statedata);
    d_abies_balsamea.addElement(cdata);
    UUID termUUID = termService.save(state).getUuid();
    descriptionService.save(d_abies_balsamea);
    commitAndStartNewTransaction(null);
    // printDataSet(System.out, new String[] {
    // "STATEDATA", "STATEDATA_DEFINEDTERMBASE", "STATEDATA_LANGUAGESTRING", "LANGUAGESTRING"});
    refreshLuceneIndex();
    Pager<SearchResult<TaxonBase>> pager = taxonService.findByDescriptionElementFullText(CategoricalData.class, "green", null, subtree, null, null, false, null, null, null, null);
    Assert.assertEquals("Expecting one entity", 1, pager.getCount().intValue());
    Assert.assertEquals("Abies balsamea sec. Kohlbecker, A., Testcase standart views, 2013", pager.getRecords().get(0).getEntity().getTitleCache());
    Assert.assertTrue("Expecting only one doc", pager.getRecords().get(0).getDocs().size() == 1);
    Assert.assertEquals("Abies balsamea sec. Kohlbecker, A., Testcase standart views, 2013", pager.getRecords().get(0).getDocs().iterator().next().get("inDescription.taxon.titleCache"));
    // TODO modify the StateData
    TaxonBase taxon = pager.getRecords().get(0).getEntity();
    String newName = "Quercus robur";
    taxon.setTitleCache(newName + " sec. ", true);
    taxonService.saveOrUpdate(taxon);
    commitAndStartNewTransaction(null);
    taxon = taxonService.find(taxon.getUuid());
    Assert.assertEquals(newName + " sec. ", taxon.getTitleCache());
    DefinedTermBase term = termService.find(termUUID);
    termService.delete(term);
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) DefinedTermBase(eu.etaxonomy.cdm.model.term.DefinedTermBase) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) State(eu.etaxonomy.cdm.model.description.State) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) SearchResult(eu.etaxonomy.cdm.api.service.search.SearchResult) UUID(java.util.UUID) StateData(eu.etaxonomy.cdm.model.description.StateData) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Aggregations

DefinedTermBase (eu.etaxonomy.cdm.model.term.DefinedTermBase)49 UUID (java.util.UUID)16 TermVocabulary (eu.etaxonomy.cdm.model.term.TermVocabulary)12 ArrayList (java.util.ArrayList)10 Media (eu.etaxonomy.cdm.model.media.Media)9 HashMap (java.util.HashMap)8 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)7 Reference (eu.etaxonomy.cdm.model.reference.Reference)7 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)7 DefinedTerm (eu.etaxonomy.cdm.model.term.DefinedTerm)7 Representation (eu.etaxonomy.cdm.model.term.Representation)6 HashSet (java.util.HashSet)6 TransactionStatus (org.springframework.transaction.TransactionStatus)5 URI (eu.etaxonomy.cdm.common.URI)4 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)4 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)4 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)4 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)4 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)4 IOException (java.io.IOException)4