Search in sources :

Example 1 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class SruServiceWrapper method doSearchRetrieve.

/**
 * The GRIB sru service is available at "http://gso.gbv.de/sru/DB=1.83/"
 * The documentation is found at http://bhleurope.gbv.de/#sru from where the following text has been retrieved:
 * <p>
 * General information about Search/Retrieve via URL (SRU) is available in
 * the official SRU specification (http://www.loc.gov/standards/sru/). The SRU-Interface of GRIB supports some
 * specific search keys. Please do not use the (dc) fields but only the
 * (pica) search fields:
 * <dl>
 * <dt>PPN</dt>
 * <dd>Internal record id without prefix 'grib:ppn:' (This may change)</dd>
 * <dt>DST</dt>
 * <dd>Digitization status (8300-8305: 8300=not digitized, 8301=should be digitized, 8302=will be digitized, 8305=document available)</dd>
 * <dt>URL</dt>
 * <dd>URL of a digitized object</dd>
 * <dt>??? (not defined yet)</td>
 * <dd>Stable identifier of a record (PICA+ field 006Y)</dd>
 * </dl>
 * </p>
 * @param cqlQuery
 *            an <b>URL encoded</b> CQL Query string see
 *            {@link http://www.loc.gov/standards/sru/specs/cql.html} for documentation
 * @param recordSchema
 * @return
 */
