Search in sources :

Example 16 with FormDataValue

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataValue 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

FormDataValue (edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)16 FormElementId (edu.stanford.bmir.protege.web.shared.form.field.FormElementId)9 HashMap (java.util.HashMap)8 FormData (edu.stanford.bmir.protege.web.shared.form.FormData)7 CollectionItemData (edu.stanford.bmir.protege.web.shared.collection.CollectionItemData)3 FormDataList (edu.stanford.bmir.protege.web.shared.form.data.FormDataList)3 FormDataObject (edu.stanford.bmir.protege.web.shared.form.data.FormDataObject)3 Test (org.junit.Test)3 FormId (edu.stanford.bmir.protege.web.shared.form.FormId)2 CheckBox (com.google.gwt.user.client.ui.CheckBox)1 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 FormDataPrimitive (edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive)1 ChoiceDescriptor (edu.stanford.bmir.protege.web.shared.form.field.ChoiceDescriptor)1 FormElementDescriptor (edu.stanford.bmir.protege.web.shared.form.field.FormElementDescriptor)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1