@Override public String getAuthor() { verifyLoaded(); return super.getAuthor(); }
@Override public String getAuthor() { verifyInitialized(); return super.getAuthor(); }
public String getModifiedBy() { return getProject().getFileData().getAuthor(); }
public String getModifiedBy() { return getProject().getFileData().getAuthor(); }
@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 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); } }
@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); } }
@Override public FileData copyHistory(String srcName, FileData destData, String version) throws IOException { if (version == null) { return copy(srcName, destData); } Connection connection = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement(settings.copyHistory); statement.setString(1, destData.getName()); statement.setString(2, destData.getAuthor()); statement.setString(3, destData.getComment()); statement.setLong(4, Long.valueOf(version)); statement.setString(5, srcName); statement.executeUpdate(); invokeListener(); return destData; } catch (SQLException e) { throw new IOException(e); } finally { safeClose(statement); safeClose(connection); } }
@Override public FileData copyHistory(String srcName, FileData destData, String version) throws IOException { if (version == null) { return copy(srcName, destData); } Connection connection = null; PreparedStatement statement = null; try { connection = getConnection(); statement = connection.prepareStatement(settings.copyHistory); statement.setString(1, destData.getName()); statement.setString(2, destData.getAuthor()); statement.setString(3, destData.getComment()); statement.setLong(4, Long.valueOf(version)); statement.setString(5, srcName); statement.executeUpdate(); invokeListener(); return destData; } catch (SQLException e) { throw new IOException(e); } finally { safeClose(statement); safeClose(connection); } }
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); } }
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); } }
@Override public FileData copy(String srcName, FileData destData) throws IOException { Lock writeLock = repositoryLock.writeLock(); try { writeLock.lock(); File src = new File(localRepositoryPath, srcName); File dest = new File(localRepositoryPath, destData.getName()); IOUtils.copyAndClose(new FileInputStream(src), new FileOutputStream(dest)); git.add().addFilepattern(destData.getName()).call(); RevCommit commit = git.commit() .setMessage(StringUtils.trimToEmpty(destData.getComment())) .setCommitter(destData.getAuthor(), "") .call(); addTagToCommit(commit); push(); } catch (Exception e) { reset(); throw new IOException(e); } finally { writeLock.unlock(); } return check(destData.getName()); }
@Override public boolean deleteHistory(FileData data) { String name = data.getName(); String version = data.getVersion(); try { ArtefactAPI artefact = getArtefact(name); if (artefact == null) { return false; } if (version == null) { CommonUser user = data.getAuthor() == null ? getUser() : new CommonUserImpl(data.getAuthor()); artefact.delete(user); return true; } else { if (!artefact.hasProperty(ArtefactProperties.PROP_PRJ_MARKED_4_DELETION)) { throw new ProjectException("Project ''{0}'' isn't marked for deletion. The method deleteHistory() in JCR Repository is supported only for undelete and erase.", null, name); } artefact.removeProperty(ArtefactProperties.PROP_PRJ_MARKED_4_DELETION); return true; } } catch (CommonException e) { log.error(e.getMessage(), e); return false; } }
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; }
@Override public FileData save(FileData data, InputStream stream) throws IOException { Lock writeLock = repositoryLock.writeLock(); try { writeLock.lock(); String fileInRepository = data.getName(); File file = new File(localRepositoryPath, fileInRepository); createParent(file); IOUtils.copyAndClose(stream, new FileOutputStream(file)); git.add().addFilepattern(fileInRepository).call(); // TODO: Add possibility to set committer email RevCommit commit = git.commit() .setMessage(StringUtils.trimToEmpty(data.getComment())) .setCommitter(data.getAuthor(), "") .setOnly(fileInRepository) .call(); addTagToCommit(commit); push(); } catch (Exception e) { reset(); throw new IOException(e); } finally { writeLock.unlock(); } return check(data.getName()); }
@Override public FileData rename(String srcName, FileData destData) throws IOException { Lock writeLock = repositoryLock.writeLock(); try { writeLock.lock(); File src = new File(localRepositoryPath, srcName); File dest = new File(localRepositoryPath, destData.getName()); FileUtils.move(src, dest); git.rm().addFilepattern(srcName).call(); git.add().addFilepattern(destData.getName()).call(); RevCommit commit = git.commit() .setMessage(StringUtils.trimToEmpty(destData.getComment())) .setCommitter(destData.getAuthor(), "") .setOnly(srcName) .setOnly(destData.getName()) .call(); addTagToCommit(commit); push(); } catch (Exception e) { reset(); throw new IOException(e); } finally { writeLock.unlock(); } return check(destData.getName()); }
@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); } }
@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()); } } }
@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()); } } }