Search in sources :

Example 1 with DashboardEntity

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

the class TissueSampleDataWriter method execute.

public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception {
    ArrayList<DashboardEntity> entities = new ArrayList<DashboardEntity>();
    for (TissueSample tissueSample : tissueSampleMap.values()) {
        String nciThesaurusId = getNCIThesaurusID(tissueSample);
        String stableURL = new StableURL().createURLWithPrefix("tissue", nciThesaurusId);
        tissueSample.setStableURL(stableURL);
        entities.add(tissueSample);
    }
    dashboardDao.batchSave(entities, batchSize);
    return RepeatStatus.FINISHED;
}
Also used : StableURL(gov.nih.nci.ctd2.dashboard.util.StableURL)

Example 2 with DashboardEntity

use of gov.nih.nci.ctd2.dashboard.model.DashboardEntity 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 3 with DashboardEntity

use of gov.nih.nci.ctd2.dashboard.model.DashboardEntity 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 4 with DashboardEntity

use of gov.nih.nci.ctd2.dashboard.model.DashboardEntity 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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with DashboardEntity

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

the class ListController method getSearchResultsInJson.

@Transactional
@RequestMapping(value = "{type}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getSearchResultsInJson(@PathVariable String type, @RequestParam(value = "filterBy", required = false) Integer filterBy, @RequestParam(value = "getAll", required = false, defaultValue = "false") Boolean getAll) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    List<? extends DashboardEntity> entities = webServiceUtil.getDashboardEntities(type, filterBy);
    if (!getAll && entities.size() > getMaxNumberOfEntities()) {
        entities = entities.subList(0, getMaxNumberOfEntities());
    }
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.serialize(entities), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)8 ArrayList (java.util.ArrayList)7 HttpHeaders (org.springframework.http.HttpHeaders)7 ResponseEntity (org.springframework.http.ResponseEntity)7 Transactional (org.springframework.transaction.annotation.Transactional)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 JSONSerializer (flexjson.JSONSerializer)6 DateTransformer (gov.nih.nci.ctd2.dashboard.util.DateTransformer)4 ImplTransformer (gov.nih.nci.ctd2.dashboard.util.ImplTransformer)4 StableURL (gov.nih.nci.ctd2.dashboard.util.StableURL)4 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)3 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)3 SubjectResponse (gov.nih.nci.ctd2.dashboard.api.SubjectResponse)2 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)2 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)2 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)2 SubjectResult (gov.nih.nci.ctd2.dashboard.util.SubjectResult)2 HashSet (java.util.HashSet)2 SyndCategory (com.rometools.rome.feed.synd.SyndCategory)1 SyndCategoryImpl (com.rometools.rome.feed.synd.SyndCategoryImpl)1