Search in sources :

Example 1 with SpecimenOrObservationType

use of eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType in project cdmlib by cybertaxonomy.

the class SpecimenImportReport method printReport.

public void printReport(PrintStream out) {
    out.println("++++++++Import Report+++++++++");
    // all specimens
    Set<UnitIdSpecimen> allSpecimens = new HashSet<>();
    for (Entry<UnitIdSpecimen, List<UnitIdSpecimen>> entry : derivateMap.entrySet()) {
        UnitIdSpecimen parentSpecimen = entry.getKey();
        allSpecimens.add(parentSpecimen);
        for (UnitIdSpecimen childSpecimen : entry.getValue()) {
            allSpecimens.add(childSpecimen);
        }
    }
    out.println("Specimens created: " + allSpecimens.size());
    Map<SpecimenOrObservationType, Integer> specimenTypeToCount = new HashMap<>();
    for (UnitIdSpecimen unitIdSpecimen : allSpecimens) {
        incrementSpecimenTypeCount(specimenTypeToCount, unitIdSpecimen);
    }
    for (Entry<SpecimenOrObservationType, Integer> entry : specimenTypeToCount.entrySet()) {
        SpecimenOrObservationType type = entry.getKey();
        out.println(type + ": " + entry.getValue());
    }
    // not imported
    out.println("Skipped/not imported: " + alreadyExistingSpecimens.size());
    out.println("\n");
    out.println("Imported unit ids");
    for (UnitIdSpecimen unitIdSpecimen : allSpecimens) {
        out.print(unitIdSpecimen.unitId + ", ");
    }
    out.println("\n");
    out.println("Ignored unit ids");
    for (UnitIdSpecimen unitIdSpecimen : alreadyExistingSpecimens) {
        out.print(unitIdSpecimen.unitId + ", ");
    }
    out.println("\n");
    // taxon name
    out.println("---Created Taxon Names (" + createdNames.size() + ")---");
    for (TaxonName taxonName : createdNames) {
        out.println(taxonName.getTitleCache());
    }
    out.println("\n");
    // taxa
    out.println("---Created Taxa (" + createdTaxa.size() + ")---");
    for (Taxon taxon : createdTaxa) {
        out.println(taxon.getTitleCache());
    }
    out.println("\n");
    // taxon nodes
    out.println("---Created Taxon Nodes (" + createdTaxonNodes.size() + ")---");
    for (TaxonNode taxonNode : createdTaxonNodes) {
        String nodeString = taxonNode.toString();
        if (taxonNode.getTaxon() != null) {
            nodeString += " (" + taxonNode.getTaxon().getTitleCache() + ")";
        }
        if (taxonNode.getParent() != null) {
            nodeString += " with parent " + taxonNode.getParent();
            if (taxonNode.getParent().getTaxon() != null) {
                nodeString += " (" + taxonNode.getParent().getTaxon().getTitleCache() + ")";
            }
        }
        out.println(nodeString);
    }
    out.println("\n");
    // not imported
    out.println("---Already existing specimen/not imported (" + alreadyExistingSpecimens.size() + ")---");
    for (UnitIdSpecimen specimen : alreadyExistingSpecimens) {
        out.println(formatSpecimen(specimen));
    }
    out.println("\n");
    // taxa with associated specimens
    out.println("---Taxa with associated specimens (" + taxonToAssociatedSpecimens.size() + ")---");
    for (Entry<Taxon, List<UnitIdSpecimen>> entry : taxonToAssociatedSpecimens.entrySet()) {
        Taxon taxon = entry.getKey();
        List<UnitIdSpecimen> specimens = entry.getValue();
        out.println(taxon.getTitleCache() + " (" + specimens.size() + ")");
        for (UnitIdSpecimen derivedUnit : specimens) {
            out.println("\t- " + formatSpecimen(derivedUnit));
            // check for derivatives
            List<UnitIdSpecimen> list = derivateMap.get(derivedUnit);
            for (UnitIdSpecimen derivate : list) {
                out.println("\t\t- " + formatSpecimen(derivate));
            }
        }
    }
    out.println("\n");
    out.println("\n");
    // info messages
    out.println("---Info messages---");
    for (String message : infoMessages) {
        out.println(message);
        out.println("---");
    }
    if (out != System.out) {
        out.close();
    }
}
Also used : TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) HashMap(java.util.HashMap) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType) ArrayList(java.util.ArrayList) List(java.util.List) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) HashSet(java.util.HashSet)

Example 2 with SpecimenOrObservationType

use of eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType in project cdmlib by cybertaxonomy.

the class SpecimenImportReport method incrementSpecimenTypeCount.

private void incrementSpecimenTypeCount(Map<SpecimenOrObservationType, Integer> specimenTypeToCount, UnitIdSpecimen specimen) {
    SpecimenOrObservationType specimenType = specimen.getSpecimen().getRecordBasis();
    Integer count = specimenTypeToCount.get(specimenType);
    if (count == null) {
        count = 1;
    } else {
        count++;
    }
    specimenTypeToCount.put(specimenType, count);
}
Also used : SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType)

