Search in sources :

Example 1 with IdentifiableEntity

use of eu.etaxonomy.cdm.model.common.IdentifiableEntity in project cdmlib by cybertaxonomy.

the class TaxonServiceSearchTaxaAndNamesTest method testFindTaxaAndNames_CommonName.

@Test
@DataSet
public final void testFindTaxaAndNames_CommonName() {
    // pass 1
    IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
    configurator.setMatchMode(MatchMode.BEGINNING);
    configurator.setDoTaxa(true);
    configurator.setDoSynonyms(true);
    configurator.setDoNamesWithoutTaxa(true);
    configurator.setDoTaxaByCommonNames(true);
    configurator.setTitleSearchString("Balsam-Tanne");
    @SuppressWarnings("rawtypes") Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(configurator);
    @SuppressWarnings("rawtypes") List<IdentifiableEntity> list = pager.getRecords();
    assertEquals(1, list.size());
    configurator.setTitleSearchString("Abies*");
    configurator.setDoTaxa(false);
    configurator.setDoSynonyms(false);
    configurator.setDoNamesWithoutTaxa(false);
    configurator.setDoTaxaByCommonNames(true);
    configurator.setDoMisappliedNames(true);
    configurator.setClassification(classificationService.load(UUID.fromString(CLASSIFICATION_UUID)));
    pager = taxonService.findTaxaAndNames(configurator);
    list = pager.getRecords();
    assertEquals(1, list.size());
}
Also used : IFindTaxaAndNamesConfigurator(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator) IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 2 with IdentifiableEntity

use of eu.etaxonomy.cdm.model.common.IdentifiableEntity in project cdmlib by cybertaxonomy.

the class TaxonServiceSearchTaxaAndNamesTest method testFindTaxaAndNamesWithHybridFormula.

@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class)
public final void testFindTaxaAndNamesWithHybridFormula() {
    // pass 1
    IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
    configurator.setTitleSearchString("Achillea*");
    configurator.setMatchMode(MatchMode.BEGINNING);
    configurator.setDoTaxa(true);
    configurator.setDoSynonyms(true);
    configurator.setDoNamesWithoutTaxa(true);
    configurator.setDoTaxaByCommonNames(true);
    @SuppressWarnings("rawtypes") Pager<IdentifiableEntity> pager = taxonService.findTaxaAndNames(configurator);
// Assert.assertEquals("Expecting one taxon",1,pager.getRecords().size());
}
Also used : IFindTaxaAndNamesConfigurator(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator) IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 3 with IdentifiableEntity

use of eu.etaxonomy.cdm.model.common.IdentifiableEntity in project cdmlib by cybertaxonomy.

the class TaxonServiceSearchTest method benchmarkFindByCommonNameHql.

