messaging_Connectors.js.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: messaging/Connectors.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: messaging/Connectors.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * Licensed Materials - Property of IBM
  21. * IBM Cognos Products: Collaboration
  22. * (C) Copyright IBM Corp. 2017, 2018
  23. *
  24. * US Government Users Restricted Rights - Use, duplication or disclosure
  25. * restricted by GSA ADP Schedule Contract with IBM Corp.
  26. */
  27. define([
  28. '../lib/@waca/core-client/js/core-client/ui/core/Class',
  29. './connectors/index'
  30. ], function (Class, connectors) {
  31. 'use strict';
  32. var Connectors = Class.extend( /** @lends Connectors */ {
  33. /**
  34. * @desc Constructor for Connectors.
  35. * @constructs Connectors
  36. * @extends Class
  37. * @public
  38. * @param {object} options Options
  39. * @param {object} options.glassContext The glass context
  40. * @param {function} options.errorHandler Function to call when an error occurs
  41. */
  42. init: function (options) {
  43. Connectors.inherited('init', this, arguments);
  44. this.glassContext = options.glassContext;
  45. if (!this.glassContext) {
  46. throw Error('Missing glassContext in options');
  47. }
  48. this.logger = this.glassContext.getCoreSvc('.Logger') || {
  49. log: console.log,
  50. error: console.error
  51. };
  52. this.errorHandler = options.errorHandler;
  53. // holds configured connectors
  54. this.connectors = [];
  55. },
  56. /**
  57. * Discovers all the providers' and returns their connector instances.
  58. * @instance
  59. * @returns {promise}
  60. */
  61. discover: function () {
  62. var ajaxSvc = this.glassContext.getCoreSvc('.Ajax');
  63. return ajaxSvc
  64. .ajax({
  65. type: 'GET',
  66. url: 'v1/collaboration/providers?flat=true'
  67. })
  68. .then(function (response) {
  69. return response.data.map(function (provider) {
  70. return this._handleSingleProvider(provider);
  71. }.bind(this));
  72. }.bind(this))
  73. .then(function (results) {
  74. return results
  75. // remove any unsupported/unknown connectors
  76. .filter(function (result) {
  77. return !!result;
  78. })
  79. // remove any connectors for which the user doesn't have the required capabilities
  80. .filter(function(result) {
  81. return result.checkUserCapabilities();
  82. });
  83. });
  84. },
  85. _handleSingleProvider: function (meta) {
  86. try {
  87. var Plugin = connectors[meta.type];
  88. if (Plugin) {
  89. var plugin = new Plugin({
  90. glassContext: this.glassContext,
  91. errorHandler: this.errorHandler,
  92. meta: meta
  93. });
  94. // ...and store it
  95. this.connectors.push(plugin);
  96. return plugin;
  97. } else {
  98. this.logger.error('Unable to load plugin: ' + meta.type);
  99. }
  100. } catch (error) {
  101. this.logger.error('Error while creating connector instance', error);
  102. }
  103. // null connectors will be removed below once all the promises are resolved
  104. return null;
  105. }
  106. });
  107. return Connectors;
  108. });</code></pre>
  109. </article>
  110. </section>
  111. </div>
  112. <nav>
  113. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ConnectorBase.html">ConnectorBase</a></li><li><a href="Connectors.html">Connectors</a></li><li><a href="EmailClient.html">EmailClient</a></li><li><a href="EmailConnector.html">EmailConnector</a></li><li><a href="MSTeamsAuth.html">MSTeamsAuth</a></li><li><a href="MSTeamsClient.html">MSTeamsClient</a></li><li><a href="MSTeamsConnector.html">MSTeamsConnector</a></li><li><a href="ShareableItems.html">ShareableItems</a></li><li><a href="ShareController.html">ShareController</a></li><li><a href="ShareView.html">ShareView</a></li><li><a href="SlackAuth.html">SlackAuth</a></li><li><a href="SlackClient.html">SlackClient</a></li><li><a href="SlackConnector.html">SlackConnector</a></li></ul><h3>Interfaces</h3><ul><li><a href="ShareInterface.html">ShareInterface</a></li></ul>
  114. </nav>
  115. <br class="clear">
  116. <footer>
  117. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed May 25 2022 13:54:53 GMT+0000 (UTC)
  118. </footer>
  119. <script> prettyPrint(); </script>
  120. <script src="scripts/linenumber.js"> </script>
  121. </body>
  122. </html>