Search in sources :

Example 1 with FormElementId

use of edu.stanford.bmir.protege.web.shared.form.field.FormElementId in project webprotege by protegeproject.

the class CollectionElementDataRepository_IT method shouldFindByCollectionIdAndElementId.

@Test
public void shouldFindByCollectionIdAndElementId() {
    Map<FormElementId, FormDataValue> map = new HashMap<>();
    map.put(FormElementId.get("theElement"), FormDataPrimitive.get("theValue"));
    FormData formData = new FormData(map);
    CollectionItemData data = new CollectionItemData(collectionId, elementId, formData);
    repository.save(data);
    assertThat(repository.find(collectionId, elementId), is(data));
}
Also used : FormData(edu.stanford.bmir.protege.web.shared.form.FormData) CollectionItemData(edu.stanford.bmir.protege.web.shared.collection.CollectionItemData) FormElementId(edu.stanford.bmir.protege.web.shared.form.field.FormElementId) HashMap(java.util.HashMap) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue) Test(org.junit.Test)

Example 2 with FormElementId

use of edu.stanford.bmir.protege.web.shared.form.field.FormElementId in project webprotege by protegeproject.

the class FormDataConverter method decodeObject.

@Override
public FormData decodeObject(DBObject fromDBObject, MappedField optionalExtraInfo) {
    Map<FormElementId, FormDataValue> map = new HashMap<>();
    fromDBObject.keySet().forEach(key -> {
        FormDataValue value = valueConverter.decodeObject(fromDBObject.get(key), optionalExtraInfo);
        map.put(FormElementId.get(key), value);
    });
    return new FormData(map);
}
Also used : FormData(edu.stanford.bmir.protege.web.shared.form.FormData) FormElementId(edu.stanford.bmir.protege.web.shared.form.field.FormElementId) HashMap(java.util.HashMap) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)

Example 3 with FormElementId

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

Example 4 with FormElementId

use of edu.stanford.bmir.protege.web.shared.form.field.FormElementId in project webprotege by protegeproject.

the class FormPresenter method setFormData.

private void setFormData(@Nonnull FormData formData) {
    formView.getElementViews().forEach(view -> {
        Optional<FormElementId> theId = view.getId();
        if (theId.isPresent()) {
            FormElementId id = theId.get();
            Optional<FormDataValue> formElementData = formData.getFormElementData(id);
            if (formElementData.isPresent()) {
                view.getEditor().setValue(formElementData.get());
            } else {
                view.getEditor().clearValue();
            }
            updateRequiredValuePresent(view);
        } else {
            view.getEditor().clearValue();
        }
    });
}
Also used : FormElementId(edu.stanford.bmir.protege.web.shared.form.field.FormElementId) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)

Example 5 with FormElementId

use of edu.stanford.bmir.protege.web.shared.form.field.FormElementId in project webprotege by protegeproject.

the class CollectionElementDataRepository_IT method shouldUpdateCollectionElementData.

@Test
public void shouldUpdateCollectionElementData() {
    Map<FormElementId, FormDataValue> map = new HashMap<>();
    map.put(FormElementId.get("theElement"), FormDataPrimitive.get("theValue"));
    FormData formData = new FormData(map);
    repository.save(new CollectionItemData(collectionId, elementId, formData));
    Map<FormElementId, FormDataValue> map2 = new HashMap<>();
    map.put(FormElementId.get("theElement"), FormDataPrimitive.get("theNewValue"));
    FormData theNewformData = new FormData(map2);
    repository.save(new CollectionItemData(collectionId, elementId, theNewformData));
    assertThat(datastore.getCount(CollectionItemData.class), is(1L));
}
Also used : FormData(edu.stanford.bmir.protege.web.shared.form.FormData) CollectionItemData(edu.stanford.bmir.protege.web.shared.collection.CollectionItemData) FormElementId(edu.stanford.bmir.protege.web.shared.form.field.FormElementId) HashMap(java.util.HashMap) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue) Test(org.junit.Test)

Aggregations

FormDataValue (edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)9 FormElementId (edu.stanford.bmir.protege.web.shared.form.field.FormElementId)9 FormData (edu.stanford.bmir.protege.web.shared.form.FormData)7 HashMap (java.util.HashMap)7 CollectionItemData (edu.stanford.bmir.protege.web.shared.collection.CollectionItemData)3 Test (org.junit.Test)3 FormId (edu.stanford.bmir.protege.web.shared.form.FormId)2 FormDataList (edu.stanford.bmir.protege.web.shared.form.data.FormDataList)2 FormDataObject (edu.stanford.bmir.protege.web.shared.form.data.FormDataObject)2 LinkedHashMap (java.util.LinkedHashMap)1