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[] {})));
}
}
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;
}
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>/{datasource-name}/portal/taxon/{taxon-uuid}/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;
}
Aggregations