Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACC-1761] Add entity information to HAL-FORMS entity profile endpoint #297

Closed
wants to merge 6 commits into from

Conversation

NielsCW
Copy link
Contributor

@NielsCW NielsCW commented Dec 10, 2024

This PR adds entity information to HAL-FORMS entity profile endpoint by using a blueprint/datamodel.json config file. Everything is read from the file, the PersistentEntity model and rest-messages.properties are not processed. The new curie blueprint: is used for the entity information profile endpoint only.

Currently supported:

  • Entity, attribute and relation names (all singular)
  • Entity, attribute and relation titles (all singular)
  • Entity, attribute and relation descriptions
  • Attribute constraints (using blueprint:constraint)
  • Attribute search parameters (using blueprint:search-param)
  • Nested attributes (using blueprint:attribute within an attribute)
  • Link to target entity profile endpoint (using blueprint:target-entity)

Not supported:

  • Sort values for sort parameter
  • Plural entity name and title (these are used in cg:entity link name and link title)
  • Search parameters across relations
  • Content endpoint url

Example from /profile/invoices (_links and _templates not shown):

{
  "name" : "customer",
  "title" : "Client",
  "description" : "Company or person that acts like a client",
  "_embedded" : {
    "blueprint:attribute" : [ {
      "name" : "id",
      "type" : "string",
      "description" : "",
      "readOnly" : true,
      "_embedded" : {
        "blueprint:constraint" : [ ],
        "blueprint:search-param" : [ ],
        "blueprint:attribute" : [ ]
      },
      "_links" : { }
    }, {
      "name" : "name",
      "title" : "Customer name",
      "type" : "string",
      "description" : "Full name of the customer",
      "_embedded" : {
        "blueprint:constraint" : [ ],
        "blueprint:search-param" : [ ],
        "blueprint:attribute" : [ ]
      },
      "_links" : { }
    }, {
      "name" : "vat",
      "title" : "VAT number",
      "type" : "string",
      "description" : "VAT number of the customer",
      "required" : true,
      "_embedded" : {
        "blueprint:constraint" : [ {
          "type" : "required"
        }, {
          "type" : "unique"
        } ],
        "blueprint:search-param" : [ {
          "name" : "vat",
          "type" : "case-insensitive-match"
        } ],
        "blueprint:attribute" : [ ]
      },
      "_links" : { }
    }, {
      "name" : "content",
      "type" : "object",
      "description" : "",
      "_embedded" : {
        "blueprint:constraint" : [ ],
        "blueprint:search-param" : [ ],
        "blueprint:attribute" : [ {
          "name" : "length",
          "type" : "long",
          "description" : "",
          "readOnly" : true,
          "_embedded" : {
            "blueprint:constraint" : [ ],
            "blueprint:search-param" : [ {
              "name" : "content.size",
              "type" : "exact-match"
            } ],
            "blueprint:attribute" : [ ]
          },
          "_links" : { }
        }, {
          "name" : "mimetype",
          "type" : "string",
          "description" : "",
          "_embedded" : {
            "blueprint:constraint" : [ ],
            "blueprint:search-param" : [ {
              "name" : "content.mimetype",
              "type" : "exact-match"
            } ],
            "blueprint:attribute" : [ ]
          },
          "_links" : { }
        }, {
          "name" : "filename",
          "type" : "string",
          "description" : "",
          "_embedded" : {
            "blueprint:constraint" : [ ],
            "blueprint:search-param" : [ {
              "name" : "content.filename",
              "type" : "exact-match"
            } ],
            "blueprint:attribute" : [ ]
          },
          "_links" : { }
        } ]
      },
      "_links" : { }
    } ],
    "blueprint:relation" : [ {
      "name" : "invoices",
      "description" : "",
      "required" : false,
      "_links" : {
        "blueprint:target-entity" : {
          "href" : "http://localhost/profile/invoices"
        }
      },
      "many_source_per_target" : false,
      "many_target_per_source" : true
    } ]
  }
}

Example config /blueprint/datamodel.json:

[
  {
    "name": "customer",
    "title": "Client",
    "domainType": "com.contentgrid.spring.test.fixture.invoicing.model.Customer",
    "description": "Company or person that acts like a client",
    "attributes": [
      {
        "name": "id",
        "propertyName": "id",
        "type": "string",
        "description": "",
        "readOnly": true,
        "constraints": [],
        "search_params": []
      },
      {
        "name": "name",
        "title": "Customer name",
        "propertyName": "name",
        "type": "string",
        "description": "Full name of the customer",
        "constraints": [],
        "search_params": []
      },
      {
        "name": "vat",
        "title": "VAT number",
        "propertyName": "vat",
        "type": "string",
        "description": "VAT number of the customer",
        "constraints": [
          {
            "type": "required"
          },
          {
            "type": "unique"
          }
        ],
        "search_params": [
          {
            "name": "vat",
            "type": "case-insensitive-match"
          }
        ]
      },
      {
        "name": "content",
        "propertyName": "content",
        "type": "object",
        "description": "",
        "constraints": [],
        "search_params": [],
        "attributes": [
          {
            "name": "length",
            "propertyName": "length",
            "type": "long",
            "description": "",
            "readOnly": true,
            "constraints": [],
            "search_params": [
              {
                "name": "content.size",
                "type": "exact-match"
              }
            ]
          },
          {
            "name": "mimetype",
            "propertyName": "mimetype",
            "type": "string",
            "description": "",
            "constraints": [],
            "search_params": [
              {
                "name": "content.mimetype",
                "type": "exact-match"
              }
            ]
          },
          {
            "name": "filename",
            "propertyName": "filename",
            "type": "string",
            "description": "",
            "constraints": [],
            "search_params": [
              {
                "name": "content.filename",
                "type": "exact-match"
              }
            ]
          }
        ]
      }
    ],
    "relations": [
      {
        "name": "invoices",
        "propertyName": "invoices",
        "target_entity": "com.contentgrid.spring.test.fixture.invoicing.model.Invoice",
        "description": "",
        "many_source_per_target": false,
        "many_target_per_source": true
      }
    ]
  },
  {
    "name": "invoice",
    ...
  }
]

The information is based on a config file named 'blueprint/datamodel.json' located under 'src/main/resources'. If the file is missing, no entity information is shown. Entities not present in 'blueprint/datamodel.json' will be skipped and non-existing entities present in 'blueprint/datamodel.json' will be ignored.
@NielsCW NielsCW marked this pull request as ready for review December 10, 2024 08:43
@NielsCW NielsCW requested a review from a team as a code owner December 10, 2024 08:43
@NielsCW NielsCW closed this Dec 19, 2024
@NielsCW
Copy link
Contributor Author

NielsCW commented Dec 19, 2024

This duplicates a lot of information, changing something will require us to change it in multiple places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant