use of ambit2.base.data.ILiteratureEntry 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.ILiteratureEntry in project ambit-mirror by ideaconsult.
the class CallableFileImport method datasetMeta.
protected SourceDataset datasetMeta(File file) {
String title = properties == null ? null : properties.get("title");
title = title == null ? fileDescription : ("".equals(title.trim()) ? fileDescription : title.trim());
String source = properties == null ? null : properties.get(AbstractDataset._props.source.name());
source = source == null ? fileDescription : source;
String license = properties == null ? null : properties.get(AbstractDataset._props.license.name());
license = license == null ? ISourceDataset.license.Unknown.getURI() : license;
String rightsHolder = properties == null ? null : properties.get(AbstractDataset._props.rightsHolder.name());
rightsHolder = rightsHolder == null ? "Unknown" : rightsHolder;
String seeAlso = properties == null ? null : properties.get(AbstractDataset._props.seeAlso.name());
String publisher = seeAlso == null ? client == null ? "File uploaded by user" : (client.getUser() == null ? client.getAddress() : client.getUser().getIdentifier() == null ? client.getAddress() : client.getUser().getIdentifier()) : seeAlso;
ILiteratureEntry reference = LiteratureEntry.getInstance(source, publisher);
reference.setType(_type.Dataset);
SourceDataset dataset = new SourceDataset(title, reference);
dataset.setLicenseURI(license);
dataset.setrightsHolder(rightsHolder);
return dataset;
}
use of ambit2.base.data.ILiteratureEntry 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.ILiteratureEntry in project ambit-mirror by ideaconsult.
the class AbstractPropertyRetrieval method getObject.
/*
WARNING: No enum const class ambit2.db.search.property.AbstractPropertyRetrieval$_PROPERTY_TYPE.
java.lang.IllegalArgumentException: No enum const class ambit2.db.search.property.AbstractPropertyRetrieval$_PROPERTY_TYPE.
at java.lang.Enum.valueOf(Enum.java:214)
at ambit2.db.search.property.AbstractPropertyRetrieval$_PROPERTY_TYPE.valueOf(AbstractPropertyRetrieval.java:104)
at ambit2.db.search.property.AbstractPropertyRetrieval.getObject(AbstractPropertyRetrieval.java:164)
at ambit2.db.search.property.AbstractPropertyRetrieval.getObject(AbstractPropertyRetrieval.java:141)
at ambit2.db.search.property.AbstractPropertyRetrieval.getObject(AbstractPropertyRetrieval.java:45)
at ambit2.db.DbReader$1.next(DbReader.java:159)
at ambit2.db.processors.AbstractBatchProcessor.process(AbstractBatchProcessor.java:105)
at ambit2.db.reporters.QueryAbstractReporter.process(QueryAbstractReporter.java:115)
at ambit2.rest.AbstractObjectConvertor.process(AbstractObjectConvertor.java:41)
at ambit2.rest.AbstractObjectConvertor.process(AbstractObjectConvertor.java:17)
at ambit2.rest.query.QueryResource.getRepresentation(QueryResource.java:183)
at ambit2.rest.AbstractResource.get(AbstractResource.java:98)
at org.restlet.resource.ServerResource.doHandle(ServerResource.java:519)
at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:579)
at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:258)
at org.restlet.resource.ServerResource.handle(ServerResource.java:818)
*/
public Property getObject(ResultSet rs, Property p) throws AmbitException {
try {
if (p == null) {
p = Property.getInstance(rs.getString("name"), rs.getString("title"), rs.getString("url"));
} else {
p.setName(rs.getString("name"));
// !!!!!!!!!!!!!!!!!! update the rest
}
try {
p.setOrder(rs.getInt("order"));
} catch (Exception x) {
}
p.setId(rs.getInt("idproperty"));
p.setUnits(rs.getString("units"));
p.setLabel(rs.getString("comments"));
p.getReference().setId(rs.getInt("idreference"));
try {
String type = rs.getString("idtype");
String[] types = null;
if (type != null && !"".equals(type)) {
types = type.split(",");
for (String t : types) try {
p.setClazz(_PROPERTY_TYPE.valueOf(t).getClazz());
} catch (Exception x) {
logger.log(Level.WARNING, x.getMessage(), t);
}
}
} catch (Exception x) {
logger.log(Level.FINE, x.getMessage(), x);
}
try {
p.setNominal(rs.getBoolean("islocal"));
} catch (Exception x) {
p.setNominal(false);
}
try {
String _type = rs.getString("type");
if (_type != null)
p.getReference().setType(ILiteratureEntry._type.valueOf(_type));
} catch (Exception x) {
}
PropertyAnnotation<String> a = null;
for (ANNOTATIONS_TABLE f : ANNOTATIONS_TABLE.values()) try {
String value = rs.getString(f.name());
if (value == null)
break;
if (a == null)
a = new PropertyAnnotation<String>();
f.setValue(a, value);
} catch (Exception x) {
}
if (a != null) {
if (p.getAnnotations() == null)
p.setAnnotations(new PropertyAnnotations());
p.getAnnotations().add(a);
}
return p;
} catch (SQLException x) {
throw new AmbitException(x);
}
}
use of ambit2.base.data.ILiteratureEntry in project ambit-mirror by ideaconsult.
the class PropertiesByDataset method getObject.
@Override
public Property getObject(ResultSet rs) throws AmbitException {
try {
Property p = Property.getInstance(rs.getString(2), rs.getString(4), rs.getString(5));
p.setId(rs.getInt(1));
p.setUnits(rs.getString(3));
p.setLabel(rs.getString(7));
p.getReference().setId(rs.getInt(6));
try {
p.setOrder(rs.getInt("order"));
} catch (Exception x) {
}
try {
String type = rs.getString(8);
if (type != null) {
String[] types = type.split(",");
for (// TODO support multiple types per property
String t : // TODO support multiple types per property
types) p.setClazz(_PROPERTY_TYPE.valueOf(t).getClazz());
}
} catch (Exception x) {
}
try {
p.setNominal(rs.getBoolean(9));
} catch (Exception x) {
p.setNominal(false);
}
try {
String _type = rs.getString(10);
if (_type != null)
p.getReference().setType(ILiteratureEntry._type.valueOf(_type));
} catch (Exception x) {
}
PropertyAnnotation<String> a = null;
for (ANNOTATIONS_TABLE f : ANNOTATIONS_TABLE.values()) try {
String value = rs.getString(f.name());
if (value == null)
break;
if (a == null)
a = new PropertyAnnotation<String>();
f.setValue(a, value);
} catch (Exception x) {
}
if (a != null) {
if (p.getAnnotations() == null)
p.setAnnotations(new PropertyAnnotations());
p.getAnnotations().add(a);
}
return p;
} catch (SQLException x) {
throw new AmbitException(x);
}
}
Aggregations