All files / lib/model/nw/extensions/sap EntityContainerExtender.js

100% Statements 17/17
100% Branches 2/2
100% Functions 6/6
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86    1x   1x 9x       1x                                     1x             1x   1x             9x       9x 2x                                         9x       9x 11x   9x 9x 7x         1x  
"use strict";
 
const ExtenderBase = require("./ExtenderBase");
 
const ATTRIBUTES_ENTITY_CONTAINER = [
  ["supported-formats", (value) => (value || "atom json").split(" ")],
  ["use-batch", ExtenderBase.defaultFalseBool],
];
 
const ATTRIBUTES_ENTITY_SET = [
  ["addressable", ExtenderBase.defaultTrueBool],
  ["change-tracking", ExtenderBase.defaultFalseBool],
  ["countable", ExtenderBase.defaultTrueBool],
  ["creatable", ExtenderBase.defaultTrueBool],
  ["deletable", ExtenderBase.defaultTrueBool],
  ["deletable-path"],
  ["delta-link-validity"],
  ["label"],
  ["maxpagesize"],
  ["pageable", ExtenderBase.defaultTrueBool],
  ["requires-filter", ExtenderBase.defaultFalseBool],
  ["searchable", ExtenderBase.defaultFalseBool],
  ["semantics"],
  ["topable", ExtenderBase.defaultTrueBool],
  ["updatable", ExtenderBase.defaultTrueBool],
  ["updatable-path"],
];
 
const ATTRIBUTES_FUNCTION_IMPORT = [
  ["action-for"],
  ["applicable-path"],
  ["label"],
  ["planning-function"],
];
 
const ATTRIBUTES_PARAMETER = [["label"]];
 
const ATTRIBUTES_ASSOCIATION_SET = [
  ["creatable", ExtenderBase.defaultTrueBool],
  ["deletable", ExtenderBase.defaultTrueBool],
  ["updatable", ExtenderBase.defaultTrueBool],
];
 
function processFunctionImport(functionImport) {
  ExtenderBase.applyAttributeExtension(
    functionImport,
    ATTRIBUTES_FUNCTION_IMPORT
  );
  functionImport.parameters.forEach((p) =>
    ExtenderBase.applyAttributeExtension(p, ATTRIBUTES_PARAMETER)
  );
}
 
/**
 * Envelope for sap vendor specific extensions for entity container.
 *
 * https://wiki.scn.sap.com/wiki/display/EmTech/SAP+Annotations+for+OData+Version+2.0
 * https://github.com/SAP/odata-vocabularies
 *
 * @class EntityContainerExtender
 */
class EntityContainerExtender {
  /**
   * Process extension for entity type and child elements.
   *
   * @static
   * @param {Object} entityContainer schema element to be processed
   * @memberof EntityContainerExtender
   */
  static process(entityContainer) {
    ExtenderBase.applyAttributeExtension(
      entityContainer,
      ATTRIBUTES_ENTITY_CONTAINER
    );
    entityContainer.entitySets.forEach((es) =>
      ExtenderBase.applyAttributeExtension(es, ATTRIBUTES_ENTITY_SET)
    );
    entityContainer.functionImports.forEach(processFunctionImport);
    entityContainer.associationSets.forEach((fi) =>
      ExtenderBase.applyAttributeExtension(fi, ATTRIBUTES_ASSOCIATION_SET)
    );
  }
}
 
module.exports = EntityContainerExtender;