NAME

AuroraDB - Interface methods to the AURORA database.

SYNOPSIS

my $dbfile="./aurora.db";
my $db=AuroraDB->new(data_source=>"DBI:SQLite:dbname=$dbfile",user=>"",pw=>"");

# create a entity of type GROUP
my $id=$db->createEntity($db->getEntityTypeIdByName("GROUP"));

# set some metadata
my %md;
$md{".DublinCore.Creator"}="Albert Einstein";
$md{".DublinCore.Created"}="20190101";
if (!$db->setEntityMetadata($id,\%md)) {
   print "Failed to set entity $id's metadata: ".$db->error()."\n";
}

# get the metadata
my $m;
$m=$db->getEntityMetadata($id);
use Data::Dumper;
print "METADATA: ".Dumper($m);

DESCRIPTION

This module interfaces with the AURORA database. AURORA stands for Archive and Upload Research Objects for Retrieval and Alteration and was created at the Norwegian University of Science and Technology (NTNU) in Trondheim, Norway to facilite retrieval of data from science labs, storage of the datasets and the ability to flexibly add metadata on each dataset.

The AURORA database module was written to be general enough to be used with most SQL engines, while still trying to optimize functions where necessary.

The AURORA database module was written by Bård Tesaker and Jan Frode Jæger

CONSTRUCTOR

new()

Instantiates the AuroraDB-class: new(data_source=>P,pw=>Q,pwfile=>R,user=>S,cachetime=>T)

Required parameters are:

The method returns the reference to the instantiated class.

METHODS

addEntityMember()

Adds a member to an entity.

Accepts these inputs in the following order:

The method returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.

assignEntityTemplate()

Assigns template(s) to an entity.

Input is in the following order:

Previous assignment on the given entity and type are overwritten with the new assignment.

Return value is 1 upon success or 0 upon failure. Check the error()-method for more information on the error.

checkEntityTemplateCompliance()

Checks a set of metadata key->value pairs compliance with an entity's aggregated template.

Input for this method are in the following order:

The return value is a HASH-reference. Undef is returned upon failure. Check the error()-method for more information upon failure.

The format of the return HASH is as follows:

( compliance => VALUE,
  noncompliance => LIST,
  metadata => { KEYx => { value => SCALAR,
                          compliance => BOOLEAN,
                          default => SCALAR,
                          regex => SCALAR,
                          flags => BITMASK,
                          min => SCALAR,
                          max => SCALAR,
                          comment => SCALAR,
                        },
                KEYy => { ... },
              },
)

The top compliance value gives the overall compliance of all the metadata in a boolean (1=success,0=failure). The noncompliance value is a LIST of keys that failed compliance (if any). The metadata sub-hash gives all the keys that the input metadata had and if they are compliant or not, their template and so on. It will also contain any missing keys and their value taken from the aggregated template of the entity when those keys are missing and the MANDATORY-flag has been set.

See also the getTemplate and setTemplate methods for documentation upon the format of the templates.

clearBitmask()

Clear bits in a bitmask.

Input is the bitmask to modify and bitmask with bits to clear. Default parameters is ''.

Return value is the resulting bitmask as a SCALAR. The input bitmask is unaltered.

clearBits()

Clear bits in a bitmask.

Input is the bitmask to modify and a list of bit numbers to clear. Default bitmask is ''.

Return value is the resulting bitmask as a SCALAR. The input bitmask is unaltered.

connected()

This method attempts to check if the we are connected to the database or not by quering the DBI-instance: connected()

Returns 1 upon being connected and 0 upon not being connected.

createBitmask()

Creates a bitmask based upon the bit number specified in the input list - iterates on the vec-method in Perl.

Input is the bit numbers to set as a LIST.

Return value is the bitmask as a SCALAR.

createEntity()

Creates an entity of a given type in the database: createEntity([type],[parent])

Input are in the following order:

Return value is the created entity's id or undef upon failure. Please call the error-method for more information on the failure.

createMetadataKey()

Creates a metadata key in the database.

Input is the name of the metadata key to create (assign a metadata key id).

Return value is the metadata key id created or if it already exists its existing key id. Undef is returned upon failure. Please call the error-method to get more information about the error.

createPermBitmask()

Creates a permission bitmask based upon a mix of names and bit position values.

Input is a LIST fo permission name(s) and/or bit position value(s).

Returns a bitmask of those name(s) and/or value(s). Undef is returned upon failure. Please check the error()-method in such cases.

createTemplate()

