use of eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException in project cdmlib by cybertaxonomy.
the class DwcaTypesExport method getFacadeFromAssociation.
private DerivedUnitFacade getFacadeFromAssociation(DwcaTaxExportState state, IndividualsAssociation individualsAssociation) {
SpecimenOrObservationBase<?> specimen = individualsAssociation.getAssociatedSpecimenOrObservation();
DerivedUnitFacade facade;
if (specimen == null) {
String message = "Individuals association " + individualsAssociation.getId() + " has no associated specimen";
state.getResult().addWarning(message);
return null;
} else if (!specimen.isInstanceOf(DerivedUnit.class)) {
String message = "Non DerivedUnit specimen can not yet be handled by this export";
state.getResult().addWarning(message);
// TODO handle empty records
return null;
} else {
DerivedUnit derivedUnit = CdmBase.deproxy(specimen, DerivedUnit.class);
try {
facade = DerivedUnitFacade.NewInstance(derivedUnit);
} catch (DerivedUnitFacadeNotSupportedException e) {
String message = "DerivedUnit is too complex to be handled by facade based darwin core archive export";
state.getResult().addError(message, e);
// TODO handle empty records
return null;
}
}
return facade;
}
use of eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException in project cdmlib by cybertaxonomy.
the class OccurrenceServiceImpl method listDerivedUnitFacades.
@Override
public List<DerivedUnitFacade> listDerivedUnitFacades(DescriptionBase description, List<String> derivedUnitFacadeInitStrategy) {
List<DerivedUnitFacade> derivedUnitFacadeList = new ArrayList<>();
IndividualsAssociation tempIndividualsAssociation;
SpecimenOrObservationBase tempSpecimenOrObservationBase;
List<IndividualsAssociation> elements = descriptionService.listDescriptionElements(description, null, IndividualsAssociation.class, null, 0, Arrays.asList(new String[] { "associatedSpecimenOrObservation" }));
for (IndividualsAssociation element : elements) {
tempIndividualsAssociation = HibernateProxyHelper.deproxy(element, IndividualsAssociation.class);
if (tempIndividualsAssociation.getAssociatedSpecimenOrObservation() != null) {
tempSpecimenOrObservationBase = HibernateProxyHelper.deproxy(tempIndividualsAssociation.getAssociatedSpecimenOrObservation(), SpecimenOrObservationBase.class);
if (tempSpecimenOrObservationBase.isInstanceOf(DerivedUnit.class)) {
try {
derivedUnitFacadeList.add(DerivedUnitFacade.NewInstance(HibernateProxyHelper.deproxy(tempSpecimenOrObservationBase, DerivedUnit.class)));
} catch (DerivedUnitFacadeNotSupportedException e) {
logger.warn(tempIndividualsAssociation.getAssociatedSpecimenOrObservation().getTitleCache() + " : " + e.getMessage());
}
}
}
}
beanInitializer.initializeAll(derivedUnitFacadeList, derivedUnitFacadeInitStrategy);
return derivedUnitFacadeList;
}
use of eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException in project cdmlib by cybertaxonomy.
the class OccurrenceCatalogueController method doGetOccurrenceSearch.
/**
* Returns a list of occurrences matching the <code>{query}</code>
* Taxon UUID.
* <p>
* Endpoint documentation can be found <a href="{@docRoot}/../remote/occurrence-catalogue-default.html">here</a>
* <p>
* URI: <b>/{datasource-name}/occurrence_catalogue</b>
*
* @param query
* The UUID of the taxon to query for. The query can
* not contain wildcard characters.
*
* @param pageNumber
* The number of the page to be returned.
* * @param pageSize
* The number of responses per page to be returned.
* @param request Http servlet request.
* @param response Http servlet response.
* @return a List of {@link OccurrenceSearch} objects each corresponding to a
* single query. These are built from {@link SpecimenOrObservationBase} entities
* which are in turn initialized using the {@link #OCCURRENCE_INIT_STRATEGY} and {@link #FACADE_INIT_STRATEGY}
* @throws IOException
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value = { "" }, method = RequestMethod.GET, params = { "taxonUuid", "pageNumber", "pageSize" })
public ModelAndView doGetOccurrenceSearch(@RequestParam(value = "taxonUuid", required = true) String taxonUuid, @RequestParam(value = "pageNumber", required = false, defaultValue = DEFAULT_PAGE_NUMBER) String pageNumber, @RequestParam(value = "pageSize", required = false, defaultValue = DEFAULT_PAGE_SIZE) String pageSize, HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.info("doGetOccurrenceSearch() " + requestPathAndQuery(request));
ModelAndView mv = new ModelAndView();
Integer pS = null;
Integer pN = null;
try {
pN = Integer.valueOf(pageNumber);
} catch (Exception e) {
pN = Integer.valueOf(DEFAULT_PAGE_NUMBER);
logger.debug("pagenumber is not a number");
}
try {
pS = Integer.valueOf(pageSize);
} catch (Exception e) {
pS = Integer.valueOf(DEFAULT_PAGE_SIZE);
logger.debug("pagesize is not a number");
}
PagerParameters pagerParams = new PagerParameters(pS, pN);
pagerParams.normalizeAndValidate(response);
List<DerivedUnit> records = new ArrayList<DerivedUnit>();
OccurrenceSearch ns = new OccurrenceSearch();
ns.setRequest(taxonUuid);
Pager<DerivedUnit> specimenOrObs = null;
OccurrenceSearch os = new OccurrenceSearch();
if (taxonUuid.equals("") || !isValid(taxonUuid)) {
ErrorResponse er = new ErrorResponse();
er.setErrorMessage("Empty or invalid taxon uuid ");
mv.addObject(er);
return mv;
} else {
Taxon taxon = null;
try {
taxon = (Taxon) taxonService.find(UUID.fromString(taxonUuid));
} catch (ClassCastException cce) {
ErrorResponse er = new ErrorResponse();
er.setErrorMessage("Given UUID is not that of an accepted taxon");
mv.addObject(er);
return mv;
}
if (taxon == null) {
ErrorResponse er = new ErrorResponse();
er.setErrorMessage("No Taxon for given UUID : " + taxonUuid);
mv.addObject(er);
return mv;
}
pagerParams.normalizeAndValidate(response);
List<OrderHint> orderHints = null;
// Only derived units are requested in the pager method since we expect
// occurrences to be of type DerivedUnit
// The only possibility for an occurrence to be of type FieldUnit is the
// describedSpecimenOrObservation in the DescriptionBase class, which ideally
// should not be used for storing occurrences
specimenOrObs = service.pageByAssociatedTaxon(DerivedUnit.class, null, taxon, null, pagerParams.getPageSize(), pagerParams.getPageIndex(), orderHints, null);
records = specimenOrObs.getRecords();
DerivedUnit derivedUnit = null;
List<DerivedUnitFacade> facades = new ArrayList<DerivedUnitFacade>();
for (SpecimenOrObservationBase<?> specimen : records) {
derivedUnit = CdmBase.deproxy(specimen, DerivedUnit.class);
DerivedUnitFacade derivedUnitFacade = null;
try {
// TODO : This is a potential performance hurdle (especially for large number
// of derived units).
// A possible solution is to already initialise the required derived unit facade
// in the 'pageByAssociatedTaxon' call. This can be done either via the initialisation
// strategy technique or by writing a new optimised hql query for this.
// This will ensure that the DerivedUnits are loaded with required fields already
// initialised and will not require the loading and initialisation of each DerivedUnit
// object as is done in the 'getDerivedUnitFacade' method.
derivedUnitFacade = occurrenceService.getDerivedUnitFacade(derivedUnit, FACADE_INIT_STRATEGY);
os.addToResponse(taxon.getTitleCache(), taxonUuid, derivedUnitFacade);
} catch (DerivedUnitFacadeNotSupportedException e) {
derivedUnitFacade = null;
}
}
}
if (os.getResponse().isEmpty()) {
ErrorResponse er = new ErrorResponse();
er.setErrorMessage("No specimen or observation for given taxon uuid");
mv.addObject(er);
return mv;
} else {
DefaultPagerImpl<OccurrenceSearchResponse> dpi = new DefaultPagerImpl<OccurrenceSearchResponse>(specimenOrObs.getCurrentIndex(), specimenOrObs.getCount(), specimenOrObs.getPageSize(), os.getResponse());
mv.addObject(dpi);
}
return mv;
}
Aggregations