Jmix version: 1.1.1
Jmix Studio plugin version: 1.1.4-213
IntelliJ IDEA 2021.3 CE - Build #IC-213.5744.223, built on November 27, 2021Operating System: macOS 12.0.1 (21A559)
File System: Case-Sensitive Journaled HFS+ (APFS)
Datebase: PostgreSQL 13
For your information, I performed my first CUBA-to-Jmix migration last weekend and am attempting to do all of the necessary manually refactoring in the meantime. I have 19 months of CUBA experience and about 19 hours of Jmix experience.
I am missing a file “size” attribute in Jmix, respectively in the FileRef class and need help. Here is my situation…
My application uses a membership model with different membership types: TRIAL, BASIC, ENANCED, ULTIMATE.
Each user has one instance of a Membership entity that stores their membership type and its restrictions. The restrictions for each type are defined in configuration attributes and copied to the Membership instance when the user choses the membership type that he wants or when he upgrades it at a later time.
In the Membership instance the application keeps track of the counts and limits of various profile instances that the user can create; let’s call them Profile-One, Profile-Two.
Therefore, in the Membership instance there are for example the following attributes:
and since Profile-One has an image (.jpg) attribute and Profile-Two contains an audio file (.mp3) attribute, the Membership instance has the following further attributes:
Easch Membership type provides for a different/larger amount of available storage.
In CUBA I use a TransactionalEventListener for each entity to keep track of the number of Profile-One and Profile-Two instances that are created and deleted and also how much storage is used by them or set free if they are deleted. Within the TransactionalEventListener the Membership attributes are updated and saved and in the UI screen controllers a check is done against the Membership attributes to either allow or prohibit the creation of a new instance of Profile-One or Profile-Two by the user.
In the screen controllers I also keep track of the size of the image and audio files that are uploaded, cleared or replaced before saving the entity. I use the Membership information in the screen controllers to set the maximum size of the file that can be uploaded and track this locally if someone clears a file, loads another one, clears it and so on and so on.
In CUBA counting the instances is not a problem and calculating the used storage is done using the FileDescriptor entity as an Association in each of Profile-One or Profile-Two instances and I can use fileDescriptor.getSize() to return the file’s size and use this information to calculate my used and remaining storage.
However, in Jmix the FileRef class, which to my understanding is the FileDescriptor replacement, does not have a size attribute and there is no reference to this in the documentation.
In “jmix-localfs/localfs/src/main/java/io/jmix/localfs/LocalFileStorage.java” I see that the function “public long saveStream(FileRef fileRef, InputStream inputStream)” returns “size” but this “size” information is not used in function “public FileRef saveStream(String fileName, InputStream inputStream)” This “size” information could be added to the fileRef instance in the function if the attribute actually existed.
Is there some specific reason why there is no “size” attribute in the FileRef class? Do you plan on adding it? When? If not, what would you recommend that I do to elegantly solve my problem?
Thanks in advance for your feedback.