v3.0.0
Changelog
Plume File v3 introduces breaking changes that require manually updating the codebase and the database of an existing project.
Plume File v3 uses what was introduced in the v2.0.0-beta5 version, which is the file name generation.
This technique prevents :
- Database ID auto-increment generation to reference a file, fixing a security issue
- Files to be override on the system disk if they have the same name
Migrate to V3 involves:
- Identifying the migration :
- Which Plume File Version is currently running
- Where does the files are currently stored (if migrating from >= v2)
- Updating the library version and import the right modules
- Running the SQL migration(s) script(s)
- SQL migration guide here
- Updating the code base
Upgrade instructions from v1.0.0-rc1 ~ v1.0.0-rc9
The first version of Plume File:
- Only stored files on database
- There were no unique names stored in the metadata for files
- The file download was included in the library
Modules needed :
- plume-file-core module
- plume-file-metadata-database module
- plume-file-storage-database module
- plume-file-web-download-jersey module (Optional, only if you use the download part)
Upgrade instructions from v2.0.0-alpha1 ~ v2.0.0-beta5
These version of Plume File:
- Stored files either on database or on the system disk
- There were unique names stored in the metadata only for the v2.0.0-beta5 version
- The file download was included in the library
If files were stored on database :
- plume-file-core module
- plume-file-metadata-database module
- plume-file-storage-database module
- plume-file-web-download-jersey module (Optional, only if the download part was used)
If your files were stored on the system disk :
- plume-file-core module
- plume-file-metadata-database module
- plume-file-storage-system module
- plume-file-web-download-jersey module (Optional, only if the download part was used)
Warning : The SQL script migration is different on the v2.0.0-beta5 as it does not include file unique name generation
If the plm_file.id
column was referenced in multiple other tables
This behavior is not supported anymore for maintenance reasons.
So in that case, these scripts might be useful to duplicated the files (this must be run after the migration to Plume File V3 has been completed):
public List<FileMetadataQuerydsl> fetchFilesByFileType(String fileType, EntityPath<?> fileEntity, StringPath column) {
return projectTransactionManager.executeAndReturn(connection -> projectTransactionManager
.selectQuery(connection)
.select(QFileMetadataQuerydsl.fileMetadata)
.from(QFileMetadataQuerydsl.fileMetadata)
.where(QFileMetadataQuerydsl.fileMetadata.fileType.eq(fileType))
.where(QFileMetadataQuerydsl.fileMetadata.uniqueName.in(
SQLExpressions
.select(column)
.from(fileEntity)
.where(column.isNotNull())
))
.fetch());
}
public void updateFileReference(RelationalPath<?> fileEntity, StringPath column, String oldUid, String newUid) {
projectTransactionManager.execute(connection -> projectTransactionManager
.update(fileEntity, connection)
.set(column, newUid)
.where(column.eq(oldUid))
.execute()
);
}
public void migrateFilesToPlm3() {
logger.info("Starting file migration from Plume-file 2.0 to 3.0");
for (FileTypeDatabase fileType : fileTypesProvider.fileTypesAvailable()) {
for (FileMetadataQuerydsl file : fileDaoDisk.fetchFilesByFileType(fileType.name(), fileType.getFileEntity(), fileType.getJoinColumn())) {
try {
// The original name is used to retrieve the data, because it was used by PLM-File 2.0 to save the file.
InputStream fileData = this.fileService.fetchData(file.getFileOriginalName()).orElse(null);
if (fileData == null) {
logger.warn("Failed to read file {}, skipping : {}", file.getUniqueName(), file);
continue;
}
String newFileUniqueName = this.fileService.add(fileType, fileData, file.getFileOriginalName());
this.fileDaoDisk.updateFileReference((RelationalPath<?>) fileType.getFileEntity(), fileType.getJoinColumn(), file.getUniqueName(), newFileUniqueName);
} catch (UncheckedIOException e) {
logger.warn("Failed to read file {}, skipping : {}", file.getUniqueName(), file, e);
}
}
}
}
}