Search in sources :

Example 6 with ModelManager

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()");
}
Also used : BeanModel(freemarker.ext.beans.BeanModel) DocumentProcessor(com.openmeap.web.DocumentProcessor) HashMap(java.util.HashMap) AuthorizerImpl(com.openmeap.AuthorizerImpl) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) GlobalSettings(com.openmeap.model.dto.GlobalSettings) IOException(java.io.IOException) ModelManager(com.openmeap.model.ModelManager) ModelServiceImpl(com.openmeap.model.ModelServiceImpl) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext)

Example 7 with ModelManager

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));
}
Also used : HttpResponse(com.openmeap.http.HttpResponse) ModelManager(com.openmeap.model.ModelManager) Application(com.openmeap.model.dto.Application)

Example 8 with ModelManager

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));
}
Also used : HashMap(java.util.HashMap) ProcessingEvent(com.openmeap.event.ProcessingEvent) ModelManager(com.openmeap.model.ModelManager) Test(org.junit.Test)

Example 9 with ModelManager

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();
}
Also used : HashMap(java.util.HashMap) ModelManager(com.openmeap.model.ModelManager) Test(org.junit.Test)

Example 10 with ModelManager

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));
}
Also used : ClusterNode(com.openmeap.model.dto.ClusterNode) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ModelManager(com.openmeap.model.ModelManager) MockHttpRequestExecuter(com.openmeap.util.MockHttpRequestExecuter) NonStrictExpectations(mockit.NonStrictExpectations) Application(com.openmeap.model.dto.Application) ModelEntityModifyEvent(com.openmeap.model.event.ModelEntityModifyEvent) Test(org.junit.Test)

Aggregations

ModelManager (com.openmeap.model.ModelManager)10 Application (com.openmeap.model.dto.Application)6 HashMap (java.util.HashMap)6 Test (org.junit.Test)5 ProcessingEvent (com.openmeap.event.ProcessingEvent)3 GlobalSettings (com.openmeap.model.dto.GlobalSettings)3 IOException (java.io.IOException)2 AuthorizerImpl (com.openmeap.AuthorizerImpl)1 AddModifyApplicationVersionBacking (com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking)1 DigestException (com.openmeap.digest.DigestException)1 HttpResponse (com.openmeap.http.HttpResponse)1 ModelServiceImpl (com.openmeap.model.ModelServiceImpl)1 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)1 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)1 ClusterNode (com.openmeap.model.dto.ClusterNode)1 ModelEntityModifyEvent (com.openmeap.model.event.ModelEntityModifyEvent)1 WebServiceException (com.openmeap.protocol.WebServiceException)1 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)1 MockHttpRequestExecuter (com.openmeap.util.MockHttpRequestExecuter)1 DocumentProcessor (com.openmeap.web.DocumentProcessor)1