Search in sources :

Example 1 with ApplicationVersion

use of com.openmeap.model.dto.ApplicationVersion 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 ApplicationVersion

use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.

the class AdminTest method _deleteApplicationVersion.

/**
	 * 
	 * @param identifier
	 * @return true if archive deleted
	 * @throws Exception
	 */
private Boolean _deleteApplicationVersion(String identifier) throws Exception {
    ApplicationVersion version = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, identifier);
    String hash = version.getArchive().getHash();
    Utils.consumeInputStream(helper.postAddModifyAppVer_delete(version).getResponseBody());
    modelManager.getModelService().clearPersistenceContext();
    version = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, identifier);
    Assert.assertTrue(version == null);
    return !_isVersionArchiveInAdminLocation(hash);
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion)

Example 3 with ApplicationVersion

use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.

the class AdminTest method testUpdateApplicationVersion.

public void testUpdateApplicationVersion() throws Exception {
    GlobalSettings settings = modelManager.getGlobalSettings();
    // validate that an unused archive is deleted
    // update version update
    // and that it is recreated when reuploaded
    ApplicationVersion version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
    String response = Utils.readInputStream(helper.postAddModifyAppVer(version1, new File(this.getClass().getResource(VERSION_02_ZIP).getFile())).getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
    modelManager.getModelService().clearPersistenceContext();
    version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
    ApplicationVersion version2 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
    Assert.assertTrue(version1.getArchive().getHash().equals(VERSION_02_HASH));
    Assert.assertTrue(version2.getArchive().getHash().equals(VERSION_02_HASH));
    Assert.assertSame(version2.getArchive(), version1.getArchive());
    // now restore the archive of version1
    // and validate that version2's archive is not erroneously updated.
    response = Utils.readInputStream(helper.postAddModifyAppVer(version1, new File(this.getClass().getResource(VERSION_01_ZIP).getFile())).getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
    modelManager.getModelService().clearPersistenceContext();
    version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
    version2 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_02);
    Assert.assertTrue(version1.getArchive().getHash().equals(VERSION_01_HASH));
    Assert.assertTrue(version1.getArchive().getFile(settings.getTemporaryStoragePath()).exists());
    Assert.assertTrue(version2.getArchive().getHash().equals(VERSION_02_HASH));
    Assert.assertTrue(version2.getArchive().getFile(settings.getTemporaryStoragePath()).exists());
    Assert.assertNotSame(version2.getArchive(), version1.getArchive());
    Result result = helper.getConnectionOpen(version1, SLIC_VERSION);
    Assert.assertTrue(result.getConnectionOpenResponse().getUpdate() == null);
    Assert.assertTrue(AuthTokenProvider.validateAuthToken(version1.getApplication().getProxyAuthSalt(), result.getConnectionOpenResponse().getAuthToken()));
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) GlobalSettings(com.openmeap.model.dto.GlobalSettings) File(java.io.File) Result(com.openmeap.protocol.dto.Result)

Example 4 with ApplicationVersion

use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.

the class AdminTest method testCreateDeployments.

public void testCreateDeployments() throws Exception {
    Result result = null;
    ApplicationVersion version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
    ApplicationVersion version2 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_02);
    UpdateHeader update = null;
    _createDeployment(VERSION_01, Deployment.Type.IMMEDIATE);
    modelManager.getModelService().clearPersistenceContext();
    Application app = modelManager.getModelService().findApplicationByName(APP_NAME);
    Assert.assertTrue(app.getDeployments().size() == 1);
    result = helper.getConnectionOpen(version2, SLIC_VERSION);
    update = result.getConnectionOpenResponse().getUpdate();
    Assert.assertTrue(update.getType().value().equals(Deployment.Type.IMMEDIATE.name()));
    Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_01));
    Assert.assertTrue(update.getHash().getValue().equals(VERSION_01_HASH));
    Assert.assertTrue(update.getStorageNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH));
    Assert.assertTrue(update.getInstallNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH + VERSION_01_BYTES_LENGTH));
    _createDeployment(VERSION_02, Deployment.Type.REQUIRED);
    modelManager.getModelService().clearPersistenceContext();
    app = modelManager.getModelService().findApplicationByName(APP_NAME);
    Assert.assertTrue(app.getDeployments().size() == 2);
    result = helper.getConnectionOpen(version1, SLIC_VERSION);
    update = result.getConnectionOpenResponse().getUpdate();
    Assert.assertTrue(update.getType().value().equals(Deployment.Type.REQUIRED.name()));
    Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_02));
    Assert.assertTrue(update.getHash().getValue().equals(VERSION_02_HASH));
    Assert.assertTrue(update.getStorageNeeds().equals(VERSION_02_UNCOMPRESSED_BYTES_LENGTH));
    Assert.assertTrue(update.getInstallNeeds().equals(VERSION_02_UNCOMPRESSED_BYTES_LENGTH + VERSION_02_BYTES_LENGTH));
    _createDeployment(VERSION_02, Deployment.Type.REQUIRED);
    Assert.assertTrue("as this deployment is created, the archive for version01 should be removed from the deployed location", !_isVersionArchiveInDeployedLocation(VERSION_01_HASH));
    _createDeployment(VERSION_01, Deployment.Type.IMMEDIATE);
    Assert.assertTrue("as this deployment is created, the archive for version01 should be in the deployed location", _isVersionArchiveInDeployedLocation(VERSION_01_HASH));
    result = helper.getConnectionOpen(version2, SLIC_VERSION);
    update = result.getConnectionOpenResponse().getUpdate();
    Assert.assertTrue(update.getType().value().equals(Deployment.Type.IMMEDIATE.name()));
    Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_01));
    Assert.assertTrue(update.getHash().getValue().equals(VERSION_01_HASH));
    Assert.assertTrue(update.getStorageNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH));
    Assert.assertTrue(update.getInstallNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH + VERSION_01_BYTES_LENGTH));
    modelManager.getModelService().clearPersistenceContext();
    app = modelManager.getModelService().findApplicationByName(APP_NAME);
    Assert.assertTrue(app.getDeployments().size() == 2);
    Assert.assertTrue(app.getDeployments().get(0).getVersionIdentifier().equals(VERSION_02));
    Assert.assertTrue(app.getDeployments().get(1).getVersionIdentifier().equals(VERSION_01));
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) Application(com.openmeap.model.dto.Application) Result(com.openmeap.protocol.dto.Result)

