use of edu.stanford.bmir.protege.web.shared.form.data.FormDataObject in project webprotege by protegeproject.
the class CompositeFieldEditor method getValue.
@Override
public Optional<FormDataValue> getValue() {
GWT.log("[CompositeFieldEditor] Getting values");
Map<String, FormDataValue> childData = new HashMap<>();
for (FormElementId childId : childEditors.keySet()) {
GWT.log("[CompositeFieldEditor] " + childId);
ValueEditor<FormDataValue> childEditor = childEditors.get(childId);
if (childEditor != null) {
Optional<FormDataValue> childValue = childEditor.getValue();
GWT.log("[CompositeFieldEditor] Value: " + childValue);
if (childValue.isPresent()) {
childData.put(childId.getId(), childValue.get());
}
}
}
GWT.log("[CompositeFieldEditor] All values: " + childData);
if (childData.isEmpty()) {
return Optional.empty();
}
FormDataObject theValue = new FormDataObject(childData);
GWT.log("[CompositeFieldEditor] The value: " + theValue);
return Optional.of(theValue);
}
use of edu.stanford.bmir.protege.web.shared.form.data.FormDataObject in project webprotege by protegeproject.
the class FormDataValueConverter method encodeObject.
@Override
public Object encodeObject(FormDataValue value, MappedField optionalExtraInfo) {
if (value instanceof FormDataObject) {
Document document = new Document();
FormDataObject object = (FormDataObject) value;
object.getMap().forEach((key, val) -> document.put(key, encodeObject(val, optionalExtraInfo)));
return document;
} else if (value instanceof FormDataList) {
List<Object> result = new ArrayList<>();
FormDataList list = (FormDataList) value;
list.getList().forEach(e -> result.add(encodeObject(e, optionalExtraInfo)));
return result;
} else if (value instanceof FormDataPrimitive) {
FormDataPrimitive primitive = (FormDataPrimitive) value;
if (primitive.isNumber()) {
return primitive.getValueAsDouble();
} else if (primitive.isString()) {
return primitive.getValueAsString();
} else if (primitive.isBoolean()) {
return primitive.getValueAsBoolean();
} else if (primitive instanceof FormDataPrimitive.LiteralPrimitive) {
OWLLiteral literal = primitive.asLiteral().get();
Document document = new Document();
document.put("literal", literal.getLiteral());
if (literal.isRDFPlainLiteral()) {
document.put("lang", literal.getLang());
} else {
document.put("datatype", literal.getDatatype());
}
return document;
} else if (primitive instanceof FormDataPrimitive.IRIPrimitive) {
return new Document("iri", primitive.asIRI().get().toString());
} else if (primitive instanceof FormDataPrimitive.OWLEntityPrimitive) {
OWLEntity entity = (OWLEntity) primitive.getValue();
return entityConverter.encodeObject(entity, optionalExtraInfo);
}
} else {
throw new RuntimeException("Unknown type of object " + value);
}
return null;
}
use of edu.stanford.bmir.protege.web.shared.form.data.FormDataObject in project webprotege by protegeproject.
the class FormDataRepository_IT method shouldRetriveData.
// @Test
public void shouldRetriveData() throws Exception {
Map<FormElementId, FormDataValue> map = new HashMap<>();
map.put(FormElementId.get("FirstName"), FormDataPrimitive.get("John"));
map.put(FormElementId.get("LastName"), FormDataPrimitive.get("Smith"));
map.put(FormElementId.get("Age"), FormDataPrimitive.get(62));
map.put(FormElementId.get("Tenure"), FormDataPrimitive.get(true));
Map<String, FormDataValue> val = new HashMap<>();
val.put("Street", FormDataPrimitive.get("1265 Welch Road"));
val.put("City", FormDataPrimitive.get("Stanford"));
val.put("State", FormDataPrimitive.get("CA"));
val.put("Zip", FormDataPrimitive.get(94304));
FormDataObject address = new FormDataObject(val);
map.put(FormElementId.get("Address"), address);
map.put(FormElementId.get("Projects"), new FormDataList(Arrays.asList(FormDataPrimitive.get("Protégé Project"), FormDataPrimitive.get("Bioportal"))));
map.put(FormElementId.get("Homepage"), FormDataPrimitive.get(IRI.create("http://www.stanford.edu/~johnsmith")));
FormData formData = new FormData(map);
FormId formId = new FormId("MyForm");
repository.store(projectId, collectionId, formId, entity, formData);
FormData fd = repository.get(projectId, collectionId, formId, entity);
assertThat(fd, Matchers.is(formData));
}
Aggregations