Search in sources :

Example 11 with Publication

use of org.nextprot.api.core.domain.Publication in project nextprot-api by calipho-sib.

the class EntryPublicationViewServiceImpl method buildEntryPublicationView.

@Override
public List<EntryPublicationView> buildEntryPublicationView(String entryAccession, PublicationCategory publicationCategory) {
    EntryPublications entryPublications = entryPublicationService.findEntryPublications(entryAccession);
    List<EntryPublicationView> list = new ArrayList<>();
    Map<Long, EntryPublication> entryPublicationMap = entryPublications.getEntryPublicationList(publicationCategory).stream().collect(Collectors.toMap(EntryPublication::getPubId, Function.identity(), (entryPublication, entryPublication2) -> entryPublication));
    List<Publication> publications = publicationService.findPublicationsByEntryName(entryPublications.getEntryAccession());
    for (Publication publication : publications) {
        if (entryPublicationMap.containsKey(publication.getPublicationId())) {
            EntryPublicationView view = new EntryPublicationView();
            EntryPublication entryPublication = entryPublicationMap.get(publication.getPublicationId());
            view.setCitedInViews(entryPublication.getCitedInViews());
            view.setDirectLinks(entryPublication.getDirectLinks());
            view.setPublication(publication);
            list.add(view);
        }
    }
    return list;
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) EntryPublicationService(org.nextprot.api.core.service.EntryPublicationService) Publication(org.nextprot.api.core.domain.Publication) List(java.util.List) Service(org.springframework.stereotype.Service) PublicationCategory(org.nextprot.api.core.domain.publication.PublicationCategory) Map(java.util.Map) EntryPublicationViewService(org.nextprot.api.core.service.EntryPublicationViewService) PublicationService(org.nextprot.api.core.service.PublicationService) EntryPublication(org.nextprot.api.core.domain.publication.EntryPublication) EntryPublications(org.nextprot.api.core.domain.publication.EntryPublications) EntryPublicationView(org.nextprot.api.core.domain.publication.EntryPublicationView) EntryPublications(org.nextprot.api.core.domain.publication.EntryPublications) EntryPublicationView(org.nextprot.api.core.domain.publication.EntryPublicationView) EntryPublication(org.nextprot.api.core.domain.publication.EntryPublication) ArrayList(java.util.ArrayList) Publication(org.nextprot.api.core.domain.Publication) EntryPublication(org.nextprot.api.core.domain.publication.EntryPublication)

Example 12 with Publication

use of org.nextprot.api.core.domain.Publication in project nextprot-api by calipho-sib.

the class EntryDataFetcherImpl method get.

@Override
public Entry get(DataFetchingEnvironment environment) {
    // TODO THIS IS A POC (Proof of Concept)
    // If we decide to go ahead with GraphQL please try to adapt this terrible function using EntryQueryResolver that implements GraphQLQueryResolver
    // graphql java tools allows to do newSchemaParser().file(schemaFile).resolvers(...).getSchemaObjects.getGraphqlSchema
    String accession = environment.getArgument("accession");
    Integer publicationLimit = -1;
    Integer annotationLimit = -1;
    String category = "";
    // Searching for publication limit
    Optional<Selection> publicationField = environment.getFields().get(0).getSelectionSet().getSelections().stream().filter(f -> ((Field) f).getName().equals("publications")).findAny();
    if (publicationField.isPresent()) {
        Optional<Argument> publicationLimitArg = ((Field) publicationField.get()).getArguments().stream().filter(f -> f.getName().equals("limit")).findAny();
        if (publicationLimitArg.isPresent()) {
            publicationLimit = Integer.valueOf(publicationLimitArg.get().getValue().toString().replace("IntValue{value=", "").replace("}", ""));
        }
    }
    // Searching for annotation field
    Optional<Selection> annotationField = environment.getFields().get(0).getSelectionSet().getSelections().stream().filter(f -> ((Field) f).getName().equals("annotations")).findAny();
    if (annotationField.isPresent()) {
        Optional<Argument> publicationLimitArg = ((Field) annotationField.get()).getArguments().stream().filter(f -> f.getName().equals("category")).findAny();
        if (publicationLimitArg.isPresent()) {
            category = publicationLimitArg.get().getValue().toString().replace("StringValue{value='", "").replace("'}", "");
        }
        Optional<Argument> annotationLimitArg = ((Field) annotationField.get()).getArguments().stream().filter(f -> f.getName().equals("limit")).findAny();
        if (annotationLimitArg.isPresent()) {
            annotationLimit = Integer.valueOf(annotationLimitArg.get().getValue().toString().replace("IntValue{value=", "").replace("}", ""));
        }
    }
    Entry entry = entryBuilderService.build(EntryConfig.newConfig(accession).with(category).withPublications().withOverview().withTargetIsoforms());
    if (publicationLimit != -1) {
        List<Publication> publications = entry.getPublications();
        List<Publication> publicationSubset = publications.subList(0, publicationLimit);
        entry.setPublications(publicationSubset);
    }
    if (annotationLimit != -1) {
        String cat = entry.getAnnotationsByCategory().keySet().iterator().next();
        entry.setAnnotations(entry.getAnnotationsByCategory(AnnotationCategory.getDecamelizedAnnotationTypeName(cat)).subList(0, annotationLimit));
    }
    return entry;
}
Also used : DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Entry(org.nextprot.api.core.domain.Entry) Autowired(org.springframework.beans.factory.annotation.Autowired) Field(graphql.language.Field) EntryBuilderService(org.nextprot.api.core.service.EntryBuilderService) Argument(graphql.language.Argument) Selection(graphql.language.Selection) Publication(org.nextprot.api.core.domain.Publication) Component(org.springframework.stereotype.Component) List(java.util.List) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) EntryConfig(org.nextprot.api.core.service.fluent.EntryConfig) DataFetcher(graphql.schema.DataFetcher) Optional(java.util.Optional) Entry(org.nextprot.api.core.domain.Entry) Argument(graphql.language.Argument) Selection(graphql.language.Selection) Publication(org.nextprot.api.core.domain.Publication)

