Search in sources :

Example 1 with LiteratureEntry

use of ambit2.base.data.LiteratureEntry in project ambit-mirror by ideaconsult.

the class BundleChemicalsResource method setGroupProperties.

protected void setGroupProperties(Context context, Request request, Response response) throws ResourceException {
    groupProperties = new Profile();
    Form form = getParams();
    String[] gp = OpenTox.params.sameas.getValuesArray(form);
    if (gp == null || gp.length == 0)
        gp = new String[] { "http://www.opentox.org/api/1.1#ChemicalName", "http://www.opentox.org/api/1.1#CASRN", "http://www.opentox.org/api/1.1#EINECS" };
    for (String g : gp) {
        Property p = new Property(g);
        p.setEnabled(true);
        p.setLabel(g);
        groupProperties.add(p);
    }
    if (enableFeatures) {
        LiteratureEntry ref = LiteratureEntry.getBundleReference(bundle);
        Property p = new Property("tag", ref);
        p.setEnabled(true);
        groupProperties.add(p);
        p = new Property("remarks", ref);
        p.setEnabled(true);
        groupProperties.add(p);
    }
}
Also used : Form(org.restlet.data.Form) LiteratureEntry(ambit2.base.data.LiteratureEntry) Property(ambit2.base.data.Property) Profile(ambit2.base.data.Profile)

Example 2 with LiteratureEntry

use of ambit2.base.data.LiteratureEntry in project ambit-mirror by ideaconsult.

the class PropertyResourceTest method testCreateEntry.

/**
 * <pre>
 * <rdf:RDF
 *     xmlns:j.0="http://purl.org/net/nknouf/ns/bibtex#"
 *     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 *     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
 *     xmlns:ot="http://www.opentox.org/api/1.1#"
 *     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
 *     xmlns:owl="http://www.w3.org/2002/07/owl#"
 *     xmlns:dc="http://purl.org/dc/elements/1.1/" >
 *   <rdf:Description rdf:about="http://www.opentox.org/api/1.1#units">
 *     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:about="http://purl.org/net/nknouf/ns/bibtex#Entry">
 *     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:about="http://www.opentox.org/api/1.1#hasSource">
 *     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:nodeID="A0">
 *     <rdfs:seeAlso>bbb</rdfs:seeAlso>
 *     <dc:title>aaa</dc:title>
 *     <rdf:type rdf:resource="http://purl.org/net/nknouf/ns/bibtex#Entry"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:about="http://www.opentox.org/api/1.1#Feature">
 *     <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
 *   </rdf:Description>
 *   <rdf:Description rdf:nodeID="A1">
 *     <dc:type>http://www.w3.org/2001/XMLSchema#string</dc:type>
 *     <ot:hasSource rdf:nodeID="A0"/>
 *     <owl:sameAs>CasRN</owl:sameAs>
 *     <ot:units></ot:units>
 *     <dc:title>cas</dc:title>
 *     <rdf:type rdf:resource="http://www.opentox.org/api/1.1#Feature"/>
 *   </rdf:Description>
 * </rdf:RDF>
 * </pre>
 *
 * @throws Exception
 */
@Test
public void testCreateEntry() throws Exception {
    OntModel model = OT.createModel();
    Property p = new Property("cas", new LiteratureEntry("aaa", "bbb"));
    p.setNominal(true);
    PropertyRDFReporter.addToModel(model, p, new PropertyURIReporter(new Reference(String.format("http://localhost:%d%s", port, PropertyResource.featuredef))), new ReferenceURIReporter());
    StringWriter writer = new StringWriter();
    model.write(writer, "RDF/XML");
    System.out.println(writer.toString());
    Response response = testPost(String.format("http://localhost:%d%s", port, PropertyResource.featuredef), MediaType.APPLICATION_RDF_XML, writer.toString());
    Assert.assertEquals(Status.SUCCESS_OK, response.getStatus());
    // Assert.assertEquals("http://localhost:8181/feature/4",
    // response.getLocationRef().toString());
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", String.format("SELECT * FROM properties join catalog_references using(idreference) where name='cas' and comments='%s' and title='aaa' and url='bbb' and isLocal=1", Property.opentox_CAS));
    Assert.assertEquals(1, table.getRowCount());
    c.close();
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) ReferenceURIReporter(ambit2.rest.reference.ReferenceURIReporter) LiteratureEntry(ambit2.base.data.LiteratureEntry) Reference(org.restlet.data.Reference) OntModel(com.hp.hpl.jena.ontology.OntModel) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Property(ambit2.base.data.Property) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Example 3 with LiteratureEntry

use of ambit2.base.data.LiteratureEntry in project ambit-mirror by ideaconsult.

the class PropertyResourceTest method testUpdateExistingEntry.

