Changeset 258
- Timestamp:
- 04/05/10 18:07:59 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/new-datamodel/src/model/datamodel.lisp ¶
r257 r258 156 156 157 157 158 ;;TODO: mark-as-deleted should call mark as deleted for every owned 159 ;; versioned-construct of the called construct 158 160 ;;TODO: check for duplicate identifiers after topic-creation/merge 159 161 ;;TODO: add: add-to-version-history (parent) to all … … 168 170 ;;TODO: use some exceptions --> more than one type, 169 171 ;; identifier, not-mergable merges, missing-init-args... 170 ;;TODO: implement merge-construct -> ReifiableConstructC -> ... 171 ;; the method should merge two constructs that are inherited from 172 ;; ReifiableConstructC 172 173 173 174 174 … … 759 759 760 760 ;;; generic definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 761 (defgeneric mark-as-deleted (construct &key source-locator revision) 762 (:documentation "Mark a construct as deleted if it comes from the source 763 indicated by source-locator")) 764 765 761 766 (defgeneric find-oldest-construct (construct-1 construct-2) 762 767 (:documentation "Returns the construct which owns the oldes version info. … … 856 861 857 862 ;;; VersionedConstructC 863 (defgeneric does-not-exist-in-revision-history (versioned-construct) 864 (:documentation "Returns t if the passed construct does not exist in any 865 revision, i.e. the construct has no version-infos or exactly 866 one whose start-revision is equal to its end-revision.") 867 (:method ((versioned-construct VersionedConstructC)) 868 (or (not (versions versioned-construct)) 869 (and (= (length (versions versioned-construct)) 1) 870 (= (start-revision (first (versions versioned-construct))) 871 (end-revision (first (versions versioned-construct)))))))) 872 873 858 874 (defmethod find-oldest-construct ((construct-1 VersionedConstructC) 859 875 (construct-2 VersionedConstructC)) … … 964 980 965 981 966 (defgeneric mark-as-deleted (construct &key source-locator revision) 967 (:documentation "Mark a construct as deleted if it comes from the source 968 indicated by source-locator") 969 (:method ((construct VersionedConstructC) &key source-locator revision) 970 (declare (ignorable source-locator)) 971 (let 972 ((last-version ;the last active version 973 (find 0 (versions construct) :key #'end-revision))) 974 (when last-version 975 (setf (end-revision last-version) revision))))) 982 (defmethod marks-as-deleted ((construct VersionedConstructC) 983 &key source-locator revision) 984 (declare (ignorable source-locator)) 985 (let 986 ((last-version ;the last active version 987 (find 0 (versions construct) :key #'end-revision))) 988 (when last-version 989 (setf (end-revision last-version) revision)))) 976 990 977 991 … … 1660 1674 (when assocs 1661 1675 (reifiable-construct (first assocs)))))) 1676 1677 1678 (defgeneric add-reified-construct (construct reified-construct &key revision) 1679 (:documentation "Sets the passed construct as reified-consturct of the given 1680 topic.") 1681 (:method ((construct TopicC) (reified-construct ReifiableConstructC) 1682 &key (revision *TM-REVISION*)) 1683 (declare (integer revision)) 1684 (add-reifier reified-construct construct :revision revision))) 1685 1686 1687 (defgeneric delete-reified-construct (construct reified-construct &key revision) 1688 (:documentation "Unsets the passed construct as reified-construct of the 1689 given topic.") 1690 (:method ((construct TopicC) (reified-construct ReifiableConstructC) 1691 &key (revision *TM-REVISION*)) 1692 (declare (integer revision)) 1693 (delete-reifier reified-construct construct :revision revision))) 1662 1694 1663 1695 … … 1932 1964 &key (revision *TM-REVISION*)) 1933 1965 (let ((already-set-parent (parent construct :revision revision)) 1934 (same-parent-assoc ;should contain a object that was marked as deleted1966 (same-parent-assoc ;should contain an object that was marked as deleted 1935 1967 (loop for parent-assoc in (slot-p construct 'parent) 1936 1968 when (eql parent-construct (parent-construct parent-assoc)) … … 2599 2631 reifier-topic) 2600 2632 reifier-topic))) 2601 (let ((all-constructs 2602 (let ((inner-construct (reified-construct merged-reifier-topic 2603 :revision revision))) 2604 (when inner-construct 2605 (list inner-construct))))) 2633 (let ((all-constructs (map 'list #'reifiable-construct 2634 (slot-p reifier-topic 'reified-construct)))) 2606 2635 (let ((merged-construct construct)) 2607 (cond ((find construct all-constructs) 2636 (cond ((reified-construct merged-reifier-topic :revision revision) 2637 (merge-constructs 2638 (reified-construct merged-reifier-topic :revision revision) 2639 construct)) 2640 ((find construct all-constructs) 2608 2641 (let ((reifier-assoc 2609 2642 (loop for reifier-assoc in … … 2614 2647 (add-to-version-history reifier-assoc 2615 2648 :start-revision revision))) 2616 (all-constructs2617 (merge-constructs (first all-constructs) construct))2618 2649 (t 2619 2650 (make-construct 'ReifierAssociationC … … 2960 2991 (error "From make-association(): start-revision must be set")) 2961 2992 (let ((association 2962 (let ((existing-association 2993 (let ((existing-associations 2963 2994 (remove-if 2964 2995 #'null … … 2971 3002 existing-association)) 2972 3003 (elephant:get-instances-by-class 'AssociationC))))) 2973 (if existing-association 2974 (first existing-association) 2975 (make-instance 'AssociationC))))) 3004 (cond ((> (length existing-associations) 1) 3005 (merge-all-constructs existing-associations)) 3006 (existing-associations 3007 (first existing-associations)) 3008 (t 3009 (make-instance 'AssociationC)))))) 2976 3010 (dolist (role-plist roles) 2977 3011 (add-role association … … 2994 3028 (error "From make-role(): start-revision must be set")) 2995 3029 (let ((role 2996 (let ((existing-role 3030 (let ((existing-roles 2997 3031 (when parent 2998 3032 (remove-if … … 3006 3040 existing-role)) 3007 3041 (map 'list #'role (slot-p parent 'roles))))))) 3008 (if existing-role 3009 (first existing-role) 3010 (make-instance 'RoleC))))) 3042 (cond ((> (length existing-roles) 1) 3043 (merge-all-constructs existing-roles)) 3044 (existing-roles 3045 (first existing-roles)) 3046 (t 3047 (make-instance 'RoleC)))))) 3011 3048 (when player 3012 3049 (add-player role player :revision start-revision)) … … 3039 3076 existing-tm)) 3040 3077 (elephant:get-instances-by-class 'TopicMapC))))) 3041 (cond (( and existing-tms (> (length existing-tms) 1))3078 (cond ((> (length existing-tms) 1) 3042 3079 (merge-all-constructs existing-tms)) 3043 3080 (existing-tms … … 3078 3115 existing-topic)) 3079 3116 (elephant:get-instances-by-class 'TopicC))))) 3080 (cond (( and existing-topics (> (length existing-topics) 1))3117 (cond ((> (length existing-topics) 1) 3081 3118 (merge-all-constructs existing-topics)) 3082 3119 (existing-topics … … 3206 3243 3207 3244 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3245 ;;; merge-constructs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3246 (defgeneric move-identifiers (source destination &key revision) 3247 (:documentation "Sets all identifiers as mark as deleted in the given 3248 version and adds the marked identifiers to the 3249 destination construct.")) 3250 3251 3252 (defmethod move-identifiers ((source ReifiableConstructC) 3253 (destination ReifiableConstructC) 3254 &key (revision *TM-REVISION*)) 3255 (declare (integer revision)) 3256 (let ((iis (item-identifiers source :revision revision))) 3257 (dolist (ii iis) 3258 (delete-item-identifier source ii :revision revision) 3259 (add-item-identifier destination ii :revision revision)) 3260 iis)) 3261 3262 3263 (defmethod move-identifiers ((source TopicC) (destination TopicC) 3264 &key (revision *TM-REVISION*)) 3265 (declare (integer revision)) 3266 (let ((iis (call-next-method)) 3267 (tids (topic-identifiers source :revision revision)) 3268 (psis (psis source :revision revision)) 3269 (sls (locators source :revision revision))) 3270 (dolist (tid tids) 3271 (delete-topic-identifier source tid :revision revision) 3272 (add-topic-identifier destination tid :revision revision)) 3273 (dolist (psi psis) 3274 (delete-psi source psi :revision revision) 3275 (add-psi destination psi :revision revision)) 3276 (dolist (sl sls) 3277 (delete-locator source sl :revision revision) 3278 (add-locator destination sl :revision revision)) 3279 (append tids iis psis sls))) 3280 3281 3282 (defgeneric move-referenced-constructs (source destination &key revision) 3283 (:documentation "Moves all referenced constructs in the given version from 3284 the source TM-construct to the destination TM-construct.")) 3285 3286 3287 (defmethod move-referenced-constructs ((source ReifiableConstructC) 3288 (destination ReifiableConstructC) 3289 &key (revision *TM-REVISION*)) 3290 (let ((source-reifier (reifier source :revision revision)) 3291 (destination-reifier (reifier destination :revision revision))) 3292 (cond ((and source-reifier destination-reifier) 3293 (delete-reifier (reified-construct source-reifier :revision revision) 3294 source-reifier :revision revision) 3295 (delete-reifier (reified-construct destination-reifier 3296 :revision revision) 3297 destination-reifier :revision revision) 3298 (let ((merged-reifier 3299 (merge-constructs source-reifier destination-reifier 3300 :revision revision))) 3301 (add-reifier destination merged-reifier :revision revision))) 3302 (source-reifier 3303 (delete-reifier (reified-construct source-reifier :revision revision) 3304 source-reifier :revision revision) 3305 (add-reifier destination source-reifier :revision revision) 3306 source-reifier) 3307 (destination-reifier 3308 (add-reifier destination destination-reifier :revision revision) 3309 destination-reifier)))) 3310 3311 3312 (defmethod move-referenced-constructs ((source TopicC) (destination TopicC) 3313 &key (revision *TM-REVISION*)) 3314 (let ((roles (player-in-roles source :revision revision)) 3315 (scopables (used-as-theme source :revision revision)) 3316 (typables (used-as-type source :revision revision))) 3317 (dolist (role roles) 3318 (delete-player role source :revision revision) 3319 (add-player role destination :revision revision)) 3320 (dolist (scopable scopables) 3321 (delete-theme scopable source :revision revision) 3322 (add-theme scopable destination :revision revision)) 3323 (dolist (typable typables) 3324 (delete-type typable source :revision revision) 3325 (add-type typable destination :revision revision)) 3326 (append roles scopables typables))) 3327 3328 3329 (defgeneric move-reified-construct (source destination &key revision) 3330 (:documentation "Moves the refied TM-construct from the source topic 3331 to the given destination topic.") 3332 (:method ((source TopicC) (destination TopicC) &key (revision *TM-REVISION*)) 3333 (declare (integer revision)) 3334 (let ((source-reified (reified-construct source :revision revision)) 3335 (destination-reified (reified-construct destination 3336 :revision revision))) 3337 (unless (eql (type-of source-reified) (type-of destination-reified)) 3338 (error "From move-reified-construct(): ~a and ~a can't be merged since the reified-constructs are not of the same type ~a ~a" 3339 source destination source-reified destination-reified)) 3340 (cond ((and source-reified destination-reified) 3341 (delete-reifier source-reified source :revision revision) 3342 (delete-reifier destination-reified destination :revision revision) 3343 (let ((merged-reified 3344 (merge-constructs source-reified destination-reified 3345 :revision revision))) 3346 (add-reifier merged-reified destination :revision revision) 3347 merged-reified)) 3348 (source-reified 3349 (delete-reifier source source-reified :revision revision) 3350 (add-reifier destination source-reified :revision revision) 3351 source-reified) 3352 (destination-reified 3353 (add-reifier destination destination-reified :revision revision) 3354 destination-reified))))) 3355 3356 3357 (defgeneric move-occurrences (source destination &key revision) 3358 (:documentation "Moves all occurrences from the source topic to the 3359 destination topic. If occurrences are TMDM equal 3360 they are merged, i.e. one is marked-as-deleted.") 3361 (:method ((source TopicC) (destination TopicC) &key (revision *TM-REVISION*)) 3362 (declare (integer revision)) 3363 (let ((occs-to-move (occurrences source :revision revision))) 3364 (dolist (occ occs-to-move) 3365 (delete-occurrence occ source :revision revision) 3366 (let ((equivalent-occ 3367 (find-if #'(lambda (destination-occ) 3368 (when 3369 (strictly-equivalent-constructs 3370 occ destination-occ :revision revision) 3371 destination-occ)) 3372 (occurrences destination :revision revision)))) 3373 (if equivalent-occ 3374 (progn 3375 (add-occurrence destination equivalent-occ :revision revision) 3376 (move-identifiers occ equivalent-occ :revision revision) 3377 (move-referenced-constructs occ equivalent-occ 3378 :revision revision)) 3379 (add-occurrence destination occ :revision revision)))) 3380 occs-to-move))) 3381 3382 3383 (defgeneric move-variants (source destination &key revision) 3384 (:documentation "Moves all variants from the source name to the destination 3385 name. If any variants are TMDM equal they are merged --> 3386 i.e. one of the variants is marked-as-deleted.") 3387 (:method ((source NameC) (destination NameC) &key (revision *TM-REVISION*)) 3388 (declare (integer revision)) 3389 (let ((vars-to-move (variants source :revision revision))) 3390 (dolist (var vars-to-move) 3391 (delete-variant source var :revision revision) 3392 (let ((equivalent-var 3393 (find-if #'(lambda (destination-var) 3394 (when 3395 (strictly-equivalent-constructs 3396 var destination-var :revision revision) 3397 destination-var)) 3398 (variants destination :revision revision)))) 3399 (if equivalent-var 3400 (progn 3401 (add-variant destination equivalent-var :revision revision) 3402 (move-identifiers var equivalent-var :revision revision) 3403 (move-referenced-constructs var equivalent-var 3404 :revision revision)) 3405 (add-variant destination var :revision revision)))) 3406 vars-to-move))) 3407 3408 3409 (defgeneric move-names (source destination &key revision) 3410 (:documentation "Moves all names from the source topic to the destination 3411 topic. If any names are equal they are merged, i.e. 3412 one of the names is marked-as-deleted.") 3413 (:method ((source TopicC) (destination TopicC) &key (revision *TM-REVISION*)) 3414 (declare (integer revision)) 3415 (let ((names-to-move (names source :revision revision))) 3416 (dolist (name names-to-move) 3417 (delete-name source name :revision revision) 3418 (let ((equivalent-name 3419 (find-if #'(lambda (destination-name) 3420 (when 3421 (strictly-equivalent-constructs 3422 name destination-name :revision revision) 3423 destination-name)) 3424 (names destination :revision revision)))) 3425 (if equivalent-name 3426 (progn 3427 (move-variants name equivalent-name :revision revision) 3428 (add-name destination equivalent-name :revision revision) 3429 (move-identifiers name equivalent-name :revision revision) 3430 (move-referenced-constructs name equivalent-name 3431 :revision revision)) 3432 (add-name destination name :revision revision)))) 3433 names-to-move))) 3434 3435 3436 (defun merge-changed-constructs (older-topic &key (revision *TM-REVISION*)) 3437 (declare (TopicC older-topic)) 3438 (dolist (construct (append (used-as-type older-topic :revision revision) 3439 (used-as-theme older-topic :revision revision) 3440 (player-in-roles older-topic :revision revision))) 3441 (let ((parent (when (or (typep construct 'RoleC) 3442 (typep construct 'CharacteristicC)) 3443 (parent construct :revision revision)))) 3444 (let ((found-equivalent 3445 (find-if #'(lambda(other-construct) 3446 (strictly-equivalent-constructs 3447 other-construct construct :revision revision)) 3448 (cond ((typep construct 'OccurrenceC) 3449 (occurrences parent :revision revision)) 3450 ((typep construct 'NameC) 3451 (names parent :revision revision)) 3452 ((typep construct 'VariantC) 3453 (variants parent :revision revision)) 3454 ((typep construct 'RoleC) 3455 (roles parent :revision revision)) 3456 ((typep construct 'AssociationC) 3457 (elephant:get-instances-by-class 'AssociationC)))))) 3458 (when found-equivalent 3459 (merge-all-constructs (append found-equivalent (list construct)))))))) 3460 3461 3462 3463 (defmethod merge-constructs ((construct-1 TopicC) (construct-2 TopicC) 3464 &key (revision *TM-REVISION*)) 3465 (let ((older-topic (find-oldest-construct construct-1 construct-2))) 3466 (let ((newer-topic (if (eql older-topic construct-1) 3467 construct-2 3468 construct-1))) 3469 (move-identifiers newer-topic older-topic :revision revision) 3470 (dolist (tm (in-topicmaps newer-topic :revision revision)) 3471 (add-to-tm tm older-topic)) 3472 (move-names newer-topic older-topic :revision revision) 3473 (move-occurrences newer-topic older-topic :revision revision) 3474 (move-referenced-constructs newer-topic older-topic :revision revision) 3475 (move-reified-construct newer-topic older-topic :revision revision) 3476 (merge-changed-constructs older-topic :revision revision) 3477 (mark-as-deleted newer-topic :revision revision) 3478 (when (does-not-exist-in-revision-history newer-topic) 3479 (delete-construct newer-topic)) 3480 older-topic))) 3481 3482 3483 3484 3485 3486 3487 3488 ;TODO: merge-constructs: RoleC, AssociationC, TopicMapC, 3489 ; OccurrenceC, NameC, VariantC --> call merge-constructs of the parent 3490 ; and return the active construct on what merge-constructs was initialy 3491 ; called 3221 3492 3222 3493 … … 3229 3500 (or revision) 3230 3501 (if construct-1 construct-1 construct-2)) 3502 3503 3504 3505 3231 3506 ;;; end hacks ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3232 3233 3234 (defun merge-characteristics (older-parent newer-parent3235 &key (revision *TM-REVISION*)3236 (characteristic-type 'OccurrenceC))3237 "Deletes all characteristics of the given type from the newer-parent.3238 Merges equivalent characteristics between the newer and the older parent.3239 Adds all characteristics from the newer-parent to the older-parent or adds3240 the merged characterisitcs to the older-parent."3241 (declare (type (or TopicC NameC) older-parent newer-parent)3242 (integer revision) (symbol characteristic-type))3243 (let ((object-name3244 (subseq (write-to-string characteristic-type) 03245 (- (length (write-to-string characteristic-type)) 1))))3246 (let ((request-fun3247 (symbol-function3248 (find-symbol (concatenate 'string object-name "S"))))3249 (delete-fun3250 (symbol-function3251 (find-symbol (concatenate 'string "DELETE-" object-name))))3252 (add-fun3253 (symbol-function3254 (find-symbol (concatenate 'string "ADD-" object-name)))))3255 (dolist (newer-char (funcall request-fun newer-parent :revision revision))3256 (let ((older-char3257 (find-if #'(lambda(char)3258 (equivalent-constructs char newer-char3259 :revision revision))3260 (funcall request-fun older-parent :revision revision))))3261 (funcall delete-fun newer-parent newer-char :revision revision)3262 (if (and newer-char older-char)3263 (progn3264 (funcall delete-fun older-parent older-char :revision revision)3265 (funcall add-fun older-parent3266 (merge-constructs newer-char older-char3267 :revision revision)))3268 (funcall add-fun older-parent newer-char)))))))3269 3270 3271 (defmethod merge-constructs ((construct-1 ReifiableConstructC)3272 (construct-2 ReifiableConstructC)3273 &key (revision *TM-REVISION*))3274 (declare (integer revision))3275 (if (eql construct-1 construct-2)3276 construct-13277 (let ((older-construct (find-oldest-construct construct-1 construct-2)))3278 (let ((newer-construct (if (eql older-construct construct-1)3279 construct-23280 construct-1)))3281 (dolist (ii (item-identifiers newer-construct :revision revision))3282 (delete-item-identifier newer-construct ii :revision revision)3283 (add-item-identifier older-construct ii :revision revision))3284 (let ((reifier-1 (reifier newer-construct :revision revision))3285 (reifier-2 (reifier older-construct :revision revision)))3286 (when reifier-13287 (delete-reifier newer-construct reifier-1 :revision revision)3288 (let ((merged-reifier3289 (if reifier-23290 (progn3291 (delete-reifier older-construct reifier-23292 :revision revision)3293 (merge-constructs reifier-1 reifier-23294 :revision revision))3295 reifier-1)))3296 (add-reifier older-construct merged-reifier :revision revision))))3297 (when (and (eql (type-of newer-construct) 'ReifiableConstructC)3298 (eql (type-of newer-construct) 'ReifiableConstructC)3299 (typep newer-construct 'VersionedConstructC)3300 (typep older-construct 'VersionedConstructC))3301 ;;If the older-construct is a "real" ReifiableConstructC and no sub3302 ;;class the older-construct must be marked as deleted.3303 ;;Sub classes are marked as deleted in the "next-method" calls.3304 (mark-as-deleted newer-construct :revision revision)3305 (add-to-version-history older-construct :start-revision revision))3306 older-construct))))3307 3308 3309 (defmethod merge-constructs ((construct-1 CharacteristicC)3310 (construct-2 CharacteristicC)3311 &key (revision *TM-REVISION*))3312 (declare (integer revision))3313 (unless (equivalent-constructs construct-1 construct-2 :revision revision)3314 (error "From merge-constructs(): ~a and ~a are not mergable"3315 construct-1 construct-2))3316 (if (eql construct-1 construct-2)3317 construct-13318 (let ((older-construct (call-next-method)))3319 (let ((newer-construct (if (eql older-construct construct-1)3320 construct-23321 construct-1)))3322 (when (and (typep construct-1 'NameC) (typep construct-2 'NameC))3323 (merge-characteristics older-construct newer-construct3324 :revision revision3325 :characteristic-type 'VariantC)))3326 older-construct)))3327 3328 3329 (defmethod merge-constructs ((construct-1 TopicC) (construct-2 TopicC)3330 &key (revision *TM-REVISION*))3331 (declare (integer revision))3332 (if (eql construct-1 construct-2)3333 construct-13334 (let ((older-construct (call-next-method)))3335 (let ((newer-construct (if (eql older-construct construct-1)3336 construct-23337 construct-1)))3338 (dolist (psi (psis newer-construct :revision revision))3339 (delete-psi newer-construct psi :revision revision)3340 (add-psi older-construct psi :revision revision))3341 (dolist (locator (locators newer-construct :revision revision))3342 (delete-locator newer-construct locator :revision revision)3343 (add-locator older-construct locator :revision revision))3344 (merge-characteristics older-construct newer-construct3345 :revision revision3346 :characteristic-type 'OccurrenceC)3347 (merge-characteristics older-construct newer-construct3348 :revision revision3349 :characteristic-type 'NameC)3350 ;;player-in-roles3351 ;;used-as-type3352 ;;used-as-scope3353 ;;reified-construct3354 ;;in-topicmaps3355 ))))3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371
Note: See TracChangeset
for help on using the changeset viewer.