Model

Create Model

Before we present how models are created in M2, let us first have a quick look at the top menu of the M2 service. This is how the top menu looks like:

_images/TopMenu.png

The top menu links are:

Home Daprota home page
M2 M2 service
My profile Currently logged in user’s profile (e.g., daprota)
Documentation Documentation page link
Sign out Signout link
daprota Currently logged in user
_images/email.png Messaging link

Now we will explain how models are created. The M2 home page that is loaded when you log in enables creation of new models and also lists all models you have access to.

There are three sets of models you can see:

  • Models you created (My Models)
  • Models created by Daprota (Daprota Models) that are publicly available
  • Models created by M2 users that made them public (Public Models)

My Models tab is the default tab you will see when the M2 service home page is loaded.

We will use the Create Model tab to create a new model.

_images/AddModel.png

Before we proceed with the creation of a sample Role-based Access Control (RBAC) model, we will first descrbe it.

Role-based Access Control (RBAC) Model

RBAC is a data model that defines all data elements needed to manage users and their access to applications. It is an example of a hybrid MongoDB data model that combines both embedding and referencing model types. The model has three collections defined: Role, Permission and User.

The Role collection models roles that can be assigned to users. A role allows an authorized user (having the role assigned to him/her) to achieve his/her associated duty requirements. A role is usually seen as a job position or a named job function within an organization. It embodies authority, responsibility, or competency. If a role does not specify any permission, it is meant to be used as a role which security semantics is embedded in an application. For example, the Admin role can represent a system admin role that has full access to a system, in which case permissions are not included in the definition of the role.

The system protection in a role-based access control model is allowed in terms of permissions. A permission describes an approval of a particular access right to an object or set of objects. Permissions can be fully embedded in Roles or if needed they can also be referenced by documents in the User collection.

And finally we have a User collection that models users of the system. Besides permissions and roles, services that a user has access to are also embedded in User documents.

As you can see in this example, users, permissions and roles can be modeled in a few different ways and the way (model type) presented here is just a sample used to show how MongoDB models can be created and managed by M2.

And this is how RBAC looks in a JSON-like form:

_images/RBAC.png

Create RBAC Model

To create a model, click the Create Model tab to load the create model page. When the create model page is loaded, enter the model name. Description of the model is not mandatory, but it can help others to understand the purpose of the model better.

In the example below, we will create a model named Role-based Access Control (RBAC):

_images/AddModel-Create.png

By clicking the Create Model button, M2 will create a new model. As soon as the model is created it will be listed on the home page. The model will be private which means that only you have access to it. When you finish the model, you can make it public by changing the value of the public field to yes.

_images/AddModel-MyModels.png

When the model is public, all M2 users will be able to see it by clicking the Public Models button. They can also copy the model and update the copy of the model in order to create their own model based on your model.

Now when you created the model, the next step is to view the model (load the model view) in order to continue with the creation of other elements of the model (Collections, Documents and Fields).

View Model

When you click a model’s link on the M2 home page,

_images/AddModel-ClickToView.png

the model view page will be loaded:

_images/ViewModel.png

This page has few buttons:

  • Models (go back to M2 home page that lists all models you have access to)
  • Full Model View (the full model view page that shows all elements of the model)
  • Update (update the model)
  • Copy (copy the model)
  • Delete (delete the model)
  • Export (export the model)
  • Doc (document the model)
  • Code Generation (generate Java code from the model)

Models that include references (Manual References and DBRefs) will have the References section which shows all references of the model. This is the case with the RBAC model as shown above. It has one Manual Reference in which Role collection is a source (parent) collection in the relationship and User collection is a target (child) collection in the relationship where the _id field of an embedded Role document in the User collection references the _id field of the Role collection document. The Add Field documentation page contains details that explains how this relationship is created in M2.

The bottom part of the model page belongs to collections of the model. They are listed on this page as soon as they are created.

Besides the default Model tab, the model view page also has the Add Collection tab. The Add Collection tab is used to add a collection to the model.

