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"); } }
localFileData != null ? localFileData : designFileData); this.localRepository = localRepository; this.localFolderName = localFileData == null ? null : localFileData.getName(); this.designRepository = designRepository; this.designFolderName = designFileData == null ? null : designFileData.getName(); this.lockEngine = lockEngine; String localVersion = localFileData.getVersion(); if (localVersion == null || designFileData.getVersion().equals(localVersion)) { fullLocalFileData = new FileData(); fullLocalFileData.setName(localFileData.getName()); fullLocalFileData.setVersion(designFileData.getVersion()); fullLocalFileData.setSize(designFileData.getSize()); fullLocalFileData.setAuthor(designFileData.getAuthor()); fullLocalFileData.setModifiedAt(designFileData.getModifiedAt()); fullLocalFileData.setComment(designFileData.getComment()); fullLocalFileData.setDeleted(designFileData.isDeleted()); setFileData(fullLocalFileData); } else { if (localFileData.getAuthor() == null || localFileData.getModifiedAt() == null) { setLastHistoryVersion(designFileData.getVersion());
private FileData createFileData(ResultSet rs) throws SQLException { FileData fileData = new FileData(); fileData.setName(rs.getString("file_name")); fileData.setSize(rs.getLong("file_size")); fileData.setAuthor(rs.getString("author")); fileData.setComment(rs.getString("file_comment")); fileData.setModifiedAt(rs.getTimestamp("modified_at")); fileData.setVersion(rs.getString("id")); fileData.setDeleted(rs.getBoolean("deleted")); return fileData; }
@Override public FileData rename(String srcName, FileData destData) throws IOException { copy(srcName, destData); FileData srcData = new FileData(); srcData.setName(srcName); srcData.setVersion(null); srcData.setAuthor(destData.getAuthor()); srcData.setComment(destData.getComment()); deleteHistory(srcData); onModified(); return check(destData.getName()); }
@Override public FileData copyHistory(String srcName, FileData destData, String version) throws IOException { FileItem fileItem = null; try { fileItem = readHistory(srcName, version); FileData copy = new FileData(); copy.setName(destData.getName()); copy.setComment(destData.getComment()); copy.setAuthor(destData.getAuthor()); copy.setSize(fileItem.getData().getSize()); return save(copy, fileItem.getStream()); } finally { if (fileItem != null) { IOUtils.closeQuietly(fileItem.getStream()); } } }
private void verifyInitialized() { if (project != null) { List<FileData> fileDatas = project.getHistoryFileDatas(); if (!fileDatas.isEmpty()) { FileData repoData = null; String version = getVersion(); if (version == null) { repoData = fileDatas.get(fileDatas.size() - 1); } else { for (FileData data : fileDatas) { if (data.getVersion().equals(version)) { repoData = data; break; } } } if (repoData != null) { super.setAuthor(repoData.getAuthor()); super.setModifiedAt(repoData.getModifiedAt()); super.setComment(repoData.getComment()); super.setSize(repoData.getSize()); super.setDeleted(repoData.isDeleted()); } } project = null; } } }
private FileData createFileData(ZipEntry entry) { FileData fileData = new FileData(); fileData.setName(zipPath + "/" + entry.getName()); fileData.setSize(entry.getSize()); fileData.setModifiedAt(new Date(entry.getTime())); fileData.setComment(entry.getComment()); return fileData; } }
@Override public FileData copy(String srcName, FileData destData) throws IOException { Connection connection = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement(settings.copyFile); statement.setString(1, destData.getName()); statement.setString(2, destData.getAuthor()); statement.setString(3, destData.getComment()); statement.setString(4, srcName); statement.executeUpdate(); invokeListener(); return destData; } catch (SQLException e) { throw new IOException(e); } finally { safeClose(statement); safeClose(connection); } }
FileItem srcPrj = designRepo.readHistory("DESIGN/rules/" + projectName, version); stream = srcPrj.getStream(); FileData dest = new FileData(); dest.setName(deploymentPath + "/" + projectName); dest.setAuthor(userName); dest.setComment(srcPrj.getData().getComment()); dest.setSize(srcPrj.getData().getSize()); deployRepo.save(dest, stream); } finally {
private FileData createFileData(S3VersionSummary latest) { FileData data = latest.isDeleteMarker() ? new FileData() : new LazyFileData(s3, bucketName); data.setName(latest.getKey()); data.setSize(latest.getSize()); data.setModifiedAt(latest.getLastModified()); data.setVersion(latest.getVersionId()); data.setDeleted(latest.isDeleteMarker()); return data; }
protected ProjectVersion createProjectVersion(FileData fileData) { if (fileData == null) { return new RepositoryProjectVersionImpl("0", null); } RepositoryVersionInfoImpl rvii = new RepositoryVersionInfoImpl(fileData.getModifiedAt(), fileData.getAuthor()); String version = fileData.getVersion(); RepositoryProjectVersionImpl projectVersion = new RepositoryProjectVersionImpl(version == null ? "0" : version, rvii); projectVersion.setVersionComment(fileData.getComment()); return projectVersion; }
private FileData insertFile(FileData data, InputStream stream) throws IOException { Connection connection = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement(settings.insertFile); statement.setString(1, data.getName()); statement.setString(2, data.getAuthor()); statement.setString(3, data.getComment()); if (stream != null) { statement.setBinaryStream(4, stream); } else { // Workaround for PostreSQL statement.setBinaryStream(4, null, 0); } statement.executeUpdate(); data.setVersion(null); invokeListener(); return data; } catch (SQLException e) { throw new IOException(e); } finally { safeClose(statement); safeClose(connection); } }
public AProject(Repository repository, FileData fileData) { super(null, repository, fileData.getName(), fileData.getVersion()); setFileData(fileData); }
@Override public boolean delete(FileData data) { File file = new File(root, data.getName()); boolean deleted = file.delete(); // Delete empty parent folders while (!(file = file.getParentFile()).equals(root) && file.delete()); return deleted; }
List<FileData> fileData = listFiles(srcName + "/", version); for (FileData data : fileData) { String fileFrom = data.getName(); FileItem fileItem = readHistory(fileFrom, data.getVersion()); String fileTo = destData.getName() + fileFrom.substring(srcName.length()); files.add(new FileChange(fileTo, fileItem.getStream())); fileItem = readHistory(srcName, version); destData.setSize(fileItem.getData().getSize());
@Override public FileData save(FileData data, InputStream stream) throws IOException { try { ObjectMetadata metaData = new ObjectMetadata(); metaData.setContentType("application/zip"); if (data.getSize() != FileData.UNDEFINED_SIZE) { metaData.setContentLength(data.getSize()); } if (!StringUtils.isBlank(data.getAuthor())) { metaData.addUserMetadata(LazyFileData.METADATA_AUTHOR, LazyFileData.encode(data.getAuthor())); } if (!StringUtils.isBlank(data.getComment())) { metaData.addUserMetadata(LazyFileData.METADATA_COMMENT, LazyFileData.encode(data.getComment())); } s3.putObject(bucketName, data.getName(), stream, metaData); onModified(); return check(data.getName()); } catch (SdkClientException e) { throw new IOException(e); } }
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); } }
@Override public List<FileData> listFolders(String path) { LinkedList<FileData> files = new LinkedList<>(); File directory = new File(root, path); File[] found = directory.listFiles(); if (found != null) { for (File file : found) { if (file.isDirectory()) { try { if (rootPathLength == 0) { init(); } FileData data = new FileData(); String relativePath = file.getCanonicalPath().substring(rootPathLength); data.setName(relativePath.replace('\\', '/')); data.setModifiedAt(new Date(file.lastModified())); files.add(data); } catch (Exception ex) { log.warn("Folder cannot be resolved in the directory {}.", directory, ex); } } } } return files; }