private void doDeploy(String name, Integer contentSize, InputStream inputStream) throws IOException { FileData dest = new FileData(); dest.setName(name); dest.setAuthor(DEFAULT_AUTHOR_NAME); if (deployRepo instanceof FolderRepository) { ((FolderRepository) deployRepo).save(dest, new FileChangesFromZip(new ZipInputStream(inputStream), name)); } else { dest.setSize(contentSize); deployRepo.save(dest, inputStream); } }
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 boolean isFolderStructure(String deploymentFolderPath) { boolean folderStructure; try { if (repository instanceof FolderRepository) { folderStructure = !((FolderRepository) repository).listFolders(deploymentFolderPath + "/").isEmpty(); } else { folderStructure = false; } } catch (IOException e) { throw RuntimeExceptionWrapper.wrap(e); } return folderStructure; } }
fileDataList = repository.listFolders(folderPath); } else { fileDataList = repository.list(folderPath);
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; }
((FolderRepository) deployRepo).save(dest, new FileChangesFromZip((ZipInputStream) stream, target)); } else { stream = new FileInputStream(zipFile);
public List<ADeploymentProject> getDDProjects() throws RepositoryException { LinkedList<ADeploymentProject> result = new LinkedList<>(); Collection<FileData> fileDatas; try { String path = deploymentConfigurationLocation; if (repository instanceof FolderRepository) { fileDatas = ((FolderRepository) repository).listFolders(path); } else { fileDatas = repository.list(path); } } catch (IOException e) { throw new RepositoryException("Cannot read the deploy repository", e); } for (FileData fileData : fileDatas) { result.add(new ADeploymentProject(getRepository(), fileData)); } return result; }
setFileData(((FolderRepository) getRepository()).save(fileData, Collections.singletonList(change))); } catch (IOException e) { throw new ProjectException(e.getMessage(), e);
public Collection<AProject> getProjects() { List<AProject> result = new LinkedList<>(); Collection<FileData> fileDatas; Repository repository = getRepository(); try { String path = rulesLocation; if (repository instanceof FolderRepository) { fileDatas = ((FolderRepository) repository).listFolders(path); } else { fileDatas = repository.list(path); } } catch (IOException ex) { throw RuntimeExceptionWrapper.wrap(ex); } synchronized (projects) { projects.clear(); projectsVersions.clear(); for (FileData fileData : fileDatas) { AProject project = new AProject(repository, fileData); // get from the repository result.add(project); projects.put(project.getName(), project); } } return result; }
@Override public void update(AProjectArtefact newFolder, CommonUser user) throws ProjectException { super.update(newFolder, user); if (this.isFolder()) { AProjectFolder from = (AProjectFolder) newFolder; List<FileChange> changes = new ArrayList<>(); try { findChanges(from, changes); FileData fileData = getFileData(); fileData.setAuthor(user == null ? null : user.getUserName()); ((FolderRepository) getRepository()).save(fileData, changes); } catch (IOException e) { throw new ProjectException("Can't update: " + e.getMessage(), e); } finally { for (FileChange change : changes) { IOUtils.closeQuietly(change.getStream()); } } } }
if (repository instanceof FolderRepository) { fileDatas = ((FolderRepository) repository).listFolders(deployPath); } else { try { if (repository instanceof FolderRepository) { folderStructure = !((FolderRepository) repository).listFolders(folderPath + "/").isEmpty(); } else { folderStructure = false;
if (repository instanceof FolderRepository) { try (ZipInputStream stream = new ZipInputStream(zipFile)) { save = ((FolderRepository) repository).save(data, new FileChangesFromZip(stream, fileName));
if (repository instanceof FolderRepository) { fileDatas = ((FolderRepository) repository).listFolders(deployPath); } else {
private void unpack(AProject projectFrom, Repository repositoryTo, String folderTo, CommonUser user) throws ProjectException { ZipInputStream stream = null; try { FileItem fileItem; if (projectFrom.isHistoric()) { fileItem = projectFrom.getRepository() .readHistory(projectFrom.getFolderPath(), projectFrom.getFileData().getVersion()); } else { fileItem = projectFrom.getRepository().read(projectFrom.getFolderPath()); } if (fileItem == null) { return; } stream = new ZipInputStream(fileItem.getStream()); FileData fileData = getFileData(); fileData.setAuthor(user == null ? null : user.getUserName()); ((FolderRepository) repositoryTo).save(fileData, new FileChangesFromZip(stream, folderTo)); } catch (IOException e) { throw new ProjectException("Can't update: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } }
deploymentData.setAuthor(userName); deploymentData.setComment(project.getFileData().getComment()); folderRepo.save(deploymentData, changes);