Search in sources :

Example 1 with PersistableDataObject

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject in project kie-wb-common by kiegroup.

the class DataModelerEventObserver method onDataObjectCreated.

public void onDataObjectCreated(@Observes DataObjectCreatedEvent event) {
    Path descriptorPath;
    PersistenceDescriptorModel persistenceDescriptor;
    if (isPersistable(event.getCurrentDataObject())) {
        descriptorPath = descriptorService.calculatePersistenceDescriptorPath(event.getCurrentModule());
        persistenceDescriptor = safeLoad(descriptorPath);
        if (persistenceDescriptor != null && !containsClass(persistenceDescriptor.getPersistenceUnit(), event.getCurrentDataObject().getClassName())) {
            persistenceDescriptor.getPersistenceUnit().getClasses().add(new PersistableDataObject(event.getCurrentDataObject().getClassName()));
            descriptorService.save(descriptorPath, persistenceDescriptor, null, "Entity added to persistence descriptor");
        }
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) PersistableDataObject(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject) PersistenceDescriptorModel(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel)

Example 2 with PersistableDataObject

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject in project kie-wb-common by kiegroup.

the class DataModelerEventObserverTest method onNonPersistableDataObjectDeletedTest.

@Test
public void onNonPersistableDataObjectDeletedTest() {
    DataObject dataObject = new DataObjectImpl("package1", "NonPersistableObject");
    DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject);
    eventObserver.onDataObjectCreated(createdEvent);
    descriptorModel.getPersistenceUnit().getClasses().add(new PersistableDataObject(createdEvent.getCurrentDataObject().getClassName()));
    verify(descriptorService, times(0)).save(eq(descriptorPath), eq(descriptorModel), Mockito.<Metadata>any(), anyString());
    assertEquals(1, descriptorModel.getPersistenceUnit().getClasses().size());
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) PersistableDataObject(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject) PersistableDataObject(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataObjectCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent) Test(org.junit.Test)

Example 3 with PersistableDataObject

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject in project kie-wb-common by kiegroup.

the class DataModelerEventObserverTest method onNonPersistableDataObjectCreatedTest.

@Test
public void onNonPersistableDataObjectCreatedTest() {
    descriptorModel.getPersistenceUnit().getClasses().add(new PersistableDataObject("package1.PersistableObject"));
    DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject);
    eventObserver.onDataObjectCreated(createdEvent);
    verify(descriptorService, times(0)).save(eq(descriptorPath), eq(descriptorModel), Mockito.<Metadata>any(), anyString());
    assertEquals(1, descriptorModel.getPersistenceUnit().getClasses().size());
}
Also used : PersistableDataObject(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject) DataObjectCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent) Test(org.junit.Test)

Example 4 with PersistableDataObject

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject in project kie-wb-common by kiegroup.

the class DataModelerEventObserverTest method onPersistableDataObjectCreatedTest.

@Test
public void onPersistableDataObjectCreatedTest() {
    DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject);
    eventObserver.onDataObjectCreated(createdEvent);
    verify(descriptorService, times(1)).save(eq(descriptorPath), eq(descriptorModel), Mockito.<Metadata>any(), anyString());
    assertTrue(descriptorModel.getPersistenceUnit().getClasses().contains(new PersistableDataObject(dataObject.getClassName())));
}
Also used : PersistableDataObject(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject) DataObjectCreatedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent) Test(org.junit.Test)

Example 5 with PersistableDataObject

use of org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject in project kie-wb-common by kiegroup.

the class DataModelerEventObserverTest method onPersistableDataObjectDeletedTest.

@Test
public void onPersistableDataObjectDeletedTest() {
    DataObjectDeletedEvent deletedEvent = new DataObjectDeletedEvent(module, dataObject);
    descriptorModel.getPersistenceUnit().getClasses().add(new PersistableDataObject(deletedEvent.getCurrentDataObject().getClassName()));
    eventObserver.onDataObjectDeleted(deletedEvent);
    verify(descriptorService, times(1)).save(eq(descriptorPath), eq(descriptorModel), Mockito.<Metadata>any(), anyString());
    assertFalse(descriptorModel.getPersistenceUnit().getClasses().contains(new PersistableDataObject(dataObject.getClassName())));
}
Also used : PersistableDataObject(org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject) DataObjectDeletedEvent(org.kie.workbench.common.screens.datamodeller.events.DataObjectDeletedEvent) Test(org.junit.Test)

Aggregations

PersistableDataObject (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistableDataObject)13 Test (org.junit.Test)6 PersistenceDescriptorModel (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorModel)5 DataObjectCreatedEvent (org.kie.workbench.common.screens.datamodeller.events.DataObjectCreatedEvent)3 PersistenceUnitModel (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceUnitModel)3 Property (org.kie.workbench.common.screens.datamodeller.model.persistence.Property)2 Path (org.uberfire.backend.vfs.Path)2 ArrayList (java.util.ArrayList)1 Overview (org.guvnor.common.services.shared.metadata.model.Overview)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 DataObjectDeletedEvent (org.kie.workbench.common.screens.datamodeller.events.DataObjectDeletedEvent)1 PersistenceDescriptorEditorContent (org.kie.workbench.common.screens.datamodeller.model.persistence.PersistenceDescriptorEditorContent)1 PersistencePresenter (org.kie.workbench.common.screens.library.client.settings.sections.persistence.PersistencePresenter)1 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)1 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)1 Element (org.w3c.dom.Element)1