Add a tag(s) property on FileDescriptor

Hi

We have a process uploading files in storage coming from a legacy system. Ideally we would like to tag these files so they can be e.g filtered out in screens or processed by a batch dedicated to legacy files.

Of course we can use a pattern in name or extension (and we do it), but that would be more clean I think, while opening new possibilities.

Mike

Hi Mike,

You should be able to extend the FileDescriptor entity in your project. Didn’t you try this?

I admit not, but I’ll certainly do. Sometimes I forget how much this platform is extensible, which is nice. Thanks Konstantin.

EDIT : found out that cuba automatically instantiate extended class when using @Extends which is great, I still need to set new attributes though.

I have now an ExtFileDescriptor class and now looking for a way to instantiate it instead of FileDescriptor class while uploading. How would you recommend to do that ?
After using REST api to upload I thought about making additional REST calls to get the entity, set new attributes and post it back, but that will not work as this is still the FileDescriptor and not the Ext one.
What about replacing the controller com.haulmont.restapi.FileUploadController by a subclass that would instantiate ExtFileDescriptor instead of FileDescriptor ? If this is the recommended way how can I unmap the old controller and map mine.
Ideally, I’d love to be able to define additional attributes in the /files POST request that the controller would set.
For instance :

  • name = “myfile.csv”
  • class = “ExtFileDescriptor.class”
  • tags = "legacy"
    Then the controller would know which class to instantiate, and that it has to set the tags attribute. Also, that would work for any additional attribute added to a subclass of FileDescriptor.
    Alternatively, I could develop another entity with a 1-1 relationship to FileDescriptor holding new attributes and post it through rest.
    Interested by your views on the topic.
    Mike

When you “extend” an entity in CUBA terms (using the @Extends annotation that corresponds to the “Replace parent” checkbox in Studio), your new class is used everywhere in the system instead of original class. This includes REST API of course.
So the simplest way to update tags is to do it by separate request as you supposed in the beginning. In case of REST API it will be like this:

{
    "id": "a369bf06-2935-4b84-a4e7-b53d0f322d53",
    "name": "a369bf06-2935-4b84-a4e7-b53d0f322d53",
    "size": 2666
}
{
    "_entityName": "sample$TaggedFileDescriptor",
    "_instanceName": "a369bf06-2935-4b84-a4e7-b53d0f322d53 (Thu Aug 31 14:38:16 SAMT 2017)",
    "id": "a369bf06-2935-4b84-a4e7-b53d0f322d53",
    "extension": "",
    "version": 2,
    "size": 2666,
    "name": "a369bf06-2935-4b84-a4e7-b53d0f322d53",
    "createDate": "2017-08-31 14:38:16.754"
}
{
    "id": "a369bf06-2935-4b84-a4e7-b53d0f322d53",
	"tags": "foo bar"
}
  • Now if you read it again you will see the tags updated:
{
    "_entityName": "sample$TaggedFileDescriptor",
    "_instanceName": "a369bf06-2935-4b84-a4e7-b53d0f322d53 (Thu Aug 31 14:38:16 SAMT 2017)",
    "id": "a369bf06-2935-4b84-a4e7-b53d0f322d53",
    "extension": "",
    "version": 2,
    "tags": "foo bar",
    "size": 2666,
    "name": "a369bf06-2935-4b84-a4e7-b53d0f322d53",
    "createDate": "2017-08-31 14:38:16.754"
}

Great, thanks Konstantin.

Small idea : be able to define custom attributes of an ExtFileDescriptor at upload time, in the http entity.

Needing to make a second call can cause a synchronisation issue : we have several processes consuming files, if one process consumes file without tags and runs before the tag is set through the second call this is an issue.

Of course, we will ensure all processes consumes specific tags, but this could be handy to make everything in one call.

In the future we plan to add other attributes : origin, ip address of origin machine, etc.

We plan to refactor file uploading controller - we will extract the behavior into some separate bean. In your project you’ll be able to override the bean and process the request. The issue: https://youtrack.cuba-platform.com/issue/PL-9624

Thanks MAx for the heads-up, making all in one call is more transactional-ish.