@RequestMapping(value = "/uploadFile", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) public Collection<Route> handleFileUpload(@RequestParam("file") MultipartFile file) { Collection<Route> result = Collections.emptyList(); if (!file.isEmpty()) { log.info("{} uploaded", file.getOriginalFilename()); try { String extension = FilenameUtils.getExtension(file.getOriginalFilename()); byte[] data = null; if ("zip".equals(extension)) { data = zipUtils.doUnzip(file.getBytes()); } else if ("js".equals(extension)) { data = file.getBytes(); } if (data == null) { throw new IllegalArgumentException("Unrecognized file extension"); } List<Route> routes = routeCacheFileUtils.parseRoutes(data); log.info("Found {} routes", routes.size()); result = routes; } catch (Exception e) { log.error("Unexpected error occured while uploading a file", e); } } return result; }
private byte[] createZip(String uuid) throws IOException { return zipUtils.doZip( routeCacheFileUtils.createFileContent(routeRepository.getAllRoutes(uuid))); }