use of ambit2.base.data.PropertyAnnotation 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;
}
use of ambit2.base.data.PropertyAnnotation in project ambit-mirror by ideaconsult.
the class PropertyAnnotationResource method createQuery.
@Override
protected IQueryRetrieval<PropertyAnnotation> createQuery(Context context, Request request, Response response) throws ResourceException {
Object o = request.getAttributes().get(PropertyResource.idfeaturedef);
if (o == null)
throw new InvalidResourceIDException(request.getResourceRef());
try {
int id = Integer.parseInt(o.toString());
ReadPropertyAnnotations q = new ReadPropertyAnnotations();
Property p = Property.getInstance("", "");
p.setId(id);
q.setFieldname(p);
return q;
} catch (NumberFormatException x) {
throw new InvalidResourceIDException(o);
} catch (Exception x) {
throw new InvalidResourceIDException(x);
} finally {
}
}
use of ambit2.base.data.PropertyAnnotation in project ambit-mirror by ideaconsult.
the class PropertyAnnotationTest method test1.
@Test
public void test1() throws Exception {
PropertyAnnotation a = new PropertyAnnotation();
a.setObject("o");
a.setPredicate("p");
a.setType("t");
Assert.assertEquals("\n\t{\t\"type\" : \"t\",\t\"p\" : \"p\",\t\"o\" : \"o\"}", a.toJSON());
}
use of ambit2.base.data.PropertyAnnotation in project ambit-mirror by ideaconsult.
the class DXParser method verifyDXProperty.
protected Property verifyDXProperty(Property property, Object value, ILiteratureEntry reference) throws AmbitException {
property.setReference(reference);
String[] split = property.getName().split("\\.");
JsonNode endpoint = (split.length > 1) ? dxRoot.get(json_fields.endpoints.name()).get(split[1]) : null;
JsonNode superEndpoint = endpoint == null ? null : endpoint.get("super");
JsonNode species = (split.length > 2) ? dxRoot.get(json_fields.species.name()).get(split[2]) : null;
if (species == null)
return null;
JsonNode ontology = null;
PropertyAnnotations pa = new PropertyAnnotations();
if (species != null) {
PropertyAnnotation a = new PropertyAnnotation();
a.setPredicate("species");
a.setObject(split[2]);
pa.add(a);
}
if (superEndpoint != null) {
PropertyAnnotation a = new PropertyAnnotation();
a.setPredicate("DX Superendpoint");
a.setObject(superEndpoint.textValue());
pa.add(a);
try {
ontology = dxRoot.get(json_fields.endpoints.name()).get(superEndpoint.textValue()).get(json_fields.ot.name());
} catch (Exception x) {
logger.log(Level.WARNING, x.getClass().getName() + " " + superEndpoint);
}
}
if (endpoint != null) {
PropertyAnnotation a = new PropertyAnnotation();
a.setPredicate("DX endpoint");
a.setObject(split[1]);
pa.add(a);
try {
if (endpoint.get(json_fields.ot.name()) != null)
ontology = endpoint.get(json_fields.ot.name());
} catch (Exception x) {
logger.log(Level.WARNING, x.getClass().getName() + " " + endpoint);
}
}
if (ontology != null)
property.setLabel(ontology.textValue());
for (PropertyAnnotation a : categories) pa.add(a);
property.setAnnotations(pa);
return property;
}
use of ambit2.base.data.PropertyAnnotation in project ambit-mirror by ideaconsult.
the class ProtocolEffectRecord2SubstanceProperty method conditions2annotations.
public PropertyAnnotations conditions2annotations(ProtocolEffectRecord<String, IParams, String> detail) throws JsonProcessingException, IOException {
PropertyAnnotations ann = new PropertyAnnotations();
/*
* works but is a hack if (detail.getStudyResultType() != null) {
* PropertyAnnotation a = new PropertyAnnotation();
* a.setType("reliability"); a.setPredicate("studyResultType");
* a.setObject(detail.getStudyResultType()); ann.add(a); }
*/
if (detail.getConditions() == null)
return ann;
Iterator<Map.Entry> entries = detail.getConditions().entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = entries.next();
Object key = entry.getKey();
Object o = entry.getValue();
if (o == null)
continue;
else if (o instanceof Value) {
Value value = (Value) o;
PropertyAnnotation a = new PropertyAnnotation();
a.setType("conditions");
a.setPredicate(key.toString());
if (value.getLoValue() instanceof String) {
a.setObject(value.getLoValue());
} else {
a.setObject(String.format("%s%s %s%s %s", value.getLoQualifier() == null ? "" : value.getLoQualifier(), value.getLoValue() == null ? "" : value.getLoValue(), value.getUpQualifier() == null ? "" : value.getUpQualifier(), value.getUpValue() == null ? "" : value.getUpValue(), value.getUnits() == null ? "" : value.getUnits()));
}
ann.add(a);
} else {
PropertyAnnotation a = new PropertyAnnotation();
a.setType("conditions");
a.setPredicate(key.toString());
a.setObject(o.toString());
ann.add(a);
}
}
return ann;
}
Aggregations