Search in sources :

Example 1 with ProtocolEffectRecord2SubstanceProperty

use of ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty in project ambit-mirror by ideaconsult.

the class SubstanceDatasetResource method getPropertyProcessors.

protected IProcessor getPropertyProcessors(final boolean removeIdentifiers, final boolean removeStringProperties) {
    IQueryRetrieval<ProtocolEffectRecord<String, String, String>> queryP = getEffectQuery();
    MasterDetailsProcessor<SubstanceRecord, ProtocolEffectRecord<String, String, String>, IQueryCondition> effectReader = new MasterDetailsProcessor<SubstanceRecord, ProtocolEffectRecord<String, String, String>, IQueryCondition>(queryP) {

        /**
         */
        private static final long serialVersionUID = -7354966336095750101L;

        ProtocolEffectRecord2SubstanceProperty processor = new ProtocolEffectRecord2SubstanceProperty();

        @Override
        public SubstanceRecord process(SubstanceRecord target) throws Exception {
            if (target == null || target.getSubstanceUUID() == null)
                return target;
            else
                return super.process(target);
        }

        @Override
        protected SubstanceRecord processDetail(SubstanceRecord master, ProtocolEffectRecord<String, String, String> detail) throws Exception {
            if (master.getIdsubstance() <= 0)
                return master;
            if (detail != null) {
                if (detail.getTextValue() != null && detail.getTextValue().toString().startsWith("{")) {
                    JsonNode node = dx.readTree(new StringReader(detail.getTextValue().toString()));
                    List<String> guideline = detail.getProtocol().getGuideline();
                    ILiteratureEntry ref = LiteratureEntry.getInstance(guideline == null ? null : guideline.size() == 0 ? null : guideline.get(0), guideline == null ? null : guideline.size() == 0 ? null : guideline.get(0));
                    Iterator<Entry<String, JsonNode>> i = node.fields();
                    while (i.hasNext()) {
                        Entry<String, JsonNode> val = i.next();
                        SubstanceProperty key = new SubstanceProperty(detail.getProtocol().getTopCategory(), detail.getProtocol().getCategory(), val.getKey(), detail.getUnit(), ref);
                        try {
                            key.setStudyResultType(_r_flags.valueOf(detail.getStudyResultType().replace(":", "").replace("_", "").replace(" ", "").replace("-", "").replace(")", "").replace("(", "")));
                        } catch (Exception x) {
                            key.setStudyResultType(null);
                        }
                        key.setExtendedURI(true);
                        key.setIdentifier(detail.getSampleID() + "/" + val.getKey());
                        groupProperties.add(key);
                        if (val.getValue().get(EffectRecord._fields.loValue.name()) != null) {
                            Number num = val.getValue().get(EffectRecord._fields.loValue.name()).asDouble();
                            master.setRecordProperty(key, num);
                            key.setClazz(Number.class);
                        } else {
                            master.setRecordProperty(key, val.getValue().textValue());
                            key.setClazz(String.class);
                        }
                    }
                } else {
                    boolean isTextValue = ((detail.getLoValue() == null) && (detail.getUpValue() == null));
                    if (isTextValue && removeStringProperties)
                        return master;
                    /*
						 * JsonNode conditions = detail.getConditions() == null
						 * ? null : dx.readTree(new StringReader(
						 * detail.getConditions()));
						 * 
						 * PropertyAnnotations ann = new PropertyAnnotations();
						 * 
						 * Iterator<Entry<String, JsonNode>> i = conditions ==
						 * null ? null : conditions.getFields();
						 * 
						 * if (i != null) while (i.hasNext()) { Entry<String,
						 * JsonNode> val = i.next(); if (val.getValue()
						 * instanceof NullNode) continue;
						 * 
						 * if (val.getValue().getTextValue() == null) try {
						 * PropertyAnnotation a = new PropertyAnnotation();
						 * String unit =
						 * val.getValue().get(EffectRecord._fields.unit.name())
						 * == null ? null :
						 * val.getValue().get(EffectRecord._fields
						 * .unit.name()).asText(); a.setPredicate(val.getKey());
						 * if (unit == null)
						 * a.setObject(val.getValue().get(EffectRecord
						 * ._fields.loValue.name()) .asText()); else {
						 * a.setObject(String.format("%s %s",
						 * val.getValue().get(
						 * EffectRecord._fields.loValue.name()).asText(),
						 * unit)); } ann.add(a); } catch (Exception x) { } else
						 * { PropertyAnnotation a = new PropertyAnnotation();
						 * a.setPredicate(val.getKey());
						 * a.setObject(val.getValue().getTextValue());
						 * ann.add(a); }
						 * 
						 * }
						 */
                    ProtocolEffectRecord<String, IParams, String> effect = new ProtocolEffectRecord<String, IParams, String>();
                    ProtocolEffectRecord2SubstanceProperty.copyEffectRecordValues(detail, effect);
                    try {
                        JsonNode conditions = detail.getConditions() == null ? null : dx.readTree(new StringReader(detail.getConditions()));
                        if (conditions instanceof ObjectNode) {
                            effect.setConditions(SubstanceStudyParser.parseParams((ObjectNode) conditions));
                        }
                    } catch (Exception x) {
                        logger.log(Level.FINE, x.getMessage());
                    }
                    SubstanceProperty key = processor.process(effect);
                    key.setIdentifier(key.createHashedIdentifier(effect.getConditions()));
                    Object oldValue = master.getRecordProperty(key);
                    groupProperties.add(key);
                    /*
						 * if (isTextValue) { //textvalue if (oldValue == null)
						 * master.setProperty(key, detail.getTextValue()); else
						 * { master.setProperty(key, String.format( "%s, %s",
						 * oldValue instanceof Number ? nf.format((Number)
						 * oldValue) : oldValue .toString(),
						 * detail.getTextValue())); }
						 * key.setClazz(String.class); } else { //numeric
						 */
                    Value value = processValue(detail, isTextValue);
                    if (value != null)
                        ProtocolEffectRecord2SubstanceProperty.addValues(master, key, value, oldValue);
                // }
                }
            }
            return master;
        }
    };
    return effectReader;
}
Also used : IQueryCondition(net.idea.modbcum.i.IQueryCondition) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) SubstanceRecord(ambit2.base.data.SubstanceRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) LiteratureEntry(ambit2.base.data.LiteratureEntry) Entry(java.util.Map.Entry) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) ProtocolEffectRecord(ambit2.base.data.study.ProtocolEffectRecord) MasterDetailsProcessor(net.idea.modbcum.p.MasterDetailsProcessor) StringReader(java.io.StringReader) Value(ambit2.base.data.study.Value) IParams(ambit2.base.data.study.IParams) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty)

