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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations