ardoq / ardoq-java-client

Java Wrapper for the Ardoq Rest-API
Eclipse Public License 1.0
2 stars 4 forks source link

Allow extra query parameters in overloaded ComponentService.getComponentById #22

Closed szatmariandras closed 4 years ago

szatmariandras commented 4 years ago

This allows fetching the references of components, which are otherwise not possible to get with the Java bindings:

var component = client.component().getComponentById("my-id", Map.of("includeReferences", "true")
mslupny commented 4 years ago

Hi @szatmariandras and welcome to ardoq-java-client 😄 ! Thanks for the PR 🙏 . Would you mind extending com.ardoq.model.Reference so that the newly added references are present on the top level instead of inside _fields? It's not a custom field so it doesn't belong in _fields.

szatmariandras commented 4 years ago

Hi @mslupny , do you mean adding it to com.ardoq.model.Component? :)

Will that affect sending components to PUT/POST endpoints? What would happen if a Component has some References attached to it and it's sent to the @POST("/api/component") endpoint?

szatmariandras commented 4 years ago

Hey @mslupny I pushed a commit in the updated Component class in the meantime, please check it out and tell me what you think 🙏

szatmariandras commented 4 years ago

It seems to do what it should. These is the Java object re-encoded with gson.

Result for ardoq.component().getComponentById("my-id"):

{
  "_id": "1f46cfc76778df9209667ce1",
  "name": "EUAVLf133MFGD02",
  "model": "c5f837c83e9c079f20870e9a",
  "created": "Jul 14, 2020, 4:11:42 PM",
  "created-by": "6443621240c3b05f3339650a",
  "last-updated": "Jul 14, 2020, 4:14:19 PM",
  "_version": 2,
  "rootWorkspace": "43e54a461ec2b0ee2da47d2d",
  "children": [],
  "parent": "f351700af638f4601b9fe33a",
  "type": "Resource",
  "typeId": "p1594734881249",
  "description": "",
  "_fields": {
    [.. sic ..]
    "ardoq": {
      "entity-type": "component",
      "incomingReferenceCount": 0.0,
      "outgoingReferenceCount": 2.0
    },
    [.. sic ..]
  }
}

Result for ardoq.component().getComponentById("my-id", Map.of("includeReferences", "true")):


{
  "_id": "1f46cfc76778df9209667ce1",
  "name": "EUAVLf133MFGD02",
  "model": "c5f837c83e9c079f20870e9a",
  "created": "Jul 14, 2020, 4:11:42 PM",
  "created-by": "6443621240c3b05f3339650a",
  "last-updated": "Jul 14, 2020, 4:14:19 PM",
  "_version": 2,
  "rootWorkspace": "43e54a461ec2b0ee2da47d2d",
  "children": [],
  "references": {
    "in": [],
    "out": [
      {
        "_id": "acbb5c8b7ee21d013c4dbb3f",
        "created": "Jul 14, 2020, 4:14:31 PM",
        "created-by": "6443621240c3b05f3339650a",
        "last-updated": "Jul 14, 2020, 4:14:31 PM",
        "_version": 1,
        "rootWorkspace": "43e54a461ec2b0ee2da47d2d",
        "type": 3,
        "source": "1f46cfc76778df9209667ce1",
        "target": "7fbd1535c20021b7f13fb517",
        "description": "",
        "targetWorkspace": "43e54a461ec2b0ee2da47d2d",
        "order": 0
      },
      {
        "_id": "2c9bb936207908d90f9b167c",
        "created": "Jul 15, 2020, 11:39:22 AM",
        "created-by": "1731913cf2b8162d043c414b",
        "last-updated": "Jul 15, 2020, 11:39:22 AM",
        "_version": 1,
        "rootWorkspace": "43e54a461ec2b0ee2da47d2d",
        "type": 4,
        "source": "1f46cfc76778df9209667ce1",
        "target": "2fc7dff029183643d3c9b53e",
        "description": "",
        "targetWorkspace": "3c755cecdd543854752c7c1d",
        "order": 0
      }
    ]
  },
  "parent": "f351700af638f4601b9fe33a",
  "type": "Resource",
  "typeId": "p1594734881249",
  "description": "",
  "_fields": {
    [.. sic ..]
    "ardoq": {
      "entity-type": "component",
      "incomingReferenceCount": 0.0,
      "outgoingReferenceCount": 2.0
    },
    [.. sic ..]
  }
}```
mslupny commented 4 years ago

Heh, yeah, I meant com.ardoq.model.Component 🤦 .

Good point about creating/updating components with that key. We're pretty permissive with what we allow on input on the API, so we'll need to do something to avoid storing these references, but I believe that should be handled on server side. I'll fix that and go back to this PR (shouldn't take long). I'll keep you posted.

szatmariandras commented 4 years ago

Great, thanks @mslupny!

When do you think this can be released? I can play around with this in my local Maven repo, but I might use it in production in a week or two :)

mslupny commented 4 years ago

I tried to release it right away, but apparently I'm missing some credentials. The person responsible for releases is on summer holidays ATM, so it may take a while. I'll let know once I have an update 🙂 .