Search in sources :

Example 1 with CollectionItemData

use of edu.stanford.bmir.protege.web.shared.collection.CollectionItemData 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 CollectionItemData

use of edu.stanford.bmir.protege.web.shared.collection.CollectionItemData in project webprotege by protegeproject.

the class GetFormDescriptorActionHander method getDummy.

private GetFormDescriptorResult getDummy(CollectionId collectionId, FormId formId, CollectionItem elementId) {
    try {
        URL url = GetFormDescriptorActionHander.class.getResource("/amino-acid-form.json");
        System.out.println(url);
        InputStream is = GetFormDescriptorActionHander.class.getResourceAsStream("/amino-acid-form.json");
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule module = new SimpleModule();
        module.addDeserializer(FormDataValue.class, new FormDataValueDeserializer(dataFactory));
        mapper.registerModule(module);
        mapper.setDefaultPrettyPrinter(new DefaultPrettyPrinter());
        FormDescriptor d = mapper.readerFor(FormDescriptor.class).readValue(new BufferedInputStream(is));
        is.close();
        CollectionItemData formData = repository.find(collectionId, elementId);
        return new GetFormDescriptorResult(projectId, collectionId, elementId, formId, d, formData.getFormData().orElse(FormData.empty()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) CollectionItemData(edu.stanford.bmir.protege.web.shared.collection.CollectionItemData) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 3 with CollectionItemData

use of edu.stanford.bmir.protege.web.shared.collection.CollectionItemData in project webprotege by protegeproject.

the class SetFormDataActionHandler method execute.

@Nonnull
@Override
public SetFormDataResult execute(@Nonnull SetFormDataAction action, @Nonnull ExecutionContext executionContext) {
    FormData formData = action.getFormData();
    CollectionItemData data = null;
    if (formData.isEmpty()) {
        data = new CollectionItemData(action.getCollectionId(), action.getElementId());
    } else {
        data = new CollectionItemData(action.getCollectionId(), action.getElementId(), formData);
    }
    repository.save(data);
    return new SetFormDataResult();
}
Also used : FormData(edu.stanford.bmir.protege.web.shared.form.FormData) CollectionItemData(edu.stanford.bmir.protege.web.shared.collection.CollectionItemData) SetFormDataResult(edu.stanford.bmir.protege.web.shared.form.SetFormDataResult) Nonnull(javax.annotation.Nonnull)

Example 4 with CollectionItemData

use of edu.stanford.bmir.protege.web.shared.collection.CollectionItemData 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)

Example 5 with CollectionItemData

use of edu.stanford.bmir.protege.web.shared.collection.CollectionItemData in project webprotege by protegeproject.

the class CollectionElementDataRepository_IT method shouldFindByCollectionId.

@Test
public void shouldFindByCollectionId() {
    CollectionItemData data = new CollectionItemData(collectionId, elementId);
    repository.save(data);
    assertThat(repository.find(collectionId), hasItem(data));
}
Also used : CollectionItemData(edu.stanford.bmir.protege.web.shared.collection.CollectionItemData) Test(org.junit.Test)

Aggregations

CollectionItemData (edu.stanford.bmir.protege.web.shared.collection.CollectionItemData)7 Test (org.junit.Test)5 FormData (edu.stanford.bmir.protege.web.shared.form.FormData)4 FormDataValue (edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)3 FormElementId (edu.stanford.bmir.protege.web.shared.form.field.FormElementId)3 HashMap (java.util.HashMap)3 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 SetFormDataResult (edu.stanford.bmir.protege.web.shared.form.SetFormDataResult)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Nonnull (javax.annotation.Nonnull)1