Search in sources :

Example 1 with MalformedDOIException

use of org.globalbioticinteractions.doi.MalformedDOIException in project eol-globi-data by jhpoelen.

the class InteractionImporter method studyOf.

private StudyImpl studyOf(Map<String, String> l) {
    String referenceCitation = l.get(REFERENCE_CITATION);
    DOI doi = null;
    String doiString = l.get(REFERENCE_DOI);
    try {
        doi = StringUtils.isBlank(doiString) ? null : DOI.create(doiString);
    } catch (MalformedDOIException e) {
        LogUtil.logWarningIfPossible(l, "found malformed doi [" + doiString + "]", logger);
    }
    StudyImpl study1 = new StudyImpl(l.get(REFERENCE_ID), doi, referenceCitation);
    final String referenceUrl = l.get(REFERENCE_URL);
    if (StringUtils.isBlank(study1.getExternalId()) && StringUtils.isNotBlank(referenceUrl)) {
        study1.setExternalId(referenceUrl);
    }
    return study1;
}
Also used : StudyImpl(org.eol.globi.domain.StudyImpl) DOI(org.globalbioticinteractions.doi.DOI) REFERENCE_DOI(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_DOI) MalformedDOIException(org.globalbioticinteractions.doi.MalformedDOIException)

Example 2 with MalformedDOIException

use of org.globalbioticinteractions.doi.MalformedDOIException in project eol-globi-data by jhpoelen.

the class ReferenceUtil method generateReferenceCitation.

public static String generateReferenceCitation(Map<String, String> properties) {
    StringBuilder citation = new StringBuilder();
    append(citation, properties.get(DatasetImporterForMetaTable.AUTHOR), ", ");
    append(citation, properties.get(DatasetImporterForMetaTable.YEAR), ". ");
    append(citation, properties.get(DatasetImporterForMetaTable.TITLE), ". ");
    append(citation, properties.get(DatasetImporterForMetaTable.JOURNAL), properties.containsKey(DatasetImporterForMetaTable.VOLUME) || properties.containsKey(DatasetImporterForMetaTable.NUMBER) || properties.containsKey(DatasetImporterForMetaTable.PAGES) ? ", " : ". ");
    append(citation, properties.get(DatasetImporterForMetaTable.VOLUME), properties.containsKey(DatasetImporterForMetaTable.NUMBER) ? "(" : (properties.containsKey(DatasetImporterForMetaTable.PAGES) ? ", " : ". "));
    append(citation, properties.get(DatasetImporterForMetaTable.NUMBER), properties.containsKey(DatasetImporterForMetaTable.VOLUME) ? ")" : "");
    if (properties.containsKey(DatasetImporterForMetaTable.NUMBER)) {
        citation.append(properties.containsKey(DatasetImporterForMetaTable.PAGES) ? ", " : ".");
    }
    append(citation, properties.get(DatasetImporterForMetaTable.PAGES), ". ", "pp.");
    String citationFromId = null;
    if (properties.containsKey(DatasetImporterForTSV.REFERENCE_DOI)) {
        String str = properties.get(DatasetImporterForTSV.REFERENCE_DOI);
        if (StringUtils.isNoneBlank(str)) {
            try {
                DOI doi = DOI.create(str);
                citationFromId = doi.toPrintableDOI();
            } catch (MalformedDOIException e) {
            // ignore malformed DOIs here
            }
        }
    }
    if (StringUtils.isBlank(citationFromId) && properties.containsKey(DatasetImporterForTSV.REFERENCE_URL)) {
        citationFromId = properties.get(DatasetImporterForTSV.REFERENCE_URL);
    }
    if (StringUtils.isNoneBlank(citationFromId)) {
        citation.append(citationFromId);
    }
    return StringUtils.trim(citation.toString());
}
Also used : DOI(org.globalbioticinteractions.doi.DOI) MalformedDOIException(org.globalbioticinteractions.doi.MalformedDOIException)

Example 3 with MalformedDOIException

