Search in sources :

Example 1 with DerivedUnitFacadeNotSupportedException

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;
}
Also used : DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DerivedUnitFacadeNotSupportedException(eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException)

Example 2 with DerivedUnitFacadeNotSupportedException

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;
}
Also used : DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) DerivedUnitFacadeNotSupportedException(eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException) IndividualsAssociation(eu.etaxonomy.cdm.model.description.IndividualsAssociation) ArrayList(java.util.ArrayList) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)

Example 3 with DerivedUnitFacadeNotSupportedException

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>&#x002F;{datasource-name}&#x002F;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;
}
Also used : OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) DerivedUnitFacadeNotSupportedException(eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException) DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) PagerParameters(eu.etaxonomy.cdm.remote.controller.util.PagerParameters) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DerivedUnitFacadeNotSupportedException(eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException) ErrorResponse(eu.etaxonomy.cdm.remote.dto.common.ErrorResponse) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) OccurrenceSearch(eu.etaxonomy.cdm.remote.dto.occurrencecatalogue.OccurrenceSearch) OccurrenceSearchResponse(eu.etaxonomy.cdm.remote.dto.occurrencecatalogue.OccurrenceSearch.OccurrenceSearchResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DerivedUnitFacade (eu.etaxonomy.cdm.api.facade.DerivedUnitFacade)3 DerivedUnitFacadeNotSupportedException (eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException)3 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)2 ArrayList (java.util.ArrayList)2 DefaultPagerImpl (eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl)1 IndividualsAssociation (eu.etaxonomy.cdm.model.description.IndividualsAssociation)1 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)1 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)1 OrderHint (eu.etaxonomy.cdm.persistence.query.OrderHint)1 PagerParameters (eu.etaxonomy.cdm.remote.controller.util.PagerParameters)1 ErrorResponse (eu.etaxonomy.cdm.remote.dto.common.ErrorResponse)1 OccurrenceSearch (eu.etaxonomy.cdm.remote.dto.occurrencecatalogue.OccurrenceSearch)1 OccurrenceSearchResponse (eu.etaxonomy.cdm.remote.dto.occurrencecatalogue.OccurrenceSearch.OccurrenceSearchResponse)1 IOException (java.io.IOException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1