// @SuppressWarnings("rawtypes")
// @Test
// @DataSet
// public final void benchmarkFindTaxaAndNamesHql() throws IOException, LuceneParseException {
// 
// createRandomTaxonWithCommonName(NUM_OF_NEW_RADOM_ENTITIES);
// 
// IFindTaxaAndNamesConfigurator configurator = new FindTaxaAndNamesConfiguratorImpl();
// configurator.setTitleSearchString("Wei"+UTF8.SHARP_S+"%");
// configurator.setMatchMode(MatchMode.BEGINNING);
// configurator.setDoTaxa(false);
// configurator.setDoSynonyms(false);
// configurator.setDoNamesWithoutTaxa(false);
// configurator.setDoTaxaByCommonNames(true);
// 
// Pager<IdentifiableEntity> pager;
// 
// long startMillis = System.currentTimeMillis();
// for (int indx = 0; indx < BENCHMARK_ROUNDS; indx++) {
// pager = taxonService.findTaxaAndNames(configurator);
// if (logger.isDebugEnabled()) {
// logger.debug("[" + indx + "]" + pager.getRecords().get(0).getTitleCache());
// }
// }
// double duration = ((double) (System.currentTimeMillis() - startMillis)) / BENCHMARK_ROUNDS;
// logger.info("Benchmark result - [find taxon by CommonName via HQL] : " + duration + "ms (" + BENCHMARK_ROUNDS + " benchmark rounds )");
// }
@SuppressWarnings("rawtypes")
@Test
@DataSet
public final void benchmarkFindByCommonNameHql() {
    // printDataSet(System.err, new String[] { "TaxonBase" });
    createRandomTaxonWithCommonName(NUM_OF_NEW_RADOM_ENTITIES);
    IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
    configurator.setTitleSearchString("Wei" + UTF8.SHARP_S + "%");
    configurator.setMatchMode(MatchMode.BEGINNING);
    configurator.setDoTaxa(false);
    configurator.setDoSynonyms(false);
    configurator.setDoNamesWithoutTaxa(false);
    configurator.setDoTaxaByCommonNames(true);
    Pager<IdentifiableEntity> pager;
    long startMillis = System.currentTimeMillis();
    for (int indx = 0; indx < BENCHMARK_ROUNDS; indx++) {
        pager = taxonService.findTaxaAndNames(configurator);
        if (logger.isDebugEnabled()) {
            logger.debug("[" + indx + "]" + pager.getRecords().get(0).getTitleCache());
        }
    }
    double duration = ((double) (System.currentTimeMillis() - startMillis)) / BENCHMARK_ROUNDS;
    logger.info("Benchmark result - [find taxon by CommonName via HQL] : " + duration + "ms (" + BENCHMARK_ROUNDS + " benchmark rounds )");
}
Also used : IFindTaxaAndNamesConfigurator(eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator) IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

Example 4 with IdentifiableEntity

use of eu.etaxonomy.cdm.model.common.IdentifiableEntity in project cdmlib by cybertaxonomy.

the class CdmPreDataChangeListener method generateCaches.

// TODO shouldn't we use the "updateCaches" method instead?
public static void generateCaches(Object entity) {
    if (entity != null) {
        entity = CdmBase.deproxy(entity);
        Class<?> entityClazz = entity.getClass();
        if (IdentifiableEntity.class.isAssignableFrom(entityClazz)) {
            IdentifiableEntity<?> identifiableEntity = (IdentifiableEntity<?>) entity;
            if (TaxonName.class.isAssignableFrom(entityClazz)) {
                // non-viral-name caches  (was NonViralName)
                TaxonName nonViralName = (TaxonName) entity;
                nonViralName.getAuthorshipCache();
                nonViralName.getNameCache();
                nonViralName.getTitleCache();
                nonViralName.getFullTitleCache();
            } else if (TeamOrPersonBase.class.isAssignableFrom(entityClazz)) {
                // team-or-person caches
                TeamOrPersonBase<?> teamOrPerson = (TeamOrPersonBase<?>) entity;
                if (teamOrPerson.isInstanceOf(Team.class)) {
                    Team team = CdmBase.deproxy(teamOrPerson, Team.class);
                    if (!team.isProtectedNomenclaturalTitleCache()) {
                        team.setNomenclaturalTitleCache(null, false);
                    }
                    if (!team.isProtectedCollectorTitleCache()) {
                        team.setCollectorTitleCache(null, false);
                    }
                }
                teamOrPerson.getNomenclaturalTitleCache();
                teamOrPerson.getCollectorTitleCache();
                if (!teamOrPerson.isProtectedTitleCache()) {
                    teamOrPerson.setTitleCache(teamOrPerson.generateTitle(), false);
                }
            // if the above is changed in future, change also in ImportDeduplicationHelper.initAuthorTitleCaches
            } else if (Reference.class.isAssignableFrom(entityClazz)) {
                // reference caches
                Reference ref = (Reference) entity;
                ref.getAbbrevTitleCache();
                ref.getTitleCache();
            } else if (SpecimenOrObservationBase.class.isAssignableFrom(entityClazz)) {
                // specimen
                SpecimenOrObservationBase<?> specimen = (SpecimenOrObservationBase<?>) entity;
                if (!specimen.isProtectedTitleCache()) {
                    specimen.setTitleCache(specimen.generateTitle(), false);
                }
            // any other
            } else {
                // identifiableEntity.setTitleCache(identifiableEntity.generateTitle(), identifiableEntity.isProtectedTitleCache());
                identifiableEntity.getTitleCache();
            }
            // titleCache should never be empty, even if protected #5763, #5849
            if (identifiableEntity.isProtectedTitleCache() && identifiableEntity.hasEmptyTitleCache()) {
                identifiableEntity.setTitleCache(null, false);
                identifiableEntity.getTitleCache();
            }
            if (identifiableEntity.hasEmptyTitleCache()) {
                identifiableEntity.setTitleCache(identifiableEntity.toString(), false);
            }
        } else if (Amplification.class.isAssignableFrom(entityClazz)) {
            Amplification amplification = (Amplification) entity;
            amplification.updateCache();
        }
    }
}
Also used : Amplification(eu.etaxonomy.cdm.model.molecular.Amplification) IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) TeamOrPersonBase(eu.etaxonomy.cdm.model.agent.TeamOrPersonBase) Reference(eu.etaxonomy.cdm.model.reference.Reference) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Team(eu.etaxonomy.cdm.model.agent.Team)

