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