Search in sources :

Example 1 with SubstancePublicName

use of ambit2.base.data.substance.SubstancePublicName in project ambit-mirror by ideaconsult.

the class SubstanceByOwnerResource method createQuery.

@Override
protected Q createQuery(Context context, Request request, Response response) throws ResourceException {
    Object owneruuid = request.getAttributes().get(OwnerSubstanceFacetResource.idowner);
    ReadSubstanceByOwner q = new ReadSubstanceByOwner(ReadSubstanceByOwner._ownersearchmode.owner_uuid, owneruuid.toString()) {

        /**
         */
        private static final long serialVersionUID = 6003910893547753024L;

        public ambit2.base.data.SubstanceRecord getObject(java.sql.ResultSet rs) throws AmbitException {
            ambit2.base.data.SubstanceRecord record = super.getObject(rs);
            record.setRecordProperty(new SubstancePublicName(), record.getPublicName());
            record.setRecordProperty(new SubstanceName(), record.getSubstanceName());
            record.setRecordProperty(new SubstanceUUID(), record.getSubstanceUUID());
            record.setRecordProperty(new SubstanceOwner(), record.getOwnerName());
            return record;
        }
    };
    return (Q) q;
}
Also used : SubstanceName(ambit2.base.data.substance.SubstanceName) SubstanceOwner(ambit2.base.data.substance.SubstanceOwner) SubstanceUUID(ambit2.base.data.substance.SubstanceUUID) SubstanceRecord(ambit2.base.data.SubstanceRecord) ReadSubstanceByOwner(ambit2.db.substance.ReadSubstanceByOwner) SubstancePublicName(ambit2.base.data.substance.SubstancePublicName)

Example 2 with SubstancePublicName

use of ambit2.base.data.substance.SubstancePublicName in project ambit-mirror by ideaconsult.

the class StructureRecordXLSXReporter method processItem.

@Override
public Object processItem(IStructureRecord item) throws Exception {
    Row row = sheet.createRow(rowIndex);
    row.setHeightInPoints(new Float(d.getHeight() + 2 * offset));
    int r = 0;
    if (item instanceof SubstanceRecord) {
        SubstanceRecord record = (SubstanceRecord) item;
        Cell cell = row.createCell(_columns.tag.ordinal());
        cell.setCellType(CellType.NUMERIC);
        cell.setCellStyle(style);
        cell.setCellValue(rowIndex);
        cell = row.createCell(_columns.name.ordinal());
        cell.setCellType(CellType.STRING);
        cell.setCellStyle(style);
        try {
            Object name = record.getRecordProperty(new SubstancePublicName());
            cell.setCellValue(name == null ? record.getRecordProperty(new SubstanceName()).toString() : name.toString());
        } catch (Exception x) {
        }
        for (Property p : record.getRecordProperties()) if (p.getLabel().startsWith(prefix)) {
            Integer colIndex = mergedProperties.get(p.getLabel());
            if (colIndex == null) {
                int last = mergedProperties.size();
                mergedProperties.put(p.getLabel(), last);
                colIndex = last;
            }
            Cell pcell = row.getCell(colIndex + _columns.component.ordinal() + 1);
            if (pcell == null) {
                pcell = row.createCell(colIndex + _columns.component.ordinal() + 1);
                pcell.setCellStyle(blueStyle);
                pcell.setCellType(CellType.STRING);
                Cell hcell = sheet.getRow(0).createCell(colIndex + _columns.component.ordinal() + 1);
                hcell.setCellType(CellType.STRING);
                hcell.setCellStyle(hstyle);
                String h = p.getLabel().replace(prefix, "");
                try {
                    Protocol._categories c = Protocol._categories.valueOf(h + "_SECTION");
                    hcell.setCellValue(c.getNumber() + ". " + c.toString());
                } catch (Exception x) {
                    hcell.setCellValue(h);
                }
                if (isAutosizeColumns())
                    sheet.autoSizeColumn(hcell.getColumnIndex(), true);
                sheet.setColumnHidden(hcell.getColumnIndex(), false);
            }
            Object value = record.getRecordProperty(p);
            try {
                String cellvalue = formatter.format((SubstanceProperty) p, value);
                if (cellvalue == null || "".equals(cellvalue.trim())) {
                // do nothing
                } else {
                    _r_flags studyResultType = ((SubstanceProperty) p).getStudyResultType();
                    String flag = "";
                    Font font = redFont;
                    if (studyResultType != null)
                        switch(studyResultType) {
                            case experimentalresult:
                                {
                                    font = blueFont;
                                    break;
                                }
                            case other:
                                {
                                    font = blackFont;
                                    break;
                                }
                            case unsupported:
                                {
                                    font = blackFont;
                                    break;
                                }
                            case NOTSPECIFIED:
                                {
                                    font = blackFont;
                                    break;
                                }
                            case nodata:
                                {
                                    font = blackFont;
                                    break;
                                }
                            default:
                                {
                                    font = redFont;
                                    flag = studyResultType.getIdentifier() + ": ";
                                }
                        }
                    RichTextString rtvalue = pcell.getRichStringCellValue();
                    if (rtvalue == null || rtvalue.length() == 0 || "".equals(rtvalue.getString().trim())) {
                        pcell.setCellValue(createRichTextString(flag + cellvalue, font));
                    } else {
                        if (rtvalue instanceof XSSFRichTextString) {
                            ((XSSFRichTextString) rtvalue).append("\n" + flag + cellvalue, (XSSFFont) font);
                        } else {
                            pcell.setCellValue(createRichTextString(pcell.getStringCellValue() + "\n" + flag + cellvalue, font));
                        }
                    }
                    if (isAutosizeColumns())
                        sheet.autoSizeColumn(pcell.getColumnIndex(), true);
                }
            } catch (Exception x) {
                if (value instanceof IValue) {
                    value = p.getName() + "=" + ((IValue) value).toHumanReadable() + ((p.getUnits() != null) ? p.getUnits() : "") + (p.getReference().getURL() != null ? ("[" + p.getReference().getURL() + "]") : "");
                } else if (value instanceof MultiValue) {
                    StringBuilder b = new StringBuilder();
                    for (int i = 0; i < ((MultiValue) value).size(); i++) {
                        if (i > 0)
                            b.append("\n");
                        b.append(p.getName());
                        b.append("=");
                        b.append(((IValue) ((MultiValue) value).get(i)).toHumanReadable());
                        if (p.getUnits() != null)
                            b.append(p.getUnits());
                    }
                    if (p.getReference().getURL() != null) {
                        b.append(" [");
                        b.append(p.getReference().getURL());
                        b.append("]");
                    }
                    value = b.toString();
                } else {
                    value = p.getName() + "=" + value.toString() + ((p.getUnits() != null) ? p.getUnits() : "") + (p.getReference().getURL() != null ? ("[" + p.getReference().getURL() + "]") : "");
                }
                pcell.setCellValue(String.format("%s%s%s", pcell.getStringCellValue() == null ? "" : pcell.getStringCellValue(), pcell.getStringCellValue() == null ? "" : "\n", value.toString()));
            }
        }
        // 
        if (record.getRelatedStructures() != null) {
            for (CompositionRelation relation : record.getRelatedStructures()) {
                Row structure = (r == 0) ? row : sheet.createRow((short) (rowIndex + r));
                try {
                    structure.setHeightInPoints(new Float(d.getHeight() + 2 * offset));
                    addPicture(relation.getSecondStructure(), structure.getRowNum(), _columns.diagram.ordinal());
                } catch (Exception x) {
                    x.printStackTrace();
                }
                Cell cellStruc = structure.createCell(_columns.component.ordinal());
                cellStruc.setCellStyle(style);
                cellStruc.setCellValue(relation.getRelationType().toHumanReadable());
                r++;
            }
        }
    }
    if (r > 1) {
        for (int c = 0; c < mergedProperties.size(); c++) {
            sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex + r - 1, c + _columns.component.ordinal() + 1, c + _columns.component.ordinal() + 1));
        }
        rowIndex += r;
    } else
        rowIndex++;
    return item;
}
Also used : SubstanceName(ambit2.base.data.substance.SubstanceName) SubstanceRecord(ambit2.base.data.SubstanceRecord) RichTextString(org.apache.poi.ss.usermodel.RichTextString) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) IOException(java.io.IOException) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) Font(org.apache.poi.ss.usermodel.Font) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) IValue(ambit2.base.data.study.IValue) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) ReliabilityParams._r_flags(ambit2.base.data.study.ReliabilityParams._r_flags) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell) Property(ambit2.base.data.Property) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) SubstancePublicName(ambit2.base.data.substance.SubstancePublicName) MultiValue(ambit2.base.data.study.MultiValue) CompositionRelation(ambit2.base.relation.composition.CompositionRelation)

