Search in sources :

Example 11 with TaxonNameDescription

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>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}&#x002F;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();
}
Also used : TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with TaxonNameDescription

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;
}
Also used : SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) Media(eu.etaxonomy.cdm.model.media.Media) ArrayList(java.util.ArrayList) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) HashSet(java.util.HashSet)

Example 13 with TaxonNameDescription

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);
        }
    }
}
Also used : Field(org.apache.lucene.document.Field) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) StringField(org.apache.lucene.document.StringField) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) TextField(org.apache.lucene.document.TextField) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName)

Example 14 with TaxonNameDescription

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());
    }
}
Also used : TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase)

Example 15 with TaxonNameDescription

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());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) ArrayList(java.util.ArrayList) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) IndividualsAssociation(eu.etaxonomy.cdm.model.description.IndividualsAssociation) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

TaxonNameDescription (eu.etaxonomy.cdm.model.description.TaxonNameDescription)23 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)15 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)14 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)14 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)9 TextData (eu.etaxonomy.cdm.model.description.TextData)8 SpecimenDescription (eu.etaxonomy.cdm.model.description.SpecimenDescription)7 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)7 Reference (eu.etaxonomy.cdm.model.reference.Reference)6 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)5 DescriptionElementSource (eu.etaxonomy.cdm.model.description.DescriptionElementSource)5 Media (eu.etaxonomy.cdm.model.media.Media)5 HashSet (java.util.HashSet)5 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)4 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)4 Classification (eu.etaxonomy.cdm.model.taxon.Classification)4 ArrayList (java.util.ArrayList)4 ReferencedObjectUndeletableException (eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException)3 CategoricalData (eu.etaxonomy.cdm.model.description.CategoricalData)3 DescriptionBase (eu.etaxonomy.cdm.model.description.DescriptionBase)3