use of org.globalbioticinteractions.doi.MalformedDOIException in project eol-globi-data by jhpoelen.

the class DatasetImporterForPensoft method addDOIReferenceIfAvailable.

private static void addDOIReferenceIfAvailable(String doiString, TreeMap<String, String> references) {
    try {
        final DOI doiObj = DOI.create(doiString);
        references.put(DatasetImporterForTSV.REFERENCE_DOI, doiString);
        references.put(DatasetImporterForTSV.REFERENCE_URL, doiObj.toURI().toString());
    } catch (MalformedDOIException e) {
    // ignore
    }
}
Also used : DOI(org.globalbioticinteractions.doi.DOI) MalformedDOIException(org.globalbioticinteractions.doi.MalformedDOIException)

Example 4 with MalformedDOIException

use of org.globalbioticinteractions.doi.MalformedDOIException in project eol-globi-data by jhpoelen.

the class ExternalIdUtil method urlForExternalId.

public static String urlForExternalId(String externalId) {
    URI uri = null;
    String url = null;
    if (externalId != null) {
        for (Map.Entry<String, String> idPrefixToUrlPrefix : getURLPrefixMap().entrySet()) {
            String idPrefix = idPrefixToUrlPrefix.getKey();
            if (StringUtils.startsWith(externalId, idPrefix)) {
                if (DOI.isCommonlyUsedDoiPrefix(idPrefix)) {
                    try {
                        DOI doi = DOI.create(externalId);
                        url = doi.toURI().toString();
                    } catch (MalformedDOIException e) {
                        LOG.warn("found malformed doi [" + externalId + "]", e);
                    }
                } else {
                    url = idPrefixToUrlPrefix.getValue() + externalId.replaceAll(idPrefix, "");
                }
                String suffix = getURLSuffixMap().get(idPrefix);
                if (StringUtils.isNotBlank(suffix)) {
                    url = url + suffix;
                }
            }
            if (url != null) {
                try {
                    URIBuilder uriBuilder = new URIBuilder(url);
                    uri = uriBuilder.build();
                // URL ur= new URL(url);
                // uri = new URI(ur.getProtocol(), ur.getUserInfo(), ur.getHost(), ur.getPort(), ur.getPath(), ur.getQuery(), ur.getRef());
                } catch (URISyntaxException e) {
                // 
                }
                break;
            }
        }
    }
    return uri == null ? null : uri.toString();
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) DOI(org.globalbioticinteractions.doi.DOI) MalformedDOIException(org.globalbioticinteractions.doi.MalformedDOIException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 5 with MalformedDOIException

use of org.globalbioticinteractions.doi.MalformedDOIException in project eol-globi-data by jhpoelen.

the class CypherQueryBuilder method extractDOIs.

private static List<DOI> extractDOIs(List<String> accordingToParams) {
    List<DOI> dois = new ArrayList<>();
    for (String accordingToParam : accordingToParams) {
        try {
            DOI doi = DOI.create(accordingToParam);
            dois.add(doi);
        } catch (MalformedDOIException e) {
        // 
        }
    }
    return dois;
}
Also used : ArrayList(java.util.ArrayList) DOI(org.globalbioticinteractions.doi.DOI) MalformedDOIException(org.globalbioticinteractions.doi.MalformedDOIException)

Aggregations

MalformedDOIException (org.globalbioticinteractions.doi.MalformedDOIException)9 DOI (org.globalbioticinteractions.doi.DOI)8 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 CSVParse (com.Ostermiller.util.CSVParse)1 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 StringUtils.defaultString (org.apache.commons.lang3.StringUtils.defaultString)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 HttpGet (org.apache.http.client.methods.HttpGet)1 REFERENCE_DOI (org.eol.globi.data.DatasetImporterForTSV.REFERENCE_DOI)1 StudyImpl (org.eol.globi.domain.StudyImpl)1 DB (org.mapdb.DB)1 Fun (org.mapdb.Fun)1