Search in sources :

Example 1 with DescriptionType

use of eu.etaxonomy.cdm.model.description.DescriptionType in project cdmlib by cybertaxonomy.

the class DescriptionDaoImpl method addDescriptionTypesCriterion.

private void addDescriptionTypesCriterion(Set<DescriptionType> descriptionTypes, Criteria criteria) {
    if (descriptionTypes != null && !descriptionTypes.isEmpty()) {
        Set<Criterion> typeCriteria = new HashSet<>();
        for (DescriptionType descriptionType : descriptionTypes) {
            typeCriteria.add(Restrictions.sqlRestriction("{alias}.types like '%" + descriptionType.getKey() + "%'"));
        }
        criteria.add(Restrictions.and(typeCriteria.toArray(new Criterion[] {})));
    }
}
Also used : DescriptionType(eu.etaxonomy.cdm.model.description.DescriptionType) Criterion(org.hibernate.criterion.Criterion) HashSet(java.util.HashSet)

Example 2 with DescriptionType

use of eu.etaxonomy.cdm.model.description.DescriptionType in project cdmlib by cybertaxonomy.

the class TaxonController method doGetDescriptionElementsByType.

@RequestMapping(value = "descriptions/elementsByType/{classSimpleName}", method = RequestMethod.GET)
public ModelAndView doGetDescriptionElementsByType(@PathVariable("uuid") UUID uuid, @PathVariable("classSimpleName") String classSimpleName, @RequestParam(value = "markerTypes", required = false) List<MarkerType> markerTypes, @RequestParam(value = "descriptionTypes", required = false) List<DescriptionType> descriptionTypes, @RequestParam(value = "count", required = false, defaultValue = "false") Boolean doCount, HttpServletRequest request, HttpServletResponse response) throws IOException {
    logger.info("doGetDescriptionElementsByType() - " + requestPathAndQuery(request));
    boolean includeUnpublished = NO_UNPUBLISHED;
    ModelAndView mv = new ModelAndView();
    List<DescriptionElementBase> allElements = new ArrayList<>();
    List<DescriptionElementBase> elements;
    int count = 0;
    List<String> initStrategy = doCount ? null : getTaxonDescriptionElementInitStrategy();
    Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>) null);
    taxon = checkExistsAndAccess(taxon, includeUnpublished, response);
    Set<MarkerType> markerTypesSet = new HashSet<>();
    if (markerTypes != null) {
        markerTypesSet.addAll(markerTypes);
    }
    Set<DescriptionType> descriptionTypesSet = new HashSet<>();
    if (descriptionTypes != null) {
        descriptionTypesSet.addAll(descriptionTypes);
    }
    List<TaxonDescription> taxonDescriptions = descriptionService.listTaxonDescriptions(taxon, null, null, markerTypesSet, descriptionTypesSet, null, null, null);
    try {
        Class type;
        type = Class.forName("eu.etaxonomy.cdm.model.description." + classSimpleName);
        if (taxonDescriptions != null) {
            for (TaxonDescription description : taxonDescriptions) {
                elements = descriptionService.listDescriptionElements(description, null, type, null, 0, initStrategy);
                allElements.addAll(elements);
                count += elements.size();
            }
        }
    } catch (ClassNotFoundException e) {
        HttpStatusMessage.create(e.getLocalizedMessage(), 400).send(response);
    }
    if (doCount) {
        mv.addObject(count);
    } else {
        mv.addObject(allElements);
    }
    return mv;
}
Also used : DescriptionType(eu.etaxonomy.cdm.model.description.DescriptionType) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) DescriptionElementBase(eu.etaxonomy.cdm.model.description.DescriptionElementBase) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with DescriptionType

use of eu.etaxonomy.cdm.model.description.DescriptionType in project cdmlib by cybertaxonomy.

the class TaxonController method doGetDescriptions.

// TODO ================================================================================ //
// move all description and descriptionElement related methods into the according
// Description Controllers
/**
 * Get the list of {@link TaxonDescription}s of the
 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
 * <p>
 * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;taxon&#x002F;{taxon-uuid}&#x002F;descriptions</b>
 *
 * @param request
 * @param response
 * @return a List of {@link TaxonDescription} entities which are initialized
 *         using the following initialization strategy:
 *         {@link #TAXONDESCRIPTION_INIT_STRATEGY}
 * @throws IOException
 */
@RequestMapping(value = { "descriptions" }, method = RequestMethod.GET)
public Pager<TaxonDescription> doGetDescriptions(@PathVariable("uuid") UUID uuid, @RequestParam(value = "markerTypes", required = false) List<MarkerType> markerTypes, @RequestParam(value = "descriptionTypes", required = false) List<DescriptionType> descriptionTypes, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (request != null) {
        logger.info("doGetDescriptions()" + requestPathAndQuery(request));
    }
    Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>) null);
    taxon = checkExistsAndAccess(taxon, NO_UNPUBLISHED, response);
    Set<MarkerType> markerTypesSet = new HashSet<>();
    if (markerTypes != null) {
        markerTypesSet.addAll(markerTypes);
    }
    Set<DescriptionType> descriptionTypesSet = new HashSet<>();
    if (descriptionTypes != null) {
        descriptionTypesSet.addAll(descriptionTypes);
    }
    List<String> taxonDescriptionInitStrategy = getTaxonDescriptionInitStrategy();
    Pager<TaxonDescription> p = descriptionService.pageTaxonDescriptions(taxon, null, null, markerTypesSet, descriptionTypesSet, null, null, taxonDescriptionInitStrategy);
    return p;
}
Also used : DescriptionType(eu.etaxonomy.cdm.model.description.DescriptionType) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) MarkerType(eu.etaxonomy.cdm.model.common.MarkerType) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DescriptionType (eu.etaxonomy.cdm.model.description.DescriptionType)3 HashSet (java.util.HashSet)3 MarkerType (eu.etaxonomy.cdm.model.common.MarkerType)2 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)2 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 DescriptionElementBase (eu.etaxonomy.cdm.model.description.DescriptionElementBase)1 OrderHint (eu.etaxonomy.cdm.persistence.query.OrderHint)1 ArrayList (java.util.ArrayList)1 Criterion (org.hibernate.criterion.Criterion)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1