public List<Reference> doSearchRetrieve(String cqlQuery, String recordSchema) {
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    SchemaAdapterBase<Reference> schemaAdapter = schemaAdapterMap.get(recordSchema);
    if (schemaAdapter == null) {
        logger.error("No SchemaAdapter found for " + recordSchema);
    }
    String sruOperation = "searchRetrieve";
    pairs.add(new BasicNameValuePair("operation", sruOperation));
    pairs.add(new BasicNameValuePair("version", sruVersion));
    pairs.add(new BasicNameValuePair("query", cqlQuery));
    pairs.add(new BasicNameValuePair("recordSchema", recordSchema));
    Map<String, String> requestHeaders = new HashMap<>();
    requestHeaders.put("Accept-Charset", "UTF-8");
    try {
        URI requestUri = createUri(null, pairs);
        InputStream stream = executeHttpGet(requestUri, requestHeaders);
        return schemaAdapter.getCmdEntities(stream);
    } catch (IOException e) {
        // thrown by doHttpGet
        logger.error(e);
    } catch (URISyntaxException e) {
        // thrown by createUri
        logger.error(e);
    }
    return null;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HashMap(java.util.HashMap) Reference(eu.etaxonomy.cdm.model.reference.Reference) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(eu.etaxonomy.cdm.common.URI) BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Example 2 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class IpniService method getAuthorFromLine.

private Person getAuthorFromLine(String line, Map<Integer, String> categoryMap, ICdmRepository repository, IpniServiceAuthorConfigurator config) {
    // Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
    String[] splits = line.split("%");
    Map<String, String> valueMap = fillValueMap(categoryMap, splits);
    Person person = Person.NewInstance();
    person.setNomenclaturalTitle(valueMap.get(STANDARD_FORM));
    person.setGivenName(valueMap.get(DEFAULT_AUTHOR_FORENAME));
    person.setFamilyName(valueMap.get(DEFAULT_AUTHOR_SURNAME));
    Reference citation = getIpniCitation(repository);
    // id, version
    person.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Author", citation, valueMap.get(VERSION));
    // dates
    TimePeriod lifespan = TimePeriodParser.parseString(valueMap.get(DATES));
    person.setLifespan(lifespan);
    // alternative_names
    String alternativeNames = valueMap.get(ALTERNATIVE_NAMES);
    if (isNotBlank(alternativeNames)) {
        String[] alternativeNameSplits = alternativeNames.split("%");
        for (String alternativeName : alternativeNameSplits) {
            if (alternativeName.startsWith(">")) {
                alternativeName = alternativeName.substring(1);
            }
            Extension.NewInstance(person, alternativeName, ExtensionType.INFORMAL_CATEGORY());
        }
    }
    return person;
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod) VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 3 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class IpniService method getNameFromLine.

private IBotanicalName getNameFromLine(String line, Map<Integer, String> parameterMap, ICdmRepository repository, IpniServiceNamesConfigurator config) {
    // Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
    String[] splits = line.split("%");
    Map<String, String> valueMap = fillValueMap(parameterMap, splits);
    IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null);
    // epithets
    name.setGenusOrUninomial(valueMap.get(GENUS));
    name.setInfraGenericEpithet(valueMap.get(INFRA_GENUS));
    name.setSpecificEpithet(valueMap.get(SPECIES));
    name.setInfraSpecificEpithet(valueMap.get(INFRA_SPECIFIC));
    // rank
    try {
        String rankStr = nomalizeRank(valueMap.get(RANK));
        Rank rank = Rank.getRankByLatinNameOrIdInVoc(rankStr, NomenclaturalCode.ICNAFP, true);
        name.setRank(rank);
    } catch (UnknownCdmTypeException e) {
        logger.warn("Rank was unknown");
    }
    // caches
    String pureName = valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS);
    String nameCache = name.getNameCache();
    if (!Nz(pureName).equals(nameCache)) {
        nvnParser.parseSimpleName(name, valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), name.getRank(), true);
    // name.setNameCache(valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), true);
    }
    String authors = "";
    // authors
    if (valueMap.get(BASIONYM_AUTHOR) != null) {
        authors = valueMap.get(BASIONYM_AUTHOR);
    // name.setBasionymAuthorship(Team.NewTitledInstance(valueMap.get(BASIONYM_AUTHOR), valueMap.get(BASIONYM_AUTHOR)));
    }
    if (valueMap.get(PUBLISHING_AUTHOR) != null) {
        authors += valueMap.get(PUBLISHING_AUTHOR);
    // name.setCombinationAuthorship(Team.NewTitledInstance(valueMap.get(PUBLISHING_AUTHOR), valueMap.get(PUBLISHING_AUTHOR)));
    }
    try {
        nvnParser.parseAuthors(name, authors);
    } catch (StringNotParsableException e1) {
    // 
    }
    if (!Nz(valueMap.get(AUTHORS)).equals(name.getAuthorshipCache())) {
        name.setAuthorshipCache(valueMap.get(AUTHORS), true);
    }
    if ("Y".equals(valueMap.get(HYBRID))) {
        if (!name.isHybrid()) {
            // Is there a concrete way to include the hybrid flag info? As it does not say which type of hybrid it seems
            // to be best to handle hybrids via parsing. But there might be a better errror handling possible.
            logger.warn("Name is flagged as hybrid at IPNI but CDM name has no hybrid flag set: " + name.getTitleCache());
        }
    }
    // publication
    if (valueMap.get(PUBLICATION) != null || valueMap.get(COLLATION) != null || valueMap.get(PUBLICATION_YEAR_FULL) != null) {
        Reference ref = ReferenceFactory.newGeneric();
        // TODO probably we can do better parsing here
        String pub = CdmUtils.concat(" ", valueMap.get(PUBLICATION), valueMap.get(COLLATION));
        if (isNotBlank(pub)) {
            String nomRefTitle = pub;
            String[] split = nomRefTitle.split(":");
            if (split.length > 1) {
                String detail = split[split.length - 1];
                name.setNomenclaturalMicroReference(detail.trim());
                nomRefTitle = nomRefTitle.substring(0, nomRefTitle.length() - detail.length() - 1).trim();
            }
            ref.setAbbrevTitle(nomRefTitle);
        }
        VerbatimTimePeriod datePublished = parsePublicationFullYear(valueMap.get(PUBLICATION_YEAR_FULL));
        ref.setDatePublished(datePublished);
        name.setNomenclaturalReference(ref);
    }
    // name status
    NomenclaturalStatusType statusType = null;
    String statusString = valueMap.get(NAME_STATUS);
    if (isNotBlank(statusString)) {
        try {
            statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusString, name);
            NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(statusType);
            name.addStatus(nomStatus);
        } catch (UnknownCdmTypeException e) {
            logger.warn("Name status not recognized: " + statusString);
            Annotation annotation = Annotation.NewInstance("Name status: " + statusString, AnnotationType.EDITORIAL(), Language.ENGLISH());
            name.addAnnotation(annotation);
        }
    }
    // remarks
    String remarks = valueMap.get(REMARKS);
    if (remarks != null) {
        Annotation annotation = Annotation.NewInstance(remarks, AnnotationType.EDITORIAL(), Language.ENGLISH());
        name.addAnnotation(annotation);
    }
    // basionym
    if (config.isDoBasionyms() && valueMap.get(BASIONYM) != null) {
        TaxonName basionym = TaxonNameFactory.NewBotanicalInstance(null);
        basionym.setTitleCache(valueMap.get(BASIONYM), true);
        name.addBasionym(basionym);
    }
    // replaced synonym
    if (config.isDoBasionyms() && valueMap.get(REPLACED_SYNONYM) != null) {
        TaxonName replacedSynoynm = TaxonNameFactory.NewBotanicalInstance(null);
        replacedSynoynm.setTitleCache(valueMap.get(REPLACED_SYNONYM), true);
        name.addReplacedSynonym(replacedSynoynm, null, null, null, null);
    }
    // type information
    if (config.isDoType() && valueMap.get(COLLECTION_DATE_AS_TEXT) != null || valueMap.get(COLLECTION_NUMBER) != null || valueMap.get(COLLECTION_DAY1) != null || valueMap.get(COLLECTION_DAY2) != null || valueMap.get(COLLECTION_MONTH1) != null || valueMap.get(COLLECTION_MONTH2) != null || valueMap.get(COLLECTION_YEAR1) != null || valueMap.get(COLLECTION_YEAR2) != null || valueMap.get(COLLECTOR_TEAM_AS_TEXT) != null || valueMap.get(LOCALITY) != null || valueMap.get(LATITUDE_DEGREES) != null || valueMap.get(LATITUDE_MINUTES) != null || valueMap.get(LATITUDE_SECONDS) != null || valueMap.get(NORTH_OR_SOUTH) != null || valueMap.get(COLLECTION_YEAR1) != null || valueMap.get(COLLECTION_YEAR2) != null) // TODO TBC
    {
        DerivedUnitFacade specimen = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
        // gathering period
        String collectionDateAsText = valueMap.get(COLLECTION_DATE_AS_TEXT);
        TimePeriod gatheringPeriod = TimePeriodParser.parseString(collectionDateAsText);
        try {
            gatheringPeriod.setStartDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY1));
            gatheringPeriod.setStartMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH1));
            gatheringPeriod.setStartYear(getIntegerDateValueOrNull(valueMap, COLLECTION_YEAR1));
            gatheringPeriod.setEndDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY2));
            gatheringPeriod.setEndMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH2));
            gatheringPeriod.setEndYear(getIntegerDateValueOrNull(valueMap, COLLECTION_YEAR2));
        } catch (IndexOutOfBoundsException e) {
            logger.info("Exception occurred when trying to fill gathering period");
        }
        specimen.setGatheringPeriod(gatheringPeriod);
        specimen.setFieldNumber(valueMap.get(COLLECTION_NUMBER));
        // collector team
        String team = valueMap.get(COLLECTOR_TEAM_AS_TEXT);
        if (team != null) {
            Team collectorTeam = Team.NewTitledInstance(team, team);
            specimen.setCollector(collectorTeam);
        }
        specimen.setLocality(valueMap.get(LOCALITY));
        try {
            String latDegrees = CdmUtils.Nz(valueMap.get(LATITUDE_DEGREES));
            String latMinutes = CdmUtils.Nz(valueMap.get(LATITUDE_MINUTES));
            String latSeconds = CdmUtils.Nz(valueMap.get(LATITUDE_SECONDS));
            String direction = CdmUtils.Nz(valueMap.get(NORTH_OR_SOUTH));
            String latitude = latDegrees + "°" + latMinutes + "'" + latSeconds + "\"" + direction;
            String lonDegrees = CdmUtils.Nz(valueMap.get(LONGITUDE_DEGREES));
            String lonMinutes = CdmUtils.Nz(valueMap.get(LONGITUDE_MINUTES));
            String lonSeconds = CdmUtils.Nz(valueMap.get(LONGITUDE_SECONDS));
            direction = CdmUtils.Nz(valueMap.get(EAST_OR_WEST));
            String longitude = lonDegrees + "°" + lonMinutes + "'" + lonSeconds + "\"" + direction;
            specimen.setExactLocationByParsing(longitude, latitude, null, null);
        } catch (ParseException e) {
            logger.info("Parsing exception occurred when trying to parse type exact location." + e.getMessage());
        } catch (Exception e) {
            logger.info("Exception occurred when trying to read type exact location." + e.getMessage());
        }
        // type annotation
        if (valueMap.get(TYPE_REMARKS) != null) {
            Annotation typeAnnotation = Annotation.NewInstance(valueMap.get(TYPE_REMARKS), AnnotationType.EDITORIAL(), Language.DEFAULT());
            specimen.addAnnotation(typeAnnotation);
        }
    }
    // TODO  Type name
    // TODO "Type locations"  , eg. holotype   CAT  ,isotype   CAT  ,isotype   FI
    // TODO Geographic unit as text
    // source
    Reference citation = getIpniCitation(repository);
    name.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Name", citation, valueMap.get(VERSION));
    /*		EXTENDED
 *      Species author,
 *       Standardised basionym author flag,
 *       Standardised publishing author flag
	      Full name
	      Full name without family
	      Full name without authors

	      Reference
	      Standardised publication flag
	      Publication year
	      publication year note
	      Publication year text
	      Volume
	      Start page
	      End page
	      Primary pagination
	      Secondary pagination
	      Reference remarks
	      Hybrid parents
	      Replaced synonym Author team
	      Other links
	      Same citation as
	      Bibliographic reference
	      Bibliographic type info

	      Original taxon name
	      Original taxon name author team
	      Original replaced synonym
	      Original replaced synonym author team
	      Original basionym
	      Original basionym author team
	      Original parent citation taxon name author team
	      Original taxon distribution
	      Original hybrid parentage
	      Original cited type
	      Original remarks

		*/
    return name;
}
Also used : DerivedUnitFacade(eu.etaxonomy.cdm.api.facade.DerivedUnitFacade) VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) Reference(eu.etaxonomy.cdm.model.reference.Reference) TimePeriod(eu.etaxonomy.cdm.model.common.TimePeriod) VerbatimTimePeriod(eu.etaxonomy.cdm.model.common.VerbatimTimePeriod) Rank(eu.etaxonomy.cdm.model.name.Rank) NomenclaturalStatusType(eu.etaxonomy.cdm.model.name.NomenclaturalStatusType) Annotation(eu.etaxonomy.cdm.model.common.Annotation) URISyntaxException(java.net.URISyntaxException) ParseException(java.text.ParseException) StringNotParsableException(eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IBotanicalName(eu.etaxonomy.cdm.model.name.IBotanicalName) NomenclaturalStatus(eu.etaxonomy.cdm.model.name.NomenclaturalStatus) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Team(eu.etaxonomy.cdm.model.agent.Team) ParseException(java.text.ParseException) StringNotParsableException(eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)

Example 4 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class BciServiceWrapper method getCollectionFromLine.

private Collection getCollectionFromLine(String line, ICdmRepository appConfig) {
    // urn:lsid:biocol.org:col:15727	http://biocol.org/urn:lsid:biocol.org:col:15727	University of Bergen Herbarium
    String[] splits = line.split("\t");
    if (splits.length != 3) {
        logger.warn("Unknwon BCI line format: " + line);
        return null;
    }
    String lsidString = splits[0];
    String urlString = splits[1];
    String collectionName = splits[2];
    Collection result = Collection.NewInstance();
    // LSID
    LSID lsid = null;
    try {
        lsid = new LSID(lsidString);
    } catch (MalformedLSIDException e) {
        logger.warn("Malformed LSID " + lsidString, e);
    }
    result.setLsid(lsid);
    String id = getCollectionId(lsid);
    result.setName(collectionName);
    // id, citation
    Reference citation = getBciCitation(appConfig);
    result.addSource(OriginalSourceType.Lineage, id, null, citation, null);
    return result;
}
Also used : LSID(eu.etaxonomy.cdm.model.common.LSID) MalformedLSIDException(com.ibm.lsid.MalformedLSIDException) Reference(eu.etaxonomy.cdm.model.reference.Reference) Collection(eu.etaxonomy.cdm.model.occurrence.Collection)

Example 5 with Reference

use of eu.etaxonomy.cdm.model.reference.Reference in project cdmlib by cybertaxonomy.

the class BciServiceWrapper method getNewBciReference.

private Reference getNewBciReference() {
    Reference bciReference;
    bciReference = ReferenceFactory.newDatabase();
    bciReference.setTitleCache("Biodiversity Collection Index (BCI))", true);
    return bciReference;
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference)

Aggregations

Reference (eu.etaxonomy.cdm.model.reference.Reference)426 Test (org.junit.Test)123 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)103 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)92 ArrayList (java.util.ArrayList)59 Classification (eu.etaxonomy.cdm.model.taxon.Classification)42 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)41 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)41 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)39 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)38 DataSet (org.unitils.dbunit.annotation.DataSet)37 Person (eu.etaxonomy.cdm.model.agent.Person)34 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)34 IntextReference (eu.etaxonomy.cdm.model.common.IntextReference)31 INomenclaturalReference (eu.etaxonomy.cdm.model.reference.INomenclaturalReference)31 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)30 IBotanicalName (eu.etaxonomy.cdm.model.name.IBotanicalName)30 UUID (java.util.UUID)30 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)27 HashSet (java.util.HashSet)23