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");
}
}
}
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());
}
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());
}
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())));
}
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())));
}
Aggregations