Search in sources :

Example 1 with QASettings

use of net.idea.i5.io.QASettings in project ambit-mirror by ideaconsult.

the class I5SubstanceWriterTest method testWriteMultipleFiles_i5d.

@Test
public void testWriteMultipleFiles_i5d() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/empty-datasets.xml");
    IDatabaseConnection c = getConnection();
    ITable chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(0, chemicals.getRowCount());
    ITable strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(0, strucs.getRowCount());
    ITable srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset");
    Assert.assertEquals(0, srcdataset.getRowCount());
    ITable struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset");
    Assert.assertEquals(0, struc_src.getRowCount());
    ITable property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    Assert.assertEquals(0, property.getRowCount());
    ITable property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(0, property_values.getRowCount());
    /**
     * Now reading only substances and reference substances Document types:
     * EndpointStudyRecord: 877 AttachmentDocument: 5 LegalEntity: 1
     * ReferenceSubstance: 6 Substance: 1 EndpointRecord: 14
     */
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("ambit2/db/substance/testNM.i5z");
    // InputStream in =
    // I5AmbitProcessor.class.getClassLoader().getResourceAsStream("net/idea/i5/_5/substance/i5z/IUC4-efdb21bb-e79f-3286-a988-b6f6944d3734.i5z");
    // InputStream in =
    // I5AmbitProcessor.class.getClassLoader().getResourceAsStream("net/idea/i5/_5/substance/i5z/IUC4-e2b69497-1c50-3d0b-a2b2-41d0a4d74c54.i5z");
    // InputStream in =
    // I5AmbitProcessor.class.getClassLoader().getResourceAsStream("net/idea/i5/_5/substance/i5z/IUC4-f5dd46ce-6fc9-316f-a468-c4f9acfcfc3c.i5z");
    Assert.assertNotNull(in);
    File i5z = File.createTempFile("test_", ".i5z");
    try {
        DownloadTool.download(in, i5z);
    } finally {
        in.close();
    }
    Assert.assertTrue(i5z.exists());
    I5ZReader reader = null;
    int records = 0;
    try {
        reader = new I5ZReader(i5z);
        QASettings qa = new QASettings(false);
        qa.setAll();
        reader.setQASettings(qa);
        PropertyKey key = new ReferenceSubstanceUUID();
        records = write(null, reader, c.getConnection(), key, true, false, false);
    } finally {
        try {
            reader.close();
        } catch (Exception x) {
        }
        try {
            c.close();
        } catch (Exception x) {
        }
        try {
            i5z.delete();
        } catch (Exception x) {
        }
    }
    Assert.assertEquals(8, records);
    c = getConnection();
    ITable substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance");
    Assert.assertEquals(1, substance.getRowCount());
    Assert.assertNotNull(substance.getValue(0, "uuid"));
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(1, chemicals.getRowCount());
    // there are two empty file without $$$$ sign, which are skipped
    strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(1, strucs.getRowCount());
    srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset where name='IUCLID5 .i5z file'");
    Assert.assertEquals(1, srcdataset.getRowCount());
    struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset");
    Assert.assertEquals(1, struc_src.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM substance_protocolapplication where topcategory='P-CHEM' and endpointcategory='ASPECT_RATIO_SHAPE_SECTION' and interpretation_result='spherical'");
    Assert.assertEquals(1, property.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM substance_experiment where topcategory='P-CHEM' and endpointcategory='ASPECT_RATIO_SHAPE_SECTION'");
    Assert.assertEquals(4, property.getRowCount());
    c.close();
}
Also used : ReferenceSubstanceUUID(ambit2.core.processors.structure.key.ReferenceSubstanceUUID) InputStream(java.io.InputStream) QASettings(net.idea.i5.io.QASettings) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) I5ZReader(net.idea.i5.io.I5ZReader) File(java.io.File) PropertyKey(ambit2.core.processors.structure.key.PropertyKey) Test(org.junit.Test)

Example 2 with QASettings

use of net.idea.i5.io.QASettings in project ambit-mirror by ideaconsult.

the class Context method importI5Z.