Example 5 with ApplicationVersion

use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.

the class AddModifyApplicationVersionsBackingTest method testFormSetup.

@Test
public void testFormSetup() {
    ModelManager mm = modelManager;
    //////////////////
    // Verify the correct templateVariables are produced when no applicationId is passed in
    // You cannot modify an app version without an application, so there will be a minimal return
    Map<Object, Object> vars = new HashMap<Object, Object>();
    Map<Object, Object> parms = new HashMap<Object, Object>();
    AddModifyApplicationVersionBacking amab = new AddModifyApplicationVersionBacking();
    amab.setModelManager(mm);
    Collection<ProcessingEvent> events = amab.process(null, vars, parms);
    Assert.assertTrue(events.size() == 1 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
    Assert.assertTrue(vars.size() == 1 && vars.get(FormConstants.ENCODING_TYPE).equals("enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\""));
    ///////////////////////
    // verify the correct templateVariables are produced with an invalid applcationId is passed
    vars = new HashMap<Object, Object>();
    parms = new HashMap<Object, Object>();
    parms.put(FormConstants.APP_ID, new String[] { "666" });
    amab = new AddModifyApplicationVersionBacking();
    amab.setModelManager(mm);
    events = amab.process(null, vars, parms);
    Assert.assertTrue(events.size() == 1 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
    Assert.assertTrue(vars.size() == 1 && vars.get(FormConstants.ENCODING_TYPE).equals("enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\""));
    /////////////////////
    // verify the correct templateVariables are produced with an valid applcationId, 
    // but invalid versionId is passed
    vars = new HashMap<Object, Object>();
    parms = new HashMap<Object, Object>();
    parms.put(FormConstants.APP_ID, new String[] { "1" });
    parms.put("versionId", new String[] { "666" });
    amab = new AddModifyApplicationVersionBacking();
    amab.setModelManager(mm);
    events = amab.process(null, vars, parms);
    Assert.assertTrue(events.size() == 4 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
    Assert.assertTrue(vars.size() == 6);
    Assert.assertTrue(vars.get(FormConstants.ENCODING_TYPE).equals("enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\""));
    Assert.assertTrue(vars.get("application") != null && ((Application) vars.get("application")).getName().compareTo("Application.name") == 0);
    Assert.assertTrue(vars.get("version") != null && ((ApplicationVersion) vars.get("version")).getIdentifier() == null);
    Assert.assertTrue(vars.get("hashTypes") != null && ((List) vars.get("hashTypes")).size() == HashAlgorithm.values().length);
    Assert.assertTrue(((String) vars.get(FormConstants.PROCESS_TARGET)).compareTo(ProcessingTargets.ADDMODIFY_APPVER) == 0);
    //////////////////////
    // verify the correct templateVariables are produced when 
    // both a valid app id and version id are passed in
    vars = new HashMap<Object, Object>();
    parms = new HashMap<Object, Object>();
    parms.put(FormConstants.APP_ID, new String[] { "1" });
    parms.put("versionId", new String[] { "1" });
    amab = new AddModifyApplicationVersionBacking();
    amab.setModelManager(mm);
    events = amab.process(null, vars, parms);
    Assert.assertTrue(events.size() == 3);
    Assert.assertTrue(vars.size() == 6);
    Assert.assertTrue(vars.get(FormConstants.ENCODING_TYPE).equals("enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\""));
    Assert.assertTrue(vars.get("application") != null && ((Application) vars.get("application")).getName().compareTo("Application.name") == 0);
    Assert.assertTrue(vars.get("version") != null && ((ApplicationVersion) vars.get("version")).getIdentifier().compareTo("ApplicationVersion.identifier.1") == 0);
    Assert.assertTrue(vars.get("hashTypes") != null && ((List) vars.get("hashTypes")).size() == HashAlgorithm.values().length);
    Assert.assertTrue(((String) vars.get(FormConstants.PROCESS_TARGET)).compareTo(ProcessingTargets.ADDMODIFY_APPVER) == 0);
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) HashMap(java.util.HashMap) ProcessingEvent(com.openmeap.event.ProcessingEvent) ModelManager(com.openmeap.model.ModelManager) AddModifyApplicationVersionBacking(com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking) Application(com.openmeap.model.dto.Application)

Aggregations

ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)26 Application (com.openmeap.model.dto.Application)12 ProcessingEvent (com.openmeap.event.ProcessingEvent)7 GlobalSettings (com.openmeap.model.dto.GlobalSettings)6 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)5 Anchor (com.openmeap.web.html.Anchor)5 HashMap (java.util.HashMap)5 AddSubNavAnchorEvent (com.openmeap.admin.web.events.AddSubNavAnchorEvent)4 MessagesEvent (com.openmeap.event.MessagesEvent)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 PersistenceException (javax.persistence.PersistenceException)4 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)3 Deployment (com.openmeap.model.dto.Deployment)3 Result (com.openmeap.protocol.dto.Result)3 AddModifyApplicationVersionBacking (com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking)2 ClusterNotificationException (com.openmeap.cluster.ClusterNotificationException)2 EventNotificationException (com.openmeap.event.EventNotificationException)2 GenericProcessingEvent (com.openmeap.web.GenericProcessingEvent)2 IOException (java.io.IOException)2