Creates a template in the database and sets the given constraints.

Input for the method are these options in the following order:

The method creates the template and sets the template constraints on the template.

Return value is the new template id upon success or 0 upon failure. Check the error-message by calling the error()-method.

deconstructBitmask()

Deconstruct a given bitmask into the bit numbers that have been set.

Input is the bitmask to deconstruct.

Return value is a LIST of bit numbers that have been set.

deleteEntity()

Deletes an entity of the given entity id from the database: deleteEntity(id)

Input is entity id to delete or it will default to the invalid entity id of zero.

It will delete all references to this entity in the database, including permission memberships, template assignments, log entries and metadata. A deletion will only succeed if the entity does not have any children entity(ies). Children must first be moved or deleted.

Return value is 1 upon success, 0 upon failure. Call the error-method to get more information on the failure.

deleteEntityMetadata()

Deletes metadata from an entity moderated by a set of metadata keys.

Input is in the following order:

Return value is 1 upon success, 0 when there are no rows to delete and undef upon failure. Please call the error-method to inquire about the details of the error in question.

deleteTemplate()

Deletes a template and its constraints and assignments to it.

Input is the template id.

Return value is 1 upon success, 0 upon failure. Check the error()-method for more information upon a failure.

doSQL()

This method prepares and executes a SQL statement and then checks the result: doSQL(SQL-Statement)

Input is the SQL statement to execute as a SCALAR. Return values are the DBI-class's statement handle upon success, undef upon failure. Please check the error-method to find out more about the issue.

This method is called from most methods in the AuroraDB-class and handles every relevant side of executing SQL-statements and handling errors. It also connects to the database if not already connected.

enumEntitiesByType()

Returns all entities of a certain type.

Input is entity type(s) as a LIST-reference. The entity type(s) are optional and if none is specified all entities will be returned.

Return value is a reference to a LIST entity id(s), if any.

It will return a reference to a LIST of entity id(s) upon success (it migth be an empty list), undef upon failure. Upon failure, call the error-method for more information on the failure.

enumEntityTypes()

Enumerates the entity type ids of the AURORA database: enumEntityTypes(). Returns a LIST of entity type IDs.

No input is required. It returns the list upon success, undef upon failure. Please check the error-method for more information on the failure.

enumLoglevels()

Enumerates the loglevels in the database.

Input is none. It returns the loglevel ids on success as a LIST-reference, undef upon failure. Call the error()-method to check information on the error.

enumPermTypes()

Enumerates the permission type names that exists in the AURORA database.

It accepts no input.

Return value is a LIST of permission type names.

enumTemplateFlags()

Enumerates the template flags that exists in the database.

Returns a sorted LIST of template flag values.

error()

Gets the last error message from the AuroraDB library and its methods. Its functionality is used and referred to by all methods.

No input required and the return value is the last error message that has happened or ""/blank if no error message found.

existsEntity()

Checks to see if an entity exists or not? existsEntity(id).

Input is entity id to check or it will default to the invalid entity id of zero.

Return value is the entity id upon success, id zero if not existing, undef upon failure. Please call the error-method for more information.

getDBI()

This method attempt to return the DBI-object that AuroraDB creates: getDBI(). If it is not already created it attempts to connect to the database and then return the instance.

The method requires no input.

Return value is the instance of the DBI-class. Returns undef upon error. Check the error-method to get more information on the issue.

It is called from the most relevant method, such as doSQL.

disconnect()

Attempts to disconnect from database if already connected.

This method requires no input.

Returns 1 upon success, 0 upon some failure and undef if database is not connected already. Please check the error()-method for more information upon failures.

getEntityByMetadataKeyAndType()

Retrieves the entity(ies) id that matches the criteria given. There must exist one or more metadata on the entity(ies) searched for in order for this method to succeed.

The method takes the following parameters in the following order:

The return value is a reference to a LIST of entity id(s) upon success in the order stated by the orderby- and order-options, or undef upon failure. Call the error-method to know more about the failure.

When using the offset- and count-options to create search windows it will also set the total number of entity(ies) found independant of the search window. This count can be retrieved by calling the getLimitTotal()-method after a successful call to this method with the offset-options.

getEntityByPermAndType()

Gets entity(ies) based upon a permission mask and entity type(s).

The method takes these options in the following order:

Return value from method is a reference to a HASH in the format: entity => PERM. The PERM gives the complete perm for the given entity for the stated subject.

getEntityChildren()

Gets an entity's children.