Example 5 with IdentifiableEntity

use of eu.etaxonomy.cdm.model.common.IdentifiableEntity in project cdmlib by cybertaxonomy.

the class GetRecordView method constructResponse.

protected void constructResponse(OAIPMH oaiPmh, Map<String, Object> model) {
    oaiPmh.getRequest().setVerb(Verb.GET_RECORD);
    oaiPmh.getRequest().setValue((String) model.get("request"));
    oaiPmh.getRequest().setMetadataPrefix((MetadataPrefix) model.get("metadataPrefix"));
    GetRecord getRecord = new GetRecord();
    AuditEventRecord<IdentifiableEntity> auditEventRecord = (AuditEventRecord<IdentifiableEntity>) model.get("object");
    Header header = (Header) mapper.map((IdentifiableEntity) auditEventRecord.getAuditableObject(), Header.class);
    Record record = new Record();
    record.setHeader(header);
    if (!auditEventRecord.getRevisionType().equals(RevisionType.DEL)) {
        Metadata metadata = new Metadata();
        constructMetadata(metadata, (IdentifiableEntity) auditEventRecord.getAuditableObject());
        record.setMetadata(metadata);
    } else {
        header.setStatus(Status.DELETED);
    }
    getRecord.setRecord(record);
    oaiPmh.setGetRecord(getRecord);
}
Also used : IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) Header(eu.etaxonomy.cdm.remote.dto.oaipmh.Header) GetRecord(eu.etaxonomy.cdm.remote.dto.oaipmh.GetRecord) Metadata(eu.etaxonomy.cdm.remote.dto.oaipmh.Metadata) Record(eu.etaxonomy.cdm.remote.dto.oaipmh.Record) GetRecord(eu.etaxonomy.cdm.remote.dto.oaipmh.GetRecord) AuditEventRecord(eu.etaxonomy.cdm.model.view.AuditEventRecord) AuditEventRecord(eu.etaxonomy.cdm.model.view.AuditEventRecord)

Aggregations

IdentifiableEntity (eu.etaxonomy.cdm.model.common.IdentifiableEntity)29 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)7 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)7 Test (org.junit.Test)7 DataSet (org.unitils.dbunit.annotation.DataSet)7 IFindTaxaAndNamesConfigurator (eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator)6 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)4 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)4 Reference (eu.etaxonomy.cdm.model.reference.Reference)4 TeamOrPersonBase (eu.etaxonomy.cdm.model.agent.TeamOrPersonBase)3 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)3 Identifier (eu.etaxonomy.cdm.model.common.Identifier)3 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)3 UuidAndTitleCache (eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache)3 OrderHint (eu.etaxonomy.cdm.persistence.query.OrderHint)3 ArrayList (java.util.ArrayList)3 Person (eu.etaxonomy.cdm.model.agent.Person)2 Team (eu.etaxonomy.cdm.model.agent.Team)2 ICdmBase (eu.etaxonomy.cdm.model.common.ICdmBase)2