JavaScript Extension Development API for Oracle Visual Builder Cloud Service - Classic Applications

Source: api/js/System.js

define([
    'core/js/api/SharedObjectRegistry',
    'core/js/api/user/UserProvider'
], function (
    sharedObjectRegistry,
    UserProvider
    ) {

    'use strict';

    /**
     * Each generated application/page has access to this object via 'Abcs.System'
     * variable and can refer to variety of global objects, constants and functions
     * defined here. In long term end user should be able to include their own
     * global constants and functions here.
     *
     * @AbcsAPI stable
     * @version 15.4.5
     *
     * @exports api/js/System
     */
    var System = function() {
        AbcsLib.throwStaticClassError();
    };

    /**
     * Namespace for ABCS internal entities.
     * Only ABCS internal entities should be prefixed with this namespace, other
     * entities are not allowed to start with this namespace.
     *
     * @static
     * @constant
     * @type {string}
     */
    System.ABCS_INTERNAL_NAMESPACE = 'Abcs.Internal';

    /**
     * Id of the system wide entity holding data about logged in user.
     * <p>
     * Data records for the entity identified by this ID have format
     * described in {@link module:api/js/Entities.UserEntity Entities.UserEntity}.
     *
     * @AbcsAPI stable
     * @version 15.4.5
     * @static
     * @constant
     * @type {string}
     */
    System.ENTITY_LOGGED_USER = System.ABCS_INTERNAL_NAMESPACE + '.LoggedInUser';

    /**
     * Id of the system wide entity holding data the system.
     * <p>
     * Data records for the entity identified by this ID have format
     * described in {@link module:api/js/Entities.SystemInfo Entities.SystemInfo}.
     *
     * @AbcsAPI stable
     * @version 15.4.5
     * @static
     * @constant
     * @type {string}
     */
    System.ENTITY_SYSTEM_INFO = System.ABCS_INTERNAL_NAMESPACE + '.SystemInfo';

    /**
     * ID of the system wide entity representing error code.
     */
    System.ENTITY_ERROR_CODE = System.ABCS_INTERNAL_NAMESPACE + '.ErrorCode';

    /**
     * Gets logged user information.
     *
     * @AbcsAPI stable
     * @version 15.4.5
     * @returns {module:api/js/Entities.UserEntity} current logged-in user
     * @static
     */
    System.getLoggedInUser = function () {
        var user = UserProvider.getUser();
        return {username: user.getId(),
            fullname: user.getFullName(),
            email: user.getEmail()};
    };

    /**
     * Gets system information.
     *
     * @AbcsAPI stable
     * @version 15.4.5
     * @returns {module:api/js/Entities.SystemInfo} system info
     * @static
     */
    System.getSystemInfo = function () {
        return {datetime: new Date()};
    };

    /**
     * Gets a shared object registered into ABCS system with the given id.
     * <p>Shared object is a global object providing various methods, fields and
     * functionality possibly registered by third-party individuals.</p>
     *
     * @AbcsAPI stable
     * @version 16.1.5
     * @param {String} id unique shared object identifier.
     * @returns {Object} shared object registered in the ABCS system with
     * a unique id or {@code undefined} if no such object is found.
     * @static
     *
     * @example
     * <caption>
     * Shows how to get a shared object and access its method.
     * </caption>
     * // get the shared object
     * var myObject = Abcs.System().getSharedObject('org.my.mySharedObject');
     * // call shared object's method
     * var message = myObject.getMessage();
     *
     * Abcs.UI().showNotification(Abcs.UI().Notification.create({
     *      message: message
     * });
     *
     */
    System.getSharedObject = function (id) {
        AbcsLib.checkParameterCount(arguments, 1);
        AbcsLib.checkDefined(id, 'id');
        return sharedObjectRegistry.getSharedObject(id);
    };

    return System;

});