Example 3 with SpecimenOrObservationType

use of eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType in project cdmlib by cybertaxonomy.

the class OccurrenceDaoHibernateImpl method createFindOccurrenceCriteria.

private <T extends SpecimenOrObservationBase> Criteria createFindOccurrenceCriteria(Class<T> clazz, String queryString, String significantIdentifier, SpecimenOrObservationType recordBasis, Taxon associatedTaxon, TaxonName associatedTaxonName, MatchMode matchmode, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
    Criteria criteria = null;
    if (clazz == null) {
        criteria = getSession().createCriteria(type);
    } else {
        criteria = getSession().createCriteria(clazz);
    }
    // queryString
    if (queryString != null) {
        if (matchmode == null) {
            matchmode = MatchMode.ANYWHERE;
            criteria.add(Restrictions.ilike("titleCache", matchmode.queryStringFrom(queryString)));
        } else if (matchmode == MatchMode.BEGINNING) {
            criteria.add(Restrictions.ilike("titleCache", matchmode.queryStringFrom(queryString), org.hibernate.criterion.MatchMode.START));
        } else if (matchmode == MatchMode.END) {
            criteria.add(Restrictions.ilike("titleCache", matchmode.queryStringFrom(queryString), org.hibernate.criterion.MatchMode.END));
        } else if (matchmode == MatchMode.EXACT) {
            criteria.add(Restrictions.ilike("titleCache", matchmode.queryStringFrom(queryString), org.hibernate.criterion.MatchMode.EXACT));
        } else {
            criteria.add(Restrictions.ilike("titleCache", matchmode.queryStringFrom(queryString), org.hibernate.criterion.MatchMode.ANYWHERE));
        }
    }
    // significant identifier
    if (significantIdentifier != null) {
        criteria.add(Restrictions.or(Restrictions.ilike("accessionNumber", significantIdentifier), Restrictions.ilike("catalogNumber", significantIdentifier), Restrictions.ilike("barcode", significantIdentifier)));
    }
    // recordBasis/SpecimenOrObservationType
    Set<SpecimenOrObservationType> typeAndSubtypes = new HashSet<>();
    if (recordBasis == null) {
        // add all types
        SpecimenOrObservationType[] values = SpecimenOrObservationType.values();
        for (SpecimenOrObservationType specimenOrObservationType : values) {
            typeAndSubtypes.add(specimenOrObservationType);
        }
    } else {
        typeAndSubtypes = recordBasis.getGeneralizationOf(true);
        typeAndSubtypes.add(recordBasis);
    }
    criteria.add(Restrictions.in("recordBasis", typeAndSubtypes));
    Set<UUID> associationUuids = new HashSet<>();
    // taxon associations
    if (associatedTaxon != null) {
        List<UuidAndTitleCache<SpecimenOrObservationBase>> associatedTaxaList = listUuidAndTitleCacheByAssociatedTaxon(clazz, associatedTaxon, limit, start, orderHints);
        if (associatedTaxaList != null) {
            for (UuidAndTitleCache<SpecimenOrObservationBase> uuidAndTitleCache : associatedTaxaList) {
                associationUuids.add(uuidAndTitleCache.getUuid());
            }
        }
    } else // taxon name associations
    if (associatedTaxonName != null) {
        List<? extends SpecimenOrObservationBase> associatedTaxaList = listByAssociatedTaxonName(clazz, associatedTaxonName, limit, start, orderHints, propertyPaths);
        if (associatedTaxaList != null) {
            for (SpecimenOrObservationBase<?> specimenOrObservationBase : associatedTaxaList) {
                associationUuids.add(specimenOrObservationBase.getUuid());
            }
        }
    }
    if (associatedTaxon != null || associatedTaxonName != null) {
        if (!associationUuids.isEmpty()) {
            criteria.add(Restrictions.in("uuid", associationUuids));
        } else {
            return null;
        }
    }
    if (limit != null) {
        if (start != null) {
            criteria.setFirstResult(start);
        } else {
            criteria.setFirstResult(0);
        }
        criteria.setMaxResults(limit);
    }
    if (orderHints != null) {
        addOrder(criteria, orderHints);
    }
    return criteria;
}
Also used : SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType) List(java.util.List) ProjectionList(org.hibernate.criterion.ProjectionList) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) UuidAndTitleCache(eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 4 with SpecimenOrObservationType

use of eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType in project cdmlib by cybertaxonomy.

the class GbifTypesAndSpecimen2CdmConverter method map.

@Override
public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item) {
    List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
    Reference sourceReference = state.getTransactionalSourceReference();
    String sourceReferecenDetail = null;
    String id = getSourceId(item);
    Taxon taxon = getTaxonBase(id, item, Taxon.class, state);
    if (taxon != null) {
        String typeStatusStr = item.get(TermUri.DWC_TYPE_STATUS);
        boolean isType = false;
        TypeDesignationStatusBase<?> typeStatus = null;
        if (!isNoTypeStatus(typeStatusStr)) {
            isType = true;
            typeStatus = getTypeStatus(typeStatusStr, item);
        }
        SpecimenOrObservationType unitType = SpecimenOrObservationType.DerivedUnit;
        if (hasDerivedUnit(item, isType)) {
            unitType = SpecimenOrObservationType.PreservedSpecimen;
        } else {
            unitType = SpecimenOrObservationType.FieldUnit;
        }
        DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(unitType);
        String catalogNumber = item.get(TermUri.DWC_CATALOG_NUMBER);
        Collection collection = getCollection(state, item, resultList);
        facade.setCollection(collection);
        facade.setCatalogNumber(catalogNumber);
        DerivedUnit specimen = facade.innerDerivedUnit();
        if (isType) {
            TaxonName name = taxon.getName();
            if (typeStatus.isInstanceOf(SpecimenTypeDesignationStatus.class)) {
                SpecimenTypeDesignationStatus status = CdmBase.deproxy(typeStatus, SpecimenTypeDesignationStatus.class);
                name.addSpecimenTypeDesignation(specimen, status, null, null, null, false, true);
                MappedCdmBase<? extends CdmBase> mcb = new MappedCdmBase<>(taxon);
                resultList.add(mcb);
            } else if (typeStatus.isInstanceOf(NameTypeDesignationStatus.class)) {
                String message = "NameTypeDesignation not yet implemented";
                fireWarningEvent(message, item, 8);
            } else {
                String message = "Undefined type status: %s";
                message = String.format(message, typeStatus);
                fireWarningEvent(message, item, 8);
            }
        }
        MappedCdmBase<? extends CdmBase> mcb = new MappedCdmBase<>(specimen);
        resultList.add(mcb);
    } else {
        String message = "Can't retrieve taxon from database for id '%s'";
        fireWarningEvent(String.format(message, id), item, 12);
    }
    // return
    return new ListReader<>(resultList);
}
Also used : DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) ListReader(eu.etaxonomy.cdm.io.stream.ListReader) Reference(eu.etaxonomy.cdm.model.reference.Reference) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ArrayList(java.util.ArrayList) MappedCdmBase(eu.etaxonomy.cdm.io.stream.MappedCdmBase) SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType) SpecimenTypeDesignationStatus(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) MappedCdmBase(eu.etaxonomy.cdm.io.stream.MappedCdmBase) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) NameTypeDesignationStatus(eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus)

