use of ambit2.smarts.Node in project ambit-mirror by ideaconsult.
the class SubstanceLookupTest method verifyResponseJSON.
public boolean verifyResponseJSON(String uri, MediaType media, InputStreamReader reader) throws Exception {
// JsonNode node = parseResponseJSON(uri, media, in);
SubstanceStudyParser p = new SubstanceStudyParser(reader);
int i = 0;
while (p.hasNext()) {
Object o = p.next();
Assert.assertTrue(o instanceof SubstanceRecord);
Assert.assertEquals(testUUID, ((SubstanceRecord) o).getSubstanceUUID());
System.out.println(o);
i++;
}
return i == 1;
}
use of ambit2.smarts.Node 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.smarts.Node in project ambit-mirror by ideaconsult.
the class SubstanceStudyParser method parseReliability.
// ProtocolApplicationAnnotated
protected void parseReliability(ObjectNode node, ProtocolApplication record) {
if (node == null)
return;
ReliabilityParams reliability = new ReliabilityParams();
JsonNode jn = node.get(_FIELDS_RELIABILITY.r_isUsedforMSDS.name());
try {
reliability.setIsUsedforMSDS(jn.asBoolean());
} catch (Exception x) {
}
jn = node.get(_FIELDS_RELIABILITY.r_isRobustStudy.name());
try {
reliability.setIsRobustStudy(jn.asBoolean());
} catch (Exception x) {
}
jn = node.get(_FIELDS_RELIABILITY.r_isUsedforClassification.name());
try {
reliability.setIsUsedforClassification(jn.asBoolean());
} catch (Exception x) {
}
jn = node.get(_FIELDS_RELIABILITY.r_purposeFlag.name());
try {
reliability.setPurposeFlag(jn.textValue());
} catch (Exception x) {
}
jn = node.get(_FIELDS_RELIABILITY.r_studyResultType.name());
try {
reliability.setStudyResultType(jn.textValue());
} catch (Exception x) {
}
jn = node.get(_FIELDS_RELIABILITY.r_value.name());
try {
reliability.setValue(jn.textValue());
} catch (Exception x) {
}
record.setReliability(reliability);
}
use of ambit2.smarts.Node in project ambit-mirror by ideaconsult.
the class SubstanceStudyParser method parseTextValueProteomics.
public static IParams parseTextValueProteomics(ObjectMapper dx, String t) {
IParams nonzero = null;
if (t != null && t.startsWith("{")) {
IParams proteomics = SubstanceStudyParser.parseConditions(dx, t.toString());
Iterator i = proteomics.keySet().iterator();
nonzero = new Params();
while (i.hasNext()) {
Object p = i.next();
try {
Value node = (Value) proteomics.get(p);
if (node != null && (node.getLoValue() != null) && (node.getLoValue() instanceof Double) && ((Double) node.getLoValue()) > 0) {
nonzero.put(p, node.getLoValue());
}
} catch (Exception x) {
x.printStackTrace();
}
}
}
return nonzero;
}
use of ambit2.smarts.Node in project ambit-mirror by ideaconsult.
the class SubstanceStudyParser method parseSubstance.
public SubstanceRecord parseSubstance(JsonNode node) {
if (node == null)
return null;
SubstanceRecord record = new SubstanceRecord();
record.setSubstanceName(node.get(SubstanceRecord.jsonSubstance.name.name()).textValue());
record.setSubstanceUUID(node.get(SubstanceRecord.jsonSubstance.i5uuid.name()).textValue());
record.setOwnerName(node.get(SubstanceRecord.jsonSubstance.ownerName.name()).textValue());
record.setOwnerUUID(node.get(SubstanceRecord.jsonSubstance.ownerUUID.name()).textValue());
record.setPublicName(node.get(SubstanceRecord.jsonSubstance.publicname.name()).textValue());
record.setSubstancetype(node.get(SubstanceRecord.jsonSubstance.substanceType.name()).textValue());
record.setFormat(node.get(SubstanceRecord.jsonSubstance.format.name()).textValue());
JsonNode subnode = node.get(SubstanceRecord.jsonSubstance.externalIdentifiers.name());
if (subnode instanceof ArrayNode) {
ArrayNode ids = (ArrayNode) subnode;
List<ExternalIdentifier> extids = new ArrayList<ExternalIdentifier>();
record.setExternalids(extids);
for (int i = 0; i < ids.size(); i++) {
if (ids.get(i) instanceof ObjectNode) {
extids.add(new ExternalIdentifier(((ObjectNode) ids.get(i)).get("type").textValue(), ((ObjectNode) ids.get(i)).get("id").textValue()));
}
}
}
subnode = node.get(SubstanceRecord.jsonSubstance.referenceSubstance.name());
if (subnode != null) {
record.setReferenceSubstanceUUID(subnode.get(SubstanceRecord.jsonSubstance.i5uuid.name()).textValue());
}
return record;
}
Aggregations