| Midgard2 Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | Object Hierarchy | Properties | Signals | ||||
#include <midgard/midgard.h> #define MIDGARD_OBJECT_GET_CLASS_BY_NAME (name) MgdObject; typedef MidgardObject; typedef midgard_object; MidgardObjectPrivate; MidgardObjectClassPrivate; MgdObject * midgard_object_new (MidgardConnection *mgd, const gchar *name, GValue *value); gboolean midgard_object_get_by_id (MgdObject *object, guint id); gboolean midgard_object_update (MgdObject *self); gboolean midgard_object_create (MgdObject *object); gboolean midgard_object_is_in_parent_tree (MgdObject *self, guint rootid, guint id); gboolean midgard_object_is_in_tree (MgdObject *self, guint rootid, guint id); gchar * midgard_object_get_tree (MgdObject *object, GSList *tnodes); gboolean midgard_object_get_by_guid (MgdObject *object, const gchar *guid); gboolean midgard_object_delete (MgdObject *object); gboolean midgard_object_purge (MgdObject *object); MgdObject * midgard_object_get_parent (MgdObject *self); GObject ** midgard_object_list (MgdObject *self, guint *n_objects); GObject ** midgard_object_list_children (MgdObject *object, const gchar *childname, guint *n_objects); gboolean midgard_object_get_by_path (MgdObject *self, const gchar *path); const gchar * midgard_object_parent (MgdObject *self); gboolean midgard_object_undelete (MidgardConnection *mgd, const gchar *guid); gboolean midgard_object_set_guid (MgdObject *self, const gchar *guid); void midgard_object_set_connection (MgdObject *self, MidgardConnection *mgd); gboolean midgard_object_lock (MgdObject *self); gboolean midgard_object_unlock (MgdObject *self); gboolean midgard_object_is_locked (MgdObject *self); gboolean midgard_object_approve (MgdObject *self); gboolean midgard_object_unapprove (MgdObject *self); gboolean midgard_object_is_approved (MgdObject *self);
"action-approve" : Action "action-approve-hook" : Action "action-approved" : Action "action-create" : Action "action-create-hook" : Action "action-created" : Action "action-delete" : Action "action-delete-hook" : Action "action-deleted" : Action "action-export" : Action "action-export-hook" : Action "action-exported" : Action "action-import" : Action "action-import-hook" : Action "action-imported" : Action "action-loaded" : Action "action-loaded-hook" : Action "action-lock" : Action "action-lock-hook" : Action "action-locked" : Action "action-purge" : Action "action-purge-hook" : Action "action-purged" : Action "action-unapprove" : Action "action-unapprove-hook" : Action "action-unapproved" : Action "action-unlock" : Action "action-unlock-hook" : Action "action-unlocked" : Action "action-update" : Action "action-update-hook" : Action "action-updated" : Action
#define MIDGARD_OBJECT_GET_CLASS_BY_NAME(name) ((MidgardObjectClass*) g_type_class_peek(g_type_from_name(name)))
|
typedef struct {
GObject parent;
MidgardDBObjectPrivate *dbpriv;
MidgardObjectPrivate *priv;
MidgardMetadata *metadata;
} MgdObject;
MgdObject * midgard_object_new (MidgardConnection *mgd, const gchar *name, GValue *value);
Creates new MgdObject object instance.
This function is mandatory one for new midgard object initialization. Unlike g_object_new ( which is typical function to create new GObject instance ), midgard_object_new initializes data which are accessible internally by object instance itself or by object's class:
- midgard connection handler is associated with object
Sitegroup value is returned from midgard connection handler and may be overwritten only by SG0 Midgard Administrator only when object is created. Setting this property is forbidden when object is already fetched from database.
Object's contructor tries to determine third optional parameter value.
If it's of G_TYPE_STRING type , then midgard_is_guid() is called to check
weather passed string is a guid , in any other case id property is used
with G_TYPE_UINT type. New "empty" instance is created (without fetching
data from database) if value parameter is explicitly set to NULL.
Any object instance created with this function should be freed using typical g_object_unref function.
Cases to return NULL:
value holds string but it's not a valid guid
value holds valid id or guid but object doesn't exists in database ( MGD_ERR_NOT_EXISTS )
more than one object identified by particular id or guid returned ( case possible if logged in user is root ) ( MGD_ERR_SITEGROUP_VIOLATION )
unspecified internal error ( MGD_ERR_INTERNAL )
gboolean midgard_object_get_by_id (MgdObject *object, guint id);
Fetch object's record(s) from database using 'id' property.
This is common practice to use 'id' property with integer type when table's id column stores unique, primary key value which identifies object and its record(s). However primary property with integer type is freely defined by user.
MgdObject object instance must be created with midgard_object_new function. When midgard connection handler is not associated with object instance, application is terminated with 'assertion fails' error message being logged.
Object instance created with this function should be freed using g_object_unref.
Cases to return FALSE:
There's no 'id' primary property registered for object's class ( MGD_ERR_INTERNAL )
Object's record can not be fetched from database ( MGD_ERR_NOT_EXISTS )
unspecified internal error ( MGD_ERR_INTERNAL )
gboolean midgard_object_update (MgdObject *self);
Update object's record(s).
Internally such metadata properties are set (overwritten):
revisor
revision ( increased by one )
revised
Cases to return FALSE:
Property registered with MGD_TYPE_GUID doesn't hold valid guid ( MGD_ERR_INVALID_PROPERTY_VALUE )
Object's class is registered with tree facilities and there is already such object in midgard tree ( MGD_ERR_DUPLICATE )
Quota is activated and its limit is reached ( MGD_ERR_QUOTA )
Unspecified internal error ( MGD_ERR_INTERNAL )
gboolean midgard_object_create (MgdObject *object);
Creates new database record(s) for object.
Internally such properties are set (overwritten):
guid (if not set by root)
id (if set as primary property)
Metadata overwritten properties:
creator
created
revisor
revised
revision
published ( set only, if not defined by user )
Cases to return FALSE:
Property registered with MGD_TYPE_GUID doesn't hold valid guid ( MGD_ERR_INVALID_PROPERTY_VALUE )
Object's class is registered with tree facilities and there is already such object in midgard tree ( MGD_ERR_DUPLICATE )
Quota is activated and its limit is reached ( MGD_ERR_QUOTA )
Unspecified internal error ( MGD_ERR_INTERNAL )
gboolean midgard_object_is_in_parent_tree (MgdObject *self, guint rootid, guint id);
Checks whether object exists in parent's type tree.
Midgard tree in #MgdSchema reference
Parent type in midgard tree is a type which can be "container" with object nodes of different types.
gboolean midgard_object_is_in_tree (MgdObject *self, guint rootid, guint id);
Checks whether object exists in tree ( of the same type ).
Midgard tree in MgdSchema reference: http://www.midgard-project.org/midcom-permalink-a4e185a08fb2d0e278ef1ba3a739f77e
This function checks only objects of the same type.
gchar * midgard_object_get_tree (MgdObject *object, GSList *tnodes);
|
|
|
|
Returns : |
gboolean midgard_object_get_by_guid (MgdObject *object, const gchar *guid);
Fetch object's record(s) from database using 'guid' property constraint.
MgdObject object instance must be created with midgard_object_new function. When midgard connection handler is not associated with object instance, application is terminated with 'assertion fails' error message being logged.
Object instance created with this function should be freed using g_object_unref.
Cases to return FALSE:
Object's record can not be fetched from database ( MGD_ERR_NOT_EXISTS )
unspecified internal error ( MGD_ERR_INTERNAL )
gboolean midgard_object_delete (MgdObject *object);
Delete object's record(s) from database, but object's record is not fully deleted
from database. Instead, it is marked as deleted , thus it is possible to undelete
object later with static method midgard_object_class_undelete().
Use midgard_object_purge() if you need to purge object's data from database.
Cases to return FALSE:
Object's has no storage defined ( MGD_ERR_OBJECT_NO_STORAGE )
Object's property guid is empty ( MGD_ERR_INVALID_PROPERTY_VALUE )
There are still dependent objects in database ( MGD_ERR_HAS_DEPENDENTS )
Unspecified internal error ( MGD_ERR_INTERNAL )
gboolean midgard_object_purge (MgdObject *object);
Purge object's record(s) from database.
Object's record(s) are purged from database without any possibility to recover.
After successfull call, only repligard table holds information about object's state.
Use midgard_object_delete(), if undelete facility is needed.
Cases to return FALSE:
Object has no storage defined ( MGD_ERR_OBJECT_NO_STORAGE )
Object's property guid value is empty ( MGD_ERR_INVALID_PROPERTY_VALUE )
There are still dependent objects in database ( MGD_ERR_HAS_DEPENDANTS )
No record has been deleted from database ( MGD_ERR_NOT_EXISTS )
Unspecified internal error ( MGD_ERR_INTERNAL )
MgdObject * midgard_object_get_parent (MgdObject *self);
Fetch parent ( in midgard tree ) object.
This function fetches "upper" object of the same type, and then parent object if object's up property holds empty value. Object is root object in tree when NULL is returned.
GObject ** midgard_object_list (MgdObject *self, guint *n_objects);
Returned array stores object(s) which up property is equal to self primary property
GObject ** midgard_object_list_children (MgdObject *object, const gchar *childname, guint *n_objects);
gboolean midgard_object_get_by_path (MgdObject *self, const gchar *path);
Fetch object's record by path
This function is slower than midgard_object_class_get_object_by_path, as it has to create new object instance and copy all properties.
MidgardError is set by midgard_object_class_get_object_by_path in this case.
Read about midgard_object_class_get_object_by_path() for more details.
const gchar * midgard_object_parent (MgdObject *self);
Returned class name is owned by midgard and should not be freed.
|
MidgardObject instance |
Returns : |
class name of parent object ( in content tree ). |
gboolean midgard_object_undelete (MidgardConnection *mgd, const gchar *guid);
Deprecated. See midgard_object_class_undelete()
gboolean midgard_object_set_guid (MgdObject *self, const gchar *guid);
Sets object's guid
Cases to return FALSE:
given guid already exists in database ( MGD_ERR_DUPLICATE )
given guid is invalid ( MGD_ERR_INVALID_PROPERTY_VALUE )
object has already set guid property ( MGD_ERR_INVALID_PROPERTY_VALUE )
void midgard_object_set_connection (MgdObject *self, MidgardConnection *mgd);
Set object's connection.
This method associate object with connection being already initialized. It's not required to use it in every aplication, however it's mandatory when object has been initialized by some underlying library. For example, object pointer is available from g_object_new instead of midgard_object_new.
Already associated connection is silently ignored.
|
MgdObject instance |
|
MidgardConnection instance |
gboolean midgard_object_lock (MgdObject *self);
Lock object.
This method doesn't affect any core's functionality like midgard_object_approve.
You should create own locking workflow and logic with methods:
midgard_object_is_locked(), midgard_object_unlock() and this one.
Updates metadata properties: locker, locked, revisor, revised and revision
Cases to return FALSE:
No user logged in ( MGD_ERR_ACCESS_DENIED )
Metadata class not defined for given object's class ( MGD_ERR_NO_METADATA )
Object is already locked ( MGD_ERR_OBJECT_IS_LOCKED )
gboolean midgard_object_unlock (MgdObject *self);
Unlock object.
Cases to return FALSE:
No user logged in ( MGD_ERR_ACCESS_DENIED )
Object is not locked ( FIXME )
Metadata class not defined for given object's class ( MGD_ERR_NO_METADATA )
gboolean midgard_object_is_locked (MgdObject *self);
Check whether object is locked
Cases to return FALSE:
Metadata class not defined for given object's class ( MGD_ERR_NO_METADATA )
gboolean midgard_object_approve (MgdObject *self);
Approve object.
Approval functionality is not used by midgard core itself.
Instead, it supports higher level's applications. It means,
that there are no core methods ( like update or delete ) which
do real check if object is approved. You should create own approval
workflow and logic with methods: midgard_object_is_approved(),
midgard_object_unapprove() and this one.
This method updates metadata properties: revisor, revised, revision, approver and approved.
Cases to return FALSE:
No user logged in ( MGD_ERR_ACCESS_DENIED )
No active person ( MGD_ERR_INTERNAL )
Object is already approved
gboolean midgard_object_unapprove (MgdObject *self);
Simply unapprove object. It doesn't affect any core functionality,
like midgard_object_approve().
This method updates metadata properties: revisor, revised, revision, approver and approved
Cases to return FALSE:
No user logged in ( MGD_ERR_ACCESS_DENIED )
Object is not approved
"metadata" property"metadata" GObject* : Read / Write
Property which holds MidgardMetadata object.
"action-approve" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-approve-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-approved" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-create" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-create-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-created" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-delete" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-delete-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-deleted" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-export" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-export-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-exported" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-import" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-import-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-imported" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-loaded" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-loaded-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-lock" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-lock-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-locked" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-purge" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-purge-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-purged" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-unapprove" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-unapprove-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-unapproved" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-unlock" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-unlock-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-unlocked" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-update" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-update-hook" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"action-updated" signalvoid user_function (midgard_object *midgard_object, gpointer user_data) : Action
|
the object which received the signal. |
|
user data set when the signal handler was connected. |