Skip to content

dynamiatools/module-entityfiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central Java Version Required Maven Build Release and Deploy

EntityFiles Module

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

Modules

  • Core: Domain and API
  • UI: Actions and views for user interface integration.
  • S3: Support to store files in Amazon S3 Bucket

Installation

Maven

<dependencies>
    <dependency>
        <groupId>tools.dynamia.modules</groupId>
        <artifactId>tools.dynamia.modules.entityfiles</artifactId>
        <version>7.1.0</version>
    </dependency>

    <dependency>
        <groupId>tools.dynamia.modules</groupId>
        <artifactId>tools.dynamia.modules.entityfiles.ui</artifactId>
        <version>7.1.0</version>
    </dependency>
</dependencies>

AWS S3 Support

    <dependency>
        <groupId>tools.dynamia.modules</groupId>
        <artifactId>tools.dynamia.modules.entityfiles.s3</artifactId>
        <version>7.1.0</version>
    </dependency>

Gradle

compile 'tools.dynamia.modules:tools.dynamia.modules.entityfiles:7.1.0'
compile 'tools.dynamia.modules:tools.dynamia.modules.entityfiles.ui:7.1.0'
compile 'tools.dynamia.modules:tools.dynamia.modules.entityfiles.s3:7.1.0'

Usage

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);

EntityFileService

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);
    }
}

EntityFileStorage

Internally EntityFileService use an instance of tools.dynamia.modules.entityfile.EntityFileStorage to process and upload files.

  • LocalEntityFileStorage is the default implementation and store files in local file system
  • S3EntityFileStorage in module S3 can upload files to AWS S3 buckets

License

EntityFiles is available under Apache 2 License