private void archiveAndSave(FolderRepository designRepo, String projectPath, String version, Repository deployRepo, FileData dest) throws ProjectException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zipOutputStream = null; try { zipOutputStream = new ZipOutputStream(out); List<FileData> files = designRepo.listFiles(projectPath, version); for (FileData file : files) { String internalPath = file.getName().substring(projectPath.length()); zipOutputStream.putNextEntry(new ZipEntry(internalPath)); FileItem fileItem = designRepo.readHistory(file.getName(), file.getVersion()); try (InputStream content = fileItem.getStream()) { IOUtils.copy(content, zipOutputStream); } zipOutputStream.closeEntry(); } zipOutputStream.finish(); dest.setSize(out.size()); deployRepo.save(dest, new ByteArrayInputStream(out.toByteArray())); } catch (IOException e) { throw new ProjectException(e.getMessage(), e); } finally { IOUtils.closeQuietly(zipOutputStream); } }
private Iterator<FileChange> getProjectIterator(String projectName, String version) { try { if (designRepo instanceof FolderRepository) { // Project in design repository is stored as a folder String srcProjectPath = rulesPath + projectName + "/"; return new FolderIterator(((FolderRepository) designRepo).listFiles(srcProjectPath, version)); } else { // Project in design repository is stored as a zip file FileItem srcPrj = designRepo.readHistory(rulesPath + projectName, version); if (srcPrj == null) { throw new FileNotFoundException("File '" + rulesPath + projectName + "' for version " + version + " is not found"); } IOUtils.closeQuietly(openedStream); ZipInputStream stream = new ZipInputStream(srcPrj.getStream()); openedStream = stream; return new FileChangesFromZip(stream, deploymentPath + projectName).iterator(); } } catch (Exception e) { log.error(e.getMessage(), e); return null; } }
protected Map<String, AProjectArtefact> createInternalArtefacts() { HashMap<String, AProjectArtefact> internalArtefacts = new HashMap<>(); Collection<FileData> fileDatas; try { String folderPath = getFolderPath(); if (!folderPath.isEmpty() && !folderPath.endsWith("/")) { folderPath += "/"; } if (isHistoric()) { if (getRepository() instanceof FolderRepository) { fileDatas = ((FolderRepository) getRepository()).listFiles(folderPath, getFileData().getVersion()); } else { throw new UnsupportedOperationException("Can't get internal artifacts for historic project version"); } } else { fileDatas = getRepository().list(folderPath); } } catch (IOException ex) { throw RuntimeExceptionWrapper.wrap(ex); } for (FileData fileData : fileDatas) { if (!fileData.getName().equals(folderPath) && !fileData.isDeleted()) { String artefactName = fileData.getName().substring(folderPath.length() + 1); internalArtefacts.put(artefactName, new AProjectResource(getProject(), getRepository(), fileData)); } } return internalArtefacts; }