protected int importI5Z(IStructureKey keytomatch, boolean i6, StructureRecordValidator validator) throws Exception {
    // validator uses parsertype
    setParserType(i6 ? _parsertype.i6z : _parsertype.i5z);
    logger_cli.log(Level.INFO, "MSG_IMPORT", new Object[] { String.format("i%sz", i6 ? "6" : "5"), inputFile.getAbsolutePath() });
    IZReader reader = null;
    Connection c = null;
    try {
        DBConnectionConfigurable<Context> dbc = null;
        dbc = getConnection(getConfigFile());
        c = dbc.getConnection();
        c.setAutoCommit(true);
        I5Options options = new I5Options();
        options.setMaxReferenceStructures(maxRefSubstances);
        options.setExceptionOnMaxReferenceStructures(false);
        options.setAllowMultipleSubstances(false);
        if (i6)
            reader = new I6ZReader<>(inputFile, options);
        else
            reader = new I5ZReader<>(inputFile, options);
        QASettings qa = new QASettings(false);
        qa.setAll();
        reader.setQASettings(qa);
        matchByKey = keytomatch == null ? new CASKey() : keytomatch;
        return write(reader, c, matchByKey, true, clearMeasurements, clearComposition, validator, null, true, false);
    } catch (Exception x) {
        throw x;
    } finally {
        if (reader != null)
            reader.close();
        try {
            if (c != null)
                c.close();
        } catch (Exception x) {
        }
    }
}
Also used : I5Options(net.idea.i5.io.I5Options) IZReader(net.idea.i5.io.IZReader) CASKey(ambit2.core.processors.structure.key.CASKey) Connection(java.sql.Connection) MySQLSingleConnection(net.idea.modbcum.c.MySQLSingleConnection) QASettings(net.idea.i5.io.QASettings) I5ZReader(net.idea.i5.io.I5ZReader) I6ZReader(net.idea.i6.io.I6ZReader) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CommunicationsException(com.mysql.jdbc.CommunicationsException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException)

Example 3 with QASettings

use of net.idea.i5.io.QASettings in project ambit-mirror by ideaconsult.

the class SubstanceResource method post.

@Override
protected Representation post(Representation entity, Variant variant) throws ResourceException {
    if ((entity == null) || !entity.isAvailable())
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Empty content");
    if (entity.getMediaType() != null)
        if (MediaType.MULTIPART_FORM_DATA.getName().equals(entity.getMediaType().getName())) {
            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()) {
                        if ("qaenabled".equals(file.getFieldName()))
                            try {
                                if ("on".equals(file.getString()))
                                    qa.setEnabled(true);
                                if ("yes".equals(file.getString()))
                                    qa.setEnabled(true);
                                if ("checked".equals(file.getString()))
                                    qa.setEnabled(true);
                            } catch (Exception x) {
                                qa.setEnabled(true);
                            }
                        else if ("clearMeasurements".equals(file.getFieldName())) {
                            try {
                                clearMeasurements = false;
                                String cm = file.getString();
                                if ("on".equals(cm))
                                    clearMeasurements = true;
                                else if ("yes".equals(cm))
                                    clearMeasurements = true;
                                else if ("checked".equals(cm))
                                    clearMeasurements = true;
                            } catch (Exception x) {
                                clearMeasurements = false;
                            }
                        } else if ("clearComposition".equals(file.getFieldName())) {
                            try {
                                clearComposition = false;
                                String cm = file.getString();
                                if ("on".equals(cm))
                                    clearComposition = true;
                                else if ("yes".equals(cm))
                                    clearComposition = true;
                                else if ("checked".equals(cm))
                                    clearComposition = true;
                            } catch (Exception x) {
                                clearComposition = false;
                            }
                        } else
                            for (IQASettings.qa_field f : IQASettings.qa_field.values()) if (f.name().equals(file.getFieldName()))
                                try {
                                    String value = file.getString("UTF-8");
                                    f.addOption(qa, "null".equals(value) ? null : value == null ? null : value.toString());
                                } catch (Exception x) {
                                }
                    } else {
                        String ext = file.getName().toLowerCase().trim();
                        if ("".equals(ext) || ext.endsWith(".i5z") || ext.endsWith(".i6z") || ext.endsWith(".csv") || ext.endsWith(".rdf") || ext.endsWith(".ttl") || ext.endsWith(".json") || ext.endsWith(".xlsx") || ext.endsWith(".xls")) {
                        } else
                            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Unsupported format " + ext);
                    }
                }
                CallableSubstanceImporter<String> callable = new CallableSubstanceImporter<String>(items, CallableFileUpload.field_files, CallableFileUpload.field_config, getRootRef(), getContext(), new SubstanceURIReporter(getRequest().getRootRef()), new DatasetURIReporter(getRequest().getRootRef()), token, getRequest().getResourceRef().toString(), getClientInfo());
                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);
            }
        } else if (MediaType.APPLICATION_WWW_FORM.getName().equals(entity.getMediaType().getName())) {
            /*
				 * web form to update substances from IUCLID5 server Expected web form fields :
				 * substance: UUID or query URL type : UUID or query or URL (ambit substance
				 * URL) qa options query : one of {@link QueryToolClient.PredefinedQuery} query
				 * parameters: depend on the query type iuclid5 server; credentials - optional,
				 * use preconfigured if not submitted [(option,UUID), (uuid,ZZZZZZZZZZ),
				 * (extidtype,CompTox), (extidvalue,Ambit Transfer), (i5server,null),
				 * (i5user,null), (i5pass,null)]
				 */
            Form form = new Form(entity);
            String token = getToken();
            CallableSubstanceI5Query<String> callable = new CallableSubstanceI5Query<String>(getRootRef(), form, getContext(), new SubstanceURIReporter(getRequest().getRootRef()), new DatasetURIReporter(getRequest().getRootRef()), token, getRequest().getResourceRef().toString(), getClientInfo());
            ITask<Reference, Object> task = ((ITaskApplication) getApplication()).addTask("Retrieve substance from IUCLID server", 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);
        }
    throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
}
Also used : ITask(net.idea.restnet.i.task.ITask) RestletFileUpload(org.restlet.ext.fileupload.RestletFileUpload) Form(org.restlet.data.Form) ITaskApplication(net.idea.restnet.i.task.ITaskApplication) FactoryTaskConvertor(ambit2.rest.task.FactoryTaskConvertor) ResourceException(org.restlet.resource.ResourceException) List(java.util.List) ArrayList(java.util.ArrayList) ITaskStorage(net.idea.restnet.i.task.ITaskStorage) Reference(org.restlet.data.Reference) QASettings(net.idea.i5.io.QASettings) IQASettings(net.idea.i5.io.IQASettings) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) IQASettings(net.idea.i5.io.IQASettings) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) PatternSyntaxException(java.util.regex.PatternSyntaxException) SQLException(java.sql.SQLException) ProcessorException(ambit2.base.processors.ProcessorException) FileItem(org.apache.commons.fileupload.FileItem) CallableSubstanceI5Query(ambit2.db.processors.CallableSubstanceI5Query) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter)

