Opened 15 years ago

Closed 15 years ago

#65 closed task (fixed)

get-item-by-id returns an empty object of TopicC instead of nil

Reported by: lgiessmann Owned by: lgiessmann
Priority: critical Milestone: miscellaneous 2010
Component: data-model Version: 0.1
Keywords: Cc:

Description

scenario:
;> cd isidorus/svn/trunk/src
;> #start emacs + slime

(asdf:operate 'asdf:load-op 'isidorus)

(xml-importer::setup-repository "unit_tests/poems.xtm" "data_base" :tm-id "http://isidorus/tmra2009" :xtm-id "tmra2009")

(d:get-item-by-id "goethe") ; --> returns the correct TopicC-object

;> restart slime

(asdf:operate 'asdf:load-op 'isidorus)

(d:get-item-by-id "goethe") ; --> returns #<TOPICC oid:oethe>, an empty object of the type TopicC

Change History (3)

comment:1 Changed 15 years ago by lgiessmann

Status: newaccepted

comment:2 Changed 15 years ago by lgiessmann

(defun get-item-by-id (topicid &key (xtm-id *current-xtm*) (revision 0) (error-if-nil nil))

"get a topic by its id, assuming a xtm-id. If xtm-id is empty, the current TM

is chosen. If xtm-id is nil, choose the global TM with its internal ID, if
applicable in the correct revision. If revison is provided, then the code checks
if the topic already existed in this revision and returns nil otherwise.
If no item meeting the constraints was found, then the return value is either
NIL or an error is thrown, depending on error-if-nil."

(declare (integer revision))
(let

((result

(if xtm-id

(let

((possible-items

(delete-if-not

(lambda (top-id)

(and

(string= (xtm-id top-id) xtm-id)
(string= (uri top-id) topicid))) ;fixes a bug in

;get-instances-by-value
;that does a
;case-insensitive
;comparision

(elephant:get-instances-by-value

'TopicIdentificationC
'uri
topicid))))

(when (and possible-items

(identified-construct-p (first possible-items)))

(unless (= (length possible-items) 1)

(error (make-condition 'duplicate-identifier-error

:message
(format nil "(length possible-items ~a) for id ~a und xtm-id ~a > 1" possible-items topicid xtm-id)
:uri topicid)))

(let

((found-topic

(identified-construct (first possible-items))))

(if (= revision 0)

found-topic
(find-item-by-revision found-topic revision)))))

(make-instance 'TopicC :from-oid (subseq topicid 1)))))

(if (and error-if-nil (not result))

(error (format nil "no such item (id: ~a, tm: ~a, rev: ~a)" topicid xtm-id revision))
result)))

(make-instance 'TopicC :from-oid (subseq topicid 1))

this line creates always a TopicC objec event if there is not topic related to the given oid.

comment:3 Changed 15 years ago by lgiessmann

Resolution: fixed
Status: acceptedclosed

replaced make-instance :from oid by elephant::controller-recreate-instance

Note: See TracTickets for help on using tickets.