use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.
the class ReleaseInfoServiceImpl method findReleaseVersions.
@Override
@Cacheable("release-versions")
public ReleaseInfoVersions findReleaseVersions() {
ReleaseInfoVersions ri = new ReleaseInfoVersions();
ri.setDatabaseRelease(releaseInfoDao.findDatabaseRelease());
ri.setApiRelease(this.getApiVersion());
return ri;
}
use of org.springframework.cache.annotation.Cacheable 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();
}
use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.
the class PublicationServiceImpl method findPublicationById.
@Cacheable("publications-get-by-id")
public Publication findPublicationById(long id) {
// Basic fields
Publication publication = this.publicationDao.findPublicationById(id);
// add non-basic fields to object
loadAuthorsAndXrefs(publication);
return publication;
}
use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.
the class RdfHelpServiceImpl method getRdfTypeFullInfoList.
@Cacheable("rdfhelp")
@Override
public synchronized List<RdfTypeInfo> getRdfTypeFullInfoList() {
long t0 = System.currentTimeMillis();
Set<String> rdfTypesNames = getRdfTypesNames();
List<Future<RdfTypeInfo>> rdfFutureTypes = new ArrayList<Future<RdfTypeInfo>>();
List<RdfTypeInfo> rdfTypes = Collections.synchronizedList(new ArrayList<RdfTypeInfo>());
ExecutorService executor = Executors.newFixedThreadPool(NUMBER_THREADS);
for (String rdfTypeName : rdfTypesNames) {
// LOGGER.info("step1 - found rdf:type name " + rdfTypeName);
Future<RdfTypeInfo> futureRdfTypeInfo = executor.submit(new FillRdfTypeInfoTask(this, rdfTypeName));
rdfFutureTypes.add(futureRdfTypeInfo);
}
executor.shutdown();
try {
executor.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException e) {
e.printStackTrace();
throw new NextProtException(e.getLocalizedMessage());
}
for (Future<RdfTypeInfo> futureRdfTypeInfo : rdfFutureTypes) {
try {
rdfTypes.add(futureRdfTypeInfo.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
// now populate parent and parent triples of each type
for (RdfTypeInfo rti : rdfTypes) {
// LOGGER.info("step2 - updating rdf:type " + rti.getTypeName());
for (RdfTypeInfo parent : rdfTypes) {
List<TripleInfo> triples = parent.findTriplesWithObjectType(rti.getTypeName());
if (triples.size() > 0) {
// LOGGER.info("step3 - linking parent rdf:type " + parent.getTypeName() + " to rdf:type " + rti.getTypeName() + " , triple size: " + triples.size());
rti.addParent(parent.getTypeName());
for (TripleInfo triple : triples) rti.addParentTriple(triple);
}
}
}
Map<String, RdfTypeInfo> fullMap = new HashMap<String, RdfTypeInfo>();
for (RdfTypeInfo rti : rdfTypes) {
fullMap.put(rti.getTypeName(), rti);
}
if (fullMap.containsKey(":Entry"))
buildPathToOrigin(fullMap, fullMap.get(":Entry"), "?entry ", 0);
long seconds = (System.currentTimeMillis() - t0) / 1000;
String duration = String.format("%d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, (seconds % 60)) + " [H:MM:SS]";
LOGGER.info("errors: " + errorCount);
LOGGER.info("duration: " + duration);
return rdfTypes;
}
use of org.springframework.cache.annotation.Cacheable in project nextprot-api by calipho-sib.
the class SparqlServiceImpl method findEntries.
@Override
@Cacheable("sparql")
public List<String> findEntries(String sparql, String sparqlEndpointUrl, String sparqlTitle) {
String query = SparqlUtils.buildQuery(prefix, sparql);
List<String> results = new ArrayList<String>();
QueryExecution qExec = null;
try {
qExec = QueryExecutionFactory.sparqlService(sparqlEndpointUrl, query);
} catch (QueryParseException qe) {
String msg = ExceptionUtils.fixLineNumberInErrorMessage(qe.getLocalizedMessage());
throw new NextProtException("Malformed SPARQL: " + msg);
}
ResultSet rs = qExec.execSelect();
/**
* This give an empty graph....
* Model m = rs.getResourceModel();
* Graph g = m.getGraph();
* System.err.println("The graph is" + g);
*/
Var x = Var.alloc("entry");
while (rs.hasNext()) {
Binding b = rs.nextBinding();
Node entryNode = b.get(x);
if (entryNode == null) {
qExec.close();
throw new NextProtException("Bind your protein result to a variable called ?entry. Example: \"?entry :classifiedWith cv:KW-0813.\"");
} else if (entryNode.toString().indexOf(ENTRY_SUFFIX_URI) == -1) {
qExec.close();
throw new NextProtException("Any entry found in the output, however was found: " + entryNode.toString());
}
String entry = entryNode.toString().replace(ENTRY_SUFFIX_URI, "").trim();
results.add(entry);
}
qExec.close();
return results;
}
Aggregations