Search in sources :

Example 16 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class ModelManagerImplTest method testGetLastDeployment.

@Test
public void testGetLastDeployment() throws Exception {
    Application app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
    Deployment d = modelManager.getModelService().getLastDeployment(app);
    Assert.assertTrue(d != null && d.getVersionIdentifier().equals("ApplicationVersion.identifier.2"));
}
Also used : Deployment(com.openmeap.model.dto.Deployment) Application(com.openmeap.model.dto.Application) Test(org.junit.Test)

Example 17 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class ModelManagerImplTest method testAddModifyApplicationVersion.

@Test
public void testAddModifyApplicationVersion() throws Exception {
    Boolean thrown = false;
    Application app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
    InvalidPropertiesException e = null;
    ////////////////////////////
    // Verify creating a new application version
    ApplicationVersion version = newValidAppVersion(app);
    modelManager.begin();
    version.setArchive(modelManager.addModify(version.getArchive(), null));
    version = modelManager.addModify(version, null);
    try {
        modelManager.getModelService().delete(version);
        modelManager.commit();
    } catch (Exception e1) {
        modelManager.rollback();
        throw new Exception(e1);
    }
    ////////////////////////////
    // Verify that attempting to create an application version 
    // with no content length specified throws an exception
    version = newValidAppVersion(app);
    version.getArchive().setBytesLength(null);
    try {
        version = modelManager.begin().addModify(version, null);
        modelManager.commit();
    } catch (InvalidPropertiesException ipe) {
        modelManager.rollback();
        e = ipe;
        thrown = true;
    }
    Assert.assertTrue("When bytes length is null, an exception should be thrown", thrown);
    Assert.assertTrue(e.getMethodMap().get(ApplicationArchive.class.getMethod("getBytesLength")) != null);
    ////////////////////////////
    // Verify that attempting to create an application version 
    // with no content length specified throws an exception
    version.getArchive().setBytesLength(0);
    try {
        version = modelManager.begin().addModify(version, null);
        modelManager.commit();
    } catch (InvalidPropertiesException ipe) {
        modelManager.rollback();
        e = ipe;
        thrown = true;
    }
    Assert.assertTrue("When bytes length is 0, an exception should be thrown", thrown);
    Assert.assertTrue(e.getMethodMap().get(ApplicationArchive.class.getMethod("getBytesLength")) != null);
    ////////////
    // Verify that trying to add a version with an invalid hash throws an exception
    version.getArchive().setHashAlgorithm("NOT_SUCH_ALGORITHM");
    try {
        version = modelManager.begin().addModify(version, null);
        modelManager.commit();
    } catch (InvalidPropertiesException ipe) {
        modelManager.rollback();
        e = ipe;
    }
    Assert.assertTrue(e != null);
    Assert.assertTrue(e.getMethodMap().size() == 2);
    Assert.assertTrue(e.getMethodMap().get(ApplicationArchive.class.getMethod("getHashAlgorithm")) != null);
    Assert.assertTrue(e.getMethodMap().get(ApplicationArchive.class.getMethod("getBytesLength")) != null);
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Application(com.openmeap.model.dto.Application) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) PersistenceException(javax.persistence.PersistenceException) EventNotificationException(com.openmeap.event.EventNotificationException) Test(org.junit.Test)

Example 18 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class ModelServiceImplTest method testDelete.