Input is in the following order: entity id, entity type(s), recursive. The entity id is the entity parent to get the children of. The entity type(s) are the type(s) to get in the result (LIST-reference). It is optional and if not set will return entities of all types. The "recursive" sets if one is to fetch all children recursively for given parent and not only its immediate children.

It returns the parents children entity ids upon success as a LIST-reference, undef upon some failure. Please check the error()-method for more information upon failure.

getEntityChildrenPerm()

Gets an entitys perm on a given entity's children: getEntityChildrenPerm

This method takes these options in the following order:

The method returns a reference to a HASH-structure in the following format:

( ID => PERM,
  ID => PERM,
)

where ID is the entity ID of ones of the object's children (see object-option). PERM is the permission mask on that child, relative to the subject (see subject-option).

Upon failure the method returns undef. Please check the error()-method for more information upon a failure.

getEntityMembers()

Get all members of given entity.

Accepts one input and that is the entity id of the entity to list the members of.

Returns a LIST-reference of entity ids that are members of the given entity:

(entity id,entity id, entity id)

The LIST can be empty. The LIST-reference is undef upon failure. Please check the error()-method for more information.

getEntityMetadata()

Gets an entity's metadata moderated by a set of metadata keys.

Required input is in the following order:

Return value is the metadata HASH-referemce with key->values (it can be empty logically enough). Upon failure undef is returned. Please call the error-method to find out more about the error.

getEntityMetadataList()

Returns a HASH-reference of entities metadata value for a given metadata-key.

Input is in the following order: metadata-keyname, entities. The metadata-keyname is the key-name for the key to get values for. The entities parameter is the entities to return that metadata-value for (LIST-ref). The entities-parameter is optional. If not given it will match against all entities in the database. And the last parameter accepted is "parent" that decides if the metadata is fetched from METADATA_COMBINED or just from METADATA. If parent is 1 (true) the metadata is fetched from METADATA_COMBINED instead of METADATA in the database. If parent is 0 or anything else metadata is fetched from METADATA.

Returns a HASH-reference upon success, undef upon failure. Please check the error()-method for more information upon failure.

The structure of the HASH returned is as follows:

(
   entid => VALUE (SCALAR or LIST)
   entid => VALUE (SCALAR or LIST)
   .
   .
   entid => VALUE (SCALAR or LIST)
)  

The VALUE will either be a SCALAR or a LIST, depending upon if the metadata key in question has multiple values or not (ARRAY or not).

getEntityMetadataMultipleList()

Returns a HASH-reference of entities metadata value for a given metadata-keys (or all keys).

Input is in the following order: metadata-keyname(s), entities, parent. The metadata-keyname is the key-name(s) for the key(s) to get values for as a LIST-reference. It can be undefined or empty upon which all metadata keys will be fetched. The entities parameter is the entities to return that metadata-value for (LIST-ref). The entities-parameter is optional. If not given it will match against all entities in the database. And the last parameter accepted is "parent" that decides if the metadata is fetched from METADATA_COMBINED or just from METADATA. If parent is 1 (true) the metadata is fetched from METADATA_COMBINED instead of METADATA in the database. If parent is 0 or anything else metadata is fetched from METADATA.

Returns a HASH-reference upon success, undef upon failure. Please check the error()-method for more information upon failure.

The structure of the HASH returned is as follows:

(
   entid => {
              KEYNAMEa => VALUE (SCALAR or LIST)
              .
              .
              KEYNAMEz => VALUE (SCALAR OR LIST)
            }
   entid => {
              KEYNAMEa => VALUE (SCALAR or LIST)
              .
              .
              KEYNAMEz => VALUE (SCALAR or LIST)
)  

The VALUE will either be a SCALAR or a LIST, depending upon if the metadata key in question has multiple values or not (ARRAY or not). The metadata keys are given its full textual name which then points to the VALUE. Not all entities need to have all KEYNAME values present and depends upon what is available in the database for that given entity ID.

getEntityParent()

Gets an entity's parent.

Input is the entity id to get the parent of.

It returns the parent entity id upon success, 0 upon some failure. Please check the error()-method for more information upon failure.

getEntityPath()

Gets entity(ies)'s parent and their parents (ancestors): getEntityPath(id1,id2,id3..idN).

Input is the entity id(s) that one wants to get the parent and ancestors of.

Return value is dependant upon the number of IDs asked for. In all cases the return value for a given entity is a LIST of ancestral entities in descending order (including the entity itself).

If the caller asked for just one ID, the return structure is a LIST as follows (backwards-compatible):

(ANCESTOR1,ANCESTOR2,ANCESTOR3..ID)

If the caller asked for more than just one ID, the return structure is a HASH-reference as follows:

(
   ID1 => [ANCESTOR1,ANCESTOR2..ID1],
   ID2 => [ANCESTOR1,ANCESTOR2,ANCESTOR3..ID2],
   .
   .
   IDn => [ANCESTOR1..IDn],
)

If some error occured the return value is undef. Check error()-method to get more information on a potential error.

getEntityPerm()

Gets an entitys permissions on a given object/entity: getEntityPerm(subject,object).

Input is in the following order:

Returns a bitmask that is an aggregate of permissions from the entity tree. The DENY mask is added before the GRANT. Returns undef upon failure. Please call the error-method for more details upon errors.

getEntityPermByObject()

Gets the permissions on a specific entity (no ancestors):

Input are in the follwing order:

The return value is a LIST of grant and deny permission masks, in that order.

Returns undef upon failure. Call the error-method to find more details on the error in question.

getEntityPermByMetadataKeyAndType()

Retrieves the entities that match the criteria of metadata and type and the permission on them for a given entity (subject). This method is a wrapper around the getEntityPerm()- and getEntityByMetadataKeyAndType()-methods.

The method takes these options in the following order:

Return value is a reference to a HASH of permissions for entity(ies). Upon failure undef is returned. Check the error()-method for more information on error.

The format of the returned HASH is:

( POS => { entity => ID,
           perm => PERM,
         }
)

where POS is the numbered position in the search result, ID the entity ID and PERM the permission mask on that entity ID.

getEntityPermByPermAndMetadataKeyAndType

Retrieves entity(ies) by a permission mask and moderated for by a metadata key->value structure and entity type(s). It is a wrapper around getEntityByPermAndType()- and getEntityByMetadataKeyAndType()-methods.

The method takes these options in the following order:

Returns a reference to a HASH-structure upon success, undef upon failure. Check the error()-method for more information on a potential error.

The format of the returned HASH-structure is:

( POS => 
   { entity => ID,
     perm => PERM,
   },
)

Where POS is the numbered position in the returned and ordered result (always starting from 1, even with search windows). ID is the entity ID in position POS and PERM is the permission mask in the same position.

getEntityPermCheck()

This method checks if an entity has all the permission of the given bitmask on a specific object.

The method have these options in the following order:

The method returns 1 if the subject entity has the required permissions, 0 if not. Undef is returned upon failure. Please check the error()-method in such a case.

getEntityPermsForObject()

Gets the permissions on a object:

Input are in the following order:

The return value is a HASH of object => permission of objects thet match the criteras.

Returns undef upon failure. Call the error-method to find more details on the error in question.

getEntityPermsForSubject()

Gets the permissions held by a subject:

Input are in the follwing order:

The return value is a HASH of object => permission of objects thet match the criteras.

Returns undef upon failure. Call the error-method to find more details on the error in question.

getEntityPermsOnObject()

Gets the permissions on an object:

Input are in the follwing order:

The return value is a HASHREF of subjects with permissions on an object. Take into account the objects inheritance, but not implisit or explisit subject membership. Hash key is subject id, value is a hash with mask for inherit, deny, grant and perm ( grant | inherit & (~inherit ^ deny))

Returns undef upon failure. Call the error-method to find more details on the error in question.

getEntityRoles()

Get a list of roles for an entity: getEntityRoles(id).

Roles are the entity itself,its ancestors and any entity tied directly or indirectly to any of them through the databases MEMBER-table.

Returns an unsorted list without duplicates. Undef upon error. Check the error()-method to get more information upon failure.

getEntityTemplate()

Get an aggregated template for an entity.

Input is in the following order:

The return value is a HASH-reference to a set of template constraints. If any of the constraints on a given metadatakey has not been set, it will revert to defaults. The defaults are as follows:

Inheritance on templates works by going from the first entity specified in the entities-parameter LIST-ref to this method and down to the last entity in that list (often the entity you need to know the aggregated template of).

Only whole key-constraints will supplant another one while recursing the tree defined in the entities-parameter. This means that parts of the key, like say max or min, will not replace just max and min. All the constraints for the key in question will be replaced upon finding a replacement key constraint definition, even undef.

Similarly, the default-constraint will not accumulate defaults as in traverses down the entity tree, but replace any defaults earlier in the tree with the new defaults defined for that key in the template being processed.

Let us assume we have the entities GROUP, USER, DATASET in addition to the special TEMPLATE-entity type.

All entities in AuroraDB can have any number of templates assigned to them (up to the limits of the database), but all assignments are type- specific. This means that the templates assigned on an entity belong in an entity type group. Eg. one can assign any number of templates having effect for DATASET-entities on a GROUP-entity. The templates themselves are type- neutral and only gain templating effect once they are assigned on an entity (see the assignEntityTemplate()-method) and a entity type for that entity.

All entities can have template assignments for entity types that are not the same as itself, since this is about aggregated templates and inheritance. When calling the getEntityTemplate()-method is called it will require the entity type to be specified in order to figure out the aggregated template.

At the end of the aggregation process, any missing or undefined constraints for a specific key will be defaulted to standard values (see above).

Upon success this method will return a HASH-reference to a aggregated entity template, undef will be returned upon any error. Please call the error()-method for more information upon failure.

See the setTemplate()-method for more information on the format of the returned, aggregated template. Please note, however, that the getEntityTemplate()-method will add two fields to the template of each "key" that are called "template" and "assignedto". The "template" fields tell which template affected the last change on the definition and "assignedto" says on which entity that this template was assigned. This information enables the user to know if the aggregated template result for a given "key" is defined on the entity that one asked for the aggregated template of, or if it was inherited from above (the assignedto id is not the same as the entity asked for). It also says which template effected that result.

getEntityTemplateAssignments

Gets template assignment(s) on an entity

Input is in the following order:

This method gets template assignment(s) on an entity and optionally just of a given type. All templates are assigned to entities based upon what type the template is to have effect for. By giving a set type, only the assignment(s) for that type on the entity in question are returned. If no type is specified this method will return all template assignments set on the entity.

Upon success returns a HASH-reference of the assignments, undef upon failure. Please check the error()-method for more information upon failure.

The return structure upon success is as follows:

(
   TYPEa => [TEMPLATEID1,TEMPLATEID2 .. TEMPLATEIDn]
   .
   .
   TYPEz => [TEMPLATEID4,TEMPLATEID5 .. TEMPLATEIDn]
)

where TYPEa and so on are the entity type id of the type assignment. TEMPLATEID1 and so on is the entity id of the template that are assigned on the given type. This is an ARRAY-reference of template entity ids and the array returns the assignments in the order that they are set, starting from element 0 and up.

If no assignments have been set on the entity in question (or of the chosen type), the HASH-structure will be empty.

getEntityTemplateId()

Retrieve template assignments on a given entity(ies). This is actual template id's and not an aggregated template.

Input is entity type to fetch template for and entity id they belong to accordingly. Entity id is expected to be a LIST of one or more elements. We recommend not using more than one elements, since it will be impossible to know which template id belongs to which entity?

Return value is a LIST reference upon success, undef upon failure. Check the error()-method for more information upon failure.

The LIST returned contains template id's that belongs to the given entity. The list is ordered according to when the templates take effect.

getEntityTemplatePath()

Retrieves the path for an entity's templates. As of writing a wrapper around getEntityPath.

See getEntityPath()-method for more information.

getEntityTree()

Gets the entity tree from given entity id.

Input is in the following order:

Returns a HASH-reference of the entities in the tree and their children with attributes.

The return HASH-structure is as follows:

(
  IDa => {
          id => IDa,
          type => INT,
          children => [ IDb...IDn ],
        }
  IDb => {
          id => IDb,
          parent => IDa,
          type => INT,
          children => [],
        }
)

IDx is the INT entity id. The subhash specified the ID of that entity again in the key id. It also gives the entity's type and parent, except for the root entity 1 (IDa in example above), which has no parent (or technically itself). It also contains a LIST of children with IDs of its immediate children (that has it has its parent). The returned HASH is therefore flat and all entities in the tree can be addressed at its root level.

Returns undef upon failure. Check error()-method for more information on the failure.

getEntityType()

Retrives the entity type of an entity id: getEntityType(entityid)

Input is entity id or it will default to the invalid id of zero.

Return value is the entity type of id referenced upon success, or 0 upon failure. Please call the error-method for more details.

getEntityTypeIdByName()

Retrieves the entity type id based upon the textual name input to the method: getEntiyTypeIdByName([name1,name2..nameN]);

No input is required and then all entity type ids are returned. If one or more names are specified (comma separated), it will return the entity type ids as a LIST for the names it recognizes or undef for unknown ones.

Return value is a LIST.

getEntityTypeName()

Retrives the textual name of the entity type: getEntityTypeName (entityid)

Input is the entity id or it will default to the invalid id of zero.

Return value is the entity ids type name upon success, undef upon failure.

Please call the error-method for more details of the error.

getEntityTypeNameById()

Retrieves the entity type name by specifying the entity type id(s): getEntityTypeNameById([id1,i2..idN]).

No input is required and it will then return all entity type textual names. If one or more type id(s) are specified (comma separated), it will return the entity type name(s) for the entity type id(s) specified.

Return value is a LIST.

getLogEntries()

Gets the log entries of entity or if none given all log entries in the database.

Input is the entity id to get the logs for. If none given it will fetch log entries for all entites.

Return value is a HASH pointer of the resulting log entries. The format of the HASH is:

( NO => { time => TIME,
          loglevel => LEVEL,
          message => SCALAR,
          idx => SCALAR,
          tag => SCALAR
        }
)

the NO is the auto increment value of the database. time is given in hires time, loglevel is the level value from possible loglevels (see enumLoglevels()-method), message is the message of the log entry and idx is the log entries auto increment index in the database.

It will return undef upon failure. Please check the error()-method for more information in the case of an error.

getLoglevelByName()

Gets the loglevel id by giving its name.

Input is the loglevel name. Defaults to "" and will result in a "0" return value (does not exist).

Returns the id upon success, 0 if it does not exist, undef upon failure. Please check the error()-method for information on a potential error.

getLoglevelNameByValue()

Gets the loglevel name by giving its value. Input is the loglevel value. If none given it defaults to 0 which will result in a "" return value (does not exist).

Return value is the loglevel name upon success, "" or blank if it does not exist, undef upon failure. Check the error-method for more information on an error.

getMetadataKey()

Get the metadata key id by specifying the metadata key name.

Input is the metadata key name.

Return value is the metadata key id upon success, 0 if it does not exist, undef upon failure. Please call the error-method to find out more about the error.

getMtime()

This methods read modification time for tables and return the newest one.

Optional parameter: table names - tables to get mtime for, default all tables with set mtime.

Return value: the newest mtime found.

Time format is floating unis time.

getPermTypeNameByValue()

Returns the permission type name(s) for the given permission type value(s).

Input is a LIST of permission type value(s).

Return value is a LIST of permission type name(s) for those value(s).

getPermTypeValueByName()

Returns the permission type value(s) for the given permission type name(s).

Input is a LIST of permission type name(s).

Return value is a LIST of permission type value(s) for those name(s).

getTemplate()

Get a template and its constraints.

Input is the template id to get the constraints for.

Return value is HASH-reference with the constraints upon success (see setTemplate for more information on structure), or undef upon failure. Check the error()-method for more information upon failure. Undef-values in the keys are to be understood as there are no more values for that "value".

getTemplateAssignments()

Retrieves all entities that the given template has been assigned to as well as type.

Input parameters are in the following order: template id (SCALAR, required), type (SCALAR, optional), duplicates (SCALAR, optional)

Template ID is the template that one wishes to get all assignments of. Type is the type id that one wishes to get assignments of (other type assignments of given template id are omitted). Duplicates sets if any duplicates of entities on the same entity type assignment will be removed or not? It is possible to assign the same template several times on the same entity and entitytype and this parameter controls if this will be visible in the returned result or not? It is evaluated as a boolean and if true will remove duplicates and if false will not remove duplicates. If parameter is undef it will default to true and duplicates will be removed.

Returns a HASH-reference upon success, undef upon failure. Please check the error()-method for more information upon failure.

The HASH structure is as follows:

( 
   all => [entity1,entity2,entity3 .. entityN]
   types => { 
              typeA => [entity1 .. entityN]
              typeB => [entity2, entity3 .. entityN]
              .
              .
              typeZ
            }
)

Please note that the "all" key contains all the entities that have the given template assigned to them, without duplicates (no matter what the duplicates-parameter says). The "types" key contains the entity assignments ordered into entity types, so that one can easily check eg. what "DATASET" assignments have been put in place with the given template.

getTemplateAssignmentsTree()

Gets a tree of template assignments and their metadata key definitions.

This method accepts the following parameters in this order:

This method returns a tree of template assignments on the entity(ies) specified according to the use of the "entities"-parameter. It will also return the metadata key-definitions of all the template assignments.

Upon success this method returns a HASH-reference, undef upon failure. Please check the error()-method for more information upon failure.

The HASH-structure returned upon success looks like this:

   (
      1 => entity => SCALAR,
           assigns => {
                         1 => { 
                                 TMPLIDa => {
                                               KEYNAMEa => {
                                                              default => ...
                                                              regex => ...
                                                              flags => ...
                                                              min => ...
                                                              max => ...
                                                              comment => ...                                  
                                                           }
                                              .
                                              .
                                              KEYNAMEz
 
                                            }
                                 .
                                 .
                                 TMPLIDz                                                                                  
                              }
                         .
                         .
                         N
                      }
      .
      .
      N
   )

The assignmenst are ordered from 1 to N in order to know which order to iterate on it. Inside each initial order number is two fields: "entity" and "assigns". "entity" defines which entity these assignments are valid for, if any? "assigns" gives the template assignments for that entity given any constraints set in the method-parameters (see above). The "assigns" sub-structure is also numbered from 1 to N and gives the order in which the template(s) are valid. After the number comes the template ID (TMPLIDa .. TMPLIDz) from the database. Each ordered assignment will only have one template ID here and is only there to inform what the template ID is for that assignment. After the template ID comes the textual metadata key-name (KEYNAMEa .. KEYNAMEz) and after that comes the actual definition of the key name (see the setTemplate()-method for more information).

If one uses the include-parameter the numbering in the assigns sub-structure will reflect which template that are included and are not a numbering reflecting the actual assignment order on that entity if the output then have been moderated.

This method optimizes the use of the getTemplate()-method to get the definition of the template by caching the response and eliminates the need to call it many times for the same template id. The method will be further optimized if one uses the include-parameter to narrow down which template ids that are to be included in the response.

getTemplateFlagValueByName()

Returns the template flag value(s) for the given name(s)

Input is a LIST of flag value name(s) to get flag value for.

Return value is a LIST of flag values of those names or undef for non-existing ones.

getTemplateFlagNameByValue()

Returns the template flag value name(s) for the given flag value(s).

Input is a LIST of flag value(s) to get name(s) for.

Return value is a LIST of flag value name(s) for those flag value(s) or undef for non-existing ones.

bitmask2Flag()

Returns the individual flags set.

Input is the flag(s) bitmask to deconstruct.

Return value is a LIST of flag value name(s) for the flags set in the input bitmask.

flag2Bitmask()

Returns the bitmask of the flags that was input.

Input is the flag(s) to set in the bitmask.

Return value is a bitmask with the valid flags set.

maxDepth()

Returns the maximum depth allowed on the entity tree.

No input is accepted.

Returns the maximum depth allowed on the tree as set through the constructor new() or the default from the global constant $VIEW_DEPTH. The value set through the constructor new() takes precedence if valid.

moveEntity()

This methods moves an entity provided the new parent or to-entity exists.

Input are in the following order:

Returns 1 upon success, 0 upon failure. Call the error-method to get more information on the failure.

removeEntityMember()

Removes member(s) from an entity.

The method accepts these parameters in the following order:

Returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.

removeEntityPermsAndRoles()

Remove all of an entity's permissions and roles in the AURORA database. Optionally all permissions other entity(ies) has/have on that entity.

This method accepts the following parameters in this order: id,others. ID is the entity ID of the entity to remove all permissions and roles of, SCALAR, Required. Others is the flag to tell the method to also remove all permissions and memberships that other entity(ies) might have on the given entity, BOOLEAN, optional. If not given will default to 0/false and do not remove permissions and roles others have on the given entity.

Returns 1 upon success, 0 upon not being able to remove it, undef upon some failure. Please check the error()-method for more information upon failure.

sequenceEntity()

(Re)sequence an entity and any descendants. Done on createEntity and moveEntity to ensure parents is sequenced before child.

Input is entity. Returns count of sequenced entitys on success, 0 on failure.

setBitmask()

Sets bits in a bitmask.

Input is the bitmask to modify and bitmask with bits to set. Default parameters is ''.

Return value is the resulting bitmask as a SCALAR. The input bitmask is unaltered.

setBits()

Sets bits in a bitmask.

Input is the bitmask to modify and a list of bit numbers to set. Default bitmask is ''.

Return value is the resulting bitmask as a SCALAR. The input bitmask is unaltered.

setEntityMetadata()

Sets an entitys metadata. Old metadata keys are overwritten with new value or new keys are added. The values allowed to be set are moderated by the templates for this entity.

The method accepts these options in the following order:

The method checks the metadata compliance against relevant aggregated template and if it fails returns the metadata keys it failed on in the error message (call the error()-method to read it). Please note that if the entity in question already have metadata on it, the existing metadata will be collected and used for the keys that are not in the input to the method. The input keys and values together with the keys that are not in the input will be checked against the aggregated template for compliance. This ensures that one can update just one key in the metadata without getting template compliance issues, since existing metadata will fill missing key-values.

This way of handling setting metadata on an entity means that the update follow the rule of the three musketeers: all for one and one for all. An update of a key or an addition of key value(s) will need to check all of the metadata for template compliance.

Please also be aware, that if you want to delete a metadata key while updating other keys, you can set that key to an empty LIST reference. Eg:

$hash->{KEYNAME}=\@list

The reason for this is that the method handles all value setting as lists (as does the database) and tries to optimize for using UPDATE/REPLACE-statements in SQL, so after setting values for a key, it removes any extra LIST values that are not needed anymore. If you set zero LIST values, it removes all LIST values afterwards since they are not needed anymore. Ergo thereby in effect performing a deletion of a key.

It return 1 upon success, 0 upon failure. Please call the error()-method to get more information on the error.

This function is simplified to work with basic and standardized SQL like UPDATE, INSERT and DELETE (no REPLACE or INSERT...on DUPLICATE UPDATE) for compability reasons. It is also optimized to favour UPDATE of values where possible (were there are existing metadatakeys), even for arrays. When no existing key or index of that key (in case of arrays) exists, it will insert new values. If the new array contains less values than the previous it will delete away surplus rows in the database. In addition it will skip running an UPDATE on values that are the same as before for a given key. This optimizes the function to work on most database engines, while also optimizing its speed and functionality. The working of the function is based upon some assumptions:

These are the main considerations for the workings of the method.

setEntityPermByObject()

Set the permissions on a specific entity.

This methods takes these options in the following order:

The method returns a reference to a LIST of the grant and deny permission masks after completion of the operation (in that order).

Undef is returned upon failure. Please check the exact error message by calling the error()-method.

setLogEntry()

Sets a log entry.

Input is in the following order:

Return value is 1 upon success, 0 upon failure. Check the error-method for more information upon error.

setMtime()

This methods updates set modification time for a table.

Required parameter: table name - table to update mtime for.

Optional parameter: mtime - time to set, defaults to now.

Time format is floating unix time.

Return value: undef on failure, 1 otherwise.

setTemplate()

Sets the constraints of a template.

Input parameters are in the following order:

The template constraints HASH has the following format:

( KEY => { 
           default => VALUE,
           regex => VALUE,
           flags => VALUE,
           min => VALUE,
           max => VALUE,
           comment => VALUE,
         }
)

You can set any number of these KEY-constraints that you want on a given template. With KEY here is meant the textual name of the metadata key on an entity.

Please note that the values undef and not exists are interchangable concepts when it comes to templates. Undef is the same as the key does not exist and/or is not defined. So when setting a template, a value not specified will appear as an undef-value when loading that same template again (see the getTemplate-method). The exception to this behaviour is when getting the aggregated template of an entity by calling the getEntityTemplate()-method. Here it will default values at the end that has not been defaulted by the metadata definition. There are in other words no valid value in AuroraDB for undef. Undef just means that it is not existing or defined.

This method will also strip away flags bit-combinations that are not allowed, such as SINGULAR at the same time as MULTIPLE. Singular is preferred (conservative approach).

The meaning of the KEY-constraints are as follow:

Return value is 1 upon success, 0 upon failure. Check the error()-method for more information on a potential error.

unassignEntityTemplate()

Removes template assignment of given type on entity. A wrapper around assignEntityTemplate.

Input is entity id and entity type. See assignEntityTemplate()-method for more information.

Return value is 1 on success, 0 on failure. Check the error()-method for more information.

updateEffectivePerms()

Updates the PERM_EFFECTIVE_* tables to keep PERM_EFFECTIVE up to date.

No input parameters

Return 1 on success, undef on failure.

updateEffectivePermsConditional()

Calls updateEffectivePerms() if mtime of the source tables differ from mtime of PERM_EFFECTIVE_PERMS.

Updates mtime for PERM_EFFECTIVE_PERMS to the mtime of the sources and return true on success.

Return undef on failure.

useDBItransaction()

This methods returns a DBItransaction instance that keep track of who started a transaction, committing transaction and handling rollback and so no with minimal code in the methods: useDBItransaction()

The methods requires no input. Returns a DBItransaction-instance.

See the DBItransaction module for more information.