Example 3 with SubstancePublicName

use of ambit2.base.data.substance.SubstancePublicName in project ambit-mirror by ideaconsult.

the class SubstanceDatasetResource method createXLSXReporter.

protected IProcessor<Q, Representation> createXLSXReporter(MediaType media, boolean hssf, String filenamePrefix) {
    groupProperties.add(new SubstancePublicName());
    groupProperties.add(new SubstanceName());
    groupProperties.add(new SubstanceUUID());
    groupProperties.add(new SubstanceOwner());
    String jsonpcallback = getParams().getFirstValue("jsonp");
    if (jsonpcallback == null)
        jsonpcallback = getParams().getFirstValue("callback");
    String configResource = String.format("config-%s.js", ((IFreeMarkerApplication) getApplication()).getProfile());
    return new OutputStreamConvertor(new StructureRecordXLSXReporter(getRequest().getRootRef().toString(), hssf, getTemplate(), getGroupProperties(), getBundles(), null, true, configResource) {

        @Override
        protected void configurePropertyProcessors() {
            getCompositionProcessors(getProcessors());
            getProcessors().add(getPropertyProcessors(false, false));
        }

        @Override
        protected void initColumns(int afterCol) {
            for (I5_ROOT_OBJECTS section : I5_ROOT_OBJECTS.values()) {
                if (section.isIUCLID5() && section.isScientificPart() && section.isSupported() && !section.isNanoMaterialTemplate()) {
                    int last = mergedProperties.size();
                    mergedProperties.put("http://www.opentox.org/echaEndpoints.owl#" + section.name(), last);
                    Cell hcell = sheet.getRow(0).createCell(last + afterCol);
                    hcell.setCellStyle(hstyle);
                    hcell.setCellType(CellType.STRING);
                    hcell.setCellValue(section.getNumber() + ". " + section.getTitle());
                    sheet.autoSizeColumn(hcell.getColumnIndex(), true);
                    // initially hide all columns, unhide if data is added
                    // to
                    sheet.setColumnHidden(hcell.getColumnIndex(), true);
                }
            }
        }
    }, media, filenamePrefix);
}
Also used : SubstanceName(ambit2.base.data.substance.SubstanceName) OutputStreamConvertor(ambit2.rest.OutputStreamConvertor) SubstanceOwner(ambit2.base.data.substance.SubstanceOwner) SubstanceUUID(ambit2.base.data.substance.SubstanceUUID) I5_ROOT_OBJECTS(net.idea.i5.io.I5_ROOT_OBJECTS) StructureRecordXLSXReporter(ambit2.db.reporters.xlsx.StructureRecordXLSXReporter) Cell(org.apache.poi.ss.usermodel.Cell) SubstancePublicName(ambit2.base.data.substance.SubstancePublicName)

Example 4 with SubstancePublicName

use of ambit2.base.data.substance.SubstancePublicName in project ambit-mirror by ideaconsult.

the class SubstanceDatasetResource method createCSVReporter.

