2021-02-16 - Translations - Functions

From Izara Wiki
Jump to navigation Jump to search

Service - Translations

Lambda Functions

CreateSubjectVertex

/**
 * Create a new vertex for the subject of translations
 * @param {string} vertexId
 * @param {string} vertexLabel
 * @param {object} [vertexProperties]
 *
 * @returns {string} vertexId
 */

HdrInv

Validator: (standard)

handler logic

(standard)

logic

  1. create vertex by invoking NPM module - izara-graph-service#vertexLib.createVertex
    1. vertexId: vertexId
    2. vertexLabel: 'vertexLabel'
    3. vertexProperties: 'vertexProperties'

CreateTranslationVertex

/**
 * Create a new vertex for a translation
 * @param {string} vertexId
 * @param {string} vertexLabel
 * @param {string} translation
 *
 * @returns {string} vertexId
 */

HdrInv

Validator: (standard)

handler logic

(standard)

logic

Create statements in graph database. Expects subject vertex to already exist (does not create subject with label/properties).

  1. create vertex by invoking NPM module - izara-graph-service#vertexLib.createVertex
    1. vertexId: vertexId
    2. vertexLabel: 'vertexLabel'
    3. vertexProperties: {translation: translation}

CreateTranslation

/**
 * Create a new translation for a source object
 * @param {string} subjectId
 * @param {string} translationLabel
 * @param {string} languageCode
 * @param {string} translation
 * @param {string} userId
 *
 * @returns {Object[]} ?translation vertex id?
 */

HdrInv

Validator: (standard)

handler logic

(standard)

logic

Main job is to create statements in graph database. Expects subject vertex to already exist (does not create subject with label/properties).

  1. create ids for translation vertex:
    1. const objectId = NPM module - izara-shared#neptuneGraphSharedLib.createVertexId('translation', {random uuid})
    2. const objectLabel = translationLabel + Translation
  2. create translation vertex by invoking async 2021-02-16 - Translations - Functions#CreateTranslationVertex
    1. vertexId: objectId
    2. vertexLabel: 'translation'
    3. translation: translation
  3. create id for PossiblyTranslatesTo edge:
    1. const possiblyTranslatesToEdgeId = subjectId + '_Possible' + translationLabel + '_' + languageCode + '_' + objectId
  4. create PossiblyTranslatesTo graph statement by invoking NPM module - izara-graph-service#edgeLib.createRelationshipStatement
    1. subjectId: subjectId
    2. edgeLabel: 'PossiblyTranslatesTo'
    3. edgeId: possiblyTranslatesToEdgeId
    4. objectId: objectId
    5. objectLabel: 'PossiblyTranslatesTo'
    6. objectProperties:
      1. languageCode: languageCode
  5. create id for TranslatesTo edge:
    1. const translatesToEdgeId = subjectId + '_' + translationLabel + '_' + languageCode + '_' + objectId
  6. create TranslatesTo graph statement by invoking async NPM module - izara-graph-service#edgeLib.createRelationshipStatement
    1. subjectId: subjectId
    2. edgeLabel: 'TranslatesTo'
    3. edgeId: translatesToEdgeId
    4. objectId: objectId
  7. create id for DefaultTranslatesTo edge:
    1. const defaultTranslatesToEdgeId = subjectId + '_Default' + translationLabel + '_' + objectId
  8. create DefaultTranslatesTo graph statement by invoking async NPM module - izara-graph-service#edgeLib.createRelationshipStatement
    1. subjectId: subjectId
    2. edgeLabel: 'DefaultTranslatesTo'
    3. edgeId: defaultTranslatesToEdgeId
    4. objectId: objectId
  9. create ids for user vertex:
    1. const userVertexId = NPM module - izara-shared#neptuneGraphSharedLib.createVertexId('user', {userId})
  10. create id for translation CreatedBy edge:
    1. const createdByEdgeId = objectId + '_CreatedBy_' + userVertexId
  11. create CreatedBy graph statement by invoking async NPM module - izara-graph-service#edgeLib.createRelationshipStatement
    1. subjectId: objectId
    2. edgeLabel: 'CreatedBy'
    3. edgeId: createdByEdgeId
    4. objectId: userVertexId