private boolean isRulesDeployed(String deploymentName) throws IOException { List<FileData> deployments = deployRepo.list(DeploymentUtils.DEPLOY_PATH + deploymentName + "/"); return !deployments.isEmpty(); }
public boolean hasDDProject(String name) { try { return getRepository().check(deploymentConfigurationLocation + name) != null; } catch (IOException ex) { return false; } }
private ZipInputStream getZipInputStream() throws IOException { FileItem fileItem = version == null ? delegate.read(zipPath) : delegate.readHistory(zipPath, version); return new ZipInputStream(fileItem.getStream()); }
List<FileData> existingProjects = deployRepo.list(deploymentPath + "/"); List<FileData> projectsToDelete = findProjectsToDelete(existingProjects, projectDescriptors); for (FileData fileData : projectsToDelete) { deployRepo.delete(fileData); String version = pd.getProjectVersion().getVersionName(); String projectName = pd.getProjectName(); FileItem srcPrj = designRepo.readHistory("DESIGN/rules/" + projectName, version); stream = srcPrj.getStream(); FileData dest = new FileData(); dest.setComment(srcPrj.getData().getComment()); dest.setSize(srcPrj.getData().getSize()); deployRepo.save(dest, stream); } finally { IOUtils.closeQuietly(stream);
FileData existing = getRepository().check(fileName); if (existing != null && existing.isDeleted()) { getRepository().deleteHistory(existing.getName(), existing.getVersion()); data.setAuthor(getUserName()); data.setSize(zipSize); FileData save = getRepository().save(data, zipFile); userWorkspace.getProject(name).unlock(); return Response.created(new URI(uri + "/" + StringTool.encodeURL(save.getVersion()))).build();
if (projectFrom.isHistoric()) { fileItem = projectFrom.getRepository() .readHistory(projectFrom.getFolderPath(), projectFrom.getFileData().getVersion()); } else { fileItem = projectFrom.getRepository().read(projectFrom.getFolderPath()); setFileData(repositoryTo.save(fileData, stream)); } catch (IOException ex) { throw new ProjectException("Can't update: " + ex.getMessage(), ex);
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); } }
public AProjectResource addResource(String name, InputStream content) throws ProjectException { try { getProject().lock(); FileData fileData = new FileData(); String fullName = folderPath + "/" + name; fileData.setName(fullName); Repository repository = getRepository(); if (repository.check(fullName) != null) { throw new ProjectException(String.format("The file '%s' exists in the folder.", name), new IOException()); } fileData = repository.save(fileData, content); AProjectResource createdResource = new AProjectResource(getProject(), repository, fileData); getArtefactsInternal().put(name, createdResource); return createdResource; } catch (IOException ex) { throw new ProjectException("Cannot add a resource", ex); } finally { IOUtils.closeQuietly(content); } }
public void undelete(CommonUser user) throws ProjectException { try { if (!isDeleted()) { throw new ProjectException("Cannot undelete non-marked project ''{0}''!", null, getName()); } Repository repository = getRepository(); FileData fileData = repository.check(getFileData().getName()); if (fileData != null && fileData.isDeleted()) { FileData data = new FileData(); data.setName(fileData.getName()); data.setVersion(fileData.getVersion()); data.setAuthor(user.getUserName()); data.setComment(Comments.restoreProject(getName())); repository.deleteHistory(data); FileData actual = repository.check(fileData.getName()); setFileData(actual); String version = actual.getVersion(); setLastHistoryVersion(version); setHistoryVersion(version); } } catch (IOException ex) { throw new ProjectException("Cannot undelete a project", ex); } }
/** * {@inheritDoc} */ public void setListener(final DataSourceListener dataSourceListener) { if (dataSourceListener == null) { repository.setListener(null); } else { repository.setListener(new Listener() { @Override public void onChange() { dataSourceListener.onDeploymentAdded(); } }); } }
/** * Returns a zipped project. * * @param name a project name * @param version a project version * @return a zipped project */ @GET @Path("project/{name}/{version}") @Produces("application/zip") public Response getProject(@PathParam("name") String name, @PathParam("version") String version) throws WorkspaceException { try { if (!isGranted(Privileges.VIEW_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have VIEW privilege").build(); } FileItem fileItem = getRepository().readHistory(getFileName(name), version); if (fileItem == null) { throw new FileNotFoundException("File '" + name + "' not found."); } String zipFileName = String.format("%s-%s.zip", name, version); return Response.ok(fileItem.getStream()) .header("Content-Disposition", "attachment;filename=\"" + zipFileName + "\"") .build(); } catch (IOException ex) { return Response.status(Status.NOT_FOUND).entity(ex.getMessage()).build(); } }
public void delete() throws ProjectException { FileData fileData = getFileData(); if (!getRepository().delete(fileData)) { throw new ProjectException("Resource is absent or can't be deleted"); } }
@Override public FileData getFileData() { FileData fileData = super.getFileData(); if (fileData == null) { Repository repository = getRepository(); if (isRepositoryVersionable()) { // In the case of FolderRepository we can retrieve FileData using check()/checkHistory() for a folder. try { if (!isHistoric() || isLastVersion()) { fileData = repository.check(getFolderPath()); if (fileData == null) { fileData = new LazyFileData(getFolderPath(), getHistoryVersion(), this); } } else { fileData = repository.checkHistory(getFolderPath(), getHistoryVersion()); } } catch (IOException ex) { throw new IllegalStateException(ex); } } else { fileData = new LazyFileData(getFolderPath(), getHistoryVersion(), this); } setFileData(fileData); } return fileData; }
public void erase(CommonUser user) throws ProjectException { FileData fileData = getFileData(); FileData data = new FileData(); data.setName(fileData.getName()); data.setVersion(null); data.setAuthor(user.getUserName()); data.setComment(Comments.eraseProject(getName())); if (!getRepository().deleteHistory(data)) { throw new ProjectException("Can't erase project because it is absent or can't be deleted"); } }
/** * Returns the latest zipped project. * * @param name a project name * @return a zipped project */ @GET @Path("project/{name}") @Produces("application/zip") public Response getLastProject(@PathParam("name") String name) throws WorkspaceException { try { if (!isGranted(Privileges.VIEW_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have VIEW privilege").build(); } FileItem fileItem = getRepository().read(getFileName(name)); if (fileItem == null) { throw new FileNotFoundException("File '" + name + "' not found."); } String zipFileName = String.format("%s-%s.zip", name, fileItem.getData().getVersion()); return Response.ok(fileItem.getStream()) .header("Content-Disposition", "attachment;filename=\"" + zipFileName + "\"") .build(); } catch (IOException ex) { return Response.status(Status.NOT_FOUND).entity(ex.getMessage()).build(); } }
List<FileData> existingProjects = deployRepo.list(deploymentPath); List<FileData> projectsToDelete = findProjectsToDelete(existingProjects, projectDescriptors); for (FileData fileData : projectsToDelete) { fileData.setAuthor(userName); deployRepo.delete(fileData); archiveAndSave((FolderRepository) designRepo, projectPath, version, deployRepo, dest); } else { FileItem srcPrj = designRepo.readHistory(rulesPath + projectName, version); stream = srcPrj.getStream(); dest.setSize(srcPrj.getData().getSize()); deployRepo.save(dest, stream);
FileData existing = repository.check(fileName); if (existing != null && existing.isDeleted()) { delData.setAuthor(existing.getAuthor()); delData.setComment(Comments.restoreProject(name)); repository.deleteHistory(delData); save = repository.save(data, zipFile);
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); } }
/** * {@inheritDoc} */ public void setListener(final DataSourceListener dataSourceListener) { if (dataSourceListener == null) { repository.setListener(null); } else { repository.setListener(new Listener() { @Override public void onChange() { dataSourceListener.onDeploymentAdded(); } }); } }