Example 13 with Publication

use of org.nextprot.api.core.domain.Publication in project nextprot-api by calipho-sib.

the class PublicationServiceImpl method getPublicationsFromDBReferenceIds.

/**
 * Get all publications not found in npPublication from pubmedids
 * @param npPublicationXrefs needed to avoid loading pubmed id publication multiple times
 * @return
 */
private List<Publication> getPublicationsFromDBReferenceIds(List<String> nxflatReferenceIds, String referenceDatabase, Map<Long, List<PublicationDbXref>> npPublicationXrefs) {
    List<Publication> nxflatPublications = new ArrayList<>();
    // Filtering publications which pubmed was not already found in np publications
    List<Long> foundPublicationIds = npPublicationXrefs.keySet().stream().filter(pubid -> npPublicationXrefs.get(pubid).stream().anyMatch(xref -> nxflatReferenceIds.contains(xref.getAccession()))).collect(Collectors.toList());
    nxflatReferenceIds.stream().filter(Objects::nonNull).forEach(pubmed -> {
        Publication pub = this.publicationDao.findPublicationByDatabaseAndAccession(referenceDatabase, pubmed);
        if (pub == null) {
            LOGGER.warn("Pubmed " + pubmed + " cannot be found");
        } else if (!foundPublicationIds.contains(pub.getPublicationId())) {
            nxflatPublications.add(pub);
        }
    });
    return nxflatPublications;
}
Also used : StatementSimpleWhereClauseQueryDSL(org.nextprot.api.core.dao.impl.StatementSimpleWhereClauseQueryDSL) java.util(java.util) StatementDao(org.nextprot.api.core.dao.StatementDao) GlobalPublicationStatistics(org.nextprot.api.core.domain.publication.GlobalPublicationStatistics) Cacheable(org.springframework.cache.annotation.Cacheable) PublicationDao(org.nextprot.api.core.dao.PublicationDao) PublicationDbXref(org.nextprot.api.core.domain.PublicationDbXref) Autowired(org.springframework.beans.factory.annotation.Autowired) StatementField(org.nextprot.commons.statements.StatementField) org.nextprot.api.core.service(org.nextprot.api.core.service) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Logger(org.apache.log4j.Logger) PublicationComparator(org.nextprot.api.core.utils.PublicationComparator) Publication(org.nextprot.api.core.domain.Publication) ImmutableList(com.google.common.collect.ImmutableList) XrefDatabase(org.nextprot.api.core.service.dbxref.XrefDatabase) Service(org.springframework.stereotype.Service) EntryPublication(org.nextprot.api.core.domain.publication.EntryPublication) PublicationAuthor(org.nextprot.api.core.domain.PublicationAuthor) Publication(org.nextprot.api.core.domain.Publication) EntryPublication(org.nextprot.api.core.domain.publication.EntryPublication)

