From 311a686f3672a00c8def9190c874d6f83a006e35 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 6 Aug 2018 01:04:54 +0000 Subject: [server/external-backends] Implemented import Objects from iDoIT renamed external-backends.js in index.js so its return when requireing the folder Added new tables for the external id mapping for clients / groups iDoIT method for importing Objects and adding them in the db with all neccessary constraints --- server/lib/external-backends/index.js | 104 ++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 server/lib/external-backends/index.js (limited to 'server/lib/external-backends/index.js') diff --git a/server/lib/external-backends/index.js b/server/lib/external-backends/index.js new file mode 100644 index 0000000..c882522 --- /dev/null +++ b/server/lib/external-backends/index.js @@ -0,0 +1,104 @@ +/* global __appdir */ +const fs = require('fs') +const path = require('path') + +class ExternalBackends { + /* + * Returns a list of all backends which have a .js file. + */ + getBackends () { + var files = fs.readdirSync(path.join(__appdir, 'lib', 'external-backends', 'backends')) + return files + } + + /* + * Returns the credential structure / fields, defined in the backends. + * + * If type === switch there can be child elements in the elements attribute. + * Those elements are only shown, if the switch is set to true. + * [{ type: 'text', id: 1, name: '', icon: '' }, + * { type: 'password', id: 2, name: '', icon: '' }, + * { type: 'switch', id: 3, name: '', icon: '' , elements: [ { type: ... } ] }, + * { type: 'select', id: 4, name: '', icon: '' }, ...] + */ + getCredentials () { + console.log('If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!') + return null + } + + /* + * type: + * + * Returns the instance of a given backend type. + */ + getInstance (type) { + const bList = this.getBackends() + const bType = type + '-backend.js' + + // Check if it's a valid backend type. + if (bList.indexOf(bType) === -1) { + console.log(bType + ' is not a valid backend type.') + return null + } + + const backend = new (require(path.join(__appdir, 'lib', 'external-backends', 'backends', bType)))() + return backend + } + + /* Returns an empty array [] if the backends doesn't have the function implemented. + * + * return: ['', ...] + */ + getSyncTypes () { + return [] + } + + /* + * credendtials: + * + * Returns a list of all objects in the backend. + */ + async getObjects (credendtials) { + return { status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a getObjects method' } + } + + /* + * credendtials: + * oid: + * + * Call the API of the backend and returns the information to the object including a list of childs. + */ + async getObject (credentials, oid) { + return { status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a getObject method' } + } + + /* + * credentials: + * objects: [{ eid: , gid: }, ...] + * EXTERNAL_ID is the id of the objects in the external backend requestet. + * + * return: [{ gid: , childs: [{ id: , }, ...]}, ...] + */ + getDataTree (credendtials, objects) { + return { status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a getDataTree method' } + } + + /* + * Checks the connection of a given backend. + * + * return: { success: , status: '', error: '' } + */ + async checkConnection (backend) { + return { success: false, status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a checkConnection method' } + } + + /* Returns an empty array [] if the backends doesn't have such a function. + * + * return: [{id: , title: }, ...] + */ + async getObjectTypes (credentials) { + return [] + } +} + +module.exports = ExternalBackends -- cgit v1.2.3-55-g7522