use of com.openmeap.model.ModelManager in project OpenMEAP by OpenMEAP.
the class AdminServlet method service.
@SuppressWarnings("unchecked")
@Override
public void service(HttpServletRequest request, HttpServletResponse response) {
logger.trace("Entering service()");
try {
DocumentProcessor documentProcessor = null;
logger.debug("Request uri: {}", request.getRequestURI());
logger.debug("Request url: {}", request.getRequestURL());
logger.debug("Query string: {}", request.getQueryString());
if (logger.isDebugEnabled()) {
logger.debug("Parameter map: {}", ParameterMapUtils.toString(request.getParameterMap()));
}
if (request.getParameter("logout") != null) {
logger.trace("Executing logout");
request.getSession().invalidate();
response.sendRedirect(request.getContextPath() + "/interface/");
}
if (request.getParameter("refreshContext") != null && context instanceof AbstractApplicationContext) {
logger.trace("Refreshing context");
((AbstractApplicationContext) context).refresh();
}
// support for clearing the persistence context
if (request.getParameter("clearPersistenceContext") != null && context instanceof AbstractApplicationContext) {
logger.trace("Clearing the persistence context");
ModelServiceImpl ms = (ModelServiceImpl) ((AbstractApplicationContext) context).getBean("modelService");
ms.clearPersistenceContext();
}
// default to the mainOptionPage, unless otherwise specified
String pageBean = null;
if (request.getParameter(FormConstants.PAGE_BEAN) != null)
pageBean = request.getParameter(FormConstants.PAGE_BEAN);
else
pageBean = FormConstants.PAGE_BEAN_MAIN;
logger.debug("Using page bean: {}", pageBean);
documentProcessor = (DocumentProcessor) context.getBean(pageBean);
ModelManager mgr = getModelManager();
Map<Object, Object> map = new HashMap<Object, Object>();
// TODO: I'm not really happy with this hacky work-around for the login form not being in actual request scope
if (documentProcessor.getProcessesFormData()) {
GlobalSettings settings = mgr.getGlobalSettings();
map = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), settings.getTemporaryStoragePath(), request);
map.put("userPrincipalName", new String[] { request.getUserPrincipal().getName() });
AuthorizerImpl authorizer = (AuthorizerImpl) context.getBean("authorizer");
authorizer.setRequest(request);
}
response.setContentType(FormConstants.CONT_TYPE_HTML);
Map<Object, Object> defaultTemplateVars = new HashMap<Object, Object>();
defaultTemplateVars.put("request", new BeanModel(request, new DefaultObjectWrapper()));
documentProcessor.setTemplateVariables(defaultTemplateVars);
documentProcessor.handleProcessAndRender(map, response.getWriter());
response.getWriter().flush();
response.getWriter().close();
} catch (IOException te) {
throw new RuntimeException(te);
}
logger.trace("Leaving service()");
}
use of com.openmeap.model.ModelManager in project OpenMEAP by OpenMEAP.
the class AdminTest method testDeleteApplication.
public void testDeleteApplication() throws Exception {
ModelManager modelManager = helper.getModelManager();
Application dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
HttpResponse response = helper.postAddModifyApp_delete(dbApp);
modelManager.getModelService().clearPersistenceContext();
dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(dbApp == null);
Assert.assertTrue(!_isVersionArchiveInAdminLocation(VERSION_01_HASH));
Assert.assertTrue(!_isVersionArchiveInAdminLocation(VERSION_02_HASH));
Assert.assertTrue(!_isVersionArchiveInDeployedLocation(VERSION_01_HASH));
Assert.assertTrue(!_isVersionArchiveInDeployedLocation(VERSION_02_HASH));
}
use of com.openmeap.model.ModelManager in project OpenMEAP by OpenMEAP.
the class AddModifyApplicationBackingTest method testDelete.
@Test
public void testDelete() {
ModelTestUtils.resetTestDb();
ModelTestUtils.createModel(null);
ModelManager mm = ModelTestUtils.createModelManager();
Map<Object, Object> vars = new HashMap<Object, Object>();
Map<Object, Object> parms = new HashMap<Object, Object>();
AddModifyApplicationBacking amab = null;
//////////////////////////
// Verify that trying to delete an application
// without submitting the correct deleteConfirm
// results in no action, except message
vars = new HashMap<Object, Object>();
parms = new HashMap<Object, Object>();
parms.put(FormConstants.PROCESS_TARGET, new String[] { ProcessingTargets.ADDMODIFY_APP });
parms.put(FormConstants.DELETE, new String[] { "Delete!" });
parms.put("deleteConfirm", new String[] { "this is squirreled up" });
parms.put(FormConstants.APP_ID, new String[] { "1" });
parms.put("name", new String[] { "Application.name.1" });
parms.put(FormConstants.APP_DESCRIPTION, new String[] { "Application.description.1_modified" });
parms.put("deviceTypes", new String[] { "1", "2" });
amab = new AddModifyApplicationBacking();
amab.setModelManager(mm);
Collection<ProcessingEvent> events = amab.process(null, vars, parms);
Assert.assertTrue(ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
Assert.assertTrue(mm.getModelService().findByPrimaryKey(Application.class, 1L) != null);
//////////////////////////
// Verify that we can use the backing to delete an application
vars = new HashMap<Object, Object>();
parms = new HashMap<Object, Object>();
parms.put(FormConstants.PROCESS_TARGET, new String[] { ProcessingTargets.ADDMODIFY_APP });
parms.put(FormConstants.DELETE, new String[] { "Delete!" });
parms.put("deleteConfirm", new String[] { "delete the application" });
parms.put(FormConstants.APP_ID, new String[] { "1" });
parms.put("name", new String[] { "Application.name.1" });
parms.put(FormConstants.APP_DESCRIPTION, new String[] { "Application.description.1_modified" });
parms.put("deviceTypes", new String[] { "1", "2" });
amab = new AddModifyApplicationBacking();
amab.setModelManager(mm);
amab.process(null, vars, parms);
Assert.assertTrue(mm.getModelService().findByPrimaryKey(Application.class, 1L) == null);
Assert.assertTrue(parms.get(FormConstants.APP_ID) == null);
Assert.assertTrue(ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
}
use of com.openmeap.model.ModelManager in project OpenMEAP by OpenMEAP.
the class GlobalSettingsBackingTest method testSettingsProcess.
@Test
public void testSettingsProcess() {
ModelTestUtils.resetTestDb();
ModelTestUtils.createModel(null);
ModelManager mm = ModelTestUtils.createModelManager();
GlobalSettingsBacking backing = new GlobalSettingsBacking();
backing.setModelManager(mm);
Map<Object, Object> templateVariables = new HashMap<Object, Object>();
Map<Object, Object> parameterMap = new HashMap<Object, Object>();
ParameterMapUtils.setValue(FormConstants.PROCESS_TARGET, ProcessingTargets.GLOBAL_SETTINGS, parameterMap);
backing.process(null, templateVariables, parameterMap);
ModelTestUtils.resetTestDb();
}
use of com.openmeap.model.ModelManager in project OpenMEAP by OpenMEAP.
the class ModelServiceRefreshNotifierTest method testHandlePostSaveOrUpdate.
@Test
public void testHandlePostSaveOrUpdate() throws Exception {
try {
new NonStrictExpectations() {
{
}
};
} catch (Exception e) {
}
;
MockHttpRequestExecuter.setResponseCode(200);
MockHttpRequestExecuter.setResponseText("");
MockHttpRequestExecuter httpExecuter = new MockHttpRequestExecuter();
final ModelManager modelManager = new MockModelManager();
final GlobalSettings globalSettings = new GlobalSettings();
globalSettings.setServiceManagementAuthSalt(UUID.randomUUID().toString());
ClusterNode clusterNode = new ClusterNode();
clusterNode.setServiceWebUrlPrefix("http://www.openmeap.com/openmeap-services-web");
globalSettings.addClusterNode(clusterNode);
new NonStrictExpectations(globalSettings, modelManager) {
{
modelManager.getGlobalSettings();
result = globalSettings;
}
};
Application app = new Application();
app.setName("Happy Name");
app.setId(1L);
ModelServiceRefreshNotifier notifier = new ModelServiceRefreshNotifier();
notifier.setModelManager(modelManager);
notifier.setHttpRequestExecuter(httpExecuter);
notifier.notify(new ModelEntityModifyEvent(app), null);
String lastPostUrl = MockHttpRequestExecuter.getLastPostUrl();
Map<String, Object> lastPostData = MockHttpRequestExecuter.getLastPostData();
String uri = lastPostUrl;
String type = (String) lastPostData.get("type");
String auth = (String) lastPostData.get("auth");
String id = (String) lastPostData.get("id").toString();
Assert.assertTrue(uri.equals("http://www.openmeap.com/openmeap-services-web/service-management/"));
Assert.assertTrue(id.equals("1"));
Assert.assertTrue(type.equals("Application"));
Assert.assertTrue(AuthTokenProvider.validateAuthToken(globalSettings.getServiceManagementAuthSalt(), auth));
}
Aggregations