Search in sources :

Example 6 with Submission

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

the class DashboardDaoImpl method searchSingleTerm.

private void searchSingleTerm(final String singleTerm, final Map<Subject, Integer> subjects, final Map<Submission, Integer> submissions) {
    FullTextSession fullTextSession = Search.getFullTextSession(getSession());
    MultiFieldQueryParser multiFieldQueryParser = new MultiFieldQueryParser(defaultSearchFields, new KeywordAnalyzer());
    Query luceneQuery = null;
    try {
        luceneQuery = multiFieldQueryParser.parse(singleTerm);
        log.debug(luceneQuery);
    } catch (ParseException e) {
        e.printStackTrace();
        return;
    }
    FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, searchableClasses);
    fullTextQuery.setReadOnly(true);
    List<?> list = fullTextQuery.list();
    fullTextSession.close();
    Integer numberOfSearchResults = getMaxNumberOfSearchResults();
    if (numberOfSearchResults > 0 && list.size() > numberOfSearchResults) {
        // if lte 0, the maximum number is ignored
        log.warn("search result number " + list.size() + " is larger than the maximum expected, " + numberOfSearchResults);
    }
    for (Object o : list) {
        if (o instanceof ObservationTemplate) {
            List<Submission> submissionList = queryWithClass("select o from SubmissionImpl as o where o.observationTemplate = :ot", "ot", (ObservationTemplate) o);
            for (Submission submission : submissionList) {
                if (submissions.containsKey(submission)) {
                    submissions.put(submission, submissions.get(submission) + 1);
                } else {
                    submissions.put(submission, 1);
                }
            }
        } else if (o instanceof Subject) {
            Subject s = (Subject) o;
            if (subjects.containsKey(s)) {
                subjects.put(s, subjects.get(s) + 1);
            } else {
                subjects.put(s, 1);
            }
        } else {
            log.warn("unexpected type returned by searching: " + o.getClass().getName());
        }
    }
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) FullTextSession(org.hibernate.search.FullTextSession) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) Query(org.apache.lucene.search.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FullTextQuery(org.hibernate.search.FullTextQuery) TypedQuery(javax.persistence.TypedQuery) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) BigInteger(java.math.BigInteger) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ParseException(org.apache.lucene.queryparser.classic.ParseException) FullTextQuery(org.hibernate.search.FullTextQuery)

Example 7 with Submission

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

the class DashboardDaoImpl method getSubmissionsForSubjectName.

/*
     * get submissions if subject name is in some of four fields of its
     * **Observation Template**: (1) DashboardEntityImpl.FIELD_DISPLAYNAME, (2)
     * ObservationTemplateImpl.FIELD_DESCRIPTION, (3)
     * ObservationTemplateImpl.FIELD_SUBMISSIONDESC, (4)
     * ObservationTemplateImpl.FIELD_SUBMISSIONNAME
     */
@Override
public List<Submission> getSubmissionsForSubjectName(String subjectName) {
    String sql = "SELECT submission.id from submission JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " JOIN dashboard_entity ON submission.id=dashboard_entity.id WHERE displayName LIKE :subjectName" + " OR description LIKE :subjectName OR submissionDescription LIKE :subjectName" + " OR submissionName LIKE :subjectName";
    Session session = getSession();
    @SuppressWarnings("unchecked") org.hibernate.query.Query<Integer> query = session.createNativeQuery(sql);
    query.setParameter("subjectName", "%" + subjectName + "%");
    List<Submission> list = new ArrayList<Submission>();
    for (Integer id : query.getResultList()) {
        Submission submission = getEntityById(Submission.class, id);
        list.add(submission);
    }
    session.close();
    return list;
}
Also used : BigInteger(java.math.BigInteger) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ArrayList(java.util.ArrayList) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 8 with Submission

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

the class ObservationDataWriter method write.

