use of eu.etaxonomy.cdm.model.description.TaxonNameDescription in project cdmlib by cybertaxonomy.
the class NamePortalController method doGetNameDescriptions.
/**
* Get the list of {@link TaxonNameDescription}s of the Name associated with the
* {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
* <p>
* URI: <b>/{datasource-name}/portal/name/{name-uuid}/descriptions</b>
*
* @param request
* @param response
* @return a List of {@link TaxonNameDescription} entities which are initialized
* using the following initialization strategy:
* {@link #NAMEDESCRIPTION_INIT_STRATEGY}
* @throws IOException
*/
@RequestMapping(value = { "taxonNameDescriptions" }, method = RequestMethod.GET)
public List<TaxonNameDescription> doGetNameDescriptions(@PathVariable("uuid") UUID uuid, HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.info("doGetNameDescriptions()" + request.getRequestURI());
TaxonName tnb = getCdmBaseInstance(uuid, response, (List<String>) null);
if (tnb == null) {
return null;
}
Pager<TaxonNameDescription> p = descriptionService.getTaxonNameDescriptions(tnb, null, null, NAMEDESCRIPTION_INIT_STRATEGY);
return p.getRecords();
}
use of eu.etaxonomy.cdm.model.description.TaxonNameDescription in project cdmlib by cybertaxonomy.
the class TaxonServiceImpl method listMedia.
@Override
public List<Media> listMedia(Taxon taxon, Set<TaxonRelationshipEdge> includeRelationships, Boolean limitToGalleries, Boolean includeTaxonDescriptions, Boolean includeOccurrences, Boolean includeTaxonNameDescriptions, List<String> propertyPath) {
// TODO let inherit
boolean includeUnpublished = INCLUDE_UNPUBLISHED;
if (logger.isTraceEnabled()) {
logger.trace("listMedia() - START");
}
Set<Taxon> taxa = new HashSet<>();
List<Media> taxonMedia = new ArrayList<>();
List<Media> nonImageGalleryImages = new ArrayList<>();
if (limitToGalleries == null) {
limitToGalleries = false;
}
// --- resolve related taxa
if (includeRelationships != null && !includeRelationships.isEmpty()) {
if (logger.isTraceEnabled()) {
logger.trace("listMedia() - resolve related taxa");
}
taxa = listRelatedTaxa(taxon, includeRelationships, null, includeUnpublished, null, null, null);
}
taxa.add((Taxon) dao.load(taxon.getUuid()));
if (includeTaxonDescriptions != null && includeTaxonDescriptions) {
if (logger.isTraceEnabled()) {
logger.trace("listMedia() - includeTaxonDescriptions");
}
List<TaxonDescription> taxonDescriptions = new ArrayList<>();
// --- TaxonDescriptions
for (Taxon t : taxa) {
taxonDescriptions.addAll(descriptionService.listTaxonDescriptions(t, null, null, null, null, propertyPath));
}
for (TaxonDescription taxonDescription : taxonDescriptions) {
if (!limitToGalleries || taxonDescription.isImageGallery()) {
for (DescriptionElementBase element : taxonDescription.getElements()) {
for (Media media : element.getMedia()) {
if (taxonDescription.isImageGallery()) {
taxonMedia.add(media);
} else {
nonImageGalleryImages.add(media);
}
}
}
}
}
// put images from image gallery first (#3242)
taxonMedia.addAll(nonImageGalleryImages);
}
if (includeOccurrences != null && includeOccurrences) {
if (logger.isTraceEnabled()) {
logger.trace("listMedia() - includeOccurrences");
}
@SuppressWarnings("rawtypes") Set<SpecimenOrObservationBase> specimensOrObservations = new HashSet<>();
// --- Specimens
for (Taxon t : taxa) {
specimensOrObservations.addAll(occurrenceDao.listByAssociatedTaxon(null, t, null, null, null, null));
}
for (SpecimenOrObservationBase<?> occurrence : specimensOrObservations) {
// direct media removed from specimen #3597
// taxonMedia.addAll(occurrence.getMedia());
// SpecimenDescriptions
Set<SpecimenDescription> specimenDescriptions = occurrence.getSpecimenDescriptions();
for (DescriptionBase<?> specimenDescription : specimenDescriptions) {
if (!limitToGalleries || specimenDescription.isImageGallery()) {
Set<DescriptionElementBase> elements = specimenDescription.getElements();
for (DescriptionElementBase element : elements) {
for (Media media : element.getMedia()) {
taxonMedia.add(media);
}
}
}
}
if (occurrence.isInstanceOf(DerivedUnit.class)) {
DerivedUnit derivedUnit = CdmBase.deproxy(occurrence, DerivedUnit.class);
// TODO why may collections have media attached? #
if (derivedUnit.getCollection() != null) {
taxonMedia.addAll(derivedUnit.getCollection().getMedia());
}
}
// media in hierarchy
taxonMedia.addAll(occurrenceService.getMediaInHierarchy(occurrence, null, null, propertyPath).getRecords());
}
}
if (includeTaxonNameDescriptions != null && includeTaxonNameDescriptions) {
if (logger.isTraceEnabled()) {
logger.trace("listMedia() - includeTaxonNameDescriptions");
}
// --- TaxonNameDescription
Set<TaxonNameDescription> nameDescriptions = new HashSet<>();
for (Taxon t : taxa) {
nameDescriptions.addAll(t.getName().getDescriptions());
}
for (TaxonNameDescription nameDescription : nameDescriptions) {
if (!limitToGalleries || nameDescription.isImageGallery()) {
Set<DescriptionElementBase> elements = nameDescription.getElements();
for (DescriptionElementBase element : elements) {
for (Media media : element.getMedia()) {
taxonMedia.add(media);
}
}
}
}
}
taxonMedia = deduplicateMedia(taxonMedia);
if (logger.isTraceEnabled()) {
logger.trace("listMedia() - initialize");
}
beanInitializer.initializeAll(taxonMedia, propertyPath);
if (logger.isTraceEnabled()) {
logger.trace("listMedia() - END");
}
return taxonMedia;
}
use of eu.etaxonomy.cdm.model.description.TaxonNameDescription in project cdmlib by cybertaxonomy.
the class DescriptionBaseClassBridge method set.
@Override
public void set(String name, Object entity, Document document, LuceneOptions luceneOptions) {
if (entity instanceof TaxonDescription) {
Taxon taxon = ((TaxonDescription) entity).getTaxon();
if (taxon != null) {
idFieldBridge.set(name + "taxon.id", taxon.getId(), document, idFieldOptions);
Field titleCachefield = new TextField(name + "taxon.titleCache", taxon.getTitleCache(), Store.YES);
document.add(titleCachefield);
// this should not be necessary since the IdentifiableEntity.titleCache already has the according annotation
/*
Field titleCacheSortfield = new SortedDocValuesField(
name + "taxon.titleCache__sort",
new BytesRef(taxon.getTitleCache())
);
LuceneDocumentUtility.setOrReplaceDocValueField(titleCacheSortfield, document);
*/
Field uuidfield = new StringField(name + "taxon.uuid", taxon.getUuid().toString(), Store.YES);
document.add(uuidfield);
for (TaxonNode node : taxon.getTaxonNodes()) {
if (node.getClassification() != null) {
idFieldBridge.set(name + "taxon.taxonNodes.classification.id", node.getClassification().getId(), document, idFieldOptions);
}
if (node.treeIndex() != null) {
Field treeIndexField = new StringField("inDescription.taxon.taxonNodes.treeIndex", node.treeIndex(), Store.YES);
document.add(treeIndexField);
}
}
}
}
if (entity instanceof TaxonNameDescription) {
TaxonName taxonName = ((TaxonNameDescription) entity).getTaxonName();
if (taxonName != null) {
idFieldBridge.set(name + "taxonName.id", taxonName.getId(), document, idFieldOptions);
}
}
}
use of eu.etaxonomy.cdm.model.description.TaxonNameDescription in project cdmlib by cybertaxonomy.
the class DbDescriptionElementTaxonMapper method getValue.
@Override
protected Object getValue(CdmBase cdmBase) {
Object result = null;
if (cdmBase.isInstanceOf(DescriptionElementBase.class)) {
DescriptionElementBase element = CdmBase.deproxy(cdmBase, DescriptionElementBase.class);
DescriptionBase<?> inDescription = element.getInDescription();
if (inDescription != null) {
if (inDescription.isInstanceOf(TaxonDescription.class)) {
TaxonDescription taxonDescription = CdmBase.deproxy(inDescription, TaxonDescription.class);
Taxon taxon = taxonDescription.getTaxon();
if (isCache) {
if (cacheIsNameTitleCache && taxon.getName() != null) {
return taxon.getName().getTitleCache();
} else {
return taxon.getTitleCache();
}
} else {
result = getState().getDbId(taxon);
}
} else if (inDescription.isInstanceOf(TaxonNameDescription.class)) {
TaxonNameDescription nameDescription = CdmBase.deproxy(inDescription, TaxonNameDescription.class);
TaxonName taxonName = nameDescription.getTaxonName();
if (isCache) {
return taxonName.getTitleCache();
} else {
result = getState().getDbId(taxonName);
}
} else {
throw new ClassCastException("Description of type " + inDescription.getClass().getName() + " not handled yet");
}
} else {
throw new ClassCastException("DescriptionElement has no description " + element.getUuid());
}
return result;
} else {
throw new ClassCastException("CdmBase for " + this.getClass().getName() + " must be of type DescriptionElementBase, but was " + cdmBase.getClass());
}
}
use of eu.etaxonomy.cdm.model.description.TaxonNameDescription in project cdmlib by cybertaxonomy.
the class CdmLightClassificationExport method handleDescriptions.
private void handleDescriptions(CdmLightExportState state, CdmBase cdmBase) {
String titleCache = null;
try {
if (cdmBase instanceof Taxon) {
Taxon taxon = HibernateProxyHelper.deproxy(cdmBase, Taxon.class);
titleCache = taxon.getTitleCache();
Set<TaxonDescription> descriptions = taxon.getDescriptions();
List<DescriptionElementBase> simpleFacts = new ArrayList<>();
List<DescriptionElementBase> specimenFacts = new ArrayList<>();
List<DescriptionElementBase> distributionFacts = new ArrayList<>();
List<DescriptionElementBase> taxonInteractionsFacts = new ArrayList<>();
List<DescriptionElementBase> commonNameFacts = new ArrayList<>();
List<DescriptionElementBase> usageFacts = new ArrayList<>();
for (TaxonDescription description : descriptions) {
if (description.getElements() != null) {
for (DescriptionElementBase element : description.getElements()) {
element = CdmBase.deproxy(element);
handleAnnotations(element);
if (element.getFeature().equals(Feature.COMMON_NAME())) {
commonNameFacts.add(element);
} else if (element.getFeature().equals(Feature.DISTRIBUTION())) {
distributionFacts.add(element);
} else if (element instanceof IndividualsAssociation || isSpecimenFeature(element.getFeature())) {
specimenFacts.add(element);
} else if (element.getFeature().isSupportsTaxonInteraction()) {
taxonInteractionsFacts.add(element);
} else {
simpleFacts.add(element);
}
}
}
}
if (!commonNameFacts.isEmpty()) {
handleCommonNameFacts(state, taxon, commonNameFacts);
}
if (!distributionFacts.isEmpty()) {
handleDistributionFacts(state, taxon, distributionFacts);
}
if (!specimenFacts.isEmpty()) {
handleSpecimenFacts(state, taxon, specimenFacts);
}
if (!simpleFacts.isEmpty()) {
handleSimpleFacts(state, taxon, simpleFacts);
}
if (!taxonInteractionsFacts.isEmpty()) {
handleTaxonInteractionsFacts(state, taxon, taxonInteractionsFacts);
}
} else if (cdmBase instanceof TaxonName) {
TaxonName name = CdmBase.deproxy(cdmBase, TaxonName.class);
titleCache = name.getTitleCache();
Set<TaxonNameDescription> descriptions = name.getDescriptions();
List<DescriptionElementBase> simpleFacts = new ArrayList<>();
for (TaxonNameDescription description : descriptions) {
if (description.getElements() != null) {
for (DescriptionElementBase element : description.getElements()) {
simpleFacts.add(element);
}
}
}
if (!simpleFacts.isEmpty()) {
handleSimpleFacts(state, name, simpleFacts);
}
}
} catch (Exception e) {
state.getResult().addException(e, "An unexpected error occurred when handling description of " + cdmBaseStr(cdmBase) + (titleCache != null ? (" " + titleCache) : "") + ": " + e.getMessage());
}
}
Aggregations