Group group = application.getOwnedGroup();
if (group != null) {
model.addAttribute("parentApplicationId", application.getId());
model.addAttribute("parentApplicationName", application.getName());
ApplicationVersionForm applicationVersionForm;
if (model.containsAttribute("version")) {
applicationVersionForm = (ApplicationVersionForm) model.asMap().get("version");
} else {
applicationVersionForm = new ApplicationVersionForm();
}
applicationVersionForm.setId(version.getId());
applicationVersionForm.setRecentChanges(version.getRecentChanges());
applicationVersionForm.setVersionName(version.getVersionName());
applicationVersionForm.setParentId(parentId);
applicationVersionForm.setAppState(version.getAppState());
if (version.getInstallationFile() != null) {
MockMultipartFile multipartFile = new MockMultipartFile(version.getInstallationFile().getName(), version.getInstallationFile().getName(), version.getInstallationFile().getType(), new byte[0]);
applicationVersionForm.setAppFile(multipartFile);
}
if (version.getProvisioningProfile() != null) {
MockMultipartFile multipartFile = new MockMultipartFile(version.getProvisioningProfile().getName(), version.getProvisioningProfile().getName(), version.getProvisioningProfile().getType(), new byte[0]);
applicationVersionForm.setProvisioningProfile(multipartFile);
}
model.addAttribute("version", applicationVersionForm);
//Put this app versions guest groups on the model so we can highlight them in the multi-select box
List<Group> currentGuestGroups = version.getGuestGroups();
Set<Long> currentGuestGroupIds = new HashSet<Long>();
if (currentGuestGroups != null) {
for (Group guestGroup : currentGuestGroups) {
currentGuestGroupIds.add(guestGroup.getId());
}
}
applicationVersionForm.setGuestGroupIds(new ArrayList<Long>(currentGuestGroupIds));
model.addAttribute("currentGuestGroupIds", currentGuestGroupIds);
//We don't want the group that owns the application in the list of guest groups
List<Group> groups = new ArrayList<Group>(group.getOrganization().getGroups());
groups.remove(group);
model.addAttribute("groups", groups);