Search in sources :

Example 16 with Submission

use of gov.nih.nci.ctd2.dashboard.model.Submission in project nci-ctd2-dashboard by CBIIT.

the class SubmissionAPI method getSubmission.

@Transactional
@RequestMapping(value = "{id}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubmission(@PathVariable String id, @RequestParam(value = "maximum", required = false, defaultValue = "") String maximum) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    int limit = 0;
    if (maximum != null && maximum.trim().length() > 0) {
        try {
            limit = Integer.parseInt(maximum.trim());
        } catch (NumberFormatException e) {
        // no-op
        }
    }
    Submission submission = dashboardDao.getEntityByStableURL("submission", "submission/" + id);
    String[] observations = dashboardDao.findObservationURLs(submission.getId(), limit);
    APISubmission apiSubmission = new APISubmission(submission, observations);
    log.debug("ready to serialize");
    JSONSerializer jsonSerializer = CTD2Serializer.createJSONSerializer();
    String json = "{}";
    try {
        json = jsonSerializer.deepSerialize(apiSubmission);
    } catch (Exception e) {
        e.printStackTrace();
        return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
    }
    return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Submission

use of gov.nih.nci.ctd2.dashboard.model.Submission in project nci-ctd2-dashboard by CBIIT.

the class RssController method searchRSS.

@Transactional
@RequestMapping(value = "search/{keyword}", method = { RequestMethod.GET, RequestMethod.POST })
public ResponseEntity<String> searchRSS(@PathVariable String keyword) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/rss+xml");
    // This is to prevent unnecessary server loads
    if (keyword.length() < 2)
        return new ResponseEntity<String>(headers, HttpStatus.BAD_REQUEST);
    try {
        keyword = URLDecoder.decode(keyword, Charset.defaultCharset().displayName());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    // Search and find the entity hits
    SearchResults entitiesWithCounts = dashboardDao.search(keyword);
    List<DashboardEntity> searchEntities = new ArrayList<DashboardEntity>();
    for (SubjectResult subjectResult : entitiesWithCounts.subject_result) {
        try {
            Class<? extends DashboardEntity> clazz = Class.forName("gov.nih.nci.ctd2.dashboard.model." + subjectResult.className).asSubclass(DashboardEntity.class);
            DashboardEntity entity = dashboardDao.getEntityById(clazz, subjectResult.id);
            searchEntities.add(entity);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            continue;
        }
    }
    String titlePostfix = keyword;
    String rssDescription = "Latest observations and submission related to '" + keyword + "'";
    String dashboardUrl = context.getScheme() + "://" + context.getServerName() + context.getContextPath() + "/";
    String rssLink = dashboardUrl + "#search/" + keyword;
    String feedStr = generateFeed(searchEntities, titlePostfix, rssDescription, rssLink);
    return new ResponseEntity<String>(feedStr, headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SubjectResult(gov.nih.nci.ctd2.dashboard.util.SubjectResult) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with Submission

use of gov.nih.nci.ctd2.dashboard.model.Submission in project nci-ctd2-dashboard by CBIIT.

the class ObservationController method getObservationsBySubmissionIdAndSubjuectId.

/*
     * For a given submission, tier is decided so there is point of further
     * specifiying tier.
     */
@Transactional
@RequestMapping(value = "bySubmissionAndSubject", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getObservationsBySubmissionIdAndSubjuectId(@RequestParam("submissionId") Integer submissionId, @RequestParam("subjectId") Integer subjectId, @RequestParam(value = "role", required = false, defaultValue = "") String role) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    String summaryTemplate = null;
    Set<Observation> observations = new HashSet<Observation>();
    Subject subject = dashboardDao.getEntityById(Subject.class, subjectId);
    for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
        Observation observation = observedSubject.getObservation();
        Submission submission = observation.getSubmission();
        if (!submission.getId().equals(submissionId)) {
            continue;
        } else if (summaryTemplate == null) {
            summaryTemplate = submission.getObservationTemplate().getObservationSummary();
        }
        String subjectRole = observedSubject.getObservedSubjectRole().getSubjectRole().getDisplayName();
        if ((role.equals("") || role.equals(subjectRole))) {
            observations.add(observation);
        }
    }
    List<ObservationWithSummary> list = new ArrayList<ObservationWithSummary>();
    for (Observation observation : observations) {
        String expanded = dashboardDao.expandSummary(observation.getId(), summaryTemplate) + " (<a class='button-link' href='#" + observation.getStableURL() + "'>details &raquo;</a>)";
        list.add(new ObservationWithSummary(observation, expanded));
    }
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.serialize(list), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) ArrayList(java.util.ArrayList) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) ResponseEntity(org.springframework.http.ResponseEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Submission

use of gov.nih.nci.ctd2.dashboard.model.Submission in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method getObservations.

@Override
public ObservationItem[] getObservations(String submissionId, Set<Integer> indexes) {
    // this works because observation URIs are totally based on submission URI
    List<String> uris = indexes.stream().map(i -> "observation/" + submissionId + "-" + i).collect(Collectors.toList());
    // uris.forEach(System.out::println);
    Session session = getSession();
    List<ObservationItem> list = new ArrayList<ObservationItem>();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<ObservationItem> query = session.createQuery("FROM ObservationItem WHERE uri IN (:uris)");
    query.setParameterList("uris", uris);
    try {
        list = query.getResultList();
    } catch (NoResultException e) {
        log.info("ObservationItem not available for submission ID " + submissionId);
    }
    ObservationItem[] x = list.stream().toArray(ObservationItem[]::new);
    log.debug("count of observations:" + x.length);
    session.close();
    return x;
}
Also used : Query(org.apache.lucene.search.Query) ObservedEvidenceRole(gov.nih.nci.ctd2.dashboard.model.ObservedEvidenceRole) Transcript(gov.nih.nci.ctd2.dashboard.model.Transcript) Arrays(java.util.Arrays) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) Cacheable(org.springframework.cache.annotation.Cacheable) NoResultException(javax.persistence.NoResultException) XRefItem(gov.nih.nci.ctd2.dashboard.api.XRefItem) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) SubmissionCenter(gov.nih.nci.ctd2.dashboard.model.SubmissionCenter) Matcher(java.util.regex.Matcher) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) Map(java.util.Map) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BigInteger(java.math.BigInteger) TissueSample(gov.nih.nci.ctd2.dashboard.model.TissueSample) Organism(gov.nih.nci.ctd2.dashboard.model.Organism) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ScrollableResults(org.hibernate.ScrollableResults) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) SubjectResult(gov.nih.nci.ctd2.dashboard.util.SubjectResult) Collection(java.util.Collection) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) FullTextQuery(org.hibernate.search.FullTextQuery) CellSample(gov.nih.nci.ctd2.dashboard.model.CellSample) Compound(gov.nih.nci.ctd2.dashboard.model.Compound) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) SubjectWithOrganism(gov.nih.nci.ctd2.dashboard.model.SubjectWithOrganism) Collectors(java.util.stream.Collectors) TissueSampleImpl(gov.nih.nci.ctd2.dashboard.impl.TissueSampleImpl) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem) List(java.util.List) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) EcoBrowse(gov.nih.nci.ctd2.dashboard.util.EcoBrowse) CompoundImpl(gov.nih.nci.ctd2.dashboard.impl.CompoundImpl) ScrollMode(org.hibernate.ScrollMode) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) DashboardEntityImpl(gov.nih.nci.ctd2.dashboard.impl.DashboardEntityImpl) Gene(gov.nih.nci.ctd2.dashboard.model.Gene) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) ShRna(gov.nih.nci.ctd2.dashboard.model.ShRna) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ParseException(org.apache.lucene.queryparser.classic.ParseException) FullTextSession(org.hibernate.search.FullTextSession) SubmissionImpl(gov.nih.nci.ctd2.dashboard.impl.SubmissionImpl) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) Session(org.hibernate.Session) HashMap(java.util.HashMap) EvidenceItem(gov.nih.nci.ctd2.dashboard.api.EvidenceItem) Evidence(gov.nih.nci.ctd2.dashboard.model.Evidence) TypedQuery(javax.persistence.TypedQuery) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) SubjectWithSummaries(gov.nih.nci.ctd2.dashboard.util.SubjectWithSummaries) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Search(org.hibernate.search.Search) Summary(gov.nih.nci.ctd2.dashboard.util.Summary) SubjectImpl(gov.nih.nci.ctd2.dashboard.impl.SubjectImpl) AnimalModel(gov.nih.nci.ctd2.dashboard.model.AnimalModel) ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) WordCloudEntry(gov.nih.nci.ctd2.dashboard.util.WordCloudEntry) SubjectWithOrganismImpl(gov.nih.nci.ctd2.dashboard.impl.SubjectWithOrganismImpl) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) FlushMode(org.hibernate.FlushMode) SubjectItem(gov.nih.nci.ctd2.dashboard.api.SubjectItem) Hierarchy(gov.nih.nci.ctd2.dashboard.util.Hierarchy) Annotation(gov.nih.nci.ctd2.dashboard.model.Annotation) ObservationTemplateImpl(gov.nih.nci.ctd2.dashboard.impl.ObservationTemplateImpl) Synonym(gov.nih.nci.ctd2.dashboard.model.Synonym) Protein(gov.nih.nci.ctd2.dashboard.model.Protein) Log(org.apache.commons.logging.Log) DashboardFactory(gov.nih.nci.ctd2.dashboard.model.DashboardFactory) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session) ObservationItem(gov.nih.nci.ctd2.dashboard.api.ObservationItem)