When you click the Full Model View button the full model view page will be loaded and it will present the whole model in a JSON-like form. For example, this is how the full view of the RBAC model will look like when the creation of the model is complete:

_images/ViewModel-FullModelView2.png

Update Model

Click the Update button on the model page to update the model

_images/UpdateModel.png

and the update model page will be loaded:

_images/UpdateModel2.png

You can update name, description and public flag of the model and click the Update button to submit the updates. Otherwise click the Cancel button if you changed your mind and do not want to update the model.

When you create a model, its public flag will have no value what means that it is the private model that can be viewed by you only. If you want to make the model public, viewable by all M2 users, you will update the public flag’s value to yes.

Copy Model

Click the Copy button on the model page to make a copy of the model:

_images/ViewModel-Copy.png

This is how the copy model page looks like when it is loaded:

_images/CopyModel.png

Enter the name of the new model that will be a copy of the original model and click the Copy button to copy the model. Otherwise click the Cancel button to go back to the model page.

The whole model is copied together with all its collections, their documents, documents’ fields and references if any. The documentation of the model is not copied.

The Copy Model can also be used to copy a model in order to start a new version of the model and keep the previous version of the model in M2.

Delete Model

Click the Delete button on the model page to remove the model:

_images/ViewModel-Delete.png

A small confirmation window will pop up. You can either confirm model removal or cancel it.

When the model is removed, all elements associated with it are also removed.

Document Model

Click the Doc button on the model page to load the documentation page:

_images/ViewModel-Document.png

The Documentation page enables the upload of model documentation. You can also provide URLs for external links holding model documentation. These external links are URLs of pages from the Web that contain either documentation or information relevant to the model.

_images/ViewModel-Documentation.png

Use the Choose Document button to browse folders for documents and then use the * Upload Document* button to upload the selected document. You can upload as many documents as you need. Their links will be listed on this page so that you and other users who have access to your model can read the model’s documentation.

For example, click the Choose Document button to browse folders for documents and select a document that describes the model. For example, if you selected the RBAC.pdf document, this page will be loaded:

_images/ViewModel-UploadDoc.png

You will then click the Upload Document button to upload the selected document. When the document is uploaded the documentation page will be presented.

_images/ViewModel-ListDocs.png

You can upload as many documents as you need. Their links will be listed on this page.

As the owner of the model, you can remove documents if you do not need them anymore. First you will select document(s) you want to remove and then you will use the Remove Document button to remove the document(s). Other users can neither remove nor upload documents for your model. They can only view the documents.

If you have external documentation content, you can enter the external link’s URL and the external link’s name for the content. For example:

_images/ViewModel-ExtLink.png

Click the Add Link button to add the link. When the link is added, the documentation page will be re-loaded:

_images/ViewModel-FinalDoc.png

As the owner of the model, you can update the selected links (Update Link button) or remove the selected links (Remove Link button) if you do not need them anymore. Other users can neither update nor remove external documentation links for your model. They can only use links to view model documentation.

Export Model

From the model view page you can click the Export Model button to export the model:

_images/ViewModel-Export.png

The model will be exported in a JSON format and stored in the M2 models repository. A link to the model’s JSON file will be created on the model page:

_images/ViewModel-AfterExport.png

Import Model

The M2 home page has the Import Model tab that enables import of a model into M2 from a JSON file:

_images/AddModel-Import.png

When you click the tab, the file upload page will be loaded:

_images/AddModel-Import2.png

When you click the Choose JSON Document button, the browse window will pop-up. You can browse folders for a JSON model file. By double-cliking on the selected file, M2 will upload the file (e.g., Tara Modelling Ontology Embedded.json):

_images/AddModel-ChosenDocument.png

Click the Import JSON Document button to import the model. When the model is imported it will be listed on the M2 home page (e.g., Tara Modeling Ontology Embedded):

_images/AddModel-ShowImportedModel.png