Search in sources :

Example 1 with ObservationURIsAndTiers

use of gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method ecoCode2ObservationURIsAndTiers.

@Override
public ObservationURIsAndTiers ecoCode2ObservationURIsAndTiers(String ecoCode) {
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> ecocodeQuery = session.createNativeQuery("SELECT ecocode, id, tier FROM observation_template WHERE LENGTH(ecocode)>0");
    List<Object[]> ecocodeResult = ecocodeQuery.list();
    List<String> observationURIs = new ArrayList<String>();
    int tier1 = 0, tier2 = 0, tier3 = 0;
    for (Object[] array : ecocodeResult) {
        String allcodes = (String) array[0];
        Integer templateId = (Integer) array[1];
        Integer tier = (Integer) array[2];
        String[] ecocodes = allcodes.split("\\|");
        if (Arrays.asList(ecocodes).contains(ecoCode)) {
            String sql = "SELECT observation.stableURL FROM observation" + " JOIN submission ON observation.submission_id=submission.id" + " WHERE submission.observationTemplate_id=" + templateId;
            @SuppressWarnings("unchecked") org.hibernate.query.Query<String> query = session.createNativeQuery(sql);
            List<String> uris = query.list();
            observationURIs.addAll(uris);
            switch(tier) {
                case 1:
                    tier1++;
                    break;
                case 2:
                    tier2++;
                    break;
                case 3:
                    tier3++;
                    break;
                default:
                    log.error("unknow tier number " + tier);
            }
        }
    }
    session.close();
    return new ObservationURIsAndTiers(observationURIs.toArray(new String[0]), tier1, tier2, tier3);
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Aggregations

ObservationURIsAndTiers (gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Session (org.hibernate.Session)1 FullTextSession (org.hibernate.search.FullTextSession)1