Search in sources :

Example 1 with AddSubNavAnchorEvent

use of com.openmeap.admin.web.events.AddSubNavAnchorEvent in project OpenMEAP by OpenMEAP.

the class DeploymentListingsBacking method 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);
    String appId = firstValue(FormConstants.APP_ID, parameterMap);
    String appVerId = firstValue("versionId", parameterMap);
    String deploymentType = firstValue("deploymentType", parameterMap);
    String processTarget = firstValue(FormConstants.PROCESS_TARGET, parameterMap);
    Application app = null;
    try {
        app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(appId));
    } catch (NumberFormatException nfe) {
        events.add(new MessagesEvent("A valid applicationId must be supplied to either view or create deployments."));
    }
    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")));
    // TODO: I'm pretty sure I should create new deployments elsewhere and forward to here from there.
    if (deploymentType != null && PROCESS_TARGET.compareTo(processTarget) == 0 && app != null) {
        ApplicationVersion version = null;
        try {
            version = modelManager.getModelService().findByPrimaryKey(ApplicationVersion.class, Long.valueOf(appVerId));
        } catch (NumberFormatException nfe) {
            events.add(new MessagesEvent("A valid versionId must be supplied to create a deployment."));
        }
        if (version != null) {
            Deployment depl = createDeployment(firstValue("userPrincipalName", parameterMap), version, deploymentType);
            try {
                modelManager.begin();
                depl = modelManager.addModify(depl, events);
                modelManager.commit(events);
                events.add(new MessagesEvent("Deployment successfully completed."));
            } catch (Exception pe) {
                modelManager.rollback();
                Throwable root = ExceptionUtils.getRootCause(pe);
                events.add(new MessagesEvent(String.format("An exception was thrown creating the deployment: %s %s", root.getMessage(), ExceptionUtils.getStackTrace(root))));
            }
        }
    }
    // making sure to order the deployments by date
    if (app != null && app.getDeployments() != null) {
        List<Deployment> deployments = modelManager.getModelService().findDeploymentsByApplication(app);
        Collections.sort(deployments, new Deployment.DateComparator());
        templateVariables.put("deployments", deployments);
        GlobalSettings settings = modelManager.getGlobalSettings();
        Map<String, String> urls = new HashMap<String, String>();
        for (Deployment depl : deployments) {
            urls.put(depl.getApplicationArchive().getHash(), depl.getApplicationArchive().getDownloadUrl(settings));
        }
        templateVariables.put("deployments", deployments);
        templateVariables.put("archiveUrls", urls);
    }
    return events;
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AddSubNavAnchorEvent(com.openmeap.admin.web.events.AddSubNavAnchorEvent) Deployment(com.openmeap.model.dto.Deployment) GlobalSettings(com.openmeap.model.dto.GlobalSettings) InvalidPropertiesException(com.openmeap.model.InvalidPropertiesException) PersistenceException(javax.persistence.PersistenceException) Anchor(com.openmeap.web.html.Anchor) MessagesEvent(com.openmeap.event.MessagesEvent) ProcessingEvent(com.openmeap.event.ProcessingEvent) Application(com.openmeap.model.dto.Application)

Example 2 with AddSubNavAnchorEvent

use of com.openmeap.admin.web.events.AddSubNavAnchorEvent 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 3 with AddSubNavAnchorEvent

use of com.openmeap.admin.web.events.AddSubNavAnchorEvent 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 4 with AddSubNavAnchorEvent

use of com.openmeap.admin.web.events.AddSubNavAnchorEvent in project OpenMEAP by OpenMEAP.

the class ApplicationVersionListingsBacking method process.

public Collection<ProcessingEvent> process(ProcessingContext context, Map<Object, Object> templateVariables, Map<Object, Object> parameterMap) {
    List<ProcessingEvent> events = new ArrayList<ProcessingEvent>();
    if (ParameterMapUtils.notEmpty(FormConstants.APP_ID, parameterMap)) {
        Application app = modelManager.getModelService().findByPrimaryKey(Application.class, Long.valueOf(ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap)));
        if (app != null) {
            setupMayCreateDeployments(templateVariables, app, events);
            Deployment lastDeployment = modelManager.getModelService().getLastDeployment(app);
            String currentVersionId = null;
            if (lastDeployment != null && lastDeployment.getVersionIdentifier() != null) {
                currentVersionId = lastDeployment.getVersionIdentifier();
            }
            currentVersionId = currentVersionId != null ? currentVersionId : "";
            templateVariables.put("application", app);
            templateVariables.put(FormConstants.PROCESS_TARGET, ProcessingTargets.DEPLOYMENTS);
            templateVariables.put("currentVersionId", currentVersionId);
            if (app.getVersions() != null && app.getVersions().size() > 0) {
                createVersionsDisplayLists(app, templateVariables);
            } else {
                events.add(new MessagesEvent("Application with id " + ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap) + " has no versions associated to it"));
            }
            if (modelManager.getAuthorizer().may(Authorizer.Action.CREATE, new ApplicationVersion())) {
                events.add(new AddSubNavAnchorEvent(new Anchor("?bean=addModifyAppVersionPage&applicationId=" + app.getId(), "Create new version", "Create new version")));
            }
            events.add(new AddSubNavAnchorEvent(new Anchor("?bean=addModifyAppPage&applicationId=" + app.getId(), "View/Modify Application", "View/Modify Application")));
            Anchor deploymentHistoryAnchor = new Anchor("?bean=deploymentListingsPage&applicationId=" + app.getId(), "Deployment History", "Deployment History");
            templateVariables.put("deploymentsAnchor", deploymentHistoryAnchor);
            events.add(new AddSubNavAnchorEvent(deploymentHistoryAnchor));
        } else {
            events.add(new MessagesEvent("Application with id " + ParameterMapUtils.firstValue(FormConstants.APP_ID, parameterMap) + " not found"));
        }
    } else {
        events.add(new MessagesEvent("An application must be selected"));
    }
    return events;
}
Also used : Anchor(com.openmeap.web.html.Anchor) ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ArrayList(java.util.ArrayList) MessagesEvent(com.openmeap.event.MessagesEvent) AddSubNavAnchorEvent(com.openmeap.admin.web.events.AddSubNavAnchorEvent) Deployment(com.openmeap.model.dto.Deployment) ProcessingEvent(com.openmeap.event.ProcessingEvent) Application(com.openmeap.model.dto.Application)

Aggregations

AddSubNavAnchorEvent (com.openmeap.admin.web.events.AddSubNavAnchorEvent)4 MessagesEvent (com.openmeap.event.MessagesEvent)4 ProcessingEvent (com.openmeap.event.ProcessingEvent)4 Application (com.openmeap.model.dto.Application)4 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)4 Anchor (com.openmeap.web.html.Anchor)4 ArrayList (java.util.ArrayList)4 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)3 PersistenceException (javax.persistence.PersistenceException)3 Deployment (com.openmeap.model.dto.Deployment)2 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 GenericProcessingEvent (com.openmeap.web.GenericProcessingEvent)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1