Application application = applicationService.get(id);
if (!model.containsAttribute("applicationForm")) {
ApplicationForm applicationForm = new ApplicationForm();
applicationForm.setId(application.getId());
applicationForm.setGroupId(application.getOwnedGroup().getId());
applicationForm.setApplicationType(application.getApplicationType());
applicationForm.setDescription(application.getDescription());
applicationForm.setName(application.getName());
applicationForm.setCategoryId(application.getCategory().getId());
StorageService storageService = storageServiceFactory.getStorageService(application.getStorageConfiguration().getStorageType());
AppFile icon = application.getIcon();
if (icon != null) {
MockMultipartFile iconMultipartFile = new MockMultipartFile(application.getIcon().getName(), application.getIcon().getName(), application.getIcon().getType(), new byte[0]);
applicationForm.setIcon(iconMultipartFile);
model.addAttribute("icon", appFileService.createImageModel(icon));
}
List<AppFile> screenShots = application.getScreenshots();
List<MultipartFile> screenShotMultipartFiles = new ArrayList<MultipartFile>();
List<ImageModel> screenshotImageModels = new ArrayList<ImageModel>();
for (AppFile screenShot : screenShots) {
MockMultipartFile screenShotMultipartFile = new MockMultipartFile(screenShot.getName(), screenShot.getName(), screenShot.getType(), storageService.getInputStream(screenShot));
screenShotMultipartFiles.add(screenShotMultipartFile);
screenshotImageModels.add(appFileService.createImageModel(screenShot));
}
applicationForm.setScreenshots(screenShotMultipartFiles);
model.addAttribute("screenshots", screenshotImageModels);
model.addAttribute("applicationForm", applicationForm);
}