public String editApplicationVersion(final HttpServletRequest request, Model model, @PathVariable Long parentId, @PathVariable Long versionId) {
checkRequiredEntity(applicationVersionService, versionId);
checkRequiredEntity(applicationService, parentId);
ApplicationVersion version = applicationVersionService.get(versionId);
Application application = applicationService.get(parentId);
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);
model.addAttribute("isEdit", true);
// Create a List of all KeyVaultEntries which are available for the given application.
List<KeyVaultEntryModel> keyVaultEntryModels = new ArrayList<KeyVaultEntryModel>();
for (KeyVaultEntry keyVaultEntry : keyVaultEntryService.getAllForDomainAndApplicationType(group, application.getApplicationType())) {
KeyVaultEntryModel keyVaultEntryModel = keyVaultEntryService.convertToModel(keyVaultEntry);
if (keyVaultEntry != null) {
keyVaultEntryModels.add(keyVaultEntryModel);
}
}
model.addAttribute("keyVaultEntries", keyVaultEntryModels);
List<InternationalizedObject> appStates = new ArrayList<InternationalizedObject>();
for (AppState appState : AppState.values()) {
try {
appStates.add(new InternationalizedObject(appState, messageSource.getMessage(appState.getMessageKey(), null, request.getLocale())));
} catch (NoSuchMessageException ex) {
log.error(String.format("No message for appState: %s", appState.name()), ex);
// Put the applicationType name so that the application doesn't error out.
appStates.add(new InternationalizedObject(appState, appState.name()));
}
}
model.addAttribute("appStates", appStates);
return "manager/manageApplicationVersionTH";
} else {
throw new EntityNotFoundException(String.format("Group Entity not found for Application: %s", application.getId()));
}
}