Search in sources :

Example 6 with ObservationTemplate

use of gov.nih.nci.ctd2.dashboard.model.ObservationTemplate 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;
}
Also used : SyndCategory(com.rometools.rome.feed.synd.SyndCategory) SyndImageImpl(com.rometools.rome.feed.synd.SyndImageImpl) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndImage(com.rometools.rome.feed.synd.SyndImage) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) SyndCategoryImpl(com.rometools.rome.feed.synd.SyndCategoryImpl) SyndContent(com.rometools.rome.feed.synd.SyndContent) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject)

Example 7 with ObservationTemplate

use of gov.nih.nci.ctd2.dashboard.model.ObservationTemplate 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);
    }
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) URLDecoder(java.net.URLDecoder) SubmissionResult(gov.nih.nci.ctd2.dashboard.util.SearchResults.SubmissionResult) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) Date(java.util.Date) HttpHeaders(org.springframework.http.HttpHeaders) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Charset(java.nio.charset.Charset) JSONSerializer(flexjson.JSONSerializer) Log(org.apache.commons.logging.Log) ResponseEntity(org.springframework.http.ResponseEntity) LogFactory(org.apache.commons.logging.LogFactory) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) HttpHeaders(org.springframework.http.HttpHeaders) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) SubmissionResult(gov.nih.nci.ctd2.dashboard.util.SearchResults.SubmissionResult) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) SearchResults(gov.nih.nci.ctd2.dashboard.util.SearchResults) ResponseEntity(org.springframework.http.ResponseEntity) SubmissionResult(gov.nih.nci.ctd2.dashboard.util.SearchResults.SubmissionResult) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) JSONSerializer(flexjson.JSONSerializer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ObservationTemplate

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

the class SubjectResponse method createInstance.

private static SubjectResponse createInstance(final Subject subject, final Filter filter, DashboardDao dashboardDao) {
    int[] tierCount = new int[3];
    Set<Integer> set = new HashSet<Integer>();
    for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
        ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
        String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
        if (filter.rolesIncluded.size() > 0 && !filter.rolesIncluded.contains(subjectRole))
            continue;
        ObservationTemplate observatinoTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
        Integer observationTier = observatinoTemplate.getTier();
        String centerNameBrief = observatinoTemplate.getSubmissionCenter().getStableURL().substring(7);
        if (filter.centerIncluded.size() > 0 && !filter.centerIncluded.contains(centerNameBrief))
            continue;
        if ((Arrays.asList(filter.tiersIncluded).contains(observationTier))) {
            set.add(observedSubject.getObservation().getId());
            tierCount[observationTier.intValue() - 1]++;
            if (filter.limit > 0 && set.size() >= filter.limit) {
                break;
            }
        }
    }
    List<ObservationItem> observations = dashboardDao.findObservationInfo(new ArrayList<Integer>(set));
    Set<String> roles = new TreeSet<String>();
    for (int i = 0; i < observations.size(); i++) {
        for (SubjectItem sub : observations.get(i).subject_list) {
            if (sub.getName().equals(subject.getDisplayName())) {
                roles.add(sub.getRole());
                break;
            }
        }
    }
    String[] uris = observations.stream().map(x -> x.uri).toArray(String[]::new);
    SubjectResponse subjectResponse = new SubjectResponse(subject, uris, roles.toArray(new String[0]), tierCount);
    return subjectResponse;
}
Also used : Arrays(java.util.Arrays) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) Set(java.util.Set) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) Synonym(gov.nih.nci.ctd2.dashboard.model.Synonym) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) TreeSet(java.util.TreeSet) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet)

Example 9 with ObservationTemplate

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

the class DashboardDaoImpl method findObservedEvidenceRole.

@Override
public ObservedEvidenceRole findObservedEvidenceRole(String templateName, String columnName) {
    List<ObservedEvidenceRole> list = new ArrayList<ObservedEvidenceRole>();
    // first grab observation template name
    List<ObservationTemplate> otList = queryWithClass("from ObservationTemplateImpl where displayName = :templateName", "templateName", templateName);
    for (ObservationTemplate ot : otList) {
        List<ObservedEvidenceRole> oerList = query2ParamsWithClass("from ObservedEvidenceRoleImpl as oer where columnName = :columnName and " + "oer.observationTemplate = :ot", "columnName", columnName, "ot", ot);
        for (ObservedEvidenceRole o : oerList) {
            list.add(o);
        }
    }
    assert list.size() <= 1;
    return (list.size() == 1) ? list.iterator().next() : null;
}
Also used : ArrayList(java.util.ArrayList) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedEvidenceRole(gov.nih.nci.ctd2.dashboard.model.ObservedEvidenceRole)

Example 10 with ObservationTemplate

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

the class DashboardDaoImpl method findSubmissionByIsStory.

@Override
public List<Submission> findSubmissionByIsStory(boolean isSubmissionStory, boolean sortByPriority) {
    List<ObservationTemplate> tmpList1 = queryWithClass("from ObservationTemplateImpl where isSubmissionStory = :iss order by submissionStoryRank desc", "iss", isSubmissionStory);
    List<ObservationTemplate> tmpList2 = queryWithClass("from ObservationTemplateImpl where isSubmissionStory = :iss", "iss", isSubmissionStory);
    List<ObservationTemplate> tmpList = sortByPriority ? tmpList1 : tmpList2;
    List<Submission> list = new ArrayList<Submission>();
    for (ObservationTemplate o : tmpList) {
        list.addAll(findSubmissionByObservationTemplate(o));
    }
    return list;
}
Also used : Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ArrayList(java.util.ArrayList)

Aggregations

ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)12 ArrayList (java.util.ArrayList)8 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)6 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)5 ObservedSubjectRole (gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole)5 HashSet (java.util.HashSet)5 ObservedEvidenceRole (gov.nih.nci.ctd2.dashboard.model.ObservedEvidenceRole)4 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)4 HashMap (java.util.HashMap)4 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)3 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)3 SubmissionCenter (gov.nih.nci.ctd2.dashboard.model.SubmissionCenter)3 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)3 List (java.util.List)3 Set (java.util.Set)3 Log (org.apache.commons.logging.Log)3 LogFactory (org.apache.commons.logging.LogFactory)3 ECOTerm (gov.nih.nci.ctd2.dashboard.model.ECOTerm)2 SubjectRole (gov.nih.nci.ctd2.dashboard.model.SubjectRole)2 Synonym (gov.nih.nci.ctd2.dashboard.model.Synonym)2