package org.pdxfinder.repositories;

import org.pdxfinder.dao.OntologyTerm;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;

/**
 * Created by csaba on 07/06/2017.
 */
@Repository
public interface OntologyTermRepository extends PagingAndSortingRepository<OntologyTerm, Long>
{

    OntologyTerm findById();

    @Query("MATCH (o:OntologyTerm) WHERE toLower(o.label) = toLower({label}) return o")
    OntologyTerm findByLabel(@Param("label") String label);

    OntologyTerm findByUrl(String url);

    //AUTO-SUGGEST: Returns all OntologyTerms with mapped samples and all their ancestors
    @Query("MATCH (st:OntologyTerm)<-[*]-(ot:OntologyTerm) " +
            "MATCH (ot)-[m:MAPPED_TO]-(s:Sample) " +
            "RETURN ot,st")
    Collection<OntologyTerm> findAllWithMappings();




}
@@ -331,16 +331,38 @@
 lection;
+%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -1015,12 +1015,547 @@
 ngs();%0A%0A
+    @Query(%22MATCH (ot:OntologyTerm) RETURN ot%22)%0A    Collection%3COntologyTerm%3E findAll();%0A%0A    @Query(%22MATCH (st:OntologyTerm)%3C-%5B*%5D-(term:OntologyTerm) %22 +%0A            %22WHERE st.label = %7Blabel%7D %22 +%0A            %22RETURN sum(term.indirectMappedSamplesNumber)%22)%0A    int getIndirectMappingNumber(@Param(%22label%22) String label);%0A%0A    @Query(%22MATCH (st:OntologyTerm)%3C-%5B*%5D-(term:OntologyTerm) %22 +%0A            %22WHERE st.label = %7Blabel%7D %22 +%0A            %22RETURN term, st%22)%0A    Set%3COntologyTerm%3E getDistinctSubTreeNodes(@Param(%22label%22) String label);
 %0A%0A%0A%7D

Add findAll() and direct/indirect mapping number getter