Example 4 with QASettings

use of net.idea.i5.io.QASettings in project ambit-mirror by ideaconsult.

the class UIResource method uploadsubstance.

@Override
protected Representation uploadsubstance(Representation entity, Variant variant) throws ResourceException {
    if ((entity == null) || !entity.isAvailable())
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Empty content");
    if (entity.getMediaType() != null && MediaType.MULTIPART_FORM_DATA.getName().equals(entity.getMediaType().getName())) {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        RestletFileUpload upload = new RestletFileUpload(factory);
        try {
            List<FileItem> items = upload.parseRequest(getRequest());
            StringBuilder json = new StringBuilder();
            json.append("{\"files\": [");
            String delimiter = "";
            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()) {
                if ("qaenabled".equals(file.getFieldName()))
                    try {
                        if ("on".equals(file.getString()))
                            qa.setEnabled(true);
                        if ("yes".equals(file.getString()))
                            qa.setEnabled(true);
                        if ("checked".equals(file.getString()))
                            qa.setEnabled(true);
                    } catch (Exception x) {
                        qa.setEnabled(true);
                    }
                else if ("clearMeasurements".equals(file.getFieldName())) {
                    try {
                        clearMeasurements = false;
                        String cm = file.getString();
                        if ("on".equals(cm))
                            clearMeasurements = true;
                        else if ("yes".equals(cm))
                            clearMeasurements = true;
                        else if ("checked".equals(cm))
                            clearMeasurements = true;
                    } catch (Exception x) {
                        clearMeasurements = false;
                    }
                } else if ("clearComposition".equals(file.getFieldName())) {
                    try {
                        clearComposition = false;
                        String cm = file.getString();
                        if ("on".equals(cm))
                            clearComposition = true;
                        else if ("yes".equals(cm))
                            clearComposition = true;
                        else if ("checked".equals(cm))
                            clearComposition = true;
                    } catch (Exception x) {
                        clearComposition = false;
                    }
                } else
                    for (IQASettings.qa_field f : IQASettings.qa_field.values()) if (f.name().equals(file.getFieldName()))
                        try {
                            String value = file.getString("UTF-8");
                            f.addOption(qa, "null".equals(value) ? null : value == null ? null : value.toString());
                        } catch (Exception x) {
                        }
            }
            for (FileItem file : items) {
                if (file.isFormField())
                    continue;
                json.append(delimiter);
                json.append("\n{\n");
                json.append("\"name\":");
                json.append(JSONUtils.jsonQuote(JSONUtils.jsonEscape(file.getName())));
                json.append(",\n\"size\":");
                json.append(file.getSize());
                String ext = file.getName().toLowerCase();
                if (ext.endsWith(".i5z") || ext.endsWith(".i6z") || ext.endsWith(".csv") || ext.endsWith(".rdf") || ext.endsWith(".ttl") || ext.endsWith(".json")) {
                    String img = "i5z.png";
                    if (ext.endsWith(".csv"))
                        img = "csv64.png";
                    else if (ext.endsWith(".xlsx"))
                        img = "xlsx.png";
                    else if (ext.endsWith(".rdf"))
                        img = "rdf64.png";
                    else if (ext.endsWith(".ttl"))
                        img = "rdf64.png";
                    else if (ext.endsWith(".json"))
                        img = "json64.png";
                    else if (ext.endsWith(".i6z"))
                        img = "i6z.png";
                    try {
                        List<FileItem> item = new ArrayList<FileItem>();
                        item.add(file);
                        CallableSubstanceImporter<String> callable = new CallableSubstanceImporter<String>(item, CallableFileUpload.field_files, CallableFileUpload.field_config, getRootRef(), getContext(), new SubstanceURIReporter(getRequest().getRootRef()), new DatasetURIReporter(getRequest().getRootRef()), null, getRequest().getResourceRef().toString(), getClientInfo());
                        callable.setClearComposition(clearComposition);
                        callable.setClearMeasurements(clearMeasurements);
                        callable.setQASettings(qa);
                        ITaskResult result = callable.call();
                        json.append(",\n\"url\":");
                        json.append(JSONUtils.jsonQuote(JSONUtils.jsonEscape(result.getReference().toString())));
                        json.append(",\n\"thumbnailUrl\":");
                        json.append(JSONUtils.jsonQuote(JSONUtils.jsonEscape(String.format("%s/images/%s", getRequest().getRootRef(), img))));
                        json.append(",\n\"deleteUrl\":");
                        json.append(JSONUtils.jsonQuote(JSONUtils.jsonEscape(result.getReference().toString())));
                        json.append(",\n\"deleteType\":");
                        json.append("\"Delete\"");
                    } catch (Exception x) {
                        json.append(",\n\"error\":");
                        json.append(JSONUtils.jsonQuote(JSONUtils.jsonEscape(x.getMessage())));
                    } finally {
                    }
                } else {
                    json.append(",\n\"error\":");
                    json.append(JSONUtils.jsonQuote(JSONUtils.jsonEscape("File type not allowed!")));
                }
                json.append("\n}");
            }
            json.append("\n]}");
            getResponse().setStatus(Status.SUCCESS_OK);
            return new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON);
        } catch (FileUploadException x) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x);
        }
    } else
        throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
}
Also used : RestletFileUpload(org.restlet.ext.fileupload.RestletFileUpload) ArrayList(java.util.ArrayList) IQASettings(net.idea.i5.io.IQASettings) QASettings(net.idea.i5.io.QASettings) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) IQASettings(net.idea.i5.io.IQASettings) ResourceException(org.restlet.resource.ResourceException) FileUploadException(org.apache.commons.fileupload.FileUploadException) FileItem(org.apache.commons.fileupload.FileItem) SubstanceURIReporter(ambit2.rest.substance.SubstanceURIReporter) StringRepresentation(org.restlet.representation.StringRepresentation) ITaskResult(net.idea.restnet.i.task.ITaskResult) ResourceException(org.restlet.resource.ResourceException) CallableSubstanceImporter(ambit2.rest.substance.CallableSubstanceImporter) FileUploadException(org.apache.commons.fileupload.FileUploadException) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter)

Example 5 with QASettings

use of net.idea.i5.io.QASettings 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)

Aggregations

QASettings (net.idea.i5.io.QASettings)5 DatasetURIReporter (ambit2.rest.dataset.DatasetURIReporter)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 FileItem (org.apache.commons.fileupload.FileItem)3 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)3 RestletFileUpload (org.restlet.ext.fileupload.RestletFileUpload)3 ResourceException (org.restlet.resource.ResourceException)3 SubstanceURIReporter (ambit2.rest.substance.SubstanceURIReporter)2 FactoryTaskConvertor (ambit2.rest.task.FactoryTaskConvertor)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 I5ZReader (net.idea.i5.io.I5ZReader)2 IQASettings (net.idea.i5.io.IQASettings)2 ITask (net.idea.restnet.i.task.ITask)2 ITaskApplication (net.idea.restnet.i.task.ITaskApplication)2 ITaskStorage (net.idea.restnet.i.task.ITaskStorage)2 Reference (org.restlet.data.Reference)2 ProcessorException (ambit2.base.processors.ProcessorException)1