private String getLastHistoryVersion() { if (lastHistoryVersion == null) { List<FileData> fileDatas = getHistoryFileDatas(); lastHistoryVersion = fileDatas.isEmpty() ? null : fileDatas.get(fileDatas.size() - 1).getVersion(); } return lastHistoryVersion; }
@Override public Object getRevision() { FileData fileData; try { fileData = check(MODIFICATION_FILE); return fileData == null ? null : fileData.getVersion(); } catch (Exception e) { log.warn(e.getMessage(), e); return null; } } }
@Override public boolean deleteHistory(FileData data) { return data.getVersion() == null && delete(data); }
public boolean isHistoric() { return getFileData().getVersion() != null; }
public AProject(Repository repository, FileData fileData) { super(null, repository, fileData.getName(), fileData.getVersion()); setFileData(fileData); }
public String getVersion() { String projectVersion = getProject().getFileData().getVersion(); return projectVersion == null ? "unversioned" : projectVersion; }
public String getVersion() { String projectVersion = getProject().getFileData().getVersion(); return projectVersion == null ? "unversioned" : projectVersion; }
/** * 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(); } }
@Override public void saveFileData(FileData fileData) { if (fileData.getVersion() == null || fileData.getAuthor() == null || fileData.getModifiedAt() == null) { // No need to save empty fileData return; } Properties properties = new Properties(); properties.setProperty(VERSION_PROPERTY, fileData.getVersion()); properties.setProperty(AUTHOR_PROPERTY, fileData.getAuthor()); properties.setProperty(MODIFIED_AT_PROPERTY, new SimpleDateFormat(DATE_FORMAT).format(fileData.getModifiedAt())); properties.setProperty(SIZE_PROPERTY, "" + fileData.getSize()); if (fileData.getComment() != null) { properties.setProperty(COMMENT_PROPERTY, fileData.getComment()); } FileOutputStream os = null; try { File file = propertiesEngine.createPropertiesFile(pathInProject, VERSION_FILE_NAME); os = new FileOutputStream(file); properties.store(os, "Project version"); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } finally { IOUtils.closeQuietly(os); } }
@Override public FileChange next() { FileData file = files.get(fileIndex++); String srcFileName = file.getName(); String fileTo = deploymentPath + srcFileName.substring(rulesPath.length()); FileItem fileItem; try { fileItem = designRepo.readHistory(file.getName(), file.getVersion()); IOUtils.closeQuietly(openedStream); openedStream = fileItem.getStream(); return new FileChange(fileTo, openedStream); } catch (Exception e) { log.error(e.getMessage(), e); return null; } }
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 void setFileData(FileData fileData) { super.setFileData(fileData); if (fileData != null) { setFolderPath(fileData.getName()); setHistoryVersion(fileData.getVersion()); } }
@Override public boolean deleteHistory(FileData data) { String name = data.getName(); String version = data.getVersion(); try { if (version == null) { deleteAllVersions(name); onModified(); return true; } else { s3.deleteVersion(bucketName, name, version); onModified(); return true; } } catch (SdkClientException e) { log.error(e.getMessage(), e); return false; } }
public static File export(WorkspaceUser user, AProject project) throws ProjectException { File zipFile = null; try { String zipComment = "Project '" + project.getName() + "' version " + project.getFileData().getVersion() + "\nExported by " + user.getUserName(); zipFile = File.createTempFile("export-", "-zip"); packIntoZip(zipFile, project, zipComment); return zipFile; } catch (ProjectException e) { FileUtils.deleteQuietly(zipFile); throw e; } catch (Exception e) { FileUtils.deleteQuietly(zipFile); throw new ProjectException("Failed to export project due I/O error!", e); } }
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; }
public InputStream getContent() throws ProjectException { try { if (isHistoric()) { return getRepository().readHistory(getFileData().getName(), getFileData().getVersion()).getStream(); } else { return getRepository().read(getFileData().getName()).getStream(); } } catch (IOException ex) { throw new ProjectException(ex.getMessage(), ex); } }
protected static String generateComments(UserWorkspaceProject userProject) { if (userProject.isLocalOnly()) { return "Local"; } if (userProject.isDeleted()) { return "Deleted"; } if (userProject.isOpenedForEditing()) { return null; } if (userProject.isOpened()) { String activeVersion = userProject.getFileData().getVersion(); if (activeVersion != null && userProject.isOpenedOtherVersion()) { return "Revision " + activeVersion; } } LockInfo lock = userProject.getLockInfo(); if (lock.isLocked()) { if (userProject.isLockedByMe(lock)) { return "Locked by you. Please close this project."; } else { return "Locked by " + lock.getLockedBy().getUserName(); } } return 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); } }
@Override public void save(CommonUser user) throws ProjectException { AProject designProject = new AProject(designRepository, designFolderName); AProject localProject = new AProject(localRepository, localFolderName); designProject.getFileData().setComment(getFileData().getComment()); designProject.update(localProject, user); String version = designProject.getFileData().getVersion(); setLastHistoryVersion(version); setHistoryVersion(version); if (!isRepositoryOnly()) { localRepository.getProjectState(localFolderName).setProjectVersion(null); } clearModifyStatus(); unlock(); refresh(); }
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); }