Search in sources :

Example 1 with ReadEffectRecordByBundleMatrix._matrix

use of ambit2.db.update.bundle.matrix.ReadEffectRecordByBundleMatrix._matrix in project ambit-mirror by ideaconsult.

the class ReadEffectRecordByBundleMatrixTest method createQuery.

@Override
protected ReadEffectRecordByBundleMatrix createQuery() throws Exception {
    SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle();
    bundle.setID(1);
    ReadEffectRecordByBundleMatrix q = new ReadEffectRecordByBundleMatrix(bundle, _matrix.matrix_working);
    SubstanceRecord record = new SubstanceRecord();
    record.setSubstanceUUID("IUC4-efdb21bb-e79f-3286-a988-b6f6944d3734");
    q.setFieldname(record);
    return q;
}
Also used : SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) ReadEffectRecordByBundleMatrix(ambit2.db.update.bundle.matrix.ReadEffectRecordByBundleMatrix) SubstanceRecord(ambit2.base.data.SubstanceRecord)

Example 2 with ReadEffectRecordByBundleMatrix._matrix

use of ambit2.db.update.bundle.matrix.ReadEffectRecordByBundleMatrix._matrix in project ambit-mirror by ideaconsult.

the class BundleMatrixResource method put.

@Override
protected Representation put(Representation entity, Variant variant) throws ResourceException {
    _matrix matrix = getList();
    if ((entity == null) || !entity.isAvailable())
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Empty content");
    if (entity.getMediaType() != null) {
        if (MediaType.APPLICATION_JSON.getName().equals(entity.getMediaType().getName())) {
            _mode importmode = _mode.studyimport;
            switch(matrix) {
                case deleted_values:
                    {
                        importmode = _mode.matrixvaluedelete;
                        break;
                    }
                case matrix_working:
                    {
                        importmode = _mode.studyimport;
                        break;
                    }
                default:
                    throw new ResourceException(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
            }
            try {
                File file = File.createTempFile("_matrix_", ".json");
                file.deleteOnExit();
                DownloadTool.download(entity.getStream(), file);
                String token = getToken();
                QASettings qa = new QASettings();
                // sets enabled to false and clears all flags
                qa.clear();
                CallableStudyBundleImporter<String> callable = new CallableStudyBundleImporter<String>(importmode, file, getRootRef(), getContext(), new SubstanceURIReporter(getRequest().getRootRef()), new DatasetURIReporter(getRequest().getRootRef()), token, getRequest().getResourceRef().toString(), getClientInfo());
                callable.setBundle(bundle);
                callable.setClearComposition(false);
                callable.setClearMeasurements(false);
                callable.setQASettings(qa);
                ITask<Reference, Object> task = ((ITaskApplication) getApplication()).addTask("Substance import", callable, getRequest().getRootRef(), token);
                ITaskStorage storage = ((ITaskApplication) getApplication()).getTaskStorage();
                FactoryTaskConvertor<Object> tc = new FactoryTaskConvertor<Object>(storage);
                task.update();
                getResponse().setStatus(task.isDone() ? Status.SUCCESS_OK : Status.SUCCESS_ACCEPTED);
                return tc.createTaskRepresentation(task.getUuid(), variant, getRequest(), getResponse(), null);
            } catch (Exception x) {
                x.printStackTrace();
            } finally {
                try {
                    entity.getStream().close();
                } catch (Exception xx) {
                }
            }
        } else if (MediaType.MULTIPART_FORM_DATA.getName().equals(entity.getMediaType().getName())) {
            switch(matrix) {
                case matrix_working:
                    {
                        break;
                    }
                default:
                    throw new ResourceException(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
            }
            DiskFileItemFactory factory = new DiskFileItemFactory();
            RestletFileUpload upload = new RestletFileUpload(factory);
            try {
                List<FileItem> items = upload.parseRequest(getRequest());
                String token = getToken();
                QASettings qa = new QASettings();
                // sets enabled to false and clears all flags
                qa.clear();
                boolean clearMeasurements = false;
                boolean clearComposition = false;
                for (FileItem file : items) {
                    if (file.isFormField()) {
                    // ignore
                    } else {
                        String ext = file.getName().toLowerCase();
                        if (ext.endsWith(".json")) {
                        } else
                            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Unsupported format " + ext);
                    }
                }
                CallableStudyBundleImporter<String> callable = new CallableStudyBundleImporter<String>(items, CallableFileUpload.field_files, CallableFileUpload.field_config, getRootRef(), getContext(), new SubstanceURIReporter(getRequest().getRootRef()), new DatasetURIReporter(getRequest().getRootRef()), token, getRequest().getResourceRef().toString(), getClientInfo());
                callable.setBundle(bundle);
                callable.setClearComposition(clearComposition);
                callable.setClearMeasurements(clearMeasurements);
                callable.setQASettings(qa);
                ITask<Reference, Object> task = ((ITaskApplication) getApplication()).addTask("Substance import", callable, getRequest().getRootRef(), token);
                ITaskStorage storage = ((ITaskApplication) getApplication()).getTaskStorage();
                FactoryTaskConvertor<Object> tc = new FactoryTaskConvertor<Object>(storage);
                task.update();
                getResponse().setStatus(task.isDone() ? Status.SUCCESS_OK : Status.SUCCESS_ACCEPTED);
                return tc.createTaskRepresentation(task.getUuid(), variant, getRequest(), getResponse(), null);
            } catch (ResourceException x) {
                throw x;
            } catch (Exception x) {
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x);
            }
        }
    }
    throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
}
Also used : CallableStudyBundleImporter(ambit2.rest.substance.CallableStudyBundleImporter) ITask(net.idea.restnet.i.task.ITask) RestletFileUpload(org.restlet.ext.fileupload.RestletFileUpload) Reference(org.restlet.data.Reference) ITaskStorage(net.idea.restnet.i.task.ITaskStorage) ITaskApplication(net.idea.restnet.i.task.ITaskApplication) QASettings(net.idea.i5.io.QASettings) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) CallableStudyBundleImporter._mode(ambit2.rest.substance.CallableStudyBundleImporter._mode) FileItem(org.apache.commons.fileupload.FileItem) SubstanceURIReporter(ambit2.rest.substance.SubstanceURIReporter) FactoryTaskConvertor(ambit2.rest.task.FactoryTaskConvertor) ResourceException(org.restlet.resource.ResourceException) List(java.util.List) ReadEffectRecordByBundleMatrix._matrix(ambit2.db.update.bundle.matrix.ReadEffectRecordByBundleMatrix._matrix) File(java.io.File) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter)

