use of ambit2.rest.AmbitApplication in project ambit-mirror by ideaconsult.
the class CallableDomainCreatorTest method test.
@Test
public void test() throws Exception {
Reference app = new Reference(String.format("http://localhost:%d", port));
Form form = new Form();
form.add("dataset_uri", String.format("http://localhost:%d/dataset/1", port));
Algorithm alg = new Algorithm();
alg.setContent(DataCoverageLeverage.class.getName());
ModelURIReporter uriReporter = new ModelURIReporter(null);
CallableNumericalModelCreator c = new CallableNumericalModelCreator(form, app, component.getApplication() == null ? null : ((AmbitApplication) component.getApplication()).getContext(), alg, uriReporter, new AlgorithmURIReporter(null), null, "test", null);
TaskResult ref = c.call();
}
use of ambit2.rest.AmbitApplication in project ambit-mirror by ideaconsult.
the class CallableWekaModelCreatorTest method test.
public void test() throws Exception {
Reference app = new Reference(String.format("http://localhost:%d", port));
Form form = new Form();
form.add("dataset_uri", DatasetReporterTest.class.getResource("/input.rdf").toString());
form.add("target", "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/11938");
ModelURIReporter uriReporter = new ModelURIReporter(null, new ResourceDoc());
CallableWekaModelCreator c = new CallableWekaModelCreator(form, app, ((AmbitApplication) component.getApplication()).getContext(), (Algorithm) null, uriReporter, new AlgorithmURIReporter(null), null, "test", null);
TaskResult ref = c.call();
}
use of ambit2.rest.AmbitApplication in project ambit-mirror by ideaconsult.
the class SimilarityResource method createQuery.
@Override
protected Q createQuery(Context context, Request request, Response response) throws ResourceException {
Form form = getResourceRef(getRequest()).getQueryAsForm();
try {
Object bundleURI = OpenTox.params.bundle_uri.getFirstValue(form);
Integer idbundle = bundleURI == null ? null : getIdBundle(bundleURI, request);
SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle(idbundle);
bundles = new SubstanceEndpointsBundle[1];
bundles[0] = bundle;
} catch (Exception x) {
bundles = null;
}
try {
includeMol = "true".equals(form.getFirstValue("mol"));
} catch (Exception x) {
includeMol = false;
}
folders = form.getValuesArray("folder");
filterBySubstance = false;
try {
String filter = form.getFirstValue("filterBySubstance");
if (filter != null) {
filter = filter.toLowerCase();
filterBySubstance = "yes".equals(filter) || "on".equals(filter) || "true".equals(filter);
}
} catch (Exception x) {
filterBySubstance = false;
}
QueryAtomEnvironment.q_modifier ae = null;
try {
String filter = form.getFirstValue("mode");
if (filter != null) {
filter = filter.toLowerCase();
ae = QueryAtomEnvironment.q_modifier.valueOf(filter.replace("ae", ""));
}
} catch (Exception x) {
ae = null;
}
mol = getMolecule(form);
if ((mol == null) || (mol.getAtomCount() == 0))
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Empty molecule");
threshold = 0.0;
try {
threshold = new Double(Reference.decode(form.getFirstValue("threshold")));
} catch (Exception x) {
threshold = 0.9;
}
QuerySimilarity q = null;
if (ae != null) {
q = new QueryAtomEnvironment(ae);
try {
q.setValue(getAE(mol));
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x);
}
} else
try {
q = new QuerySimilarityBitset();
q.setValue(getBitset(mol));
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x);
}
q.setChemicalsOnly(true);
q.setThreshold(threshold);
q.setCondition(NumberCondition.getInstance(">"));
q.setName("Similarity");
try {
q.setForceOrdering(((AmbitApplication) getApplication()).isSimilarityOrder());
} catch (Exception x) {
q.setForceOrdering(true);
}
try {
if (filterBySubstance) {
ChemicalBySubstanceRelation qa = new ChemicalBySubstanceRelation();
QueryCombinedStructure qc = new QueryCombinedStructure();
qc.add(q);
qc.setChemicalsOnly(true);
qc.setScope(qa);
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) qc;
} else if ((folders != null) && (folders.length > 0)) {
ChemicalByQueryFolder qa = new ChemicalByQueryFolder(folders);
QueryCombinedStructure qc = new QueryCombinedStructure();
qc.add(q);
qc.setChemicalsOnly(true);
qc.setScope(qa);
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) qc;
} else {
Object datasetURI = OpenTox.params.dataset_uri.getFirstValue(form);
ISourceDataset srcdataset = null;
if (datasetURI != null)
try {
srcdataset = getDataset(datasetURI.toString());
QueryCombinedStructure qc = new QueryCombinedStructure();
qc.add(q);
qc.setChemicalsOnly(true);
if (srcdataset instanceof SourceDataset) {
ChemicalByDataset cd = new ChemicalByDataset(new Integer(srcdataset.getID()));
qc.setScope(cd);
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) qc;
} else {
// TODO, resort to all db
}
} catch (Exception x) {
srcdataset = null;
}
QueryCombinedStructure qc = null;
try {
this.dataset_id = Reference.decode(getRequest().getAttributes().get(DatasetResource.datasetKey).toString());
qc = new QueryCombinedStructure();
qc.add(q);
qc.setChemicalsOnly(true);
ChemicalByDataset cd = new ChemicalByDataset(new Integer(dataset_id));
qc.setScope(cd);
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) qc;
} catch (Exception x) {
setTemplate(createTemplate(context, request, response));
setGroupProperties(context, request, response);
return (Q) q;
}
}
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x);
}
}
use of ambit2.rest.AmbitApplication in project ambit-mirror by ideaconsult.
the class QueryResource method getRepresentation.
protected Representation getRepresentation(Variant variant) throws ResourceException {
try {
if (MediaType.APPLICATION_JAVA_OBJECT.equals(variant.getMediaType())) {
if ((queryObject != null) && (queryObject instanceof Serializable))
return new ObjectRepresentation((Serializable) returnQueryObject(), MediaType.APPLICATION_JAVA_OBJECT);
else
throw new ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
}
if (MediaType.APPLICATION_JAVASCRIPT.equals(variant.getMediaType())) {
if (!isJSONPEnabled())
throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
}
if (queryObject != null) {
IProcessor<Q, Representation> convertor = null;
Connection connection = null;
int retry = 0;
while (retry < maxRetry) {
try {
DBConnection dbc = new DBConnection(getContext());
configureRDFWriterOption(((AmbitApplication) getApplication()).getProperties().getRDFwriter());
configureSDFLineSeparators(((AmbitApplication) getApplication()).getProperties().getConfigChangeLineSeparator());
configureDatasetMembersPrefixOption(((AmbitApplication) getApplication()).getProperties().isDatasetMembersPrefix());
convertor = createConvertor(variant);
if (convertor instanceof RepresentationConvertor)
((RepresentationConvertor) convertor).setLicenseURI(getLicenseURI());
connection = dbc.getConnection();
Reporter reporter = ((RepresentationConvertor) convertor).getReporter();
if (reporter instanceof IDBProcessor)
((IDBProcessor) reporter).setConnection(connection);
Representation r = convertor.process(queryObject);
r.setCharacterSet(CharacterSet.UTF_8);
return r;
} catch (ResourceException x) {
throw x;
} catch (NotFoundException x) {
Representation r = processNotFound(x, retry);
retry++;
if (r != null)
return r;
} catch (BatchProcessingException x) {
if (x.getCause() instanceof NotFoundException) {
Representation r = processNotFound((NotFoundException) x.getCause(), retry);
retry++;
if (r != null)
return r;
} else {
Context.getCurrentLogger().severe(x.getMessage());
throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
}
} catch (SQLException x) {
Representation r = processSQLError(x, retry, variant);
retry++;
if (r == null)
continue;
else
return r;
} catch (Exception x) {
Context.getCurrentLogger().severe(x.getMessage());
throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
} finally {
// try { if (connection !=null) connection.close(); }
// catch (Exception x) {};
// try { if ((convertor !=null) &&
// (convertor.getReporter() !=null))
// convertor.getReporter().close(); } catch (Exception
// x) {}
}
}
return null;
} else {
if (variant.getMediaType().equals(MediaType.TEXT_HTML))
try {
IProcessor<Q, Representation> convertor = createConvertor(variant);
Representation r = convertor.process(null);
return r;
} catch (Exception x) {
throw new RResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x, variant);
}
else {
throw new RResourceException(Status.CLIENT_ERROR_BAD_REQUEST, error, variant);
}
}
} catch (RResourceException x) {
throw x;
} catch (ResourceException x) {
throw new RResourceException(x.getStatus(), x, variant);
} catch (Exception x) {
throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
}
}
use of ambit2.rest.AmbitApplication in project ambit-mirror by ideaconsult.
the class DatasetCompoundResource method doInit.
@Override
protected void doInit() throws ResourceException {
DBConnection dbc = new DBConnection(getContext());
configureDatasetMembersPrefixOption(((AmbitApplication) getApplication()).getProperties().isDatasetMembersPrefix());
super.doInit();
}
Aggregations