Ignore:
Timestamp:
02/17/10 18:59:30 (15 years ago)
Author:
lgiessmann
Message:

new-datamodel: fixed some problems; removed some unnecessary functions; implemented RoleC, PlayerAssociationC, RoleAssociationC; updated the UML-schema

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/new-datamodel/src/model/datamodel.lisp

    r192 r193  
    1212  (:nicknames :d)
    1313  (:export ;;classes
     14           :RoleC
     15           :OccurrenceC
     16           :NameC
     17           :VariantC
    1418           :PersistentIdC
    1519           :ItemIdentifierC
     
    2226           :uri
    2327           :identifieid-construct
    24            :all-identified-constructs
    2528           :item-identifiers
    2629           :reifier
     
    3841           :add-parent
    3942           :delete-parent
     43           :variants
     44           :add-variant
     45           :delete-variant
     46           :parent
     47           :add-parent
     48           :delete-parent
     49           :player
     50           :add-player
     51           :delete-player
    4052           :mark-as-deleted
    4153
     
    4557(in-package :datamodel)
    4658
    47 
    48 ;;TODO: implement delete-item-identifier
    49 ;;TODO: implement delete-reifier
    50 ;;TODO: implement all-reified-constructs (:with-deleted t) -> TopicC
    51 ;;      the method should return all reifed-constructs of the given topic
     59;;TODO: use some exceptions --> more than one type,
     60;;      identifier, not-mergeable merges, ...
    5261;;TODO: implement make-construct -> symbol
    5362;;      replace the latest make-construct-method
     
    6170
    6271;;; start hacks -> just some temporary hacks to avoid compiler-errors ;;;;;;;;;;
    63 (defpclass NameC (TopicMapConstructC)
    64   ()
    65   (:documentation "A temporary emtpy class to avoid compiler-errors."))
    66 
    67 (defpclass OccurrenceC (TopicMapConstructC)
    68   ()
    69   (:documentation "A temporary emtpy class to avoid compiler-errors."))
    70 
    71 
    7272(defpclass TopicC (TopicMapConstructC)
    7373  ()
    7474  (:documentation "A temporary emtpy class to avoid compiler-errors."))
     75
     76(defpclass AssociationC (TopicMapConstructC)
     77  ()
     78  (:documentation "A temporary emtpy class to avoid compiler-errors."))
     79
    7580
    7681(defgeneric merge-constructs(construc-1 construct-2 &key revision)
     
    7883            &key (revision *TM-REVISION*))
    7984    (or construct-1 construct-2 revision)))
    80 
    81 
    82 (defgeneric all-reified-constructs(topic &key with-deleted)
    83   (:method ((topic TopicC) &key (with-deleted t))
    84     (or topic with-deleted)))
    8585
    8686
     
    302302
    303303;;; Characterics ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     304(defpclass OccurrenceC(CharacteristicC)
     305  ((datatype :accessor datatype
     306             :initarg :datatype
     307             :initform nil
     308             :documentation "The XML Schema datatype of the occurrencevalue
     309                             (optional, always IRI for resourceRef).")))
     310
     311
     312(defpclass NameC(CharacteristicC)
     313  ((variants :associate (VaraitnAssociationC name)
     314             :documentation "Associates this obejct with varian-associations."))
     315  (:documentation "Scoped name of a topic."))
     316
     317
     318(defgeneric variants (construct &key revision)
     319  (:documentation "Returns all variants that correspond with the given revision
     320                   and that are associated with the passed construct.")
     321  (:method ((construct NameC) &key (revision *TM-REVISION*))
     322    (let ((valid-associations
     323           (filter-slot-value-by-revision construct 'variants
     324                                          :start-revision revision)))
     325      (map 'list #'characteristic valid-associations))))
     326
     327
     328(defgeneric add-variant (construct variant &key revision)
     329  (:documentation "Adds the given theme-topic to the passed
     330                   scopable-construct.")
     331  (:method ((construct ScopableC) (variant VariantC)
     332            &key (revision *TM-REVISION*))
     333    (let ((all-variants
     334           (map 'list #'characteristic
     335                (remove-if #'marked-as-deleted-p
     336                           (slot-p construct 'variants)))))
     337      (if (find variant all-variants)
     338          (let ((variant-assoc
     339                 (loop for variant-assoc in (slot-p construct 'variants)
     340                    when (eql (characteristic variant-assoc) variant)
     341                    return variant-assoc)))
     342            (add-to-version-history variant-assoc :start-revision revision))
     343          (make-instance 'VariantAssociationC
     344                         :start-revision revision
     345                         :characteristic variant
     346                         :name construct)))
     347    construct))
     348
     349
     350(defgeneric delete-variant (construct variant &key revision)
     351  (:documentation "Deletes the passed variant by marking it's association as
     352                   deleted in the passed revision.")
     353  (:method ((construct NameC) (variant VariantC)
     354            &key (revision (error "From delete-theme(): revision must be set")))
     355    (let ((assoc-to-delete (loop for variant-assoc in (slot-p construct
     356                                                              'variants)
     357                              when (eql (characteristic variant-assoc) variant)
     358                              return variant-assoc)))
     359      (when assoc-to-delete
     360        (mark-as-deleted assoc-to-delete :revision revision))
     361      construct)))
     362
     363
     364(defpclass VariantC(CharacteristicC)
     365  ((datatype :accessor datatype
     366             :initarg :datatype
     367             :initform nil
     368             :documentation "The XML Schema datatype of the occurrencevalue
     369                             (optional, always IRI for resourceRef).")))
     370
     371
    304372(defpclass CharacteristicC(ReifiableConstructC ScopableC TypableC)
    305373  ((parent :associate (CharacteriticAssociationC characteristic)
     
    422490
    423491;;; Versioned-Associations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     492;;; PlayerAssociationC
     493;;; RoleAssociationC
    424494;;; VariantAssociationC
    425495;;; NameAssociationC
     
    435505;;; PointerAssociationC
    436506;;; VersionedAssociationC
     507(defpclass PlayerAssociationC(VersionedAssociationC)
     508  ((player-topic :initarg :player-topic
     509                 :accessor player-topic
     510                 :associate TopicC
     511                 :initform (error "From PlayerAssociationC(): player-topic must be set")
     512                 :documentation "Associates this object with a topic that is
     513                                 a player.")
     514   (role :initarg :role
     515         :accessor role
     516         :associate RoleC
     517         :initform (error "From PlayerAssociationC(): role must be set")
     518         :documentation "Associates this object with the parent-association."))
     519  (:documentation "This class associates roles and their player in given
     520                   revisions."))
     521
     522
     523(defmethod delete-construct :before ((construct PlayerAssociationC))
     524  "Deletes all elephant-associations."
     525  (delete-1-n-association construct 'player-topic)
     526  (delete-1-n-association construct 'role))
     527
     528
     529(defpclass RoleAssociationC(VersionedAssociationC)
     530  ((role :initarg :role
     531         :accessor role
     532         :associate RoleC
     533         :initform (error "From RoleAssociationC(): role must be set")
     534         :documentation "Associates this objetc with a role-object.")
     535   (association :initarg :association
     536                :accessor association
     537                :associate AssociationC
     538                :initform (error "From RoleAssociationC(): association  must be set")
     539                :documentation "Assocates thius object with an association-object."))
     540  (:documentation "Associates roles with assoications and adds some
     541                   version-infos between these realtions."))
     542
     543
     544(defmethod delete-construct :before ((construct RoleAssociationC))
     545  "Deletes all elephant-associations and the entire role if it is not
     546   associated with another AssociationC object."
     547  (let ((role (role construct)))
     548    (delete-1-n-association construct 'role)
     549    (when (not (slot-p role 'parent))
     550      (delete-construct role))
     551    (delete-1-n-association construct 'association)))
     552
     553
    437554(defpclass VariantAssociationC(CharateristicAssociationC)
    438555  ((name :initarg :name
     
    441558         :associate NameC
    442559         :documentation "Associates this object with a name."))
    443   (:index t)
    444560  (:documentation "Associates variant objects with name obejcts.
    445561                   Additionally version-infos are stored."))
     
    456572          :associate TopicC
    457573          :documentation "Associates this object with a topic."))
    458   (:index t)
    459574  (:documentation "Associates name objects with their parent topics.
    460575                   Additionally version-infos are stored."))
     
    471586          :associate TopicC
    472587          :documentation "Associates this object with a topic."))
    473   (:index t)
    474588  (:documentation "Associates occurrence objects with their parent topics.
    475589                   Additionally version-infos are stored."))
     
    515629                                      construct that is typed by the
    516630                                      type-topic."))
    517   (:index t)
    518631  (:documentation "This class associates topics that are used as type for
    519632                   typable constructcs. Additionally there are stored some
     
    541654                                       construct that is scoped by the
    542655                                       scope-topic."))
    543   (:index t)
    544656  (:documentation "This class associates topics that are used as scope with
    545657                   scopable construtcs. Additionally there are stored some
     
    566678                  :documentation "The reifier-topic that reifies the
    567679                                  reifiable-construct."))
    568   (:index t)
    569680  (:documentation "A versioned-association that relates a reifiable-construct
    570681                   with a topic."))
     
    588699                     :documentation "The actual topic which is associated
    589700                                     with the subject-locator."))
    590   (:index t)
    591701  (:documentation "A pointer that associates subject-locators, versions
    592702                   and topics."))
     
    604714                     :documentation "The actual topic which is associated
    605715                                     with the subject-identifier/psi."))
    606   (:index t)
    607716  (:documentation "A pointer that associates subject-identifiers, versions
    608717                   and topics."))
     
    620729                     :documentation "The actual topic which is associated
    621730                                     with the topic-identifier."))
    622   (:index t)
    623731  (:documentation "A pointer that associates topic-identifiers, versions
    624732                   and topics."))
     
    636744                     :documentation "The actual parent which is associated
    637745                                     with the item-identifier."))
    638   (:index t)
    639746  (:documentation "A pointer that associates item-identifiers, versions
    640747                   and reifiable-constructs."))
     
    662769  (let ((id (slot-p construct 'identifier)))
    663770    (delete-1-n-association construct 'identifier)
    664     (when (= (length (all-identified-constructs id)) 0)
     771    (when (= (length (slot-p id 'identified-construct)) 0)
    665772      (delete-construct id))))
    666773
     
    669776  ()
    670777  (:documentation "An abstract base class for all versioned associations."))
     778
     779
     780;;; RoleC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     781(defpclass RoleC(ReifiableConstructC TypableC)
     782  ((parent :associate (RoleAssociationC role)
     783           :documentation "Associates this object with a role-association.")
     784   (player :associate (PlayerAssociationC parent-role)
     785           :documentation "Associates this object with a player-association.")))
     786
     787
     788(defmethod delete-construct :before ((construct RoleC))
     789  "Deletes all association-objects."
     790  (dolist (assoc (slot-p construct 'parent))
     791    (delete-construct assoc))
     792  (dolist (assoc (slot-p construct 'player))
     793    (delete-construct assoc)))
     794
     795
     796(defgeneric parent (construct &key revision)
     797  (:documentation "Returns the construct's parent corresponding to
     798                   the given revision.")
     799  (:method ((construct RoleC) &key (revision *TM-REVISION*))
     800    (let ((valid-associations
     801           (filter-slot-value-by-revision construct 'parent
     802                                          :start-revision revision)))
     803      (when valid-associations
     804        (association (first valid-associations))))))
     805
     806
     807(defmethod add-parent ((construct RoleC) (parent-construct AssociationC)
     808                       &key (revision *TM-REVISION*))
     809  (let ((already-set-parent
     810           (map 'list #'association
     811                (filter-slot-value-by-revision construct 'parent
     812                                               :start-revision revision))))
     813      (cond ((and already-set-parent
     814                  (eql (first already-set-parent) parent-construct))
     815             (let ((parent-assoc
     816                    (loop for parent-assoc in (slot-p construct 'parent)
     817                       when (eql parent-construct (association parent-assoc))
     818                       return parent-assoc)))
     819               (add-to-version-history parent-assoc :start-revision revision)))
     820            ((not already-set-parent)
     821             (make-instance 'RoleAssociationC
     822                            :start-revision revision
     823                            :role construct
     824                            :association parent-construct))
     825            (t
     826             (error "From add-parent(): ~a can't be a parent of ~a since it is already owned by the association ~a"
     827                    parent-construct construct already-set-parent)))
     828      construct))
     829
     830
     831(defmethod delete-parent ((construct RoleC) (parent-construct AssociationC)
     832            &key (revision (error "From delete-parent(): revision must be set")))
     833  (let ((assoc-to-delete
     834         (loop for parent-assoc in (slot-p construct 'parent)
     835            when (eql (association parent-assoc) parent-construct)
     836            return parent-assoc)))
     837    (when assoc-to-delete
     838      (mark-as-deleted assoc-to-delete :revision revision))
     839    construct))
     840
     841
     842(defgeneric player (construct &key revision)
     843  (:documentation "Returns the construct's player corresponding to
     844                   the given revision.")
     845  (:method ((construct RoleC) &key (revision *TM-REVISION*))
     846    (let ((valid-associations
     847           (filter-slot-value-by-revision construct 'player
     848                                          :start-revision revision)))
     849      (when valid-associations
     850        (player-topic (first valid-associations))))))
     851
     852
     853(defgeneric add-player (construct player-topic &key revision)
     854  (:documentation "Adds a topic as a player to a role in the given revision.")
     855  (:method ((construct RoleC) (player-topic TopicC)
     856            &key (revision *TM-REVISION*))
     857    (let ((already-set-player
     858           (map 'list #'player-topic
     859                (filter-slot-value-by-revision construct 'player
     860                                               :start-revision revision))))
     861      (cond ((and already-set-player
     862                  (eql (first already-set-player) player-topic))
     863             (let ((player-assoc
     864                    (loop for player-assoc in (slot-p construct 'player)
     865                       when (eql player-topic (player-topic player-assoc))
     866                       return player-assoc)))
     867               (add-to-version-history player-assoc :start-revision revision)))
     868            ((not already-set-player)
     869             (make-instance 'PlayerAssociationC
     870                            :start-revision revision
     871                            :role construct
     872                            :player-topic player-topic))
     873            (t
     874             (error "From add-player(): ~a can't be a player of ~a since it has already the player ~a"
     875                    player-topic construct already-set-player)))
     876      construct)))
     877
     878
     879(defgeneric delete-player (construct player-topic &key revision)
     880  (:documentation "Deletes the passed topic as a player of the passed role
     881                   object by marking its association-object as deleted.")
     882  (:method ((construct RoleC) (player-topic TopicC)
     883            &key (revision (error "From delete-parent(): revision must be set")))
     884    (let ((assoc-to-delete
     885           (loop for player-assoc in (slot-p construct 'player)
     886              when (eql (player-topic player-assoc) player-topic)
     887              return player-assoc)))
     888      (when assoc-to-delete
     889        (mark-as-deleted assoc-to-delete :revision revision))
     890      construct)))
    671891
    672892
     
    746966
    747967
    748 (defgeneric all-identified-constructs (construct &key with-deleted)
    749   (:documentation "Returns all constructs which are associated with this
    750                    pointer.")
    751   (:method ((construct PointerC) &key (with-deleted t))
    752     (let ((all-values (slot-p construct 'identified-construct)))
    753       (let ((filtered-values
    754              (if with-deleted
    755                  all-values
    756                  (remove-if #'marked-as-deleted-p all-values))))
    757         (map 'list #'parent-construct filtered-values)))))
    758 
    759 
    760968;;; ReifiableConstructC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    761969(defpclass ReifiableConstructC(TopicMapConstructC)
     
    8091017  (:method ((construct ReifiableConstructC) (item-identifier ItemIdentifierC)
    8101018            &key (revision *TM-REVISION*))
    811     (let ((all-constructs
    812            (all-identified-constructs item-identifier
    813                                       :with-deleted nil)))
    814       (cond ((find construct all-constructs)
    815              (let ((ii-assoc
    816                     (loop for ii-assoc in (slot-p construct 'item-identifiers)
    817                          when (eql (identifier ii-assoc) item-identifier)
    818                          return ii-assoc)))
    819                (add-to-version-history ii-assoc :start-revision revision)
    820                construct))
    821             (all-constructs
    822              (merge-constructs (first all-constructs) construct))
     1019    (let ((all-ids
     1020           (map 'list #'identifier
     1021                (remove-if #'marked-as-deleted-p
     1022                           (slot-p construct 'item-identifiers)))))
     1023      (cond ((find item-identifier all-ids)
     1024             (let ((ii-assoc (loop for ii-assoc in (slot-p construct
     1025                                                           'item-identifiers)
     1026                                when (eql (identifier ii-assoc) item-identifier)
     1027                                return ii-assoc)))
     1028               (add-to-version-history ii-assoc :start-revision revision)))
     1029            (all-ids
     1030             (merge-constructs (identified-construct (first all-ids)
     1031                                                     :revision revision)
     1032                               construct))
    8231033            (t
    8241034             (make-construct 'ItemIdAssociationC
     
    9101120
    9111121(defgeneric themes (construct &key revision)
    912   (:documentation "Returns all topics that are not marked as deleted and are
     1122  (:documentation "Returns all topics that correspond with the given revision
    9131123                   as a scope for the given topic.")
    9141124  (:method ((construct ScopableC) &key (revision *TM-REVISION*))
     
    9241134  (:method ((construct ScopableC) (theme-topic TopicC)
    9251135            &key (revision *TM-REVISION*))
    926     (let ((all-themes (themes construct)))
     1136    (let ((all-themes
     1137           (map 'list #'theme-topic
     1138                (remove-if #'marked-as-deleted-p (slot-p construct 'themes)))))
    9271139      (if (find theme-topic all-themes)
    9281140          (let ((theme-assoc
Note: See TracChangeset for help on using the changeset viewer.