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());
}
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations