use of com.openmeap.event.EventNotificationException in project OpenMEAP by OpenMEAP.
the class DeploymentAddModifyNotifier method maintainDeploymentHistoryLength.
/**
* Trim the deployment history table. Deleting old archives as we go.
* @param app
* @throws EventNotificationException
* @throws PersistenceException
* @throws InvalidPropertiesException
*/
private Boolean maintainDeploymentHistoryLength(Application app, List<ProcessingEvent> events) throws EventNotificationException {
getModelManager().getModelService().refresh(app);
Integer lengthToMaintain = app.getDeploymentHistoryLength();
List<Deployment> deployments = app.getDeployments();
if (deployments != null && deployments.size() > lengthToMaintain) {
Integer currentSize = deployments.size();
List<Deployment> newDeployments = new ArrayList<Deployment>(deployments.subList(currentSize - lengthToMaintain, currentSize));
List<Deployment> oldDeployments = new ArrayList<Deployment>(deployments.subList(0, currentSize - lengthToMaintain));
for (Deployment deployment : oldDeployments) {
getModelManager().delete(deployment, events);
}
for (Deployment deployment : newDeployments) {
app.getDeployments().add(deployment);
}
try {
getModelManager().addModify(app, events);
} catch (InvalidPropertiesException e) {
throw new EventNotificationException(e);
} catch (PersistenceException e) {
throw new EventNotificationException(e);
}
return true;
}
return false;
}
use of com.openmeap.event.EventNotificationException in project OpenMEAP by OpenMEAP.
the class ModelManagerImplTest method testFireEventHandlers.
@Test
public void testFireEventHandlers() throws InvalidPropertiesException, PersistenceException {
List<ModelServiceEventNotifier> handlers = new ArrayList<ModelServiceEventNotifier>();
class MockUpdateNotifier extends AbstractModelServiceEventNotifier<ModelEntity> {
public Boolean eventFired = false;
public Boolean getEventFired() {
return eventFired;
}
@Override
public Boolean notifiesFor(ModelServiceOperation operation, ModelEntity payload) {
return true;
}
@Override
public <E extends Event<ModelEntity>> void onInCommitAfterCommit(E event, List<ProcessingEvent> events) throws EventNotificationException {
eventFired = true;
}
}
;
handlers.add(new MockUpdateNotifier());
modelManager.setEventNotifiers(handlers);
Application app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
try {
modelManager.begin().addModify(app, null);
modelManager.commit();
} catch (Exception e) {
modelManager.rollback();
}
Assert.assertTrue(((MockUpdateNotifier) modelManager.getEventNotifiers().toArray()[0]).getEventFired());
}
Aggregations