[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bricolage-commits
Subject:    [Bricolage-Commits] Added support for story-specific output channels to SOAP.
From:       David Wheeler <wheeler () users ! sourceforge ! net>
Date:       2002-11-20 20:52:10
[Download RAW message or body]

Log Message:
-----------
Added support for story-specific output channels to SOAP.

Modified Files:
--------------
    /cvsroot/bricolage/bricolage/lib/Bric:
        Changes.pod
    /cvsroot/bricolage/bricolage/lib/Bric/SOAP:
        Media.pm
        Story.pm
        Util.pm
["wheeler-20021120205210-diff.txt" (wheeler-20021120205210-diff.txt)]

Index: Changes.pod
===================================================================
RCS file: /cvsroot/bricolage/bricolage/lib/Bric/Changes.pod,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -w -d -r1.199 -r1.200
--- Changes.pod	13 Nov 2002 22:58:52 -0000	1.199
+++ Changes.pod	20 Nov 2002 20:52:04 -0000	1.200
@@ -280,6 +280,11 @@
 to be constructed and used to publish stories from within templates. This is
 useful for generating tables of contents and such. [David]
 
+=item *
+
+Added support for the association between business assets and output channels
+to the SOAP interface. [David]
+
 =back
 
 =head1 VERSION 1.4.5
Index: Media.pm
===================================================================
RCS file: /cvsroot/bricolage/bricolage/lib/Bric/SOAP/Media.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -w -d -r1.17 -r1.18
--- Media.pm	9 Nov 2002 01:43:45 -0000	1.17
+++ Media.pm	20 Nov 2002 20:52:06 -0000	1.18
@@ -21,6 +21,7 @@
                         parse_asset_document
                         serialize_elements
                         deserialize_elements
+                        do_output_channels
                        );
 
 use SOAP::Lite;
@@ -117,7 +118,7 @@
 
 =item category
 
-The category containing the story, given as the complete category path
+The category containing the media, given as the complete category path
 from the root.  Example: "/news/linux".
 
 =item workflow
@@ -605,7 +606,7 @@
     }
 
     # loop over media, filling in @media_ids
