Search in sources :

Example 1 with EventNotificationException

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;
}
Also used : InvalidPropertiesException(com.openmeap.model.InvalidPropertiesException) EventNotificationException(com.openmeap.event.EventNotificationException) ArrayList(java.util.ArrayList) PersistenceException(javax.persistence.PersistenceException) Deployment(com.openmeap.model.dto.Deployment)

Example 2 with EventNotificationException

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());
}
Also used : ArrayList(java.util.ArrayList) AbstractModelServiceEventNotifier(com.openmeap.model.event.notifier.AbstractModelServiceEventNotifier) ModelServiceEventNotifier(com.openmeap.model.event.notifier.ModelServiceEventNotifier) PersistenceException(javax.persistence.PersistenceException) EventNotificationException(com.openmeap.event.EventNotificationException) AbstractModelServiceEventNotifier(com.openmeap.model.event.notifier.AbstractModelServiceEventNotifier) ProcessingEvent(com.openmeap.event.ProcessingEvent) Event(com.openmeap.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) Application(com.openmeap.model.dto.Application) Test(org.junit.Test)

Aggregations

EventNotificationException (com.openmeap.event.EventNotificationException)2 ArrayList (java.util.ArrayList)2 PersistenceException (javax.persistence.PersistenceException)2 Event (com.openmeap.event.Event)1 ProcessingEvent (com.openmeap.event.ProcessingEvent)1 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)1 Application (com.openmeap.model.dto.Application)1 Deployment (com.openmeap.model.dto.Deployment)1 AbstractModelServiceEventNotifier (com.openmeap.model.event.notifier.AbstractModelServiceEventNotifier)1 ModelServiceEventNotifier (com.openmeap.model.event.notifier.ModelServiceEventNotifier)1 List (java.util.List)1 Test (org.junit.Test)1