Search in sources :

Example 36 with Cacheable

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;
}
Also used : ReleaseInfoVersions(org.nextprot.api.core.domain.release.ReleaseInfoVersions) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 37 with Cacheable

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

Example 38 with Cacheable

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;
}
Also used : Publication(org.nextprot.api.core.domain.Publication) EntryPublication(org.nextprot.api.core.domain.publication.EntryPublication) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 39 with Cacheable

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;
}
Also used : HashMap(java.util.HashMap) RdfTypeInfo(org.nextprot.api.rdf.domain.RdfTypeInfo) ArrayList(java.util.ArrayList) TripleInfo(org.nextprot.api.rdf.domain.TripleInfo) NextProtException(org.nextprot.api.commons.exception.NextProtException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 40 with Cacheable

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;
}
Also used : Binding(com.hp.hpl.jena.sparql.engine.binding.Binding) NextProtException(org.nextprot.api.commons.exception.NextProtException) Var(com.hp.hpl.jena.sparql.core.Var) Node(com.hp.hpl.jena.graph.Node) ArrayList(java.util.ArrayList) ResultSet(com.hp.hpl.jena.query.ResultSet) QueryExecution(com.hp.hpl.jena.query.QueryExecution) QueryParseException(com.hp.hpl.jena.query.QueryParseException) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

Cacheable (org.springframework.cache.annotation.Cacheable)142 ArrayList (java.util.ArrayList)35 HashMap (java.util.HashMap)25 Query (javax.persistence.Query)13 HashSet (java.util.HashSet)11 SystemOptions (org.kuali.kfs.sys.businessobject.SystemOptions)10 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)7 List (java.util.List)7 IOException (java.io.IOException)6 LinkedHashMap (java.util.LinkedHashMap)6 Set (java.util.Set)6 NextProtException (org.nextprot.api.commons.exception.NextProtException)6 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)5 TypedQuery (javax.persistence.TypedQuery)5 PageRequest (org.springframework.data.domain.PageRequest)5 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 QRoleMenu (com.github.liuweijw.business.admin.domain.QRoleMenu)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Map (java.util.Map)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4