Search in sources :

Example 1 with ModelEntityEvent

use of com.openmeap.model.event.ModelEntityEvent in project OpenMEAP by OpenMEAP.

the class ModelManagerImpl method addModify.

@Override
public <T extends ModelEntity> T addModify(T entity, List<ProcessingEvent> events) throws InvalidPropertiesException, PersistenceException {
    T revised = entity;
    authorize(entity, determineCreateUpdateAction(entity));
    ModelEntityEvent event = new ModelEntityEvent(ModelServiceOperation.SAVE_OR_UPDATE, entity);
    stashModelEntityEventTillCommit(event);
    callEventNotifiers(CutPoint.BEFORE_OPERATION, event, events);
    revised = (T) event.getPayload();
    revised = (T) _addModify(revised, events);
    event.setPayload(revised);
    callEventNotifiers(CutPoint.AFTER_OPERATION, event, events);
    revised = (T) event.getPayload();
    validate(revised);
    return revised;
}
Also used : ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent)

Example 2 with ModelEntityEvent

use of com.openmeap.model.event.ModelEntityEvent in project OpenMEAP by OpenMEAP.

the class ModelManagerImpl method processModelEntityEventQueue.

private void processModelEntityEventQueue(CutPoint cutPoint, List<ProcessingEvent> events) {
    List<ModelEntityEvent> modelEvents;
    if ((modelEvents = eventQueue.get(Thread.currentThread())) != null) {
        int size = modelEvents.size();
        for (int i = 0; i < size; i++) {
            ModelEntityEvent event = modelEvents.get(i);
            callEventNotifiers(cutPoint, event, events);
        }
    }
}
Also used : ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent) CutPoint(com.openmeap.model.event.notifier.ModelServiceEventNotifier.CutPoint)

Example 3 with ModelEntityEvent

use of com.openmeap.model.event.ModelEntityEvent in project OpenMEAP by OpenMEAP.

the class ModelManagerImpl method delete.

@Override
public <T extends ModelEntity> ModelManager delete(T entity, List<ProcessingEvent> events) {
    authorize(entity, Authorizer.Action.DELETE);
    ModelEntityEvent event = new ModelEntityEvent(ModelServiceOperation.DELETE, entity);
    stashModelEntityEventTillCommit(event);
    callEventNotifiers(CutPoint.BEFORE_OPERATION, event, events);
    _delete(entity, events);
    callEventNotifiers(CutPoint.AFTER_OPERATION, event, events);
    return this;
}
Also used : ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent)

Example 4 with ModelEntityEvent

use of com.openmeap.model.event.ModelEntityEvent in project OpenMEAP by OpenMEAP.

the class AbstractModelServiceClusterServiceMgmtNotifier method makeRequest.

@Override
protected void makeRequest(URL url, Event<T> message) throws ClusterNotificationException {
    try {
        ModelEntityEvent event = (ModelEntityEvent) message;
        T modelEntity = (T) event.getPayload();
        String authToken = newAuthToken();
        Hashtable<String, Object> parms = new Hashtable<String, Object>();
        ;
        parms.put(UrlParamConstants.CLUSTERNODE_KEY, url.toString());
        String sendUrl = url.toString() + "/" + ServletNameConstants.SERVICE_MANAGEMENT + "/?" + UrlParamConstants.ACTION + "=" + getEventActionName() + "&" + UrlParamConstants.AUTH_TOKEN + "=" + authToken;
        addRequestParameters(modelEntity, parms);
        logger.debug("Notification to {} with params {}", sendUrl, parms);
        HttpResponse response = this.getHttpRequestExecuter().postData(sendUrl, parms);
        int statusCode = response.getStatusCode();
        logger.debug("Notification to {} returned status code {}", sendUrl, statusCode);
        if (statusCode != 200) {
            String responseText = Utils.readInputStream(response.getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
            logger.error(responseText);
            throw new ClusterNotificationException(url, String.format("Notification to %s returned status code %s and response text was ", sendUrl, statusCode));
        } else {
            Utils.consumeInputStream(response.getResponseBody());
        }
    } catch (Exception e) {
        throw new ClusterNotificationException(url, e.getMessage(), e);
    }
}
Also used : ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent) Hashtable(java.util.Hashtable) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) HttpResponse(com.openmeap.http.HttpResponse) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) EventNotificationException(com.openmeap.event.EventNotificationException)

Example 5 with ModelEntityEvent

use of com.openmeap.model.event.ModelEntityEvent in project OpenMEAP by OpenMEAP.

the class ModelManagerImpl method refresh.

@Override
public <T extends ModelEntity> ModelManager refresh(T obj2Refresh, List<ProcessingEvent> events) throws PersistenceException {
    ModelEntityEvent event = new ModelEntityEvent(ModelServiceOperation.REFRESH, obj2Refresh);
    stashModelEntityEventTillCommit(event);
    callEventNotifiers(CutPoint.BEFORE_OPERATION, event, events);
    modelService.refresh(obj2Refresh);
    callEventNotifiers(CutPoint.AFTER_OPERATION, event, events);
    return this;
}
Also used : ModelEntityEvent(com.openmeap.model.event.ModelEntityEvent)

Aggregations

ModelEntityEvent (com.openmeap.model.event.ModelEntityEvent)6 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)2 EventHandlingException (com.openmeap.event.EventHandlingException)1 EventNotificationException (com.openmeap.event.EventNotificationException)1 HttpResponse (com.openmeap.http.HttpResponse)1 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)1 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)1 Deployment (com.openmeap.model.dto.Deployment)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 MapPayloadEvent (com.openmeap.model.event.MapPayloadEvent)1 CutPoint (com.openmeap.model.event.notifier.ModelServiceEventNotifier.CutPoint)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1