use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class BookmarkJSONReporter method processItem.
@Override
public Object processItem(Bookmark item) throws AmbitException {
try {
Writer writer = getOutput();
if (comma != null)
writer.write(comma);
writer.write(item.toJSON());
comma = ",";
} catch (Exception x) {
logger.log(java.util.logging.Level.SEVERE, x.getMessage(), x);
}
return item;
}
use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class CSLSResource method get.
@Override
protected Representation get(Variant variant) throws ResourceException {
setFrameOptions("SAMEORIGIN");
try {
if (term != null) {
if (variant.getMediaType().equals(ChemicalMediaType.CHEMICAL_MDLSDF))
return new OutputRepresentation(variant.getMediaType()) {
@Override
public void write(OutputStream stream) throws IOException {
try {
CSLSRequest<InputStream> q = new CSLSRequest<InputStream>() {
/**
*/
private static final long serialVersionUID = 2638378178348461366L;
@Override
protected InputStream read(InputStream in) throws Exception {
return in;
}
};
q.setRepresentation(representation);
DownloadTool.download(q.process(term), stream);
stream.flush();
} catch (ResourceException x) {
throw x;
} catch (AmbitException x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
// throw new IOException(x.getMessage());
} finally {
try {
if (stream != null)
stream.flush();
} catch (Exception x) {
getLogger().log(Level.WARNING, x.getMessage(), x);
}
}
}
};
else {
CSLSStringRequest q = new CSLSStringRequest();
q.setRepresentation(representation);
return new StringRepresentation(q.process(term), MediaType.TEXT_PLAIN);
}
} else
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
} catch (NotFoundException x) {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND, "No results for query " + term);
return null;
} catch (ResourceException x) {
throw x;
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x);
}
}
use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class ModelTextReporter method processItem.
@Override
public Object processItem(ModelQueryResults model) throws AmbitException {
try {
ModelPredictor predictor = ModelResource.getPredictor(model, request);
getOutput().write(predictor.toString());
return null;
} catch (AmbitException x) {
throw x;
} catch (Exception x) {
throw new AmbitException(x);
}
}
use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class AbstractDepict method process.
public Representation process(Variant variant) {
try {
Form form = getParams();
w = 400;
h = 200;
recordType = "2d";
try {
w = Integer.parseInt(form.getFirstValue("w"));
} catch (Exception x) {
w = 400;
}
try {
h = Integer.parseInt(form.getFirstValue("h"));
} catch (Exception x) {
h = 200;
}
try {
recordType = form.getFirstValue("record_type");
} catch (Exception x) {
}
try {
qType = QueryType.valueOf(form.getFirstValue("type"));
} catch (Exception x) {
qType = QueryType.smiles;
}
switch(qType) {
case mol:
{
// base64 encoded mol files
smiles = form.getValuesArray(QueryResource.b64search_param);
if (smiles != null)
for (int i = 0; i < smiles.length; i++) smiles[i] = new String(Base64.decode(smiles[i]));
break;
}
default:
{
smiles = form.getValuesArray(QueryResource.search_param);
if ((smiles == null) || (smiles.length < 1))
smiles = new String[] { null };
else
smiles[0] = smiles[0] == null ? "" : smiles[0].trim();
}
}
setSmarts(form.getFirstValue("smarts"));
setSmirks(null);
String[] smirks_patterns = form.getValuesArray("smirks");
for (String sm : smirks_patterns) if (sm != null) {
setSmirks(sm);
break;
}
if (variant.getMediaType().equals(MediaType.TEXT_HTML) || (smiles == null)) {
StringConvertor convertor = new StringConvertor(new AbstractReporter<String, Writer>() {
/**
*/
private static final long serialVersionUID = -6791292888357737097L;
public void close() throws Exception {
}
public Writer process(String target) throws AmbitException {
try {
if (headless)
output.write(target);
else {
AmbitResource.writeTopHeader(output, smiles[0] == null ? "2D structural diagram" : smiles[0], getRequest(), getResourceRef(getRequest()), header_gplus);
writeSearchForm(output, smiles[0] == null ? "N/A" : smiles[0], getRequest(), "", Method.GET, params);
output.write(target);
AmbitResource.writeHTMLFooter(output, smiles[0] == null ? "" : smiles[0], getRequest());
}
} catch (Exception x) {
}
return output;
}
}, MediaType.TEXT_HTML);
return convertor.process(getTitle(getResourceRef(getRequest()), smiles));
}
final BufferedImage image;
if (smiles[0] != null) {
image = getImage(smiles[0], w, h, recordType, qType);
if (image == null) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Invalid smiles %s", smiles));
return null;
}
} else
image = createDefaultImage(w, h);
return new OutputRepresentation(MediaType.IMAGE_PNG) {
@Override
public void write(OutputStream out) throws IOException {
try {
ImageIO.write(image, "PNG", out);
} catch (IOException x) {
throw x;
} catch (Exception x) {
} finally {
try {
out.flush();
} catch (Exception x) {
}
try {
out.close();
} catch (Exception x) {
}
}
}
};
} catch (ResourceException x) {
getResponse().setStatus(x.getStatus(), x, x.getMessage());
return null;
} catch (Exception x) {
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST, x, x.getMessage());
return null;
}
}
use of net.idea.modbcum.i.exceptions.AmbitException in project ambit-mirror by ideaconsult.
the class CDKDepict method get.
@Override
public Representation get(Variant variant) {
try {
Form form = getParams();
smiles = form.getValuesArray(QueryResource.search_param);
if ((smiles == null) || (smiles.length < 1))
smiles = new String[] { null };
setSmarts(form.getFirstValue("smarts"));
if (MediaType.TEXT_HTML.equals(variant.getMediaType())) {
StringConvertor convertor = new StringConvertor(new AbstractReporter<String, Writer>() {
/**
*/
private static final long serialVersionUID = -1232605257681949242L;
public void close() throws Exception {
}
public Writer process(String target) throws AmbitException {
try {
AmbitResource.writeTopHeader(output, smiles[0] == null ? "2D structure diagram" : smiles[0], getRequest(), getResourceRef(getRequest()), "");
writeSearchForm(output, smiles[0], getRequest(), "", Method.GET, params);
output.write(target);
AmbitResource.writeHTMLFooter(output, smiles[0], getRequest());
} catch (Exception x) {
}
return output;
}
}, MediaType.TEXT_HTML);
return convertor.process(getTitle(getResourceRef(getRequest()), smiles));
} else {
return process(variant);
}
} catch (Exception x) {
}
return null;
}
Aggregations