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());
}
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());
}
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 )");
}
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();
}
}
}
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);
}
Aggregations