-    my @media_ids;
+    my (@media_ids, %melems);
     foreach my $mdata (@{$data->{media}}) {
         my $id = $mdata->{id};
 
@@ -618,12 +619,19 @@
         # get user__id from Bric::App::Session
         $init{user__id} = get_user_id;
 
+        unless ($melems{$mdata->{element}}) {
+            my $e = (Bric::Biz::AssetType->list
+              ({ name => $mdata->{element}, media => 1 }))[0]
+                or die __PACKAGE__ . "::create : no media element found " .
+                "matching (element => \"$mdata->{element}\")\n";
+            $melems{$mdata->{element}} =
+              [ $e->get_id,
+                { map { $_->get_name => $_ } $e->get_output_channels } ];
+        }
+
+
         # get element object for asset type
-        ($init{element__id}) = Bric::Biz::AssetType->list_ids(
-                                 { name => $mdata->{element}, media => 1 });
-        die __PACKAGE__ . "::create : no media element found matching " .
-            "(element => \"$mdata->{element}\")\n"
-                unless defined $init{element__id};
+        $init{element__id} = $melems{$mdata->{element}}->[0];
 
         # get source__id from source
         ($init{source__id}) = Bric::Biz::Org::Source->list_ids(
@@ -777,6 +785,16 @@
         $media->deactivate;
         $media->save;
 
+        # Manage the output channels.
+        do_output_channels($media, $mdata->{output_channels}{output_channel},
+                           $melems{$mdata->{element}}->[1], 'media', $update);
+
+        # sanity checks
+        die __PACKAGE__ . "::create : no output channels defined!"
+            unless $media->get_output_channels;
+        die __PACKAGE__ . "::create : no primary output channel defined!"
+            unless defined $media->get_primary_oc_id;
+
         # updates are in-place, no need to futz with workflows and desks
         my $desk;
         unless ($update) {
@@ -872,6 +890,17 @@
 
     # output categories
     $writer->dataElement(category => $media->get_category->ancestry_path);
+
+    # Output output channels.
+    $writer->startTag("output_channels");
+    my $poc = $media->get_primary_oc;
+    $writer->dataElement(output_channel => $poc->get_name, primary => 1);
+    my $pocid = $poc->get_id;
+    foreach my $oc ($media->get_output_channels) {
+        next if $oc->get_id == $pocid;
+        $writer->dataElement(output_channel => $oc->get_name);
+    }
+    $writer->endTag("output_channels");
 
     # output contributors
     $writer->startTag("contributors");
Index: Story.pm
===================================================================
RCS file: /cvsroot/bricolage/bricolage/lib/Bric/SOAP/Story.pm,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -w -d -r1.34 -r1.35
--- Story.pm	13 Nov 2002 06:02:09 -0000	1.34
+++ Story.pm	20 Nov 2002 20:52:06 -0000	1.35
@@ -7,6 +7,7 @@
 use Bric::Biz::Asset::Business::Story;
 use Bric::Biz::AssetType;
 use Bric::Biz::Category;
+use Bric::Biz::OutputChannel;
 use Bric::Util::Grp::Parts::Member::Contrib;
 use Bric::Biz::Workflow qw(STORY_WORKFLOW);
 use Bric::App::Session  qw(get_user_id);
@@ -20,6 +21,7 @@
                         parse_asset_document
                         serialize_elements
                         deserialize_elements
+                        do_output_channels
                        );
 use Bric::SOAP::Media;
 
@@ -224,13 +226,13 @@
 
 {
 # hash of allowed parameters
-my %allowed = map { $_ => 1 } qw(title description slug category 
-                                 keyword simple primary_uri priority
-                                 workflow no_workflow publish_status element
-                                 publish_date_start publish_date_end
-                                 cover_date_start cover_date_end
-                                 expire_date_start expire_date_end
-                                 Order OrderDirection Limit Offset);
+my %allowed = map { $_ => 1 } qw(title description slug category keyword simple
+                                 primary_uri priority workflow no_workflow
+                                 publish_status element publish_date_start
+                                 publish_date_end cover_date_start
+                                 cover_date_end expire_date_start
+                                 expire_date_end Order OrderDirection Limit
+                                 Offset);
 
 sub list_ids {
     my $self = shift;
@@ -695,7 +697,7 @@
     print STDERR Data::Dumper->Dump([$data],['data']) if DEBUG;
 
     # loop over stories, filling in %story_ids and @relations
-    my (%story_ids, @story_ids, @relations);
+    my (%story_ids, @story_ids, @relations, %selems);
     foreach my $sdata (@{$data->{story}}) {
         my $id = $sdata->{id};
 
@@ -708,12 +710,18 @@
         # get user__id from Bric::App::Session
         $init{user__id} = get_user_id;
 
+        unless ($selems{$sdata->{element}}) {
+            my $e = (Bric::Biz::AssetType->list
+              ({ name => $sdata->{element}, media => 0 }))[0]
+                or die __PACKAGE__ . "::create : no story element found " .
+                "matching (element => \"$sdata->{element}\")\n";
+            $selems{$sdata->{element}} =
+              [ $e->get_id,
+                { map { $_->get_name => $_ } $e->get_output_channels } ];
+        }
+
         # get element__id from story element
-        ($init{element__id}) = Bric::Biz::AssetType->list_ids(
-                                 { name => $sdata->{element}, media => 0 });
-        die __PACKAGE__ . "::create : no story element found matching " .
-            "(element => \"$sdata->{element}\")\n"
-                unless defined $init{element__id};
+        $init{element__id} = $selems{$sdata->{element}}->[0];
 
         # get source__id from source
         ($init{source__id}) = Bric::Biz::Org::Source->list_ids(
@@ -871,6 +879,16 @@
         $story->deactivate;
         $story->save;
 
+        # Manage the output channels.
+        do_output_channels($story, $sdata->{output_channels}{output_channel},
+                           $selems{$sdata->{element}}->[1], 'story', $update);
+
+        # sanity checks
+        die __PACKAGE__ . "::create : no output channels defined!"
+            unless $story->get_output_channels;
+        die __PACKAGE__ . "::create : no primary output channel defined!"
+            unless defined $story->get_primary_oc_id;
+
         # remove all keywords if updating
         $story->delete_keywords([ $story->get_keywords ])
             if $update and $story->get_keywords;
@@ -1048,6 +1066,17 @@
         $writer->dataElement(category => $cat->ancestry_path);
     }
     $writer->endTag("categories");
+
+    # Output output channels.
+    $writer->startTag("output_channels");
+    my $poc = $story->get_primary_oc;
+    $writer->dataElement(output_channel => $poc->get_name, primary => 1);
+    my $pocid = $poc->get_id;
+    foreach my $oc ($story->get_output_channels) {
+        next if $oc->get_id == $pocid;
+        $writer->dataElement(output_channel => $oc->get_name);
+    }
+    $writer->endTag("output_channels");
 
     # output keywords
     $writer->startTag("keywords");
Index: Util.pm
===================================================================
RCS file: /cvsroot/bricolage/bricolage/lib/Bric/SOAP/Util.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -w -d -r1.14 -r1.15
--- Util.pm	13 Nov 2002 22:58:53 -0000	1.14
+++ Util.pm	20 Nov 2002 20:52:07 -0000	1.15
@@ -20,6 +20,7 @@
                     parse_asset_document
                     serialize_elements
                     deserialize_elements
+                    do_output_channels
                    );
 
 # set to 1 to see debugging output on STDERR
@@ -148,7 +149,7 @@
     return XMLin($document,
                  keyattr       => [],
                  suppressempty => '',
-                 forcearray    => [qw( contributor category
+                 forcearray    => [qw( contributor category output_channel
                                        keyword element container
                                        data story media template ),
                                    @extra_force_array
@@ -196,6 +197,47 @@
 
     $writer->endTag("elements");
     return @related;
+}
+
+sub do_output_channels {
+    my ($asset, $ocdata, $elem_ocs, $key, $update) = @_;
+        my %ocs;
+        if ($update) {
+            # Note the current output channels.
+            %ocs =  map { $_->get_name => $_ } $asset->get_output_channels;
+        } else {
+            # Delete the existing output channels.
+            $asset->del_output_channels;
+            $asset->set_primary_oc_id;
+        }
+
+        # Update the output channels.
+        foreach my $ocdata (@$ocdata) {
+            # Construct the output channel.
+            my $ocname = ref $ocdata ? $ocdata->{content} : $ocdata;
+            my $oc = delete $ocs{$ocname};
+            unless ($oc) {
+                # We have to add the new output channel to the media. Grab the
+                # OC object from the element.
+                $oc = $elem_ocs->{$ocname} or
+                  die __PACKAGE__ . "::create : output channel matching " .
+                  "(name => \"$ocname\") not allowed or cannot be found\n";
+                $asset->add_output_channels($oc);
+                log_event("${key}_add_oc", $asset,
+                          { 'Output Channel' => $oc->get_name });
+            }
+
+            # Set the primary OC ID, if necessary.
+            $asset->set_primary_oc_id($oc->get_id)
+              if ref $ocdata and $ocdata->{primary};
+        }
+
+        # Delete any remaining output channels.
+        foreach my $oc (values %ocs) {
+            log_event("${key}_del_oc", $asset,
+                      { 'Output Channel' => $oc->get_name });
+            $asset->del_output_channels($oc->get_id);
+        }
 }
 
 =item @relations = deseralize_elements(object => $story, data => $data,
-------------------------------------------------------
This sf.net email is sponsored by: 
Battle your brains against the best in the Thawte Crypto 
Challenge. Be the first to crack the code - register now: 
http://www.gothawte.com/rd521.html
_______________________________________________
Bricolage-Commits mailing list
Bricolage-Commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bricolage-commits

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic