Search in sources :

Example 6 with MessagesEvent

use of com.openmeap.event.MessagesEvent in project OpenMEAP by OpenMEAP.

the class AddModifyApplicationVersionBacking method validateStorageConfiguration.

private void validateStorageConfiguration(Map<Object, Object> templateVariables, List<ProcessingEvent> events) {
    String storagePathErrors = modelManager.getGlobalSettings().validateTemporaryStoragePath();
    if (storagePathErrors != null) {
        events.add(new MessagesEvent("WARNING: The archive storage path is not set and file uploads will not be processed.  The archive storage path can be set on the settings page."));
        templateVariables.put(FormConstants.ENCODING_TYPE, "");
    } else {
        templateVariables.put(FormConstants.ENCODING_TYPE, "enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\"");
    }
}
Also used : MessagesEvent(com.openmeap.event.MessagesEvent)

Example 7 with MessagesEvent

use of com.openmeap.event.MessagesEvent in project OpenMEAP by OpenMEAP.

the class AddModifyApplicationVersionBacking 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>();
    Application app = null;
    ApplicationVersion version = null;
    // make sure we're configured to accept uploads, warn otherwise
    validateStorageConfiguration(templateVariables, events);
    // we must have an application in order to add a version
    if (!notEmpty(FormConstants.APP_ID, parameterMap)) {
        return ProcessingUtils.newList(new GenericProcessingEvent<String>(ProcessingTargets.MESSAGES, "An application must be specified in order to add a version"));
    }
    Long appId = Long.valueOf(firstValue(FormConstants.APP_ID, parameterMap));
    app = modelManager.getModelService().findByPrimaryKey(Application.class, appId);
    if (app == null) {
        return ProcessingUtils.newList(new GenericProcessingEvent<String>(ProcessingTargets.MESSAGES, "The application with id " + appId + " could not be found."));
    }
    events.add(new AddSubNavAnchorEvent(new Anchor("?bean=addModifyAppPage&applicationId=" + app.getId(), "View/Modify Application", "View/Modify Application")));
    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")));
    // at this point, we're committed to form setup at least
    templateVariables.put(FormConstants.PROCESS_TARGET, PROCESS_TARGET);
    version = obtainExistingApplicationVersionFromParameters(app, appId, events, parameterMap);
    if (version == null) {
        version = new ApplicationVersion();
    }
    // determine if the user is allowed to modify application versions
    Boolean willProcess = canUserModifyOrCreate(app, version);
    if (!willProcess) {
        events.add(new MessagesEvent("Current user does not have permissions to make changes here."));
    }
    if (!version.getActiveFlag()) {
        events.add(new MessagesEvent("This version is not currently active."));
        willProcess = false;
    }
    templateVariables.put("willProcess", willProcess);
    if (notEmpty(FormConstants.PROCESS_TARGET, parameterMap) && PROCESS_TARGET.compareTo(firstValue(FormConstants.PROCESS_TARGET, parameterMap)) == 0 && willProcess) {
        // TODO: check to see if the user can delete versions
        if (ParameterMapUtils.notEmpty(FormConstants.DELETE, parameterMap) && ParameterMapUtils.notEmpty("deleteConfirm", parameterMap)) {
            if (ParameterMapUtils.firstValue("deleteConfirm", parameterMap).equals(FormConstants.APPVER_DELETE_CONFIRM_TEXT)) {
                try {
                    modelManager.begin();
                    modelManager.delete(version, events);
                    modelManager.commit(events);
                } catch (Exception e) {
                    modelManager.rollback();
                    String msg = String.format("Unable to delete the version - %s", ExceptionUtils.getRootCauseMessage(e));
                    logger.error(msg, e);
                    events.add(new MessagesEvent(msg));
                }
            } else {
                events.add(new MessagesEvent("You must confirm your desire to delete by typing in the delete confirmation message."));
            }
        } else {
            processApplicationVersionFromParameters(app, version, events, parameterMap);
        }
    }
    if (version != null) {
        templateVariables.put("version", version);
    }
    templateVariables.put("application", app);
    createHashTypes(templateVariables, version != null ? version.getArchive() : null);
    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) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Anchor(com.openmeap.web.html.Anchor) MessagesEvent(com.openmeap.event.MessagesEvent) GenericProcessingEvent(com.openmeap.web.GenericProcessingEvent) ProcessingEvent(com.openmeap.event.ProcessingEvent) Application(com.openmeap.model.dto.Application)

Example 8 with MessagesEvent

use of com.openmeap.event.MessagesEvent in project OpenMEAP by OpenMEAP.

the class AddModifyApplicationVersionBacking method processApplicationVersionFromParameters.

private void processApplicationVersionFromParameters(Application app, ApplicationVersion version, List<ProcessingEvent> events, Map<Object, Object> parameterMap) {
    // then create a new archive for it.
    if (version.getPk() == null) {
        version.setArchive(new ApplicationArchive());
        version.getArchive().setApplication(app);
        version.setApplication(app);
    }
    fillInApplicationVersionFromParameters(app, version, events, parameterMap);
    if (version != null && version.getArchive() == null) {
        events.add(new MessagesEvent("Application archive could not be created.  Not creating empty version."));
    } else {
        try {
            modelManager.begin();
            version.setLastModifier(firstValue("userPrincipalName", parameterMap));
            ApplicationArchive savedArchive = version.getArchive();
            version.setArchive(null);
            savedArchive = modelManager.addModify(savedArchive, events);
            version.setArchive(savedArchive);
            version = modelManager.addModify(version, events);
            app.addVersion(version);
            app = modelManager.addModify(app, events);
            modelManager.commit(events);
            modelManager.refresh(app, events);
            events.add(new MessagesEvent("Application version successfully created/modified!"));
        } catch (InvalidPropertiesException ipe) {
            modelManager.rollback();
            logger.error("Unable to add/modify version " + version.getIdentifier(), ipe);
            events.add(new MessagesEvent("Unable to add/modify version - " + ipe.getMessage()));
        } catch (PersistenceException pe) {
            modelManager.rollback();
            logger.error("Unable to add/modify version " + version.getIdentifier(), pe);
            events.add(new MessagesEvent("Unable to add/modify version - " + pe.getMessage()));
        }
    }
}
Also used : InvalidPropertiesException(com.openmeap.model.InvalidPropertiesException) MessagesEvent(com.openmeap.event.MessagesEvent) PersistenceException(javax.persistence.PersistenceException) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive)

Example 9 with MessagesEvent

use of com.openmeap.event.MessagesEvent 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)

Example 10 with MessagesEvent

use of com.openmeap.event.MessagesEvent 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)

Aggregations

MessagesEvent (com.openmeap.event.MessagesEvent)15 PersistenceException (javax.persistence.PersistenceException)9 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)6 ProcessingEvent (com.openmeap.event.ProcessingEvent)5 Application (com.openmeap.model.dto.Application)5 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)5 GlobalSettings (com.openmeap.model.dto.GlobalSettings)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 AddSubNavAnchorEvent (com.openmeap.admin.web.events.AddSubNavAnchorEvent)4 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)4 Anchor (com.openmeap.web.html.Anchor)4 File (java.io.File)4 Deployment (com.openmeap.model.dto.Deployment)3 ZipFile (java.util.zip.ZipFile)3 FileOperationException (com.openmeap.file.FileOperationException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 DigestException (com.openmeap.digest.DigestException)1 ClusterNode (com.openmeap.model.dto.ClusterNode)1 GenericProcessingEvent (com.openmeap.web.GenericProcessingEvent)1