Search in sources :

Example 1 with ModelEntity

use of com.openmeap.model.ModelEntity in project OpenMEAP by OpenMEAP.

the class ModelServiceRefreshNotifier method makeRequest.

/**
	 * This MUST remain state-less
	 * 
	 * @param <T>
	 * @param thisUrl
	 * @param obj
	 */
@Override
protected void makeRequest(final URL url, final Event<ModelEntity> mesg) throws ClusterNotificationException {
    com.openmeap.http.HttpResponse httpResponse = null;
    String simpleName = null;
    String thisUrl = url.toString() + "/" + ServletNameConstants.SERVICE_MANAGEMENT + "/";
    ModelEntity obj = mesg.getPayload();
    // I am not using obj.getClass().getSimpleName() because of Hibernate Proxy object wrapping
    if (obj instanceof Application)
        simpleName = "Application";
    else if (obj instanceof ApplicationVersion)
        simpleName = "ApplicationVersion";
    else if (obj instanceof ApplicationArchive)
        simpleName = "ApplicationArchive";
    else if (obj instanceof ApplicationInstallation)
        simpleName = "ApplicationInstallation";
    else if (obj instanceof GlobalSettings)
        simpleName = "GlobalSettings";
    else
        return;
    Hashtable<String, Object> parms = new Hashtable<String, Object>();
    parms.put(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
    parms.put(UrlParamConstants.AUTH_TOKEN, newAuthToken());
    parms.put(UrlParamConstants.REFRESH_TYPE, simpleName);
    parms.put(UrlParamConstants.REFRESH_OBJ_PKID, obj.getPk());
    try {
        logger.debug("Refresh post to {} for {} with id {}", new Object[] { thisUrl, simpleName, obj.getPk() });
        httpResponse = getHttpRequestExecuter().postData(thisUrl, parms);
        Utils.consumeInputStream(httpResponse.getResponseBody());
        int statusCode = httpResponse.getStatusCode();
        if (statusCode != 200) {
            String exMesg = "HTTP " + statusCode + " returned for refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk();
            logger.error(exMesg);
            throw new ClusterNotificationException(url, exMesg);
        }
    } catch (Exception e) {
        String exMesg = "Refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk() + " threw an exception";
        logger.error(exMesg, e);
        throw new ClusterNotificationException(url, exMesg, e);
    }
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Hashtable(java.util.Hashtable) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) ClusterNotificationException(com.openmeap.cluster.ClusterNotificationException) ApplicationInstallation(com.openmeap.model.dto.ApplicationInstallation) ModelEntity(com.openmeap.model.ModelEntity) Application(com.openmeap.model.dto.Application)

Example 2 with ModelEntity

use of com.openmeap.model.ModelEntity in project OpenMEAP by OpenMEAP.

the class ModelServiceRefreshHandler method handleRefresh.

public Boolean handleRefresh(String refreshType, String objectId) throws ClassNotFoundException {
    Object id = null;
    if (refreshType.equals("ApplicationInstallation"))
        id = objectId;
    else
        id = Long.valueOf(objectId);
    @SuppressWarnings("unchecked") Class<ModelEntity> clazz = (Class<ModelEntity>) Class.forName("com.openmeap.model.dto." + refreshType);
    ModelEntity entity = (ModelEntity) modelManager.getModelService().findByPrimaryKey(clazz, id);
    if (entity != null) {
        modelManager.refresh(entity, null);
    }
    return true;
}
Also used : ModelEntity(com.openmeap.model.ModelEntity)

Aggregations

ModelEntity (com.openmeap.model.ModelEntity)2 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)1 Application (com.openmeap.model.dto.Application)1 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)1 ApplicationInstallation (com.openmeap.model.dto.ApplicationInstallation)1 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 Hashtable (java.util.Hashtable)1