International-Data-Spaces-Association / Java-Representation-of-IDS-Information-Model

Apache License 2.0
2 stars 7 forks source link

Deserialization gone wrong #6

Closed brianjahnke closed 3 years ago

brianjahnke commented 3 years ago

Hi, when we try too deserialize a permission like following this does not result in a permission but only in the contained Post Duty. Changing from Rule.class to Permission.class does fix the problem, but it is not an option in our use case since we do not know the type of the rule. @maboeckmann

package io.dataspaceconnector;

import java.io.IOException;

import de.fraunhofer.iais.eis.Action;
import de.fraunhofer.iais.eis.Rule;
import de.fraunhofer.iais.eis.ids.jsonld.Serializer;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Testing {

    @Test
    public void test() throws IOException {
        /* ARRANGE */
        final var serializer = new Serializer();
        final var input = "{\n"
                          + "        \"@context\" : {\n"
                          + "            \"ids\" : \"https://w3id.org/idsa/core/\",\n"
                          + "            \"idsc\" : \"https://w3id.org/idsa/code/\"\n"
                          + "        },\n"
                          + "      \"@type\": \"ids:Permission\",\n"
                          + "      \"@id\": \"https://w3id"
                          + ".org/idsa/autogen/permission/c0bdb9d5-e86a-4bb3-86d2-2b1dc9d226f5\",\n"
                          + "      \"ids:description\": [\n"
                          + "        {\n"
                          + "          \"@value\": \"usage-notification\",\n"
                          + "          \"@type\": \"http://www.w3.org/2001/XMLSchema#string\"\n"
                          + "        }\n"
                          + "      ],\n"
                          + "      \"ids:title\": [\n"
                          + "        {\n"
                          + "          \"@value\": \"Example Usage Policy\",\n"
                          + "          \"@type\": \"http://www.w3.org/2001/XMLSchema#string\"\n"
                          + "        }\n"
                          + "      ],\n"
                          + "      \"ids:action\": [\n"
                          + "        {\n"
                          + "          \"@id\": \"idsc:USE\"\n"
                          + "        }\n"
                          + "      ],\n"
                          + "      \"ids:postDuty\": [\n"
                          + "        {\n"
                          + "          \"@type\": \"ids:Duty\",\n"
                          + "          \"@id\": \"https://w3id"
                          + ".org/idsa/autogen/duty/863d2fac-1072-476d-b504-9d6347fe4b6f\",\n"
                          + "          \"ids:action\": [\n"
                          + "            {\n"
                          + "              \"@id\": \"idsc:NOTIFY\"\n"
                          + "            }\n"
                          + "          ],\n"
                          + "          \"ids:constraint\": [\n"
                          + "            {\n"
                          + "              \"@type\": \"ids:Constraint\",\n"
                          + "              \"@id\": \"https://w3id"
                          + ".org/idsa/autogen/constraint/c91e64ce-1fc1-44fd-bec1-6c6778603919\",\n"
                          + "              \"ids:rightOperand\": {\n"
                          + "                \"@value\": \"https://localhost:8080/api/ids/data\",\n"
                          + "                \"@type\": \"xsd:anyURI\"\n"
                          + "              },\n"
                          + "              \"ids:leftOperand\": {\n"
                          + "                \"@id\": \"idsc:ENDPOINT\"\n"
                          + "              },\n"
                          + "              \"ids:operator\": {\n"
                          + "                \"@id\": \"idsc:DEFINES_AS\"\n"
                          + "              }\n"
                          + "            }\n"
                          + "          ]\n"
                          + "        }\n"
                          + "      ]\n"
                          + "    }";

        /* ACT */
        final var result = serializer.deserialize(input, Rule.class);

        /* ASSERT */
        assertEquals(Action.USE, result.getAction().get(0));
    }
}
maboeckmann commented 3 years ago

Thanks for the report. This is a problem with the serializer. Basically, the RDF provided here is just a graph and as such does not need to have something like an obvious root node. Telling the serializer to parse this graph to a Rule gives it some freedom as to which element to choose as the entry point, as there are several rules in here. We are planning to come up with some fix, making the serializer try to find the "root object" in case it has several options to choose from. The fix should be ready within no more than one week.

brianjahnke commented 3 years ago

Hi, this does not seem to be fixed with version 4.0.10. Is this correct? And if so how far is the progress?

maboeckmann commented 3 years ago

Hi @brianjahnke, it seems like we first did the release and then merged the PR with the fix. I have now re-released the 4.0.10 including the fix. Could you please give it another shot?

brianjahnke commented 3 years ago

Hi, the serialization seems to pick the right type now. But this produces quite a lot of log messages (for us), is this intended?

maboeckmann commented 3 years ago

Hi, good point. I have changed it to print the warning only once. Afterward, this message is printed to debug. This enhancement is included in the latest SNAPSHOT and will be released as 4.0.11 on July 5th. Does this resolve the issue?

brianjahnke commented 3 years ago

Hi, could you move the message completly into debug? I think this is not information that should be logged to our users and i would like to not disable logging for the infomodel packages.

maboeckmann commented 3 years ago

All right - debug only it is. Done.