Search in sources :

Example 1 with FormDataList

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataList in project webprotege by protegeproject.

the class PropertyValueFormDataTranslator method toOWLObject.

private Set<OWLObject> toOWLObject(FormDataValue dataValue) {
    if (dataValue instanceof FormDataPrimitive) {
        FormDataPrimitive formDataPrimitive = (FormDataPrimitive) dataValue;
        OWLObject owlObject = formDataPrimitive.toOWLObject();
        return Collections.singleton(owlObject);
    } else if (dataValue instanceof FormDataList) {
        FormDataList formDataList = (FormDataList) dataValue;
        return formDataList.getList().stream().flatMap(e -> toOWLObject(e).stream()).collect(toSet());
    } else {
        throw new RuntimeException("Cannot convert to OWL Object");
    }
}
Also used : FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) FormDataPrimitive(edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive)

Example 2 with FormDataList

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataList 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;
}
Also used : TypeSafeConverter(edu.stanford.bmir.protege.web.server.persistence.TypeSafeConverter) Document(org.bson.Document) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLEntityConverter(edu.stanford.bmir.protege.web.server.persistence.OWLEntityConverter) HashMap(java.util.HashMap) FormDataPrimitive(edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive) FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) MappedField(org.mongodb.morphia.mapping.MappedField) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) List(java.util.List) FormDataObject(edu.stanford.bmir.protege.web.shared.form.data.FormDataObject) DBObject(com.mongodb.DBObject) IRI(org.semanticweb.owlapi.model.IRI) Map(java.util.Map) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue) SimpleValueConverter(org.mongodb.morphia.converters.SimpleValueConverter) FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) FormDataPrimitive(edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive) FormDataObject(edu.stanford.bmir.protege.web.shared.form.data.FormDataObject) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Document(org.bson.Document) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with FormDataList

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataList 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));
}
Also used : FormData(edu.stanford.bmir.protege.web.shared.form.FormData) FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) FormElementId(edu.stanford.bmir.protege.web.shared.form.field.FormElementId) HashMap(java.util.HashMap) FormDataObject(edu.stanford.bmir.protege.web.shared.form.data.FormDataObject) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue) FormId(edu.stanford.bmir.protege.web.shared.form.FormId)

Example 4 with FormDataList

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataList in project webprotege by protegeproject.

the class PropertyValueFormDataTranslator method toFormData.

/**
 * Translates the specified property values into form data using the specified binding.
 *
 * @param propertyValues The property values to be translated.
 * @return The form data corresponding to the translated frame.
 */
public FormData toFormData(@Nonnull Set<PropertyValue> propertyValues, @Nonnull Map<OWLProperty, FormElementId> binding) {
    ListMultimap<FormElementId, FormDataValue> dataMultiMap = ArrayListMultimap.create();
    propertyValues.forEach(propertyValue -> {
        OWLProperty entity = propertyValue.getProperty().getEntity();
        FormElementId formElementId = binding.get(entity);
        if (formElementId != null) {
            OWLPrimitiveData owlVal = propertyValue.getValue();
            FormDataValue val = toFormDataValue(owlVal);
            dataMultiMap.put(formElementId, val);
        }
    });
    Map<FormElementId, FormDataValue> dataMap = new HashMap<>();
    for (FormElementId formElementId : dataMultiMap.keySet()) {
        List<FormDataValue> dataValues = dataMultiMap.get(formElementId);
        if (dataValues.size() == 1) {
            dataMap.put(formElementId, dataValues.get(0));
        } else {
            dataMap.put(formElementId, new FormDataList(dataValues));
        }
    }
    return new FormData(dataMap);
}
Also used : FormData(edu.stanford.bmir.protege.web.shared.form.FormData) FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) FormElementId(edu.stanford.bmir.protege.web.shared.form.field.FormElementId) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)

Aggregations

FormDataList (edu.stanford.bmir.protege.web.shared.form.data.FormDataList)4 FormDataValue (edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)3 FormData (edu.stanford.bmir.protege.web.shared.form.FormData)2 FormDataObject (edu.stanford.bmir.protege.web.shared.form.data.FormDataObject)2 FormDataPrimitive (edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive)2 FormElementId (edu.stanford.bmir.protege.web.shared.form.field.FormElementId)2 HashMap (java.util.HashMap)2 DBObject (com.mongodb.DBObject)1 OWLEntityConverter (edu.stanford.bmir.protege.web.server.persistence.OWLEntityConverter)1 TypeSafeConverter (edu.stanford.bmir.protege.web.server.persistence.TypeSafeConverter)1 FormId (edu.stanford.bmir.protege.web.shared.form.FormId)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Inject (javax.inject.Inject)1 Document (org.bson.Document)1 SimpleValueConverter (org.mongodb.morphia.converters.SimpleValueConverter)1 MappedField (org.mongodb.morphia.mapping.MappedField)1 IRI (org.semanticweb.owlapi.model.IRI)1 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)1