public void write(List<? extends ObservationData> items) throws Exception {
    // calls) (2) there is at least one observation in each call
    if (items.size() == 0) {
        // this might happen when some suject is rejected
        log.debug("no item");
        return;
    }
    final Submission submission = items.get(0).observation.getSubmission();
    final String submissionName = submission.getDisplayName();
    StableURL stableURL = new StableURL();
    synchronized (submission) {
        log.debug("[" + ++counter + "]SUBMISSION " + submissionName + ": " + items.size() + " observation(s)");
        final String submissionCacheKey = submissionName + new SimpleDateFormat("yyyy.MM.dd").format(submission.getSubmissionDate()) + submission.getObservationTemplate().getDisplayName();
        if (!submissionCache.contains(submissionCacheKey)) {
            submission.setStableURL(stableURL.createURLWithPrefix("submission", submissionName));
            dashboardDao.save(submission);
            submissionCache.add(submissionCacheKey);
            observationIndex.put(submissionName, 0);
        }
    }
    List<Observation> observations = new ArrayList<Observation>();
    List<Evidence> evidences = new ArrayList<Evidence>();
    List<ObservedSubject> observedSubjects = new ArrayList<ObservedSubject>();
    List<ObservedEvidence> observedEvidences = new ArrayList<ObservedEvidence>();
    for (ObservationData observationData : items) {
        Observation observation = observationData.observation;
        int index = observationIndex.get(submissionName);
        observation.setStableURL(stableURL.createURLWithPrefix("observation", submissionName) + "-" + index);
        observations.add(observation);
        observationIndex.put(submissionName, index + 1);
        for (DashboardEntity e : observationData.evidence) {
            evidences.add((Evidence) e);
        }
        for (DashboardEntity e : observationData.observedEntities) {
            String className = e.getClass().getName();
            switch(className) {
                case "gov.nih.nci.ctd2.dashboard.impl.ObservedSubjectImpl":
                    observedSubjects.add((ObservedSubject) e);
                    break;
                case "gov.nih.nci.ctd2.dashboard.impl.ObservedEvidenceImpl":
                    observedEvidences.add((ObservedEvidence) e);
                    break;
                default:
                    log.error("unexpected type " + className);
            }
        }
    }
    // use a smaller batch size to prevent 'lock wait timeout'
    int batchSize = 100;
    log.debug("observations to write " + observations.size());
    dashboardDao.batchSave(observations, batchSize);
    log.debug("observedSubjects to write " + observedSubjects.size());
    dashboardDao.batchSave(observedSubjects, batchSize);
    log.debug("evidences to write " + evidences.size());
    dashboardDao.batchSave(evidences, batchSize);
    log.debug("observedEvidences to write " + observedEvidences.size());
    dashboardDao.batchSave(observedEvidences, batchSize);
    log.debug("ALL WRITTEN: " + submissionName);
}
Also used : ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) StableURL(gov.nih.nci.ctd2.dashboard.util.StableURL) ArrayList(java.util.ArrayList) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) Evidence(gov.nih.nci.ctd2.dashboard.model.Evidence) ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) SimpleDateFormat(java.text.SimpleDateFormat) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject)

Example 9 with Submission

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

the class StoriesController method getSearchResultsInJson.

@Transactional
@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSearchResultsInJson(@RequestParam("limit") Integer limit) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    ArrayList<Observation> entities = new ArrayList<Observation>();
    // If no limit, then show everything
    if (limit == -1)
        limit = Integer.MAX_VALUE;
    for (Submission submission : dashboardDao.findSubmissionByIsStory(true, true)) {
        List<Observation> observationsBySubmission = dashboardDao.findObservationsBySubmission(submission);
        // Story submissions have a single observation in them
        assert observationsBySubmission.size() == 1;
        entities.addAll(observationsBySubmission);
    }
    Collections.sort(entities, new Comparator<Observation>() {

        @Override
        public int compare(Observation o1, Observation o2) {
            Integer rank1 = o1.getSubmission().getObservationTemplate().getSubmissionStoryRank();
            Integer rank2 = o2.getSubmission().getObservationTemplate().getSubmissionStoryRank();
            return rank1 - rank2;
        }
    });
    /*
        entities.sort(new Comparator<Observation>() {
            @Override
            public int compare(Observation o1, Observation o2) {
                Integer rank1 = o1.getSubmission().getObservationTemplate().getSubmissionStoryRank();
                Integer rank2 = o2.getSubmission().getObservationTemplate().getSubmissionStoryRank();
                return rank1-rank2;
            }
        });
        */
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.serialize(entities.subList(0, Math.min(limit, entities.size()))), 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) ResponseEntity(org.springframework.http.ResponseEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Submission

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

the class RssController method submissionRSS.

@Transactional
@RequestMapping(value = "submissions", method = { RequestMethod.GET, RequestMethod.POST })
public ResponseEntity<String> submissionRSS() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/rss+xml");
    List<Submission> submissions = dashboardDao.findEntities(Submission.class);
    String titlePostfix = "Submissions";
    String rssDescription = "Lates submissions on the CTD^2 Dashboard.";
    String dashboardUrl = context.getScheme() + "://" + context.getServerName() + context.getContextPath() + "/";
    String rssLink = dashboardUrl + "#centers";
    String feedStr = generateFeed(submissions, titlePostfix, rssDescription, rssLink);
    return new ResponseEntity<String>(feedStr, headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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