Skip to content

Base Services

Mathieu Savy edited this page Jun 13, 2016 · 6 revisions

Wakanda-Client is built on a n-tier architecture:

  • Presentation: what is exposed to the developer who uses Wakanda-Client
  • Business: the logic of Wakanda-Client
  • Data access: handle the communication with Wakanda Server REST API

The DataAccess layer, in our case, is split into two parts. Services, which are used by the business layer, and Base Services, which are used by services.

The point of this separation is because Services carry little information on their instances, like "This collection is an entity set, so some details are to be handle while talking to the REST API".

But, we want to be able to use services outside of Wakanda-Client (without this extra information), so that we can have the benefit of the communication with REST API handled, without having to use the whole ORM.

That's why Base Services exists, they're basically static classes, with static methods. It's a raw wrapper to the REST API. No less, no more.

Base services are on src/data-access/service/base directory. All methods return a Promise.

CatalogBaseService

get({httpClient, dataClasses})

Retrieve a Catalog with all the dataClasses, or only the one given in parameter.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • dataClasses: (optional) string or string array representing the name of the dataClasses to retrieve

DataClassBaseService

find({httpClient, key, options, dataClassName})

Find an entity of the dataClass with the given key and options.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • key: entity key
  • options: Object that contains options to filter the request (attribute expanding, ordering, filtering, etc.)
  • dataClassName: name of the dataClass on which the query will be performed

query({httpClient, options, dataClassName})

Find multiple entities according to options on the given dataClass.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • options: Object that contains options to filter the request (attribute expanding, ordering, filtering, etc.)
  • dataClassName: name of the dataClass on which the query will be performed

callMethod({httpClient, methodName, parameters, dataClassName})

Call a method defined on a dataClass

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • methodName: name of the method
  • parameters: array (may be empty) of parameters to pass to the method
  • options: Object that contains options to filter the request (attribute expanding, ordering, filtering, etc.)
  • dataClassName: name of the dataClass on which the query will be performed

EntityBaseService

save({httpClient, data, expand, dataClassName})

Perform a save of the given entity on data parameter. If a key and a stamp are provided, it will perform an update. Either way, a new entity will be created.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • data: object containing properties of the entity to save (including key and stamp if needed)
  • expand: (optional) string of the attributes to expand when the server returns the entity after save
  • dataClassName: name of the dataClass on which the query will be performed

recompute({httpClient, dataClassName, data})

Execute server-side logic by simulating a save of the entity. The entity will be modified the following way:

  • Calculated attributes are filled
  • init event is triggered if recompute is called on a new entity (eg. that has never been saved yet)
  • clientrefresh event is triggered

The entity is not saved, and all server-side computation that occured won't be persisted.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • data: object containing properties of the entity to save (including key and stamp if needed)
  • dataClassName: name of the dataClass on which the query will be performed

callMethod({httpClient, dataClassName, methodName, parameters, entityKey})

Call a method defined on the entity

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • methodName: name of the method
  • parameters: array (may be empty) of parameters to pass to the method
  • entityKey: key of the entity on which the method is called
  • dataClassName: name of the dataClass on which the query will be performed

delete({httpClient, dataClassName, entityKey})

Delete the entity.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • entityKey: key of the entity on which the method is called
  • dataClassName: name of the dataClass on which the query will be performed

CollectionBaseService

fetch({httpClient, collectionUri, isEntitySet, options})

Fetch a collection with given options.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • collectionUri: URI of the collection previously returned by REST API when retrieving it (or the entity owning it) for the first time
  • isEntitySet: boolean indicating if the collectionUri is an EntitySet URI or not
  • options: Object that contains options to filter the request (attribute expanding, ordering, filtering, etc.)

callMethod({httpClient, collectionUri, isEntitySet, methodName, parameters})

Call a method defined on the collection.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • collectionUri: URI of the collection previously returned by REST API when retrieving it (or the entity owning it) for the first time
  • isEntitySet: boolean indicating if the collectionUri is an EntitySet URI or not
  • methodName: name of the method
  • parameters: array (may be empty) of parameters to pass to the method

MediaBaseService

upload({httpClient, dataClassName, entityKey, attributeName, file, isImage})

Upload a file to an entity blob or image attribute.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • dataClassName: name of the dataClass on which the query will be performed
  • entityKey: key of the entity to upload the file to
  • attributeName: name of the file attribute to upload the file to
  • file: file to upload
  • isImage: boolean indicating if the filed to upload the file to is of type image

delete({httpClient, dataClassName, entityKey, entityStamp, attributeName})

Delete the existing file of blob or image attribute.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • dataClassName: name of the dataClass on which the query will be performed
  • entityKey: key of the entity to remove the file from
  • entityStamp: stamp of the entity
  • attributeName: name of the file attribute to remove the file from

DirectoryBaseService

login({httpClient, username, password, duration})

Login with given credentials.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • username: Username
  • password: Password
  • duration: Duration (in seconds) of the session

logout({httpClient})

Logout from Wakanda Server.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)

currentUser({httpClient})

Get the current user if any.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)

currentUserBelongsTo({httpClient, group})

Check if the current user belongs to the given group.

Params
  • httpClient: instance of HttpClient, usually got on WakandaClient instance (for example wakandaClient._httpClient)
  • group: name of the group to check