Example 5 with SpecimenOrObservationType

use of eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType in project cdmlib by cybertaxonomy.

the class TaxonXExtractor method getFacade.

protected DerivedUnitFacade getFacade(String recordBasis, SpecimenOrObservationType defaultAssoc) {
    // System.out.println("getFacade() for "+recordBasis+", defaultassociation: "+defaultAssoc);
    SpecimenOrObservationType type = null;
    // create specimen
    if (recordBasis != null) {
        String recordBasisL = recordBasis.toLowerCase();
        if (recordBasisL.startsWith("specimen") || recordBasisL.contains("specimen") || recordBasisL.contains("type")) {
            // specimen
            type = SpecimenOrObservationType.PreservedSpecimen;
        }
        if (recordBasisL.startsWith("observation")) {
            type = SpecimenOrObservationType.Observation;
        }
        if (recordBasisL.contains("fossil")) {
            type = SpecimenOrObservationType.Fossil;
        }
        if (recordBasisL.startsWith("living")) {
            type = SpecimenOrObservationType.LivingSpecimen;
        }
        if (type == null) {
            logger.info("The basis of record does not seem to be known: *" + recordBasisL + "*");
            type = defaultAssoc;
        }
    // TODO fossils?
    } else {
        logger.info("The basis of record is null");
        type = defaultAssoc;
    }
    DerivedUnitFacade derivedUnitFacade = DerivedUnitFacade.NewInstance(type);
    return derivedUnitFacade;
}
Also used : DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType)

Aggregations

SpecimenOrObservationType (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType)21 DerivedUnitFacade (eu.etaxonomy.cdm.api.facade.DerivedUnitFacade)7 SpecimenOrObservationBase (eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase)6 Color (java.awt.Color)5 ArrayList (java.util.ArrayList)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)3 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)3 List (java.util.List)3 OccurrenceServiceRequestParameterDto (eu.etaxonomy.cdm.ext.geo.OccurrenceServiceRequestParameterDto)2 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)2 Point (eu.etaxonomy.cdm.model.location.Point)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 UUID (java.util.UUID)2 AltitudeMode (de.micromata.opengis.kml.v_2_2_0.AltitudeMode)1 ExtendedData (de.micromata.opengis.kml.v_2_2_0.ExtendedData)1 INameService (eu.etaxonomy.cdm.api.service.INameService)1