This DynamiaTools extension allow attaching files to database entities. Files are saved to locale disk or using AWS S3 and file
metadata are store in the database in table mod_entity_files using JPA entity EntityFile
- Core: Domain and API
- UI: Actions and views for user interface integration.
- S3: Support to store files in Amazon S3 Bucket
<dependencies>
<dependency>
<groupId>tools.dynamia.modules</groupId>
<artifactId>tools.dynamia.modules.entityfiles</artifactId>
<version>7.4.0</version>
</dependency>
<dependency>
<groupId>tools.dynamia.modules</groupId>
<artifactId>tools.dynamia.modules.entityfiles.ui</artifactId>
<version>7.4.0</version>
</dependency>
</dependencies> <dependency>
<groupId>tools.dynamia.modules</groupId>
<artifactId>tools.dynamia.modules.entityfiles.s3</artifactId>
<version>7.4.0</version>
</dependency>compile 'tools.dynamia.modules:tools.dynamia.modules.entityfiles:7.4.0'
compile 'tools.dynamia.modules:tools.dynamia.modules.entityfiles.ui:7.4.0'
compile 'tools.dynamia.modules:tools.dynamia.modules.entityfiles.s3:7.4.0'Add a field of type tools.dynamia.modules.entityfile.domain.EntityFile in your JPA entity with association @OneToOne
import tools.dynamia.modules.entityfile.domain.EntityFile;
@Entity
public class Person implements AccountAware {
@OneToOne
private EntityFile photo;
@OneToOne
private EntityFile cover;
// other fields
//getter and setters
}Beside entities, the UI module install a new Action called FileAction to manage files attached to entities. This
action is showed in CrudState.READ (tables or tree) of CrudView.
The same functionality of FileAction can be using anywhere in your user interface code invoking
EntityFileUtils.showFileExplorer(entity);tools.dynamia.modules.entityfile.service.EntityFileService
This service is the central core of this module, it helps you to attach any kind of file to any JPA entity.
Examples:
//somewhere in your code
@Component
class SomeSpringCompoonent{
@Autowired
private EntityFileService service;
public void attachPhoto(File file, Person entity) {
var fileInfo = new UploadFileInfo(file);
var photo = entityService.createEntityFile(fileInfo, entity);
entity.setPhoto(photo);
}
}Internally EntityFileService use an instance of tools.dynamia.modules.entityfile.EntityFileStorage to process and upload
files.
LocalEntityFileStorageis the default implementation and store files in local file systemS3EntityFileStoragein module S3 can upload files to AWS S3 buckets
EntityFiles is available under Apache 2 License