Example 20 with Submission

use of gov.nih.nci.ctd2.dashboard.model.Submission in project nci-ctd2-dashboard by CBIIT.

the class DashboardDaoImpl method getEcoBrowse.

@Override
public List<EcoBrowse> getEcoBrowse() {
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> ecocodeQuery = session.createNativeQuery("SELECT ecocode, id, tier, submissionCenter_id FROM observation_template WHERE LENGTH(ecocode)>0");
    List<Object[]> ecocodeResult = ecocodeQuery.list();
    Map<String, EcoBrowse> map = new HashMap<String, EcoBrowse>();
    Map<String, Set<Integer>> mapTier1centers = new HashMap<String, Set<Integer>>();
    Map<String, Set<Integer>> mapTier2centers = new HashMap<String, Set<Integer>>();
    Map<String, Set<Integer>> mapTier3centers = new HashMap<String, Set<Integer>>();
    for (Object[] array : ecocodeResult) {
        String allcodes = (String) array[0];
        Integer templateId = (Integer) array[1];
        Integer tier = (Integer) array[2];
        Integer centerId = (Integer) array[3];
        String countSql = "SELECT COUNT(DISTINCT submission.id), COUNT(DISTINCT observation.id)" + " FROM observation JOIN submission ON observation.submission_id=submission.id" + " JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " WHERE submission.observationTemplate_id=" + templateId;
        @SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query = session.createNativeQuery(countSql);
        Object[] result = query.getSingleResult();
        BigInteger submissionCount = (BigInteger) result[0];
        BigInteger tierCount = (BigInteger) result[1];
        String[] ecocodes = allcodes.split("\\|");
        for (String code : ecocodes) {
            EcoBrowse b = map.get(code);
            if (b == null) {
                // this term not in the map yet
                @SuppressWarnings("unchecked") org.hibernate.query.Query<ECOTerm> ecotermQuery = session.createQuery("FROM ECOTermImpl WHERE code='" + code + "'");
                ECOTerm term = ecotermQuery.getSingleResult();
                b = new EcoBrowse(term.getDisplayName(), term.getStableURL(), 0);
                map.put(code, b);
            }
            b.setNumberOfSubmissions(b.getNumberOfSubmissions() + submissionCount.intValue());
            Set<Integer> centerSet = null;
            switch(tier) {
                case 1:
                    b.setNumberOfTier1Observations(b.getNumberOfTier1Observations() + tierCount.intValue());
                    centerSet = mapTier1centers.get(code);
                    if (centerSet == null) {
                        centerSet = new HashSet<Integer>();
                        mapTier1centers.put(code, centerSet);
                    }
                    break;
                case 2:
                    b.setNumberOfTier2Observations(b.getNumberOfTier2Observations() + tierCount.intValue());
                    centerSet = mapTier2centers.get(code);
                    if (centerSet == null) {
                        centerSet = new HashSet<Integer>();
                        mapTier2centers.put(code, centerSet);
                    }
                    break;
                case 3:
                    b.setNumberOfTier3Observations(b.getNumberOfTier3Observations() + tierCount.intValue());
                    centerSet = mapTier3centers.get(code);
                    if (centerSet == null) {
                        centerSet = new HashSet<Integer>();
                        mapTier3centers.put(code, centerSet);
                    }
                    break;
                default:
                    log.error("unknow tier number " + tier);
            }
            centerSet.add(centerId);
        }
    }
    map.forEach((code, browseItem) -> {
        int tier1 = 0, tier2 = 0, tier3 = 0;
        Set<Integer> set1 = mapTier1centers.get(code);
        Set<Integer> set2 = mapTier2centers.get(code);
        Set<Integer> set3 = mapTier3centers.get(code);
        if (set1 != null)
            tier1 = set1.size();
        if (set2 != null)
            tier2 = set2.size();
        if (set3 != null)
            tier3 = set3.size();
        browseItem.setNumberOfTier1SubmissionCenters(tier1);
        browseItem.setNumberOfTier2SubmissionCenters(tier2);
        browseItem.setNumberOfTier3SubmissionCenters(tier3);
    });
    session.close();
    log.debug("map size " + map.size());
    return new ArrayList<EcoBrowse>(map.values());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EcoBrowse(gov.nih.nci.ctd2.dashboard.util.EcoBrowse) BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Aggregations

Submission (gov.nih.nci.ctd2.dashboard.model.Submission)15 BigInteger (java.math.BigInteger)14 ArrayList (java.util.ArrayList)14 FullTextSession (org.hibernate.search.FullTextSession)13 Session (org.hibernate.Session)12 HttpHeaders (org.springframework.http.HttpHeaders)9 ResponseEntity (org.springframework.http.ResponseEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)8 Transactional (org.springframework.transaction.annotation.Transactional)8 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)7 JSONSerializer (flexjson.JSONSerializer)6 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)6 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)6 Summary (gov.nih.nci.ctd2.dashboard.util.Summary)6 HashMap (java.util.HashMap)6 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)5 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)5 HashSet (java.util.HashSet)5 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)4