Example 2 with ProtocolEffectRecord2SubstanceProperty

use of ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty in project ambit-mirror by ideaconsult.

the class CallableSubstancePropertyCreatorTest method testCreateSubstancePropertyFromRDF.

@Test
public void testCreateSubstancePropertyFromRDF() throws Exception {
    URL url = getClass().getClassLoader().getResource("feature.rdf");
    File file = new File(url.getFile());
    Assert.assertTrue(file.exists());
    try {
        PropertyURIReporter reporter = new PropertyURIReporter(new Reference("http://localhost:8081/ambit2"));
        CallableSubstancePropertyCreator callable = new CallableSubstancePropertyCreator(reporter, Method.POST, file, MediaType.APPLICATION_RDF_XML, null, null);
        TaskResult task = callable.call();
        ProtocolEffectRecord2SubstanceProperty p = new ProtocolEffectRecord2SubstanceProperty();
        ProtocolEffectRecord<String, IParams, String> effect = new ProtocolEffectRecord<String, IParams, String>();
        Protocol protocol = new Protocol(null);
        Protocol._categories category = Protocol._categories.EC_DAPHNIATOX_SECTION;
        protocol.setCategory(category.name());
        protocol.setTopCategory(category.getTopCategory());
        protocol.addGuideline("http://localhost:8080/ambit2/dataset/Method%3A+other%3A+Am.+Soc.+Test.+Mater.+%281980%29+and+U.S.+EPA+%281975%29");
        effect.setProtocol(protocol);
        effect.setEndpoint("EC10");
        effect.setUnit("mg/L");
        effect.setConditions(new Params());
        /*
			 * Value value = new Value(); value.setLoValue(48.0);
			 * value.setUnits("h"); effect.getConditions().put("Exposure",
			 * value);
			 */
        SubstanceProperty prop = p.process(effect);
        prop.setIdentifier(prop.createHashedIdentifier(effect.getConditions()));
        Assert.assertEquals(reporter.getURI(prop), task.getUri());
    } catch (Exception x) {
        throw x;
    } finally {
    }
}
Also used : Reference(org.restlet.data.Reference) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) Params(ambit2.base.data.study.Params) IParams(ambit2.base.data.study.IParams) URL(java.net.URL) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) ProtocolEffectRecord(ambit2.base.data.study.ProtocolEffectRecord) TaskResult(net.idea.restnet.i.task.TaskResult) IParams(ambit2.base.data.study.IParams) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) CallableSubstancePropertyCreator(ambit2.rest.substance.property.CallableSubstancePropertyCreator) Protocol(ambit2.base.data.study.Protocol) File(java.io.File) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Aggregations

IParams (ambit2.base.data.study.IParams)2 ProtocolEffectRecord (ambit2.base.data.study.ProtocolEffectRecord)2 SubstanceProperty (ambit2.base.data.substance.SubstanceProperty)2 ProtocolEffectRecord2SubstanceProperty (ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty)2 ILiteratureEntry (ambit2.base.data.ILiteratureEntry)1 LiteratureEntry (ambit2.base.data.LiteratureEntry)1 SubstanceRecord (ambit2.base.data.SubstanceRecord)1 Params (ambit2.base.data.study.Params)1 Protocol (ambit2.base.data.study.Protocol)1 Value (ambit2.base.data.study.Value)1 PropertyURIReporter (ambit2.rest.property.PropertyURIReporter)1 CallableSubstancePropertyCreator (ambit2.rest.substance.property.CallableSubstancePropertyCreator)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 File (java.io.File)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 Entry (java.util.Map.Entry)1 IQueryCondition (net.idea.modbcum.i.IQueryCondition)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1