@Override public boolean deleteHistory(String name, String version) { FileData fileData = new FileData(); fileData.setName(name); return version == null && delete(fileData); }
@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; }
private FileData getFileData(File file) throws IOException { if (!file.exists()) { throw new FileNotFoundException("File [" + file + "] does not exist."); } if (!file.isFile()) { throw new FileNotFoundException("File [" + file + "] is not a file."); } if (rootPathLength == 0) { init(); } FileData data = new FileData(); String canonicalPath = file.getCanonicalPath(); String relativePath = canonicalPath.substring(rootPathLength); String converted = relativePath.replace('\\', '/'); data.setName(converted); long timestamp = file.lastModified(); Date date = new Date(timestamp); data.setModifiedAt(date); long size = file.length(); data.setSize(size); return data; }
private FileData getFileData(File file) throws IOException { if (!file.exists()) { throw new FileNotFoundException("File [" + file + "] does not exist."); } if (rootPathLength == 0) { init(); } FileData data = new FileData(); String canonicalPath = file.getCanonicalPath(); String relativePath = canonicalPath.substring(rootPathLength); String converted = relativePath.replace('\\', '/'); data.setName(converted); long timestamp = file.lastModified(); Date date = new Date(timestamp); data.setModifiedAt(date); if (file.isFile()) { long size = file.length(); data.setSize(size); } return data; }
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; }
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; } }
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; }
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 doDeploy(String name, Integer contentSize, InputStream inputStream) throws IOException { FileData dest = new FileData(); dest.setName(name); dest.setAuthor(DEFAULT_AUTHOR_NAME); 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); } }
@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()); }
private FileData createFileData(String name, ArtefactAPI project) throws PropertyException { FileData fileData = new FileData(); fileData.setName(name); // It's impossible to calculate zip size if project contains artefacts if (((FolderAPI) project).getArtefacts().size() == 0) { fileData.setSize(0); } fileData.setDeleted(project.hasProperty(ArtefactProperties.PROP_PRJ_MARKED_4_DELETION)); if (project.hasProperty(ArtefactProperties.VERSION_COMMENT)) { Property property = project.getProperty(ArtefactProperties.VERSION_COMMENT); fileData.setComment(property.getString()); } ProjectVersion version = project.getVersion(); fileData.setAuthor(version.getVersionInfo().getCreatedBy()); fileData.setModifiedAt(version.getVersionInfo().getCreatedAt()); fileData.setVersion(String.valueOf(version.getRevision())); return fileData; }
private FileData createFileData(String name, ArtefactAPI project) throws PropertyException { FileData fileData = new FileData(); fileData.setName(name); // It's impossible to calculate zip size if project contains artefacts if (((FolderAPI) project).getArtefacts().size() == 0) { fileData.setSize(0); } fileData.setDeleted(project.hasProperty(ArtefactProperties.PROP_PRJ_MARKED_4_DELETION)); if (project.hasProperty(ArtefactProperties.VERSION_COMMENT)) { Property property = project.getProperty(ArtefactProperties.VERSION_COMMENT); fileData.setComment(property.getString()); } ProjectVersion version = project.getVersion(); fileData.setAuthor(version.getVersionInfo().getCreatedBy()); fileData.setModifiedAt(version.getVersionInfo().getCreatedAt()); fileData.setVersion(String.valueOf(version.getRevision())); 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"); } }
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; }
@Override public void erase(CommonUser user) throws ProjectException { try { if (designFolderName != null) { FileData data = new FileData(); data.setName(designFolderName); data.setVersion(null); data.setAuthor(getUser().getUserName()); data.setComment(Comments.eraseProject(getName())); if (!designRepository.deleteHistory(data)) { throw new ProjectException("Can't erase project because it is absent or can't be deleted"); } } else { deleteFromLocalRepository(); } } finally { refresh(); } }
@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()); } } }
@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()); } } }
public void delete(CommonUser user) throws ProjectException { if (isDeleted()) { throw new ProjectException("Project ''{0}'' is already marked for deletion!", null, getName()); } unlock(); close(user); FileData fileData = getFileData(); FileData data = new FileData(); data.setName(fileData.getName()); data.setVersion(fileData.getVersion()); data.setAuthor(user.getUserName()); data.setComment(Comments.archiveProject(getName())); if (!getRepository().delete(data)) { throw new ProjectException("Resource is absent or can't be deleted"); } setFileData(null); }
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); } }