Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Introduction

Most of the basic objects that Synapse currently supports are Entities. Each Entity has first class data that makes up the fields of an entity. All Entities also have Annotations that store additional data about an entity.

...

While defining entities using Java allowed us to quickly get a first version of Synapse built, we always planed on supporting a more dynamic approach to object definitions. Ideally we would like our users to define entities without writing Java code. As it stands now if our users want to add a field to an entity, an engineering task must be scheduled to get the change implemented. In theory, if we used a schema like JSON Schema 03, for both entity definitions and data constraints, we could make changes to schema with little or no engineering effort. Engineering would no longer be the bottle-neck for the evolution of Synapse Entities and data.

Proposal

We are proposing to use JSON Schema 03 to define both an Entity and the Annotations of an Entity. The JSON Schema breaks an object definition into two major categories; properties and additional properties.

...

There is a lot more detail to the JSON Schema definition that we will not cover here.

Schema Life-cycle

For the initial implementation we are proposing that an Entity Schema can only be defined and edited as part of the compile of synapse. This means run-time edits or additions to each schema will not be possible. The reason for this limitation is to keep the Life-cycle of the schema as simple as possible. As we will see, the life-cycle is already complicated even with this limitation.

Define Entities

A new entity will be created by first creating a new JSON text file in the lib-auto-generated project's src/main/resources folder. Folder hierarchies should be used to represent the equivalent of "packages" for each entity.
The following example show where an Example entity might be created:

...

Code Block
{
        "type":"string",
	"format":"uri",
	"enum":["SPARQLNCBO":"
		PREFIX abc: <httpSELECT fullId FROM http://purlrest.bioontology.org/bioportal/ontology/MCCL#>
		SELECT ?uri
		WHERE {
  			?y abc:FullId ?uri ;
     			abc:isA abc:/FMA_9637 .
		}concepts/4531?conceptid=tbio:Organ&ligth=1&apikey=2fb9306a-7f3f-477a-821e-e3ccd7356a18
	"]
   }

In this example, we can see that we expect the values to be URI strings limited to the values returned from a SPARQL query. In this case, the SPARQL query translates to the following:

...

The first thing to point out about our Example.json is that it extends Entity.json, which makes it a Synapse Entity. This implies it inherits all of its values from the base Entity. The second thing to point out is that it defines a type called "tissue" in its additional properties that is based on the annotation type we defined earlier.

Compile JPJOs (first time)

Since we still want Java POJOs to represent all entities, we will use the schema-to-pojo-maven-plugin to build these POJOs. This is done by simply added the following to the lib-auto-generated/pom.xml file:

...

The plugin will automatically create a POJOs class for each JSON schema found in the resource directory. These POJOs will be placed in the target/auto-generated-pojos directory.

Synapse Deploy (first time)

The first time Synapse is deployed after creating Entities, the org.sagebionetworks.repo.model.bootstrap.EntityBootstrapper will read all JSON schema files found in the lib-auto-generated.jar file and create a Synapse SchemaEntity (to be defined) for each using the directory structure create each path. All schema entities will be placed in the folder:

...

The API user will be able to get the SchemaEntity objects but they will be READ-ONLY copies. This is important, because the "truth" of each entity is the JSON text file from the auto-generated-pojos project. Hopefully, this will make more sense as the rest of the life-cycle is outlined.

Edit of an Schema

Imagine that we want to add a new primary field to our Example.json Entity. To do this we need to modify the original JSON file in the lib-auto-generated

...

Code Block
{
     "extends":"org/sagebionetworks/entity/type/Entity.json"
     "name":"Product",
     "properties":{
       "id":{
         "type":"number",
         "description":"Example identifier",
         "required":true
       },
       "name":{
         "description":"Name of the Example",
         "type":"string",
         "required":true
       },
	"status":{
         "type":"string",
         "required":true,
	"enum":[ "PROTOTYPE", "RELEASED", "RECALLED", "DEPRECIATED"],
	"default":"PROTOTYPE"
       },
     },
     "additionalProperties":{
	"tissue":{
	"type":"object",
	"$ref":"org/sagebionetworks/annotation/types/BioOntologyTissueType.json"
       }
     }
   }

Compile POJOs (Nth Time)

This time when we compile the new Example.java POJO, the resulting POJO will have a new field called "status" with a default value of "PROTYPE".

Backup Deployed Synapse

Before we can deploy our update schema we must create a backup of the deployed Synapse. See: Repository+Administration
This is an important step. We will use this backup to deploy our changes to the repository.

Synapse Deploy (Nth Time)

Just like before, the bootstrap system will per-populate all SchemaEntites on the new empty repository. At this point we have an empty Synapse that is up-to-date with regard to the current schema.

Restore Synapse from Backup

After we have a clean repository, we can restore the backup from the earlier step. See: Repository+Administration

...