Example 14 with Publication

use of org.nextprot.api.core.domain.Publication in project nextprot-api by calipho-sib.

the class PublicationServiceImpl method findPublicationByMD5.

@Override
public Publication findPublicationByMD5(String md5) {
    Publication publication = this.publicationDao.findPublicationByMD5(md5);
    loadAuthorsAndXrefs(publication);
    return publication;
}
Also used : Publication(org.nextprot.api.core.domain.Publication) EntryPublication(org.nextprot.api.core.domain.publication.EntryPublication)

Example 15 with Publication

use of org.nextprot.api.core.domain.Publication in project nextprot-api by calipho-sib.

the class PublicationServiceImpl method findPublicationsByEntryName.

// TODO: Publications are already cached in publications-get-by-id - even worse, some publication are linked to more than 10000 entries!!!)
// almost 5GB of cache here !!!
@Override
@Cacheable("publications")
public List<Publication> findPublicationsByEntryName(String uniqueName) {
    Long masterId = masterIdentifierService.findIdByUniqueName(uniqueName);
    List<Publication> publications = publicationDao.findSortedPublicationsByMasterId(masterId);
    Map<Long, List<PublicationDbXref>> npPublicationsXrefs = updateMissingPublicationFields(publications);
    // Getting publications from nx flat database
    List<Publication> nxflatPublications = new ArrayList<>();
    Arrays.asList(XrefDatabase.DOI, XrefDatabase.PUB_MED).forEach(db -> {
        List<String> referenceIds = this.statementDao.findAllDistinctValuesforFieldWhereFieldEqualsValues(StatementField.REFERENCE_ACCESSION, new StatementSimpleWhereClauseQueryDSL(StatementField.ENTRY_ACCESSION, uniqueName), new StatementSimpleWhereClauseQueryDSL(StatementField.REFERENCE_DATABASE, db.getName()));
        nxflatPublications.addAll(getPublicationsFromDBReferenceIds(referenceIds, db.getName(), npPublicationsXrefs));
    });
    updateMissingPublicationFields(nxflatPublications);
    publications.addAll(nxflatPublications);
    Comparator<Publication> comparator = PublicationComparator.StringComparator(Publication::getPublicationYear).reversed().thenComparing(Comparator.comparing(Publication::getPublicationType)).thenComparing(PublicationComparator.StringComparator(Publication::getPublicationLocatorName)).thenComparing(PublicationComparator.FormattedNumberComparator(Publication::getVolume)).thenComparing(PublicationComparator.FormattedNumberComparator(Publication::getFirstPage));
    // sort according to order with criteria defined in publication-sorted-for-master.sql
    publications.sort(comparator);
    // returns a immutable list when the result is cacheable (this prevents modifying the cache, since the cache returns a reference) copy on read and copy on write is too much time consuming
    return new ImmutableList.Builder<Publication>().addAll(publications).build();
}
Also used : Publication(org.nextprot.api.core.domain.Publication) EntryPublication(org.nextprot.api.core.domain.publication.EntryPublication) ImmutableList(com.google.common.collect.ImmutableList) StatementSimpleWhereClauseQueryDSL(org.nextprot.api.core.dao.impl.StatementSimpleWhereClauseQueryDSL) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Publication (org.nextprot.api.core.domain.Publication)33 Test (org.junit.Test)17 CoreUnitBaseTest (org.nextprot.api.core.test.base.CoreUnitBaseTest)13 EntryPublication (org.nextprot.api.core.domain.publication.EntryPublication)6 Ignore (org.junit.Ignore)4 StatementSimpleWhereClauseQueryDSL (org.nextprot.api.core.dao.impl.StatementSimpleWhereClauseQueryDSL)4 ImmutableList (com.google.common.collect.ImmutableList)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Cacheable (org.springframework.cache.annotation.Cacheable)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 PublicationAuthor (org.nextprot.api.core.domain.PublicationAuthor)2 PublicationDbXref (org.nextprot.api.core.domain.PublicationDbXref)2 GlobalPublicationStatistics (org.nextprot.api.core.domain.publication.GlobalPublicationStatistics)2 Service (org.springframework.stereotype.Service)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Sets (com.google.common.collect.Sets)1 Argument (graphql.language.Argument)1 Field (graphql.language.Field)1