use of com.openmeap.web.GenericProcessingEvent in project OpenMEAP by OpenMEAP.
the class AddModifyApplicationVersionBacking method obtainExistingApplicationVersionFromParameters.
/**
* @param app
* @param appId
* @param events
* @param parameterMap
* @return The application version indicated by the parameterMap, or null
*/
private ApplicationVersion obtainExistingApplicationVersionFromParameters(Application app, Long appId, List<ProcessingEvent> events, Map<Object, Object> parameterMap) {
// if we're not processing and there is a versionId or an identifier in the request
// then we're pre-populating the form with information from the version
ApplicationVersion version = null;
String versionId = firstValue("versionId", parameterMap);
String identifier = firstValue("identifier", parameterMap);
if (StringUtils.isNotBlank(versionId) || StringUtils.isNotBlank(identifier)) {
if (StringUtils.isNotBlank(versionId)) {
version = modelManager.getModelService().findByPrimaryKey(ApplicationVersion.class, Long.valueOf(versionId));
}
if (version == null && StringUtils.isNotBlank(identifier)) {
version = modelManager.getModelService().findAppVersionByNameAndId(app.getName(), identifier);
}
if (version == null) {
events.add(new GenericProcessingEvent(ProcessingTargets.MESSAGES, "An Application Version matching input could not be found. Creating a new version."));
} else if (version.getApplication() != null && version.getApplication().getId().compareTo(appId) != 0) {
version = null;
events.add(new GenericProcessingEvent(ProcessingTargets.MESSAGES, "The Application Version with id " + versionId + " is not a version of the Application with id " + appId));
}
}
return version;
}
use of com.openmeap.web.GenericProcessingEvent 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;
}
Aggregations