Search in sources :

Example 1 with ChangeEvent

use of org.geneontology.minerva.UndoAwareMolecularModelManager.ChangeEvent in project minerva by geneontology.

the class OperationsImpl method getCurrentUndoRedoForModel.

private void getCurrentUndoRedoForModel(M3BatchResponse response, IRI modelId, String userId) {
    Pair<List<ChangeEvent>, List<ChangeEvent>> undoRedoEvents = m3.getUndoRedoEvents(modelId);
    initMetaResponse(response);
    List<Map<Object, Object>> undos = new ArrayList<Map<Object, Object>>();
    List<Map<Object, Object>> redos = new ArrayList<Map<Object, Object>>();
    final long currentTime = System.currentTimeMillis();
    for (ChangeEvent undo : undoRedoEvents.getLeft()) {
        Map<Object, Object> data = new HashMap<Object, Object>(3);
        data.put("user-id", undo.getUserId());
        data.put("time", Long.valueOf(currentTime - undo.getTime()));
        // TODO add a summary of the change? axiom count?
        undos.add(data);
    }
    for (ChangeEvent redo : undoRedoEvents.getRight()) {
        Map<Object, Object> data = new HashMap<Object, Object>(3);
        data.put("user-id", redo.getUserId());
        data.put("time", Long.valueOf(currentTime - redo.getTime()));
        // TODO add a summary of the change? axiom count?
        redos.add(data);
    }
    response.data.undo = undos;
    response.data.redo = redos;
}
Also used : ChangeEvent(org.geneontology.minerva.UndoAwareMolecularModelManager.ChangeEvent) JsonObject(com.google.gson.JsonObject)

Example 2 with ChangeEvent

use of org.geneontology.minerva.UndoAwareMolecularModelManager.ChangeEvent in project minerva by geneontology.

the class UndoAwareMolecularModelManagerTest method testUndoRedo.

@Test
public void testUndoRedo() throws Exception {
    OWLOntology tbox = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(this.getClass().getResourceAsStream("/go-mgi-signaling-test.obo"));
    m3 = new UndoAwareMolecularModelManager(tbox, curieHandler, "http://testmodel.geneontology.org/", folder.newFile().getAbsolutePath(), null, go_lego_journal_file, true);
    String userId = "test-user-id";
    ModelContainer model = m3.generateBlankModel(null);
    // GO:0001158 ! enhancer sequence-specific DNA binding
    OWLNamedIndividual bindingIdividual = m3.createIndividual(model.getModelId(), "GO:0001158", null, new UndoMetadata(userId));
    String bindingId = bindingIdividual.getIRI().toString();
    // BFO:0000066 GO:0005654 ! occurs_in nucleoplasm
    m3.addType(model.getModelId(), bindingId, "BFO:0000066", "GO:0005654", new UndoMetadata(userId));
    MolecularModelJsonRenderer renderer = new MolecularModelJsonRenderer(model, null, curieHandler);
    JsonOwlIndividual render1 = renderer.renderObject(bindingIdividual);
    assertEquals(2, render1.type.length);
    // check event count
    Pair<List<ChangeEvent>, List<ChangeEvent>> undoRedoEvents = m3.getUndoRedoEvents(model.getModelId());
    List<ChangeEvent> undoEvents = undoRedoEvents.getLeft();
    List<ChangeEvent> redoEvents = undoRedoEvents.getRight();
    assertEquals(0, redoEvents.size());
    assertEquals(2, undoEvents.size());
    // undo
    assertTrue(m3.undo(model, userId));
    JsonOwlIndividual render2 = renderer.renderObject(bindingIdividual);
    assertEquals(1, render2.type.length);
    // redo
    assertTrue(m3.redo(model, userId));
    JsonOwlIndividual render3 = renderer.renderObject(bindingIdividual);
    assertEquals(2, render3.type.length);
    // undo again
    assertTrue(m3.undo(model, userId));
    JsonOwlIndividual render4 = renderer.renderObject(bindingIdividual);
    assertEquals(1, render4.type.length);
    // add new type
    // GO:0001664 ! G-protein coupled receptor binding
    m3.addType(model.getModelId(), bindingId, "GO:0001664", new UndoMetadata(userId));
    // redo again, should fail
    assertFalse(m3.redo(model, userId));
    if (m3 != null) {
        m3.dispose();
    }
}
Also used : ChangeEvent(org.geneontology.minerva.UndoAwareMolecularModelManager.ChangeEvent) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) UndoMetadata(org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) List(java.util.List) JsonOwlIndividual(org.geneontology.minerva.json.JsonOwlIndividual) MolecularModelJsonRenderer(org.geneontology.minerva.json.MolecularModelJsonRenderer) Test(org.junit.Test)

Aggregations

ChangeEvent (org.geneontology.minerva.UndoAwareMolecularModelManager.ChangeEvent)2 JsonObject (com.google.gson.JsonObject)1 List (java.util.List)1 UndoMetadata (org.geneontology.minerva.UndoAwareMolecularModelManager.UndoMetadata)1 JsonOwlIndividual (org.geneontology.minerva.json.JsonOwlIndividual)1 MolecularModelJsonRenderer (org.geneontology.minerva.json.MolecularModelJsonRenderer)1 Test (org.junit.Test)1 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1