@Test void testUploadApp() throws Exception { AppConfig appConfig = mock(AppConfig.class); when(appConfig.getName()).thenReturn(""); when(appManagerService.checkAndObtainConfig(null, null)).thenReturn(appConfig); String testFile = AppManagerControllerTest.class.getResource("/test-app.zip").getFile(); mockMvc .perform(multipart(AppManagerController.URI + "/upload").file("file", testFile.getBytes())) .andExpect(status().is(200)); }
@ResponseStatus(HttpStatus.OK) @PostMapping("/upload") public void uploadApp(@RequestParam("file") MultipartFile multipartFile) { String filename = multipartFile.getOriginalFilename(); String formFieldName = multipartFile.getName(); try (InputStream fileInputStream = multipartFile.getInputStream()) { String tempDir = appManagerService.uploadApp(fileInputStream, filename, formFieldName); String configFile = appManagerService.extractFileContent(tempDir, ZIP_CONFIG_FILE); AppConfig appConfig = appManagerService.checkAndObtainConfig(tempDir, configFile); String htmlTemplate = appManagerService.extractFileContent( APPS_DIR + separator + appConfig.getName(), ZIP_INDEX_FILE); appManagerService.configureApp(appConfig, htmlTemplate); } catch (IOException err) { throw new CouldNotUploadAppException(filename); } }
AppManagerController extends PluginController { @ResponseStatus(HttpStatus.OK) @PostMapping("/upload") public void uploadApp(@RequestParam("file") MultipartFile multipartFile) { String filename = multipartFile.getOriginalFilename(); String formFieldName = multipartFile.getName(); try (InputStream fileInputStream = multipartFile.getInputStream()) { String tempDir = appManagerService.uploadApp(fileInputStream, filename, formFieldName); String configFile = appManagerService.extractFileContent(tempDir, ZIP_CONFIG_FILE); AppConfig appConfig = appManagerService.checkAndObtainConfig(tempDir, configFile); String htmlTemplate = appManagerService.extractFileContent( APPS_DIR + separator + appConfig.getName(), ZIP_INDEX_FILE); appManagerService.configureApp(appConfig, htmlTemplate); } catch (IOException err) { throw new CouldNotUploadAppException(filename); } } }
AppManagerController extends PluginController { @ResponseStatus(HttpStatus.OK) @PostMapping("/upload") public void uploadApp(@RequestParam("file") MultipartFile multipartFile) { String filename = multipartFile.getOriginalFilename(); String formFieldName = multipartFile.getName(); try (InputStream fileInputStream = multipartFile.getInputStream()) { String tempDir = appManagerService.uploadApp(fileInputStream, filename, formFieldName); String configFile = appManagerService.extractFileContent(tempDir, ZIP_CONFIG_FILE); AppConfig appConfig = appManagerService.checkAndObtainConfig(tempDir, configFile); String htmlTemplate = appManagerService.extractFileContent( APPS_DIR + separator + appConfig.getName(), ZIP_INDEX_FILE); appManagerService.configureApp(appConfig, htmlTemplate); } catch (IOException err) { throw new CouldNotUploadAppException(filename); } } AppManagerController(AppManagerService appManagerService, DataService dataService); }
AppManagerController extends PluginController { @ResponseStatus(HttpStatus.OK) @PostMapping("/upload") public void uploadApp(@RequestParam("file") MultipartFile multipartFile) { String filename = multipartFile.getOriginalFilename(); String formFieldName = multipartFile.getName(); try (InputStream fileInputStream = multipartFile.getInputStream()) { String tempDir = appManagerService.uploadApp(fileInputStream, filename, formFieldName); String configFile = appManagerService.extractFileContent(tempDir, ZIP_CONFIG_FILE); AppConfig appConfig = appManagerService.checkAndObtainConfig(tempDir, configFile); String htmlTemplate = appManagerService.extractFileContent( APPS_DIR + separator + appConfig.getName(), ZIP_INDEX_FILE); appManagerService.configureApp(appConfig, htmlTemplate); } catch (IOException err) { throw new CouldNotUploadAppException(filename); } } AppManagerController(AppManagerService appManagerService, DataService dataService); @GetMapping String init(); @ResponseBody @GetMapping("/apps") List<AppResponse> getApps(); @ResponseStatus(HttpStatus.OK) @PostMapping("/activate/{id}") void activateApp(@PathVariable(value = "id") String id); @ResponseStatus(HttpStatus.OK) @PostMapping("/deactivate/{id}") void deactivateApp(@PathVariable(value = "id") String id); @ResponseStatus(HttpStatus.OK) @DeleteMapping("/delete/{id}") void deleteApp(@PathVariable("id") String id); @ResponseStatus(HttpStatus.OK) @PostMapping("/upload") void uploadApp(@RequestParam("file") MultipartFile multipartFile); }
AppManagerController extends PluginController { @ResponseStatus(HttpStatus.OK) @PostMapping("/upload") public void uploadApp(@RequestParam("file") MultipartFile multipartFile) { String filename = multipartFile.getOriginalFilename(); String formFieldName = multipartFile.getName(); try (InputStream fileInputStream = multipartFile.getInputStream()) { String tempDir = appManagerService.uploadApp(fileInputStream, filename, formFieldName); String configFile = appManagerService.extractFileContent(tempDir, ZIP_CONFIG_FILE); AppConfig appConfig = appManagerService.checkAndObtainConfig(tempDir, configFile); String htmlTemplate = appManagerService.extractFileContent( APPS_DIR + separator + appConfig.getName(), ZIP_INDEX_FILE); appManagerService.configureApp(appConfig, htmlTemplate); } catch (IOException err) { throw new CouldNotUploadAppException(filename); } } AppManagerController(AppManagerService appManagerService, DataService dataService); @GetMapping String init(); @ResponseBody @GetMapping("/apps") List<AppResponse> getApps(); @ResponseStatus(HttpStatus.OK) @PostMapping("/activate/{id}") void activateApp(@PathVariable(value = "id") String id); @ResponseStatus(HttpStatus.OK) @PostMapping("/deactivate/{id}") void deactivateApp(@PathVariable(value = "id") String id); @ResponseStatus(HttpStatus.OK) @DeleteMapping("/delete/{id}") void deleteApp(@PathVariable("id") String id); @ResponseStatus(HttpStatus.OK) @PostMapping("/upload") void uploadApp(@RequestParam("file") MultipartFile multipartFile); static final String ID; static final String URI; }