Search in sources :

Example 1 with MapperException

use of com.sdicons.json.mapper.MapperException in project Gemma by PavlidisLab.

the class AssayViewTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    StringBuilder buf = new StringBuilder();
    buf.append("<div>");
    // create table
    Map<BioMaterialValueObject, Map<ArrayDesignValueObject, Collection<BioAssayValueObject>>> bioAssayMap = new HashMap<>();
    Set<ArrayDesignValueObject> designs = new HashSet<>();
    Map<ArrayDesignValueObject, Long> arrayMaterialCount = new HashMap<>();
    // package all of this information into JSON for javascript dynamic retrieval
    Map<String, String> assayToMaterial = new HashMap<>();
    for (BioAssayValueObject assay : bioAssays) {
        // map for bioassays linked to a specific arraydesign
        // map for the bioassays linked to a specific biomaterial
        BioMaterialValueObject material = assay.getSample();
        ArrayDesignValueObject design = assay.getArrayDesign();
        designs.add(design);
        // check if the assay list is initialized yet
        Map<ArrayDesignValueObject, Collection<BioAssayValueObject>> assayMap;
        if (bioAssayMap.containsKey(material)) {
            assayMap = bioAssayMap.get(material);
        } else {
            assayMap = new HashMap<>();
            bioAssayMap.put(material, assayMap);
        }
        if (assayMap.containsKey(design)) {
            assayMap.get(design).add(assay);
        } else {
            Collection<BioAssayValueObject> assayList = new ArrayList<>();
            assayList.add(assay);
            assayMap.put(design, assayList);
        }
        if (arrayMaterialCount.containsKey(design)) {
            Long count = arrayMaterialCount.get(design);
            count++;
            arrayMaterialCount.put(design, count);
        } else {
            Long count = new Long(1);
            arrayMaterialCount.put(design, count);
        }
    }
    int materialCount = bioAssayMap.keySet().size();
    buf.append("<table class='detail row-separated odd-gray'><tr>");
    buf.append("<th>" + materialCount + " BioMaterials</th>");
    // display arraydesigns
    for (ArrayDesignValueObject design : designs) {
        Long count = arrayMaterialCount.get(design);
        buf.append("<th>" + count + " BioAssays on<br /><a target='_blank' href=\"" + Settings.getRootContext() + "/arrays/showArrayDesign.html?id=" + design.getId() + "\" title=\"" + design.getName() + "\" >" + (design.getShortName() == null ? design.getName() : design.getShortName()) + "</a></th>");
    }
    buf.append("</tr>");
    // display bioMaterials and the corresponding bioAssays
    int count = 1;
    Iterator<BioMaterialValueObject> iter = bioAssayMap.keySet().iterator();
    List<BioMaterialValueObject> materials = new ArrayList<>();
    while (iter.hasNext()) {
        materials.add(iter.next());
    }
    Comparator<BioMaterialValueObject> comparator = new BioMaterialComparator();
    Collections.sort(materials, comparator);
    int elementCount = 1;
    int emptyCount = 0;
    for (BioMaterialValueObject material : materials) {
        if (count % 2 == 0) {
            buf.append("<tr class='even' align=justify>");
        } else {
            buf.append("<tr class='odd' align=justify>");
        }
        String bmLink = "<a href='" + Settings.getRootContext() + "/bioMaterial/showBioMaterial.html?id=" + material.getId() + "'> " + material.getName() + "</a>";
        buf.append("<td>" + bmLink + "</td>");
        Map<ArrayDesignValueObject, Collection<BioAssayValueObject>> assayMap = bioAssayMap.get(material);
        String image = "&nbsp;&nbsp;&nbsp;<img height=16 width=16 src='" + Settings.getRootContext() + "/images/icons/arrow_switch.png' />&nbsp;&nbsp;&nbsp;";
        for (ArrayDesignValueObject design : designs) {
            if (assayMap.containsKey(design)) {
                Collection<BioAssayValueObject> assays = assayMap.get(design);
                Collection<Long> ids = new ArrayList<>();
                Collection<String> tooltips = new ArrayList<>();
                for (BioAssayValueObject assay : assays) {
                    ids.add(assay.getId());
                    tooltips.add(StringUtils.abbreviate(assay.getName() + assay.getDescription(), 120));
                    this.addMaterial(assayToMaterial, assay.getId(), material.getId());
                }
                if (assayMap.get(design).size() > 1) {
                    String link = "<a title='" + StringUtils.join(tooltips.toArray(), "\n") + "' href='" + Settings.getRootContext() + "/bioAssay/showAllBioAssays.html?id=" + StringUtils.join(ids.toArray(), ",") + "'> (list) </a>";
                    buf.append("<td>" + assayMap.get(design).size() + link + "&nbsp;" + elementCount + "</td>\n");
                } else {
                    /*
                         * Each bioassay has a unique id; the div it sits in is identified by the class 'dragitem'. See
                         * expressionExperiment.edit.jsp.
                         */
                    BioAssayValueObject assay = ((List<BioAssayValueObject>) assayMap.get(design)).get(0);
                    String shortDesc = StringUtils.abbreviate(assay.getDescription(), 60);
                    String link = "<a target=\"_blank\" title='" + shortDesc + "' href='" + Settings.getRootContext() + "/bioAssay/showBioAssay.html?id=" + assay.getId() + "'>" + assay.getName() + "</a>";
                    String editAttributes = " align='left' class='dragItem' id='bioassay." + assay.getId() + "' material='" + material.getId() + "' assay='" + assay.getId() + "' arrayDesign='" + design.getId() + "'";
                    if (edit && designs.size() > 1) {
                        buf.append("\n<td><span " + editAttributes + ">" + image + link);
                    } else {
                        buf.append("\n<td ><span>" + link + "&nbsp;");
                    }
                    buf.append("</span></td>\n");
                }
            } else {
                emptyCount = addEmpty(buf, assayToMaterial, emptyCount, material, image, design);
            }
        }
        buf.append("</tr>");
        count++;
        elementCount++;
    }
    // add a few blanks, but only if we are editing.
    if (edit) {
        addNovelBiomaterialSlots(buf, designs, assayToMaterial, count, emptyCount);
    }
    buf.append("</table>");
    if (edit) {
        // append JSON serialization
        try {
            String jsonSerialization = JSONMapper.toJSON(assayToMaterial).render(false);
            buf.append("<input type='hidden' id='assayToMaterialMap' name='assayToMaterialMap' value='" + jsonSerialization + "'/>");
        } catch (MapperException e) {
        // cannot serialize
        }
    }
    buf.append("</div>");
    try {
        pageContext.getOut().print(buf.toString());
    } catch (Exception ex) {
        throw new JspException("assayViewTag: " + ex.getMessage());
    }
    return SKIP_BODY;
}
Also used : JspException(javax.servlet.jsp.JspException) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) MapperException(com.sdicons.json.mapper.MapperException) MapperException(com.sdicons.json.mapper.MapperException) JspException(javax.servlet.jsp.JspException) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject)

Example 2 with MapperException

use of com.sdicons.json.mapper.MapperException in project Gemma by PavlidisLab.

the class JSONTableRenderer method render.

public String render(List<Object> tableObjects) {
    try {
        StringBuilder b = new StringBuilder();
        for (Object o : tableObjects) {
            JSONValue v;
            v = JSONMapper.toJSON(o);
            b.append(v.render(true));
        }
        return b.toString();
    } catch (MapperException e) {
        throw new RuntimeException(e);
    }
}
Also used : JSONValue(com.sdicons.json.model.JSONValue) MapperException(com.sdicons.json.mapper.MapperException)

Aggregations

MapperException (com.sdicons.json.mapper.MapperException)2 JSONValue (com.sdicons.json.model.JSONValue)1 JspException (javax.servlet.jsp.JspException)1 ArrayDesignValueObject (ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject)1 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)1 BioMaterialValueObject (ubic.gemma.model.expression.biomaterial.BioMaterialValueObject)1