// Path: tanaguru-survey-api/src/main/java/org/opens/tanaguru/survey/view/data/ContractResult.java
// public interface ContractResult {
// 
//     /**
//      *
//      * @return
//      */
//     String getLabel();
// 
//     /**
//      *
//      * @param label
//      */
//     void setLabel(String label);
// 
//     /**
//      * 
//      * @return
//      */
//     String getUrl();
//     
//     /**
//      *
//      * @param url
//      */
//     void setUrl(String url);
// 
//     /**
//      *
//      * @return
//      */
//     int getMark();
// 
//     /**
//      * 
//      * @param mark
//      */
//     void setMark(int mark);
// 
//     /**
//      *
//      * @return
//      */
//     Long getWebResourceId();
// 
//     /**
//      * 
//      * @param webResourceId
//      */
//     void setWebResourceId(Long webResourceId);
// 
// }
// 
// Path: tanaguru-survey-api/src/main/java/org/opens/tanaguru/survey/view/data/factory/ContractResultFactory.java
// public interface ContractResultFactory {
// 
//     /**
//      * 
//      * @return
//      */
//     ContractResult createContractResult();
// 
//     /**
//      *
//      * @param contractLabel
//      * @param contractUrl
//      * @param mark
//      * @param webResourceId
//      * @return
//      */
//     ContractResult createContractResult(String contractLabel, String contractUrl, int mark, Long webResourceId);
// 
// }


import org.opens.tgol.entity.contract.Contract;
import org.opens.tgol.entity.contract.ContractImpl;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigInteger;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.opens.tanaguru.sdk.entity.dao.jpa.AbstractJPADAO;
import org.opens.tanaguru.survey.view.data.ContractResult;
import org.opens.tanaguru.survey.view.data.factory.ContractResultFactory;
            return ((Integer)result);
        } else {
            return Integer.valueOf(0);
        }
    }

    /**
     * Native sql query :
     * SELECT c.Label, c.Url, wrs.Raw_Mark FROM TGSI_USER AS u
     *       INNER JOIN TGSI_CONTRACT AS c ON ( u.Id_User = c.USER_Id_User )
     *       INNER JOIN TGSI_ACT AS a ON
     *       ( c.Id_Contract = a.CONTRACT_Id_Contract AND a.End_Date = (SELECT End_Date FROM TGSI_ACT WHERE CONTRACT_Id_Contract = a.CONTRACT_Id_Contract ORDER BY End_Date DESC LIMIT 1 ) )
     *       INNER JOIN TGSI_ACT_WEB_RESOURCE awr ON ( a.Id_Act = awr.ACT_Id_Act )
     *       INNER JOIN WEB_RESOURCE_STATISTICS AS wrs ON ( awr.WEB_RESOURCE_Id_Web_Resource = wrs.Id_Web_Resource )
     *       WHERE u.Email1 = :listUser
     *       ORDER BY wrs.Raw_Mark  DESC
     *       LIMIT :nbOfResults;
     *
     * @param listUser
     * @param nbOfResults
     * @return
     *      a collection of initialised ContractResult instances
     */
    @Override
    public Collection<ContractResult> findTopNContractsFromListUser(String listUser, int nbOfResults) {
        StringBuilder queryString = new StringBuilder();
        queryString.append(FIND_TOP_N_CONTRACT_QUERY);
        Query query = entityManager.createNativeQuery(queryString.toString());
        query.setParameter("listUser", listUser);
        query.setParameter("nbOfResults", nbOfResults);
// Path: tanaguru-survey-api/src/main/java/org/opens/tanaguru/survey/view/data/ContractResult.java
// public interface ContractResult {
// 
//     /**
//      *
//      * @return
//      */
//     String getLabel();
// 
//     /**
//      *
//      * @param label
//      */
//     void setLabel(String label);
// 
//     /**
//      * 
//      * @return
//      */
//     String getUrl();
//     
//     /**
//      *
//      * @param url
//      */
//     void setUrl(String url);
// 
//     /**
//      *
//      * @return
//      */
//     int getMark();
// 
//     /**
//      * 
//      * @param mark
//      */
//     void setMark(int mark);
// 
//     /**
//      *
//      * @return
//      */
//     Long getWebResourceId();
// 
//     /**
//      * 
//      * @param webResourceId
//      */
//     void setWebResourceId(Long webResourceId);
// 
// }
// 
// Path: tanaguru-survey-api/src/main/java/org/opens/tanaguru/survey/view/data/factory/ContractResultFactory.java
// public interface ContractResultFactory {
// 
//     /**
//      * 
//      * @return
//      */
//     ContractResult createContractResult();
// 
//     /**
//      *
//      * @param contractLabel
//      * @param contractUrl
//      * @param mark
//      * @param webResourceId
//      * @return
//      */
//     ContractResult createContractResult(String contractLabel, String contractUrl, int mark, Long webResourceId);
// 
// }


// Path: tanaguru-survey-persistence/src/main/java/org/opens/tanaguru/entity/dao/tgol/contract/TanaguruSurveyContractDAOImpl.java
import org.opens.tgol.entity.contract.Contract;
import org.opens.tgol.entity.contract.ContractImpl;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigInteger;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.opens.tanaguru.sdk.entity.dao.jpa.AbstractJPADAO;
import org.opens.tanaguru.survey.view.data.ContractResult;
import org.opens.tanaguru.survey.view.data.factory.ContractResultFactory;

            return ((Integer)result);
        } else {
            return Integer.valueOf(0);
        }
    }

    /**
     * Native sql query :
     * SELECT c.Label, c.Url, wrs.Raw_Mark FROM TGSI_USER AS u
     *       INNER JOIN TGSI_CONTRACT AS c ON ( u.Id_User = c.USER_Id_User )
     *       INNER JOIN TGSI_ACT AS a ON
     *       ( c.Id_Contract = a.CONTRACT_Id_Contract AND a.End_Date = (SELECT End_Date FROM TGSI_ACT WHERE CONTRACT_Id_Contract = a.CONTRACT_Id_Contract ORDER BY End_Date DESC LIMIT 1 ) )
     *       INNER JOIN TGSI_ACT_WEB_RESOURCE awr ON ( a.Id_Act = awr.ACT_Id_Act )
     *       INNER JOIN WEB_RESOURCE_STATISTICS AS wrs ON ( awr.WEB_RESOURCE_Id_Web_Resource = wrs.Id_Web_Resource )
     *       WHERE u.Email1 = :listUser
     *       ORDER BY wrs.Raw_Mark  DESC
     *       LIMIT :nbOfResults;
     *
     * @param listUser
     * @param nbOfResults
     * @return
     *      a collection of initialised ContractResult instances
     */
    @Override
    public Collection<ContractResult> findTopNContractsFromListUser(String listUser, int nbOfResults) {
        StringBuilder queryString = new StringBuilder();
        queryString.append(FIND_TOP_N_CONTRACT_QUERY);
        Query query = entityManager.createNativeQuery(queryString.toString());
        query.setParameter("listUser", listUser);
        query.setParameter("nbOfResults", nbOfResults);
        Collection<ContractResult> contractResultSet = new LinkedHashSet<ContractResult>();