define([
'entity/js/api/DataModel',
'entity/js/api/DataModelHooks'
], function (
DataModel,
DataModelHooks
) {
'use strict';
/**
* Entity API shorthand module.
*
* <p>Provides various entry-point methods into the Entity API, mainly for
* aquiring entity instances.</p>
*
* @AbcsAPI stable
* @version 15.4.5
* @exports api/js/Entities
*/
var Entity = function() {
AbcsLib.throwStaticClassError();
};
/**
* Finds entity by a given ID - ignoring the case
*
* @AbcsAPI stable
* @version 15.4.5
* @param {String} entityId ID of the entity to get
* @returns {entity/js/api/Entity} entity
*
* @example
* <caption>
* Gets an instance of an entity with a given ID.
* </caption>
* var Entities = Abcs.Entities();
*
* var entity = Entities.findById('EntityID');
*/
Entity.findById = function (entityId) {
var res;
if (entityId) {
res = DataModel.getInstance().getEntities().getEntityById(entityId);
if (!res) {
// API backwards compatability with migrated entity ids
res = DataModelHooks.findLegacyId(entityId);
}
}
// Hidden BOs shouldn't be exposed via public API
if (res && !res.isHidden()) {
return res;
}
};
/**
* Gets all entities.
*
* @AbcsAPI stable
* @version 15.4.5
* @returns {entity/js/api/Entity[]} array of entities
*
* @example
* <caption>
* Gets instances of all entities known to ABCS and prints all their
* properties.
* </caption>
* var Entities = Abcs.Entities();
*
* var entityInstances = Entities.getAll();
* // do something with the entities
* entityInstances.forEach(function (entity) {
* // do something with the entity, such as:
* console.log('Entity ' + entity.getId() + ' has the following properties:');
* entity.getProperties().forEach(function (property) {
* console.log(property.getId());
* };
* };
*/
Entity.getAll = function () {
return DataModel.getInstance().getEntities().getEntities(); //getEntities().getEntities() will be fixed as well :-)
};
/**
* Holds data related to the current logged-in User.
*
* <p>
* This object describes the structure of data records for
* {@link api/js/System.ENTITY_LOGGED_USER ENTITY_LOGGED_USER} entities.
* </p>
*
* @AbcsAPI stable
* @memberof module:api/js/Entities
* @objectLiteral
*
* @see {@link module:api/js/System.getLoggedInUser System.getLoggedInUser}
* @see {@link module:api/js/System.ENTITY_LOGGED_USER System.ENTITY_LOGGED_USER}
*/
var UserEntity = function() {
};
/**
* Holds currently logged-in user's login name.
*
* @AbcsAPI stable
* @version 15.4.5
* @type {string}
*/
UserEntity.prototype.username = '';
/**
* Holds currently logged-in user's full name.
*
* @AbcsAPI stable
* @version 15.4.5
* @type {string}
*/
UserEntity.prototype.fullname = '';
/**
* Holds currently logged-in user's email.
*
* @AbcsAPI stable
* @version 15.4.5
* @type {string}
*/
UserEntity.prototype.email = '';
/**
* Holds system information.
*
* <p>
* This object describes the structure of data records for
* {@link api/js/System.ENTITY_SYSTEM_INFO ENTITY_SYSTEM_INFO} entities.
* </p>
*
* @AbcsAPI stable
* @memberof module:api/js/Entities
* @objectLiteral
*
* @see {@link module:api/js/System.getSystemInfo System.getSystemInfo}
* @see {@link module:api/js/System.ENTITY_SYSTEM_INFO System.ENTITY_SYSTEM_INFO}
*/
var SystemInfo = function() {
};
/**
* Holds current date and time.
*
* @AbcsAPI stable
* @version 15.4.5
* @type {Date}
*/
SystemInfo.prototype.datetime = null;
return Entity;
});