@Transactional public Package downloadPackage(PackageMetadata packageMetadata) { Assert.notNull(packageMetadata, "Can't download PackageMetadata, it is a null value."); // Database contains the package file from a previous upload if (packageMetadata.getPackageFile() != null) { return deserializePackageFromDatabase(packageMetadata); } else { return downloadAndDeserializePackage(packageMetadata); } }
@Transactional public Package downloadPackage(PackageMetadata packageMetadata) { Assert.notNull(packageMetadata, "Can't download PackageMetadata, it is a null value."); // Database contains the package file from a previous upload if (packageMetadata.getPackageFile() != null) { return deserializePackageFromDatabase(packageMetadata); } else { return downloadAndDeserializePackage(packageMetadata); } }
private Package deserializePackageFromDatabase(PackageMetadata packageMetadata) { // package file was uploaded to a local DB hosted repository Path tmpDirPath = null; try { tmpDirPath = TempFileUtils.createTempDirectory("skipper"); File targetPath = new File(tmpDirPath + File.separator + packageMetadata.getName()); targetPath.mkdirs(); File targetFile = PackageFileUtils.calculatePackageZipFile(packageMetadata, targetPath); try { StreamUtils.copy(packageMetadata.getPackageFile().getPackageBytes(), new FileOutputStream(targetFile)); } catch (IOException e) { throw new SkipperException( "Could not copy package file for " + packageMetadata.getName() + "-" + packageMetadata.getVersion() + " from database to target file " + targetFile, e); } ZipUtil.unpack(targetFile, targetPath); Package pkgToReturn = this.packageReader.read(new File(targetPath, packageMetadata.getName() + "-" + packageMetadata.getVersion())); pkgToReturn.setMetadata(packageMetadata); return pkgToReturn; } finally { if (tmpDirPath != null && !FileSystemUtils.deleteRecursively(tmpDirPath.toFile())) { logger.warn("Temporary directory can not be deleted: " + tmpDirPath); } } }
private Package deserializePackageFromDatabase(PackageMetadata packageMetadata) { // package file was uploaded to a local DB hosted repository Path tmpDirPath = null; try { tmpDirPath = TempFileUtils.createTempDirectory("skipper"); File targetPath = new File(tmpDirPath + File.separator + packageMetadata.getName()); targetPath.mkdirs(); File targetFile = PackageFileUtils.calculatePackageZipFile(packageMetadata, targetPath); try { StreamUtils.copy(packageMetadata.getPackageFile().getPackageBytes(), new FileOutputStream(targetFile)); } catch (IOException e) { throw new SkipperException( "Could not copy package file for " + packageMetadata.getName() + "-" + packageMetadata.getVersion() + " from database to target file " + targetFile, e); } ZipUtil.unpack(targetFile, targetPath); Package pkgToReturn = this.packageReader.read(new File(targetPath, packageMetadata.getName() + "-" + packageMetadata.getVersion())); pkgToReturn.setMetadata(packageMetadata); return pkgToReturn; } finally { if (tmpDirPath != null && !FileSystemUtils.deleteRecursively(tmpDirPath.toFile())) { logger.warn("Temporary directory can not be deleted: " + tmpDirPath); } } }