// putting this last because it corrupts the model
public void testDelete() {
    // verify that we 
    Application app = modelService.findByPrimaryKey(Application.class, 1L);
    ApplicationVersion appVer = modelService.findByPrimaryKey(ApplicationVersion.class, 1L);
    modelService.delete(appVer);
    appVer = modelService.findByPrimaryKey(ApplicationVersion.class, 1L);
    Assert.assertTrue(appVer == null);
    app = modelService.findByPrimaryKey(Application.class, 1L);
    modelService.delete(app);
    app = modelService.findByPrimaryKey(Application.class, 1L);
    appVer = modelService.findByPrimaryKey(ApplicationVersion.class, 2L);
    Assert.assertTrue(appVer != null);
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Application(com.openmeap.model.dto.Application)

Example 19 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class AddModifyApplicationBacking method process.

/**
	 * With the first of the bean name matching "addModifyApp", there are
	 * three ways to access this:
	 *    - request has applicationId and processTarget - modifying an application
	 *    - request has applicationId only              - pulling up an application to modify
	 *    - request has processTarget only              - submitting a brand new application  
	 *
	 * See the WEB-INF/ftl/form-application-addmodify.ftl for input/output parameters.
	 *    
	 * @param context Not referenced at all, may be null
	 * @param templateVariables Variables output to for the view
	 * @param parameterMap Parameters passed in to drive processing
	 * @return on errors, returns an array of error processingevents
	 * @see TemplatedSectionBacking::process()
	 */
public Collection<ProcessingEvent> process(ProcessingContext context, Map<Object, Object> templateVariables, Map<Object, Object> parameterMap) {
    List<ProcessingEvent> events = new ArrayList<ProcessingEvent>();
    templateVariables.put(FormConstants.PROCESS_TARGET, PROCESS_TARGET);
    Application app = new Application();
    if (ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) {
        app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap)));
    }
    Boolean mayCreate = modelManager.getAuthorizer().may(Authorizer.Action.CREATE, new Application());
    Boolean mayModify = modelManager.getAuthorizer().may(Authorizer.Action.MODIFY, app);
    Boolean willProcess = mayCreate || mayModify;
    if (!willProcess) {
        events.add(new MessagesEvent("Current user does not have permissions to make changes here"));
    }
    templateVariables.put("willProcess", willProcess);
    // the user is submitting the form for either an add or modify
    if (ParameterMapUtils.notEmpty(FormConstants.PROCESS_TARGET, parameterMap) && PROCESS_TARGET.equals(((String[]) parameterMap.get(FormConstants.PROCESS_TARGET))[0]) && willProcess) {
        app = createApplicationFromParameters(app, parameterMap, events);
        if (ParameterMapUtils.firstValue("submit", parameterMap).equals("true")) {
            if (events.size() == 0) {
                try {
                    app.setLastModifier(firstValue("userPrincipalName", parameterMap));
                    modelManager.begin();
                    app = modelManager.addModify(app, events);
                    modelManager.commit(events);
                    events.add(new MessagesEvent("Application successfully created/modified!"));
                } catch (InvalidPropertiesException e) {
                    events.add(new MessagesEvent(String.format("Application add/modify failed: %s %s", ExceptionUtils.getRootCauseMessage(e), ExceptionUtils.getRootCauseStackTrace(e)[0])));
                    logger.error("Add/Modify application with id " + app.getId() + " failed", e);
                    modelManager.rollback();
                } catch (PersistenceException e) {
                    events.add(new MessagesEvent(String.format("Application add/modify failed: %s %s", ExceptionUtils.getRootCauseMessage(e), ExceptionUtils.getRootCauseStackTrace(e)[0])));
                    logger.error("Add/Modify application with id " + app.getId() + " failed", e);
                    modelManager.rollback();
                }
            }
            if (app == null && ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap))
                app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap)));
        }
        if (ParameterMapUtils.notEmpty("delete", parameterMap) && ParameterMapUtils.firstValue("delete", parameterMap).equals("true")) {
            if (!ParameterMapUtils.empty("deleteConfirm", parameterMap) && ParameterMapUtils.firstValue("deleteConfirm", parameterMap).equals(FormConstants.APP_DELETE_CONFIRM_TEXT)) {
                try {
                    modelManager.begin();
                    modelManager.delete(app, events);
                    modelManager.commit(events);
                    events.add(new MessagesEvent("Application successfully deleted!"));
                    app = null;
                    // we remove the applicationId parameter, so that the form can populate empty
                    parameterMap.remove(FormConstants.APP_ID);
                } catch (Exception e) {
                    events.add(new MessagesEvent(String.format("Application delete failed: %s %s", ExceptionUtils.getRootCauseMessage(e), ExceptionUtils.getRootCauseStackTrace(e)[0])));
                    logger.error("Deleting application with id " + app.getId() + " failed", e);
                    modelManager.rollback();
                }
            } else {
                events.add(new MessagesEvent("You must confirm your desire to delete by typing in the delete confirmation message."));
            }
        }
    } else // the user is visiting the page to view or modify an application
    if (ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) {
        app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap)));
    }
    if (app == null && ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) {
        events.add(new MessagesEvent("Application with id " + ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap) + " not found"));
    } else if (app != null && app.getId() != null) {
        // in order to create the 
        ApplicationVersion testVer = new ApplicationVersion();
        testVer.setApplication(app);
        Boolean mayCreateVersions = modelManager.getAuthorizer().may(Authorizer.Action.CREATE, testVer);
        if (mayCreateVersions) {
            events.add(new AddSubNavAnchorEvent(new Anchor("?bean=addModifyAppVersionPage&applicationId=" + app.getId(), "Create new version", "Create new version")));
        }
        events.add(new AddSubNavAnchorEvent(new Anchor("?bean=appVersionListingsPage&applicationId=" + app.getId(), "Version Listings", "Version Listings")));
        events.add(new AddSubNavAnchorEvent(new Anchor("?bean=deploymentListingsPage&applicationId=" + app.getId(), "Deployment History", "Deployment History")));
    }
    fillInVariablesFromApplication(templateVariables, app);
    return events;
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ArrayList(java.util.ArrayList) AddSubNavAnchorEvent(com.openmeap.admin.web.events.AddSubNavAnchorEvent) InvalidPropertiesException(com.openmeap.model.InvalidPropertiesException) PersistenceException(javax.persistence.PersistenceException) InvalidPropertiesException(com.openmeap.model.InvalidPropertiesException) Anchor(com.openmeap.web.html.Anchor) MessagesEvent(com.openmeap.event.MessagesEvent) PersistenceException(javax.persistence.PersistenceException) ProcessingEvent(com.openmeap.event.ProcessingEvent) Application(com.openmeap.model.dto.Application)

