use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class ApplicationVersionListingsBacking method createVersionsDisplayLists.
private void createVersionsDisplayLists(Application app, Map<Object, Object> templateVariables) {
templateVariables.put("versions", app.getVersions());
GlobalSettings settings = modelManager.getGlobalSettings();
Map<String, String> downloadUrls = new HashMap<String, String>();
Map<String, String> viewUrls = new HashMap<String, String>();
for (ApplicationVersion version : app.getVersions().values()) {
if (version.getArchive() == null) {
viewUrls.put(version.getIdentifier(), "");
} else {
downloadUrls.put(version.getIdentifier(), version.getArchive().getDownloadUrl(settings));
File exploded = version.getArchive().getExplodedPath(settings.getTemporaryStoragePath());
if (exploded != null && exploded.exists()) {
viewUrls.put(version.getIdentifier(), version.getArchive().getViewUrl(settings));
}
}
}
templateVariables.put("downloadUrls", downloadUrls);
templateVariables.put("viewUrls", viewUrls);
}
use of com.openmeap.model.dto.ApplicationVersion 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));
}
use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class AdminTest method _createDeployment.
private void _createDeployment(String identifier, Deployment.Type type) throws Exception {
modelManager.getModelService().clearPersistenceContext();
ApplicationVersion version = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, identifier);
String body = Utils.readInputStream(helper.postCreateDeployment(version, type).getResponseBody(), FormConstants.CHAR_ENC_DEFAULT);
logger.info(body);
Assert.assertTrue(_isVersionArchiveInDeployedLocation(version.getArchive().getHash()));
}
use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class AddModifyApplicationVersionsBackingTest method testFormPost.
@Test
public void testFormPost() {
ApplicationVersion version = null;
Map<Object, Object> vars = null;
Map<Object, Object> parms = null;
////////////
// Verify that we can create a new ApplicationVersion
vars = new HashMap<Object, Object>();
parms = new HashMap<Object, Object>();
parms.put(FormConstants.PROCESS_TARGET, new String[] { ProcessingTargets.ADDMODIFY_APPVER });
parms.put(FormConstants.APP_ID, new String[] { "1" });
parms.put("versionId", new String[] { "" });
parms.put("identifier", new String[] { "ApplicationVersion.identifier.1" });
parms.put("url", new String[] { "ANewDownloadUrl" });
parms.put("hashType", new String[] { "MD5" });
parms.put("hash", new String[] { "ANewHashValue" });
parms.put("notes", new String[] { "These are them application version notes" });
parms.put("deviceTypes", new String[] { "1", "2" });
parms.put("bytesLength", new String[] { "13456342" });
parms.put("bytesLengthUncompressed", new String[] { "13456342" });
AddModifyApplicationVersionBacking amab = new AddModifyApplicationVersionBacking();
amab.setModelManager(modelManager);
Collection<ProcessingEvent> events = amab.process(null, vars, parms);
Assert.assertTrue(events.size() == 4 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
Assert.assertTrue(vars.get("hashTypes") != null);
Assert.assertTrue(vars.get(FormConstants.PROCESS_TARGET) != null && ((String) vars.get(FormConstants.PROCESS_TARGET)).compareTo(ProcessingTargets.ADDMODIFY_APPVER) == 0);
Assert.assertTrue(vars.get("version") != null);
version = ((ApplicationVersion) vars.get("version"));
Assert.assertTrue(version.getIdentifier().compareTo("ApplicationVersion.identifier.1") == 0);
Assert.assertTrue(version.getArchive() != null);
/////////////
// Verify that we can change pretty much everything
Long ourVersionId = ((ApplicationVersion) vars.get("version")).getId();
parms.put("versionId", new String[] { ourVersionId.toString() });
parms.put("identifier", new String[] { "ApplicationVersion.new_version.identifier" });
parms.put("url", new String[] { "AnotherNewDownloadUrl" });
parms.put("hashType", new String[] { "SHA1" });
parms.put("hash", new String[] { "AnotherNewHashValue" });
parms.put("notes", new String[] { "New notes" });
parms.put("deviceTypes", new String[] { "1" });
parms.put("bytesLength", new String[] { "10000" });
parms.put("bytesLengthUncompressed", new String[] { "10000" });
amab = new AddModifyApplicationVersionBacking();
amab.setModelManager(modelManager);
events = amab.process(null, vars, parms);
version = modelManager.getModelService().findByPrimaryKey(ApplicationVersion.class, ourVersionId);
Assert.assertTrue(version.getIdentifier().compareTo("ApplicationVersion.new_version.identifier") == 0);
Assert.assertTrue(version.getArchive().getUrl().compareTo("AnotherNewDownloadUrl") == 0);
Assert.assertTrue(version.getArchive().getHashAlgorithm().compareTo("SHA1") == 0);
Assert.assertTrue(version.getArchive().getHash().compareTo("AnotherNewHashValue") == 0);
Assert.assertTrue(version.getNotes().compareTo("New notes") == 0);
Assert.assertTrue(version.getArchive().getBytesLength() == 10000);
Assert.assertTrue(version.getArchive().getBytesLengthUncompressed() == 10000);
/////////////
// Verify that we cannot change an inactive version
ourVersionId = ((ApplicationVersion) vars.get("version")).getId();
((ApplicationVersion) vars.get("version")).setActiveFlag(false);
parms.put("versionId", new String[] { ourVersionId.toString() });
parms.put("identifier", new String[] { "ApplicationVersion.new_version_2.identifier" });
parms.put("url", new String[] { "AnotherNewDownloadUrl2" });
parms.put("hashType", new String[] { "MD5" });
parms.put("hash", new String[] { "AnotherNewHashValue2" });
parms.put("notes", new String[] { "New notes2" });
parms.put("deviceTypes", new String[] { "12" });
parms.put("bytesLength", new String[] { "100002" });
parms.put("bytesLengthUncompressed", new String[] { "100002" });
amab = new AddModifyApplicationVersionBacking();
amab.setModelManager(modelManager);
events = amab.process(null, vars, parms);
version = modelManager.getModelService().findByPrimaryKey(ApplicationVersion.class, ourVersionId);
Assert.assertTrue(version.getIdentifier().compareTo("ApplicationVersion.new_version.identifier") == 0);
Assert.assertTrue(version.getArchive().getUrl().compareTo("AnotherNewDownloadUrl") == 0);
Assert.assertTrue(version.getArchive().getHashAlgorithm().compareTo("SHA1") == 0);
Assert.assertTrue(version.getArchive().getHash().compareTo("AnotherNewHashValue") == 0);
Assert.assertTrue(version.getNotes().compareTo("New notes") == 0);
Assert.assertTrue(version.getArchive().getBytesLength() == 10000);
Assert.assertTrue(version.getArchive().getBytesLengthUncompressed() == 10000);
}
use of com.openmeap.model.dto.ApplicationVersion in project OpenMEAP by OpenMEAP.
the class ApplicationVersionListingsBackingTest method testFormSetup.
@Test
public void testFormSetup() {
Map<Object, Object> vars = new HashMap<Object, Object>();
Map<Object, Object> parms = new HashMap<Object, Object>();
////////////////
// If no application id is specified, then we should get only a MessageBacking targeting event back
ApplicationVersionListingsBacking avlb = new ApplicationVersionListingsBacking();
avlb.setModelManager(modelManager);
Collection<ProcessingEvent> events = avlb.process(null, vars, parms);
Assert.assertTrue(events != null && events.size() == 1 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
Assert.assertTrue(vars.size() == 0);
////////////////
// Verify that a valid application id returns
// - a "Create Application Version" anchor
// - a list of versions
parms.put(FormConstants.APP_ID, new String[] { "1" });
events = avlb.process(null, vars, parms);
Assert.assertTrue(events != null && events.size() == 3 && ProcessingUtils.containsTarget(events, ProcessingTargets.NAV_SUB));
for (ProcessingEvent event : events) {
Assert.assertTrue(event.getPayload() instanceof Anchor);
}
Assert.assertTrue(vars.get("versions") != null && ((Map<String, ApplicationVersion>) vars.get("versions")).size() == 2);
}
Aggregations