Example 3 with ReadEffectRecordByBundleMatrix._matrix

use of ambit2.db.update.bundle.matrix.ReadEffectRecordByBundleMatrix._matrix in project ambit-mirror by ideaconsult.

the class BundleMatrixResource method delete.

@Override
protected Representation delete(Variant variant) throws ResourceException {
    _matrix matrix = getList();
    switch(matrix) {
        case matrix_working:
            break;
        default:
            throw new ResourceException(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
    }
    String token = getToken();
    SubstanceEndpointsBundle bundle = null;
    Object id = getRequest().getAttributes().get(OpenTox.URI.bundle.getKey());
    if ((id != null))
        try {
            Integer i = new Integer(Reference.decode(id.toString()));
            if (i > 0)
                bundle = new SubstanceEndpointsBundle(i);
        } catch (Exception x) {
        }
    Connection conn = null;
    try {
        DatasetURIReporter r = new DatasetURIReporter(getRequest());
        DBConnection dbc = new DBConnection(getApplication().getContext(), getConfigFile());
        conn = dbc.getConnection(30, true, 8);
        CallableBundleMatrixCreator callable = new CallableBundleMatrixCreator(_matrix.matrix_working, Method.DELETE, null, bundle, r, conn, getToken());
        ITask<Reference, Object> task = ((ITaskApplication) getApplication()).addTask("Delete matrix from bundle", callable, getRequest().getRootRef(), token);
        ITaskStorage storage = ((ITaskApplication) getApplication()).getTaskStorage();
        FactoryTaskConvertor<Object> tc = new FactoryTaskConvertor<Object>(storage);
        task.update();
        getResponse().setStatus(task.isDone() ? Status.SUCCESS_OK : Status.SUCCESS_ACCEPTED);
        return tc.createTaskRepresentation(task.getUuid(), variant, getRequest(), getResponse(), null);
    } catch (Exception x) {
        x.printStackTrace();
        try {
            conn.close();
        } catch (Exception xx) {
        }
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x);
    }
}
Also used : DBConnection(net.idea.restnet.db.DBConnection) Reference(org.restlet.data.Reference) ITaskStorage(net.idea.restnet.i.task.ITaskStorage) Connection(java.sql.Connection) DBConnection(net.idea.restnet.db.DBConnection) ITaskApplication(net.idea.restnet.i.task.ITaskApplication) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) FactoryTaskConvertor(ambit2.rest.task.FactoryTaskConvertor) ResourceException(org.restlet.resource.ResourceException) ReadEffectRecordByBundleMatrix._matrix(ambit2.db.update.bundle.matrix.ReadEffectRecordByBundleMatrix._matrix) CallableBundleMatrixCreator(ambit2.rest.substance.CallableBundleMatrixCreator) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter)

Aggregations

SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)2 ReadEffectRecordByBundleMatrix._matrix (ambit2.db.update.bundle.matrix.ReadEffectRecordByBundleMatrix._matrix)2 DatasetURIReporter (ambit2.rest.dataset.DatasetURIReporter)2 FactoryTaskConvertor (ambit2.rest.task.FactoryTaskConvertor)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 ITaskApplication (net.idea.restnet.i.task.ITaskApplication)2 ITaskStorage (net.idea.restnet.i.task.ITaskStorage)2 Reference (org.restlet.data.Reference)2 ResourceException (org.restlet.resource.ResourceException)2 SubstanceRecord (ambit2.base.data.SubstanceRecord)1 ReadEffectRecordByBundleMatrix (ambit2.db.update.bundle.matrix.ReadEffectRecordByBundleMatrix)1 CallableBundleMatrixCreator (ambit2.rest.substance.CallableBundleMatrixCreator)1 CallableStudyBundleImporter (ambit2.rest.substance.CallableStudyBundleImporter)1 CallableStudyBundleImporter._mode (ambit2.rest.substance.CallableStudyBundleImporter._mode)1 SubstanceURIReporter (ambit2.rest.substance.SubstanceURIReporter)1 File (java.io.File)1 Connection (java.sql.Connection)1 List (java.util.List)1 QASettings (net.idea.i5.io.QASettings)1 DBConnection (net.idea.restnet.db.DBConnection)1