$w->{"dcterms:contributor"} = { 'rdf:resource' => 'https://machine:port/jts/users/_763467823' };
$task->setContributor("d159308");
We will also do our best to hide many enumerations and typenames like com.ibm.team.workitem.taskWorkflow.
And last but not least, tricky bits like changing state of a workitem from New to In Progress will be well-encapsulated within the workitem object, not left as a dangerous safari into the world of the special ?_action= arg.
my $task = new CLM2::WorkItem(); # No! $task->setState("foo"); # Is foo acceptable as a state in the project area # we eventually INTEND to write? Unknown! my $cmpa = $clm->getCMProjectArea("Test Project Area"); my $task = $cmpa->vendWorkItem("task"); # Yes! # $task is properly set up "on the inside" to be saved into the # "Test Project Area."
The "traditional and simple" way to handle something like this would be to have a hashref of info that would be processed and then a NEW hashref return of material coming back from the web service, e.g.
$w->{"dcterms:contributor"} = { 'rdf:resource' => 'https://machine:port/jts/users/_763467823' }; $w->{"dcterms:title"} = { "A Title" }; $result = CLMsave($w); if($result->ok()) { print "new key: ", $result->{content}->{'dcterms:identifier'}; } # Or, if you were a little more fancy about it: my $task = new CLM2::Task(); $task->setTitle("A title"); $task->setContribute("me"); if($clm->save($task) == 0) { print "new key: ", $task->getKey() ; # Ahhh... This is BAD part... }
my $task = new CLM2::Task(); $task->getKey(); # huh? not yet set!
Instead, we will crisply separate workitems, tasks, requirements, etc. as objects independent of the keys in the CLM datastore:
my $task = $cmpa->vendWorkItem("task"); $task->setTitle("a title"); # At this point, the $task object exists in memory only! There is no # id, not resource URI, nothing. my $key = $cmpa->create($task); # At this point, the $task object data exists in the CLM datastore and # is referenced by the $key. $key is an abstract object representing # one item in the CLM datastore. It is NOT the same as $task.
my $task = $cmpa->vendWorkItem(); # no-arg vends task, the simplest workitem my $task2 = $task->copy(); # value semantics! for(my $i = 0; $i < 3; $i++) { $task->setTitle("Title $i"); # reuse task over and over again push(@keys, $cmpa->create($task)); }
my $task = $cmpa->vendTask(); my $key = $cmpa->create($task); doSomething($key); # unless doSomething calls fetch() on $key there is not going to be # much you can do. doOther($task); # You won't be able to update this task in doOther() as it exists # under $key because there's no way to get the key from the object!
my $z = {}; for $k (qw/10404 10565/) { # Assume 10404 and 10565 are valid workitem ids... # More on query() in just a bit but for now.... my ($key, $tsk) = $cmpa->query( { id => $k } ); $z->{$key} = $tsk; # ah HA! Exploit stringy-ness of perl hashrefs... } doSomething($cmpa, $z); # Ah! $z carries everything we need! sub doSomething { my($cmpa, $info) = @_; for $key (keys %{$info}) { # key to hash is full fledged $id object! my $task = $z->{$key}; # Modify the title as an example: $task->setTitle( $task->getTitle() . " -- and more!" ) ; my $rc = $cmpa->update($key, $task); } }
my $workItem = $cmpa->fetch($key); # assume we had $key from somewhere
# General syntax: my @resultPairs = $cmpa->query( various kinds of params ); # Most basic use: a hashref on input; values to keys assumed to be # operator "equals" and implied AND across keys. In this example, # we see id, which is the actual identifier as can be "seen" by a # user of the system (as opposed to the internal key, usually a # wretched URI... my ($key, $task) = $cmpa->query( { id => '10565' } ); # we assume one here! # This is the juice: my @resultPairs = $cmpa->query( { ownedBy => 'd159308' } ); # @resultPairs will be ($key1, $task1, $key2, $task2, $key3, $task3, ...) # One way to work with this material: for $key (@resultPairs) { my $task = shift @resultPairs; # now you can operate on $key, $task; }
my $cmpa = $clm->getCMProjectArea("Test Project Area"); my $qmpa = $clm->getQMProjectArea("A quality place"); my $rmpa = $clm->getRMProjectArea("What do you require?");