Skip to content

Encoded Paths are Not Read Back In #320

@AndreasMeier12

Description

@AndreasMeier12

I have a crate that contains an @id with escaped characters, id 1 and an associated file.

Expected Behavior

The path for this entity is found.

Observed behavior

There is an entity id%201 and a path in the crate id%201.

The path for this entity obtained via dataEntity.getPath() is null.

I did some experiments:

  1. When I change the @id to id%25201, i.e. the percent encoding of the path, the path is read back in.
  2. When I change the path to id 1 inside the crate and leave the @id: "id%201" , the path is found.

I read the discussion on #5 and the official documentation https://www.researchobject.org/ro-crate/specification/1.1/data-entities.html#core-metadata-for-data-entities. I understand that the path inside the crate itself should not be encoded, i.e. the decoded @id should be the same as the path.

To Reproduce

Writing


import edu.kit.datamanager.ro_crate.RoCrate;
import edu.kit.datamanager.ro_crate.entities.data.DataEntity;
import edu.kit.datamanager.ro_crate.entities.data.FileEntity;
import edu.kit.datamanager.ro_crate.writer.FolderWriter;
import edu.kit.datamanager.ro_crate.writer.RoCrateWriter;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.UUID;

public class WriteExample

{

    public static void main(String[] args) throws IOException
    {
        RoCrate.RoCrateBuilder builder = new RoCrate.RoCrateBuilder();
        {
            FileEntity.DataEntityBuilder dataEntityBuilder = new DataEntity.DataEntityBuilder();
            dataEntityBuilder.setId("id 1");
            dataEntityBuilder.addTypes(List.of("File"));
            UUID uuid = UUID.randomUUID();
            Path path = Path.of("/tmp/" + uuid.toString());
            Files.write(path, "File".getBytes(StandardCharsets.UTF_8));
            dataEntityBuilder.setLocation(path);

            builder.addDataEntity(dataEntityBuilder.build());

        }
        {
            FileEntity.DataEntityBuilder dataEntityBuilder = new DataEntity.DataEntityBuilder();
            dataEntityBuilder.setId("id\uD83E\uDD791");
            dataEntityBuilder.addTypes(List.of("File"));
            UUID uuid = UUID.randomUUID();
            Path path = Path.of("/tmp/" + uuid.toString());
            Files.write(path, "File".getBytes(StandardCharsets.UTF_8));
            dataEntityBuilder.setLocation(path);

            builder.addDataEntity(dataEntityBuilder.build());

        }
        {
            FileEntity.DataEntityBuilder dataEntityBuilder = new DataEntity.DataEntityBuilder();
            dataEntityBuilder.setId("id|1");
            dataEntityBuilder.addTypes(List.of("File"));
            UUID uuid = UUID.randomUUID();
            Path path = Path.of("/tmp/" + uuid.toString());
            Files.write(path, "File".getBytes(StandardCharsets.UTF_8));
            dataEntityBuilder.setLocation(path);

            builder.addDataEntity(dataEntityBuilder.build());

        }

        RoCrate crate  = builder.build();
        RoCrateWriter writer = new RoCrateWriter(new FolderWriter());
        writer.save(crate, "/tmp/out-crate-simple-file");



    }
}

Reading

import edu.kit.datamanager.ro_crate.RoCrate;
import edu.kit.datamanager.ro_crate.entities.data.DataEntity;
import edu.kit.datamanager.ro_crate.reader.FolderReader;
import edu.kit.datamanager.ro_crate.reader.RoCrateReader;

public class ReadExample
{

    public static void main(String[] args)
    {
        String location = "/tmp/out-crate-simple-file";
        RoCrateReader roCrateReader = new RoCrateReader(new FolderReader());

        RoCrate roCrate = roCrateReader.readCrate(location);
        for (DataEntity dataEntity : roCrate.getAllDataEntities()){
            System.out.println(dataEntity.getId() + ": " + dataEntity.getPath());

        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions