use of com.openmeap.model.dto.Application 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;
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ApplicationListingsBacking method process.
public Collection<ProcessingEvent> process(ProcessingContext context, Map<Object, Object> templateVariables, Map<Object, Object> parameterMap) {
List<Application> applications = modelManager.getModelService().findAll(Application.class);
if (applications != null && applications.size() > 0) {
Map<String, Anchor> deplUrls = new HashMap<String, Anchor>();
for (Application app : applications) {
Deployment d = modelManager.getModelService().getLastDeployment(app);
if (d != null) {
deplUrls.put(app.getName(), new Anchor("?bean=addModifyAppVersionPage" + "&applicationId=" + app.getId() + "&versionId=" + d.getId(), d.getVersionIdentifier(), d.getVersionIdentifier()));
}
}
templateVariables.put("applications", applications);
templateVariables.put("deplUrls", deplUrls);
}
return null;
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ApplicationManagementPortTypeImplTest method testConnectionOpen_verifyUpdateHeaderOnUpdateRequired.
/**
* Verify that an update header is returned if the version reported by SLIC
* does not match the version of the most recent deployment and
* verify that the authentication token is generated using the proxy salt
* associated to the application.
* @throws Exception
*/
@Test
public void testConnectionOpen_verifyUpdateHeaderOnUpdateRequired() throws Exception {
////////////////
// Verify that, when version that exists, but is not the current version, is specified,
// an authentication token is generated AS WELL AS an UpdateHeader
request.getApplication().setVersionId("ApplicationVersion.identifier.1");
com.openmeap.model.dto.ApplicationVersion appVer = modelManager.getModelService().findAppVersionByNameAndId(request.getApplication().getName(), "ApplicationVersion.identifier.2");
com.openmeap.model.dto.Application app = appVer.getApplication();
response = appMgmtSvc.connectionOpen(request);
Assert.assertTrue(response.getAuthToken() != null && response.getAuthToken().length() > 0);
Assert.assertTrue(response.getUpdate() != null);
Assert.assertTrue(response.getUpdate().getInstallNeeds().intValue() == appVer.getArchive().getBytesLength() + appVer.getArchive().getBytesLengthUncompressed());
Assert.assertTrue(response.getUpdate().getStorageNeeds().intValue() == appVer.getArchive().getBytesLengthUncompressed());
Assert.assertTrue(response.getUpdate().getHash().getValue().compareTo(appVer.getArchive().getHash()) == 0);
Assert.assertTrue(AuthTokenProvider.validateAuthToken(app.getProxyAuthSalt(), response.getAuthToken()));
}
use of com.openmeap.model.dto.Application 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;
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class AdminTest method _createApplicationVersion.
/*
* PRIVATE HELPER METHODS
*/
private void _createApplicationVersion(String identifier, String notes, String archiveName, String hash) throws Exception {
Application app = modelManager.getModelService().findApplicationByName(APP_NAME);
ApplicationVersion version = new ApplicationVersion();
version.setIdentifier(identifier);
version.setNotes(notes);
app.addVersion(version);
File uploadArchive = new File(this.getClass().getResource(archiveName).getFile());
Utils.consumeInputStream(helper.postAddModifyAppVer(version, uploadArchive).getResponseBody());
// archive is uploaded
modelManager.getModelService().clearPersistenceContext();
app = modelManager.getModelService().findApplicationByName(APP_NAME);
version = app.getVersions().get(identifier);
Assert.assertTrue(version != null);
// validate that the archive was uploaded and exploded
Assert.assertTrue(_isVersionArchiveInAdminLocation(hash));
}
Aggregations