molgenis / molgenis-emx2

MOLGENIS EMX2, the latest version of the MOLGENIS data platform.
GNU Lesser General Public License v3.0
14 stars 16 forks source link

File information is lost on cloning a record via TableExplorer #1623

Open MaxPostema opened 1 year ago

MaxPostema commented 1 year ago

What version of EMX2 are you using (see footer) Software version: 8.114.11-SNAPSHOT Database version: 5.

Describe the bug Cloning a record removed the uploaded file

To Reproduce Steps to reproduce the behavior:

  1. Log in
  2. Go to 'https://emx2.dev.molgenis.org/pet%20store/tables/#/User'
  3. Create a record with a 'picture'
  4. Clone (copy) the record
  5. Notice the the clone does not have the file information anymore

Expected behavior I Expect the clone to keep the uploaded file or to have a cloned file

MaxPostema commented 1 year ago

Traced to the backend. On a 'clone' of the record the same information is send to the server as is send when a record is updated. I am pretty sure the frontend does wat it needs to do.

clemens-tolboom commented 1 year ago

In org/molgenis/emx2/web/GraphqlApi.java:102 is file info

private static String executeQuery(GraphQL g, Request request) throws IOException {
mutation update($value:[UserInput]){update(User:$value){message}}

Screenshot 2023-09-11 at 15 14 58

in org/molgenis/emx2/sql/SqlTable.java:139 file name is lost

public int update(Iterable<Row> rows) {

image

clemens-tolboom commented 1 year ago

Code flow goes through BinaryFileWrapper which has no property to store fileName.

  public BinaryFileWrapper(String contentType, String fileName, byte[] contents) {
    this.contents = contents;
    this.mimetype = contentType;
    this.extension = deriveExtension(fileName);
  }

So we need to add fileName to org.molgenis.emx2.Binary to even store the name.

When we have a File object we can use getName().

clemens-tolboom commented 1 year ago

We discussed this and supposed a File has also a ~*_labelcolumn .. "Pet store". "User" table haspicture` but there is none according SQL DDL

...
    picture character varying COLLATE pg_catalog."default",
    picture_mimetype character varying COLLATE pg_catalog."default",
    picture_extension character varying COLLATE pg_catalog."default",
    picture_size integer,
    picture_contents bytea,

In Java I like to access the picture value too:

Can s() call provide this as I need the column value as well

.select(s(columnName, s("contents"), s("mimetype"), s("extension")))

results into data like

Screenshot 2023-09-11 at 15 14 58

mswertz commented 1 year ago

Probably the solution is to recognize during insert that file metadata is included (but not the byte stream of course). See screenshot below of an example clone. You can see that it is a clone because file metadata is included

See

image