use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class SubjectScorer method scoreAllRoles.
@Transactional
public void scoreAllRoles() {
log.info("Removing all role-based scores...");
List<SubjectWithSummaries> oldEntities = dashboardDao.findEntities(SubjectWithSummaries.class);
for (SubjectWithSummaries subjectWithSummaries : oldEntities) {
dashboardDao.delete(subjectWithSummaries);
}
log.info("Removed " + oldEntities.size() + " old scores.");
log.info("Re-scoring all roles...");
List<SubjectWithSummaries> subjectWithSummariesList = new ArrayList<SubjectWithSummaries>();
List<SubjectRole> entities = dashboardDao.findEntities(SubjectRole.class);
for (SubjectRole subjectRole : entities) {
String keyword = subjectRole.getDisplayName();
log.info("Scoring subject with role: " + keyword);
HashMap<Subject, SubjectWithSummaries> subjectToSummaries = new HashMap<Subject, SubjectWithSummaries>();
HashMap<Subject, HashSet<SubmissionCenter>> subjectToCenters = new HashMap<Subject, HashSet<SubmissionCenter>>();
HashMap<Subject, HashMap<SubmissionCenter, Integer>> centerBasedScores = new HashMap<Subject, HashMap<SubmissionCenter, Integer>>();
for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectByRole(keyword)) {
Subject subject = observedSubject.getSubject();
SubjectWithSummaries withSummaries = subjectToSummaries.get(subject);
ObservationTemplate observationTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
SubmissionCenter submissionCenter = observationTemplate.getSubmissionCenter();
Integer tier = observationTemplate.getTier();
if (withSummaries == null) {
withSummaries = new SubjectWithSummaries();
withSummaries.setRole(keyword);
withSummaries.setSubject(subject);
withSummaries.setMaxTier(tier);
withSummaries.setNumberOfObservations(1);
HashSet<SubmissionCenter> centers = new HashSet<SubmissionCenter>();
centers.add(submissionCenter);
withSummaries.setNumberOfSubmissionCenters(1);
withSummaries.addSubmission(tier, submissionCenter.getId());
subjectToCenters.put(subject, centers);
subjectToSummaries.put(subject, withSummaries);
HashMap<SubmissionCenter, Integer> cScores = new HashMap<>();
cScores.put(submissionCenter, tier);
centerBasedScores.put(subject, cScores);
} else {
withSummaries.setMaxTier(Math.max(withSummaries.getMaxTier(), tier));
withSummaries.setNumberOfObservations(withSummaries.getNumberOfObservations() + 1);
HashSet<SubmissionCenter> submissionCenters = subjectToCenters.get(subject);
submissionCenters.add(submissionCenter);
withSummaries.setNumberOfSubmissionCenters(submissionCenters.size());
withSummaries.addSubmission(tier, submissionCenter.getId());
HashMap<SubmissionCenter, Integer> cScores = centerBasedScores.get(subject);
Integer previousScore = cScores.get(submissionCenter);
cScores.put(submissionCenter, previousScore == null ? tier : Math.max(tier, previousScore));
}
}
Collection<SubjectWithSummaries> perRole = subjectToSummaries.values();
for (SubjectWithSummaries subjectWithSummaries : perRole) {
Integer totalScore = 0;
for (Integer aScore : centerBasedScores.get(subjectWithSummaries.getSubject()).values()) {
totalScore += aScore;
}
subjectWithSummaries.setScore(totalScore);
}
subjectWithSummariesList.addAll(perRole);
log.info("Done scoring role: " + keyword);
}
dashboardDao.batchSave(subjectWithSummariesList, 0);
log.info("Done scoring all roles...");
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class WordCloudController method getSubjectCounts.
@Transactional
@RequestMapping(method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubjectCounts() {
log.debug("request received");
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
WordCloudEntry[] words = dashboardDao.getSubjectCounts();
JSONSerializer jsonSerializer = new JSONSerializer().exclude("class");
String json = "{}";
try {
json = jsonSerializer.deepSerialize(words);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
log.debug("get subject counts");
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class RssController method generateFeed.
private String generateFeed(List<? extends DashboardEntity> dashboardEntities, String rssTitlePostfix, String rssDescription, String rssLink) {
String dashboardUrl = context.getScheme() + "://" + context.getServerName() + context.getContextPath() + "/";
// Set the stage and define metadata on the RSS feed
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setTitle("CTD^2 Dashboard - " + rssTitlePostfix);
feed.setDescription(rssDescription);
feed.setLink(rssLink);
// We will have two major categories: Subject and Submission
// and will have subcategories of Subject for each particular subject
List<SyndCategory> categories = new ArrayList<SyndCategory>();
SyndCategory subjectCategory = new SyndCategoryImpl();
subjectCategory.setName("Subject");
categories.add(subjectCategory);
SyndCategory submissionCategory = new SyndCategoryImpl();
submissionCategory.setName("Submission");
categories.add(submissionCategory);
feed.setCategories(categories);
feed.setLanguage("en");
feed.setManagingEditor("ocg@mail.nih.gov (CTD^2 Network)");
SyndImage feedImg = new SyndImageImpl();
feedImg.setTitle("CTD^2 Logo");
feedImg.setUrl(dashboardUrl + "img/logos/ctd2_overall.png");
feedImg.setLink(dashboardUrl);
feed.setImage(feedImg);
// And prepare the items to be put into the RSS
List<SyndEntry> rssItems = new ArrayList<SyndEntry>();
for (DashboardEntity entity : dashboardEntities) {
if (entity instanceof Subject) {
Subject subject = (Subject) entity;
// Collect all role & submission pairs for this particular subject
Map<Submission, Set<String>> roleMap = new HashMap<Submission, Set<String>>();
Map<Submission, Set<ObservedSubject>> osMap = new HashMap<Submission, Set<ObservedSubject>>();
List<ObservedSubject> sObservations = dashboardDao.findObservedSubjectBySubject((Subject) entity);
for (ObservedSubject sObservation : sObservations) {
String role = sObservation.getObservedSubjectRole().getSubjectRole().getDisplayName();
Submission submission = sObservation.getObservation().getSubmission();
Set<String> roles = roleMap.get(submission);
if (roles == null) {
roles = new HashSet<String>();
roleMap.put(submission, roles);
}
roles.add(role);
Set<ObservedSubject> oses = osMap.get(submission);
if (oses == null) {
oses = new HashSet<ObservedSubject>();
osMap.put(submission, oses);
}
oses.add(sObservation);
}
// These will always belong to "Subject"
List<SyndCategory> sCategories = new ArrayList<SyndCategory>();
sCategories.add(subjectCategory);
// and "Subject/<name>" categories
SyndCategory sCategory = new SyndCategoryImpl();
sCategory.setName(subjectCategory.getName() + "/" + entity.getDisplayName());
categories.add(sCategory);
// Also add this specific category to the global list
sCategories.add(sCategory);
// And now combine this information into individual items around submissions/subject
for (Submission submission : roleMap.keySet()) {
Set<String> roles = roleMap.get(submission);
assert roles != null;
Set<ObservedSubject> oses = osMap.get(submission);
assert oses != null;
SyndEntry item = new SyndEntryImpl();
item.setCategories(sCategories);
// Construct title
ObservationTemplate observationTemplate = submission.getObservationTemplate();
String description = observationTemplate.getDescription();
Integer tier = observationTemplate.getTier();
String combinedRoles = StringUtils.join(roles, ", ");
String name = subject.getDisplayName();
int noOfObservations = oses.size();
StringBuilder title = new StringBuilder();
title.append("Role '").append(combinedRoles).append("'").append(": ").append(description).append(" ").append("(").append("Tier ").append(tier).append(" - ").append(noOfObservations).append(" ").append(noOfObservations > 1 ? "observations" : "observation").append(" on ").append(name).append(")");
item.setTitle(title.toString());
String centerName = observationTemplate.getSubmissionCenter().getDisplayName();
item.setAuthor(centerName);
item.setPublishedDate(submission.getSubmissionDate());
String submissionDescription = observationTemplate.getSubmissionDescription();
StringBuilder itemDescStr = new StringBuilder();
itemDescStr.append("<b>Project</b>: ").append(observationTemplate.getProject()).append("<br />");
if (submissionDescription != null && !submissionDescription.isEmpty()) {
itemDescStr.append("<b>Summary</b>: ").append(submissionDescription);
}
SyndContent itemDesc = new SyndContentImpl();
itemDesc.setType("text/html");
itemDesc.setValue(itemDescStr.toString());
item.setDescription(itemDesc);
// Create a link to the subject page with filters enabled
item.setLink(dashboardUrl + "#subject/" + subject.getId() + "/" + combinedRoles + "/" + tier);
item.setUri(String.format("#ctd2#subject#%s#%d", name, title.hashCode() & Integer.MAX_VALUE));
rssItems.add(item);
}
// End of subject-centered items
} else if (entity instanceof Submission) {
Submission submission = (Submission) entity;
SyndEntry item = new SyndEntryImpl();
ObservationTemplate observationTemplate = submission.getObservationTemplate();
int noOfObservations = dashboardDao.findObservationsBySubmission(submission).size();
StringBuilder title = new StringBuilder();
Boolean isStory = observationTemplate.getIsSubmissionStory();
title.append(isStory ? "Story" : "Submission").append(": ");
title.append(observationTemplate.getDescription().replaceAll("\\.$", "")).append(" (").append("Tier ").append(observationTemplate.getTier()).append(" - ").append(noOfObservations).append(" ").append(noOfObservations > 1 ? "observations" : "observation").append(")");
item.setTitle(title.toString());
String submissionDescription = observationTemplate.getSubmissionDescription();
StringBuilder itemDescStr = new StringBuilder();
itemDescStr.append("<b>Project</b>: ").append(observationTemplate.getProject()).append("<br />");
if (submissionDescription != null && !submissionDescription.isEmpty()) {
itemDescStr.append("<b>Summary</b>: ").append(submissionDescription);
}
SyndContent itemDesc = new SyndContentImpl();
itemDesc.setType("text/html");
itemDesc.setValue(itemDescStr.toString());
item.setDescription(itemDesc);
item.setPublishedDate(submission.getSubmissionDate());
String centerName = observationTemplate.getSubmissionCenter().getDisplayName();
item.setAuthor(centerName);
item.setLink(dashboardUrl + "#submission/" + submission.getId());
item.setUri(String.format("ctd2#submission#%d", title.hashCode() & Integer.MAX_VALUE));
rssItems.add(item);
}
// End of submission item(s)
}
// Add all items into the feed
feed.setEntries(rssItems);
// And print the XML/RSS version out
SyndFeedOutput feedOutput = new SyndFeedOutput();
String feedStr = null;
try {
feedStr = feedOutput.outputString(feed, true);
} catch (FeedException e) {
e.printStackTrace();
}
return feedStr;
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class JSONController method getEntityInJson.
@Transactional
@RequestMapping(value = "{type}/{id}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getEntityInJson(@PathVariable String type, @PathVariable String id) {
DashboardEntity entityById = null;
Class<? extends DashboardEntity> clazz = Subject.class;
if (type.equalsIgnoreCase("subject")) {
clazz = Subject.class;
} else if (type.equals("observedsubject")) {
clazz = ObservedSubject.class;
}
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
log.debug("JSONController " + type + " " + id);
if (typesWithStableURL.contains(type)) {
String stableURL = type + "/" + id;
if (type.equals("observedevidence"))
stableURL = "mra/" + id;
entityById = dashboardDao.getEntityByStableURL(type, stableURL);
} else {
entityById = dashboardDao.getEntityById(clazz, Integer.parseInt(id));
}
if (entityById == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
return new ResponseEntity<String>(jsonSerializer.deepSerialize(entityById), headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.model.Subject in project nci-ctd2-dashboard by CBIIT.
the class OntologySearchController method searchExtraSubmissions.
@RequestMapping(value = "extra-submissions", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> searchExtraSubmissions(@RequestParam("subject-name") String subjectName) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
try {
List<SubmissionResult> submission_result = dashboardDao.getSubmissionsForSubjectName(subjectName).stream().map(submission -> {
ObservationTemplate template = submission.getObservationTemplate();
return new SearchResults.SubmissionResult(submission.getStableURL(), submission.getSubmissionDate(), template.getDescription(), template.getTier(), template.getSubmissionCenter().getDisplayName(), submission.getId(), dashboardDao.findObservationsBySubmission(submission).size(), template.getIsSubmissionStory());
}).collect(Collectors.toList());
JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
return new ResponseEntity<String>(jsonSerializer.deepSerialize(submission_result), headers, HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
}
Aggregations