protected IProcessor<Q, Representation> createCSVReporter(String filenamePrefix) {
    groupProperties.add(new SubstancePublicName());
    groupProperties.add(new SubstanceName());
    groupProperties.add(new SubstanceUUID());
    groupProperties.add(new SubstanceOwner());
    CSVReporter csvreporter = new CSVReporter(getRequest().getRootRef().toString(), getTemplate(), groupProperties, String.format("%s%s", getRequest().getRootRef(), "")) {

        @Override
        protected void configurePropertyProcessors() {
            getProcessors().add(getPropertyProcessors(false, false));
        }
    };
    try {
        Form form = getParams();
        csvreporter.setNumberofHeaderLines(Integer.parseInt(form.getFirstValue("headerlines")));
    } catch (Exception x) {
        csvreporter.setNumberofHeaderLines(3);
    }
    return new OutputWriterConvertor<SubstanceRecord, Q>(csvreporter, MediaType.TEXT_CSV, filenamePrefix);
}
Also used : SubstanceName(ambit2.base.data.substance.SubstanceName) SubstanceOwner(ambit2.base.data.substance.SubstanceOwner) SubstanceUUID(ambit2.base.data.substance.SubstanceUUID) Form(org.restlet.data.Form) OutputWriterConvertor(net.idea.restnet.db.convertors.OutputWriterConvertor) CSVReporter(ambit2.db.reporters.CSVReporter) SubstancePublicName(ambit2.base.data.substance.SubstancePublicName) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException)

Example 5 with SubstancePublicName

use of ambit2.base.data.substance.SubstancePublicName in project ambit-mirror by ideaconsult.

the class SubstanceDatasetResource method createRDFReporter.

protected IProcessor<Q, Representation> createRDFReporter(MediaType media, String filenamePrefix) {
    groupProperties.add(new SubstancePublicName());
    groupProperties.add(new SubstanceName());
    groupProperties.add(new SubstanceUUID());
    groupProperties.add(new SubstanceOwner());
    DatasetRDFReporter reporter = new DatasetRDFReporter(getRequest(), media, getTemplate(), getGroupProperties()) {

        @Override
        protected boolean acceptProperty(Property p) {
            return true;
        }

        @Override
        protected void configurePropertyProcessors() {
            getProcessors().add(getPropertyProcessors(false, false));
        }
    };
    return new RDFJenaConvertor(reporter, media, filenamePrefix);
}
Also used : SubstanceName(ambit2.base.data.substance.SubstanceName) SubstanceOwner(ambit2.base.data.substance.SubstanceOwner) SubstanceUUID(ambit2.base.data.substance.SubstanceUUID) DatasetRDFReporter(ambit2.rest.dataset.DatasetRDFReporter) RDFJenaConvertor(ambit2.rest.RDFJenaConvertor) Property(ambit2.base.data.Property) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) SubstancePublicName(ambit2.base.data.substance.SubstancePublicName)

Aggregations

SubstanceName (ambit2.base.data.substance.SubstanceName)9 SubstancePublicName (ambit2.base.data.substance.SubstancePublicName)9 SubstanceOwner (ambit2.base.data.substance.SubstanceOwner)8 SubstanceUUID (ambit2.base.data.substance.SubstanceUUID)8 SubstanceRecord (ambit2.base.data.SubstanceRecord)5 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)5 Property (ambit2.base.data.Property)3 SubstanceProperty (ambit2.base.data.substance.SubstanceProperty)3 ResourceException (org.restlet.resource.ResourceException)3 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)2 ProtocolEffectRecord2SubstanceProperty (ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty)2 ReadSubstanceChemicalsUnionByBundle (ambit2.db.update.bundle.substance.ReadSubstanceChemicalsUnionByBundle)2 ReadSubstancesByBundle (ambit2.db.update.bundle.substance.ReadSubstancesByBundle)2 ResultSet (java.sql.ResultSet)2 OutputWriterConvertor (net.idea.restnet.db.convertors.OutputWriterConvertor)2 Cell (org.apache.poi.ss.usermodel.Cell)2 Form (org.restlet.data.Form)2 LiteratureEntry (ambit2.base.data.LiteratureEntry)1 IValue (ambit2.base.data.study.IValue)1 MultiValue (ambit2.base.data.study.MultiValue)1