Example 20 with Application

use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.

the class AddModifyApplicationBacking method createApplicationFromParameters.

/**
	 * Create a new application object from the parameters passed in
	 * 
	 * @param parameterMap
	 * @return
	 */
private Application createApplicationFromParameters(Application app, Map<Object, Object> parameterMap, List<ProcessingEvent> events) {
    if (app == null) {
        app = new Application();
    }
    app.setName(ParameterMapUtils.firstValue("name", parameterMap));
    app.setAdmins(ParameterMapUtils.firstValue(FormConstants.APP_ADMINS, parameterMap));
    app.setVersionAdmins(ParameterMapUtils.firstValue(FormConstants.APP_VERSIONADMINS, parameterMap));
    app.setDescription(ParameterMapUtils.firstValue(FormConstants.APP_DESCRIPTION, parameterMap));
    app.setInitialVersionIdentifier(ParameterMapUtils.firstValue("initialVersionIdentifier", parameterMap));
    String deploymentHistoryLength = ParameterMapUtils.firstValue(FormConstants.APP_DEPL_HIST_LEN, parameterMap);
    if (deploymentHistoryLength != null && deploymentHistoryLength.trim().matches("[\\d]+")) {
        app.setDeploymentHistoryLength(Integer.valueOf(deploymentHistoryLength.trim()));
    }
    // update the salt used for generating authentication tokens
    String salt = ParameterMapUtils.firstValue("proxyAuthSalt", parameterMap);
    String saltConf = ParameterMapUtils.firstValue("proxyAuthSaltConfirm", parameterMap);
    if (salt != null && saltConf != null) {
        if (salt.length() > 0 && saltConf.equals(salt)) {
            app.setProxyAuthSalt(salt);
        } else if (!salt.equals(saltConf)) {
            events.add(new MessagesEvent("Proxy authentication salt value not set.  Entries did not match."));
        }
    }
    return app;
}
Also used : MessagesEvent(com.openmeap.event.MessagesEvent) Application(com.openmeap.model.dto.Application)

Aggregations

Application (com.openmeap.model.dto.Application)34 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)12 Test (org.junit.Test)9 ProcessingEvent (com.openmeap.event.ProcessingEvent)7 Deployment (com.openmeap.model.dto.Deployment)7 ModelManager (com.openmeap.model.ModelManager)6 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)6 GlobalSettings (com.openmeap.model.dto.GlobalSettings)6 PersistenceException (javax.persistence.PersistenceException)6 MessagesEvent (com.openmeap.event.MessagesEvent)5 Anchor (com.openmeap.web.html.Anchor)5 ArrayList (java.util.ArrayList)5 AddSubNavAnchorEvent (com.openmeap.admin.web.events.AddSubNavAnchorEvent)4 EventNotificationException (com.openmeap.event.EventNotificationException)4 HashMap (java.util.HashMap)4 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)3 DigestException (com.openmeap.digest.DigestException)2 HttpResponse (com.openmeap.http.HttpResponse)2 WebServiceException (com.openmeap.protocol.WebServiceException)2 UpdateHeader (com.openmeap.protocol.dto.UpdateHeader)2