@Test
public void testUpdateExistingEntry() throws Exception {
    // now we can only update by PUT, not POST
    Property p = new Property("Property 1", new LiteratureEntry("Dummy", "NA"));
    p.setLabel("Test");
    p.setNominal(true);
    OntModel model = OT.createModel();
    PropertyRDFReporter.addToModel(model, p, new PropertyURIReporter(new Reference(String.format("http://localhost:%d%s", port, PropertyResource.featuredef))), new ReferenceURIReporter());
    StringWriter writer = new StringWriter();
    model.write(writer, "RDF/XML");
    Response response = testPut(String.format("http://localhost:%d%s/1", port, PropertyResource.featuredef), MediaType.TEXT_URI_LIST, new StringRepresentation(writer.toString(), MediaType.APPLICATION_RDF_XML));
    Assert.assertEquals(Status.SUCCESS_OK, response.getStatus());
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", String.format("SELECT isLocal FROM properties join catalog_references using(idreference) where name='Property 1' and comments='%s' and title='Dummy' and url='NA'", "http://www.opentox.org/api/1.1#Test"));
    Assert.assertEquals(1, table.getRowCount());
    Assert.assertEquals(true, table.getValue(0, "isLocal"));
    c.close();
    Assert.assertEquals("http://localhost:8181/feature/1", response.getLocationRef().toString());
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) ReferenceURIReporter(ambit2.rest.reference.ReferenceURIReporter) StringRepresentation(org.restlet.representation.StringRepresentation) LiteratureEntry(ambit2.base.data.LiteratureEntry) Reference(org.restlet.data.Reference) OntModel(com.hp.hpl.jena.ontology.OntModel) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Property(ambit2.base.data.Property) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Example 4 with LiteratureEntry

use of ambit2.base.data.LiteratureEntry in project ambit-mirror by ideaconsult.

the class PropertyResourceTest method testUpdateExistingEntry1.

// this fails because of mysql foreign key constraints
public void testUpdateExistingEntry1() throws Exception {
    Property p = new Property("Property 1", new LiteratureEntry("Dummy 1", "NA"));
    p.setLabel("Test");
    p.setId(1);
    OntModel model = OT.createModel();
    PropertyRDFReporter.addToModel(model, p, new PropertyURIReporter(new Reference(String.format("http://localhost:%d%s", port))), new ReferenceURIReporter());
    StringWriter writer = new StringWriter();
    model.write(writer, "RDF/XML");
    Response response = testPost(String.format("http://localhost:%d%s/2", port, PropertyResource.featuredef), MediaType.APPLICATION_RDF_XML, writer.toString());
    Assert.assertEquals(Status.SUCCESS_OK, response.getStatus());
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", String.format("SELECT * FROM properties join catalog_references using(idreference) where name='Property 1' and comments='%s' and title='Dummy' and url='NA'", "http://www.opentox.org/api/1.1#Test"));
    Assert.assertEquals(1, table.getRowCount());
    c.close();
    Assert.assertEquals("http://localhost:8181/feature/2", response.getLocationRef().toString());
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) ReferenceURIReporter(ambit2.rest.reference.ReferenceURIReporter) LiteratureEntry(ambit2.base.data.LiteratureEntry) Reference(org.restlet.data.Reference) OntModel(com.hp.hpl.jena.ontology.OntModel) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Property(ambit2.base.data.Property) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter)

Example 5 with LiteratureEntry

use of ambit2.base.data.LiteratureEntry in project ambit-mirror by ideaconsult.

the class MetaDatasetResourceTest method testUpdateExistingEntry.

@Test
public void testUpdateExistingEntry() throws Exception {
    // name and license uri can be updated only (for now)
    String name = "New dataset name";
    String title = "AAAA";
    String url = "BBBB";
    SourceDataset p = new SourceDataset(name, new LiteratureEntry(title, url));
    p.setLicenseURI(ISourceDataset.license.CC0_1_0.getURI());
    OntModel model = OT.createModel();
    DatasetURIReporter uriReporter = new DatasetURIReporter(new Reference(String.format("http://localhost:%d", port)));
    MetadataRDFReporter.addToModel(model, p, uriReporter.getURI(p));
    StringWriter writer = new StringWriter();
    model.write(writer, "RDF/XML");
    System.out.println(writer.toString());
    Response response = testPut(getTestURI(), MediaType.TEXT_URI_LIST, new StringRepresentation(writer.toString(), MediaType.APPLICATION_RDF_XML));
    Assert.assertEquals(Status.SUCCESS_OK, response.getStatus());
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", String.format("SELECT * FROM src_dataset join catalog_references using(idreference) where name='%s' and licenseURI='%s' ", name, ISourceDataset.license.CC0_1_0.getURI()));
    Assert.assertEquals(1, table.getRowCount());
    c.close();
    Assert.assertEquals("http://localhost:8181/dataset/1/metadata", response.getLocationRef().toString());
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) StringRepresentation(org.restlet.representation.StringRepresentation) LiteratureEntry(ambit2.base.data.LiteratureEntry) Reference(org.restlet.data.Reference) OntModel(com.hp.hpl.jena.ontology.OntModel) ISourceDataset(ambit2.base.data.ISourceDataset) SourceDataset(ambit2.base.data.SourceDataset) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Aggregations

LiteratureEntry (ambit2.base.data.LiteratureEntry)51 Property (ambit2.base.data.Property)35 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)23 Reference (org.restlet.data.Reference)15 IStructureRecord (ambit2.base.interfaces.IStructureRecord)14 SQLException (java.sql.SQLException)12 Test (org.junit.Test)12 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)11 OntModel (com.hp.hpl.jena.ontology.OntModel)9 StringWriter (java.io.StringWriter)9 ITable (org.dbunit.dataset.ITable)9 Response (org.restlet.Response)9 ResourceException (org.restlet.resource.ResourceException)9 StructureRecord (ambit2.base.data.StructureRecord)8 ResourceTest (ambit2.rest.test.ResourceTest)8 IOException (java.io.IOException)8 ILiteratureEntry (ambit2.base.data.ILiteratureEntry)7 SourceDataset (ambit2.base.data.SourceDataset)7 File (java.io.File)7 PropertyURIReporter (ambit2.rest.property.PropertyURIReporter)6