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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations