Search in sources :

Example 21 with Application

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;
}
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 22 with Application

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;
}
Also used : Anchor(com.openmeap.web.html.Anchor) HashMap(java.util.HashMap) Deployment(com.openmeap.model.dto.Deployment) Application(com.openmeap.model.dto.Application)

Example 23 with Application

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()));
}
Also used : Application(com.openmeap.model.dto.Application) Test(org.junit.Test)

Example 24 with Application

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;
}
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)

Example 25 with Application

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));
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) Application(com.openmeap.model.dto.Application) File(java.io.File)

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