Skip to content

Changing the Ember data model

John Abrahams edited this page Apr 11, 2018 · 1 revision

The PASS ember app currently uses a custom Ember adapter to talk directly to Fedora, our backend data store of choice. This has some implications to the development of the PASS Ember UI, especially when making changes to the Ember data model.

The Ember Fedora Adapter

The README from the OA-PASS/ember-fedora-adapter has some relevant information. This custom adapter receives data from Fedora formatted as JSON-LD, a JSON based representation of RDF data. The fedora adapter then compacts the data, basically mapping the URI keys to shortened keys, based on a JSON-LD context that is configurable. The translated properties are what the adapter uses to create Ember data model objects. This means that the Ember data model and the JSON-LD context provided to the fedora adapter must be kept in sync (the context must also be kept in sync with the context being used by Fedora!).

Many changes to the Ember data model will break the context used by the fedora adapter. In order to see the model changes properly apply from the UI back down to the develompent Fedora back end, you must also provide an updated context. You will most likely have to stand up the context locally in order to test against the changes. This can be done using any means you want, such as standing up a local Apache instance to host the test context. When testing against this local context, you will also need to update the pass-ember configurations to point to the correct place (all locations will be in your pass-ember repo):

Fedora and ember-fedora-adapter relevant configs

  • environment.js:ENV.fedora.context must be updated to use your local test context
  • .env:COMPACTION_URI must be updated to use your local test context

Notes on adapter support

  • The adapter currently does not support string arrays
  • The adapter currently does not support Ember transforms
  • DS.belongsTo relationship must have @id JSON-LD type
  • DS.hasMany relationship must have @container: @set, @id types

Context Example

Take these three properties defined in a sample context (note this by itself is not a valid context):

"Person": "pass:Person",
"person": {"@id": "pass:person"},
"author": {"@id": "pass:author", "@type": "@id"},
"authors": {"@id": "pass:authors",  "@container": "@set", "@type": "@id"},
  • These properties can be used in any model object
  • Person is a defined object type
  • person maps to DS.attr('string') in Ember: note no @type: @id
  • author the @type: @id marks it as a reference, will ultimately map to DS.belongsTo('person')
  • authors has @container: @set which marks it as a Set of values, with the value type being @id (a reference to another object). This ultimately maps to DS.hasMany('person')

Making changes to the Ember model

You are free to change the Ember data model freely as you need in development. We can sync up a modified UI data model with the overall project data model when we think the changes are somewhat stable.

You have to update the context when adding properties not already present in the context

Whenever you make a change to the data model OR the test data:

  • Make a change to the data model as needed
  • Update a test context and make sure both Fedora and the fedora adapter are pointing to the test context as needed
  • Update test data as needed
  • Stop, clean, and start the Fedora docker image. This must be done to clear out the old (now obsolete) data from the Fedora container.
    docker-compose down
    docker system prune 
    docker-compose up
    

For development, you can run Fedora in a Docker container provided with the pass-ember repo with docker-compose up. This will bring Fedora up at http://localhost:8080/fcrepo.

Further Reading