Changeset 616

Show
Ignore:
Timestamp:
05/03/07 10:33:43 (2 years ago)
Author:
sacha
Message:

added comments to the code
added methods to provide information about the ebXML message. These methods are called from the Message Tracker toolkit.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/hefeweizen_library_ebMS_message2.rb

    r606 r616  
    175175      end 
    176176       
    177       # ebMS ifno 
     177      # ebMS message info based on the ebMS info (from the CPA). 
     178      # The infos are service, action, from name, to name, and the cpa id. 
    178179      def ebMS_info_summary ebMS_info 
    179         return "ebXML Message Info: service is '#{ebMS_info['service']}', action is '#{ebMS_info['action']}', sender is '#{ebMS_info['from']}', receiver is '#{ebMS_info['to']}', CPA ID is '#{ebMS_info['info']['cpa_id']}'." 
     180        "ebXML Message Info: service is '#{ebMS_info['service']}', action is '#{ebMS_info['action']}', sender is '#{ebMS_info['from']}', receiver is '#{ebMS_info['to']}', CPA ID is '#{ebMS_info['info']['cpa_id']}'." 
    180181      end 
    181182 
     
    238239 
    239240      public  
     241 
    240242      def set_new_ebXML_message_file ebXML_message_id, temp_file_path 
    241243        FileUtils.mv temp_file_path, "#{@message_store_directory}/messages/#{ebXML_message_id}/ebXML_message.ebMS2" 
     
    288290 
    289291    # This is the ebXML message class. 
     292    # This class is used for all ebXML Messages version 2.0. This includes user messages and ebMS signals (acks, error, ping, pong etc) 
    290293    class EBMessage2 
    291294 
     
    295298      attr_reader :references, :payloads 
    296299      attr_reader :errors 
    297       attr_accessor :raw_message_file_path 
    298300      attr_reader :ack_ref_to_msg_id 
    299301      attr_reader :message_data_ref_to_message_id 
     
    301303      attr_reader :time_to_live 
    302304      attr_reader :soap_only 
     305      attr_reader :ebXML_message_path 
     306      attr_accessor :raw_message_file_path 
     307 
    303308      def me 
    304309        "EBMessage2" 
     
    309314      end 
    310315 
     316      # This method calculates the hash value of this ebXML message. 
     317      # The values service, action, from name, and to name are used. 
    311318      def get_hash_value cpa 
    312319        hash = Hash.new 
     
    318325      end 
    319326 
     327      # This method returns the current state of the message as a string 
     328      def get_message_state 
     329        states = Dir.glob("#{File.dirname @ebXML_message_path}/message_state/*") 
     330        return "No history for this message." if states.empty? 
     331        (File.basename states[0]).gsub /_/, " " 
     332      end 
     333 
     334      # This method returns a history summary in the form of a string. 
     335      # This is typically used in a text user interface 
     336      def get_history_summary 
     337        out = "" 
     338        counter = 1 
     339        history_events = Dir.glob("#{File.dirname @ebXML_message_path}/message_history/*") 
     340        return "No history for this message." if history_events.empty? 
     341        details_size = 10 
     342        content_size = 12 
     343        event_size = 55 
     344        time_date_size = 15 
     345        out += sprintf "\n  %1$*2$s %3$*4$s %5$*6$s %7$*8$s", "Details Key", -details_size, "Has details", -content_size, "Event", -event_size, "Date/Time", -time_date_size 
     346        history_events.sort.each{ | dir | 
     347          if dir =~ /.*__(.*)/ then 
     348            event = $1.gsub /_/, " " 
     349            time_date = File.ctime(dir).to_s 
     350            has_content = (FileTest.size? dir) ? "x" : "-" 
     351            out += sprintf "\n  H%1$*2$s %3$*4$s %5$*6$s %7$*8$s", counter, -details_size, has_content, -content_size, event, -event_size, time_date, time_date_size 
     352          end 
     353          counter += 1 
     354        } 
     355        return out 
     356      end 
     357 
     358      # This is a online line summary of the message. This includes the service, the action, the from name and to to name. 
    320359      def summary 
    321         return "ebXML Message: service is '#{@service}', action is '#{@action}', sender is '#{@from_name}', receiver is '#{@to_name}'." 
    322       end 
    323  
    324       def ack_requested? 
    325         return @is_ack_requested 
    326       end 
     360        "ebXML Message: service is '#{@service}', action is '#{@action}', sender is '#{@from_name}', receiver is '#{@to_name}'." 
     361      end 
     362 
     363      # This method returns a complete summary of an ebXML message. 
     364      # This is typcially used in a text user interface 
     365      def long_summary 
     366        row = 20 
     367        content_length = 50 
     368        out = "" 
     369        out += sprintf "%1$*2$s %3$*4$s\n", "Title", -row, "Content", -content_length 
     370        out += "-"*(row+content_length) + "\n" 
     371        out += sprintf "%1$*2$s %3$*4$s\n", "Message Id", -row, message_id, -content_length 
     372        out += sprintf "%1$*2$s %3$*4$s\n", "Conversation Id", -row, conversation_id, -content_length 
     373        out += sprintf "%1$*2$s %3$*4$s\n", "CPA ID", -row, cpa_id, -content_length 
     374        out += sprintf "%1$*2$s %3$*4$s\n", "From", -row, from_name, -content_length 
     375        out += sprintf "%1$*2$s %3$*4$s\n", "From Role", -row, (from_role rescue "-"), -content_length 
     376        out += sprintf "%1$*2$s %3$*4$s\n", "To", -row, to_name, -content_length 
     377        out += sprintf "%1$*2$s %3$*4$s\n", "To Role", -row, (to_role rescue "-"), -content_length 
     378        out += sprintf "%1$*2$s %3$*4$s\n", "Service ", -row, service, -content_length 
     379        out += sprintf "%1$*2$s %3$*4$s\n", "Action", -row, action, -content_length 
     380        out += sprintf "%1$*2$s %3$*4$s\n", "Timestamp", -row, message_timestamp, -content_length 
     381        out += sprintf "%1$*2$s %3$*4$s\n", "Message State", -row, get_message_state, -content_length 
     382        if is_user_message? 
     383          out += sprintf "%1$*2$s %3$*4$s\n", "Type of Message", -row, "User Message", -content_length 
     384          out += sprintf "%1$*2$s %3$*4$s\n", "Number of payloads: ", -row, references.size.to_s, -content_length 
     385        else 
     386          out += sprintf "%1$*2$s %3$*4$s\n", "Type of Message", -row, "ebMS Signal Message", -content_length 
     387          if is_ack? then 
     388            out += sprintf "%1$*2$s %3$*4$s\n", "Ref to Messsage ID", -row, ack_ref_to_msg_id, -content_length 
     389          end 
     390        end 
     391        out += sprintf "%1$*2$s %3$s\n", "History" , -row, get_history_summary 
     392      end 
     393 
    327394 
    328395      def is_multipart? 
     
    330397      end 
    331398       
     399      # This method returns whether this message is digitally signed. 
    332400      def is_signed? 
    333401        @has_signature 
     
    335403 
    336404      # TODO : IMPLEMENT 
     405      # This method returns whether this message is encrypted. 
    337406      def is_encrypted? 
    338407        @is_encrypted 
     
    340409       
    341410      # TODO : IMPLEMENT 
     411      # This method returns the encryption protocol of this message if there is a encryption protocol. Nil 
     412      # otherwise 
    342413      def encryption_protocol? 
    343414        @encryption_protocol || nil 
    344415      end 
    345416 
     417      # This method returns the encryption algorithm of this message if there is an encryption algorithm. Nil  
     418      # otherwise. 
    346419      def encryption_algorithm? 
    347420        @encryption_algorithm || nil 
    348421      end 
    349422 
     423      # This method returns whether the message has an Acknowledgement element. 
    350424      def is_ack? 
    351425        @is_ack 
     
    359433      end 
    360434      
    361       def has_ack_requested? 
     435      # This method returns whether the ebXML Message has the AckRequested element. 
     436      def ack_requested? 
    362437        @is_ack_requested 
    363438      end 
    364439 
     440      # has_ack_requested? is another way to find out whether the message has an AckRequested element. 
     441      alias has_ack_requested? ack_requested?  
     442 
     443      # This method returns whether the AckRequested element has the request to be signed. 
    365444      def has_signed_ack_requested? 
    366445        @is_ack_signed_requested rescue false 
    367446      end 
    368  
    369       def has_ack_signature_requested? 
    370         @is_ack_signed_requested rescue false 
    371       end 
    372  
     447       
     448      # has_ack_signature_requested? is another way to find out whether the message has a signed AckRequested element. 
     449      alias has_ack_signature_requested? has_signed_ack_requested? 
     450 
     451      # This method returns whether this message is a non ebMS message service 
    373452      def is_user_message? 
    374453        @service != "urn:oasis:names:tc:ebxml-msg:service" 
     
    403482      end 
    404483 
     484      # This method returns whether the message has the DuplicateElimination element set. 
    405485      def has_duplicate_elimination? 
    406486        @duplicate_elimination 
    407487      end 
    408  
     488       
     489      # This method returns whether the passed in ebMS info (from the CPA) represents an ebXML signal message. 
     490      def EBMessage2.ebMS_info_includes_ebMS_signal? ebMS_info 
     491        (ebMS_info['service'] == "urn:oasis:names:tc:ebxml-msg:service" and ["MessageError", "Ping", "Pong", "StatusRequest", "StatusResponse", "Acknowledgment"].include? ebMS_info['action']) ? true : false 
     492      end 
     493       
     494      # This method is used to get the message type. This is required for ebMS protocol logic. 
    409495      def get_message_type 
    410496        return "User" if is_user_message? 
     
    418504      end 
    419505 
    420       # TODO 
    421       # XML DateTime DataType 
     506      # This method returns the current time in an XML XSD format. 
    422507      def EBMessage2.create_timestamp 
    423508        Time.new.strftime('%Y-%m-%dT%H:%M:%SZ') 
    424509      end 
    425510 
     511      # This method returns the current time in an XML XSD format. 
     512      def create_timestamp 
     513        Time.new.strftime('%Y-%m-%dT%H:%M:%SZ') 
     514      end 
     515 
     516      # This method returns a new ebXML message id 
    426517      def EBMessage2.get_good_message_id 
    427518        HefeWeizen::HefeWeizenLibrary::Execution.uuid.strip.gsub( /-/, "") 
    428519      end 
    429520 
    430       def create_timestamp 
    431         Time.new.strftime('%Y-%m-%dT%H:%M:%SZ') 
    432       end 
    433  
    434521      def EBMessage2.create_message_header_id  
    435522        "ID#{EBMessage2.get_good_message_id}#{HefeWeizen}" 
     
    465552 
    466553      # This method creates an ebXML Message based on directives and ebMS message infos. 
     554      # This includes ebXML user messages and ebMS signals 
     555      # ############################################################# 
     556      # TASKER SMELL 
     557      # TODO A ebXML user message should be constructed in a tasker. 
     558      # The reason being that there can be multiple payloads 
     559      # ############################################################# 
    467560      def EBMessage2.create_message party_ids, directive, ebMS_message_info, complete_ebXML_message_file_path,  
    468561        config, message_id, conversation_id 
     
    749842      end 
    750843       
    751       def EBMessage2.ebMS_info_includes_ebMS_signal? ebMS_info 
    752         (ebMS_info['service'] == "urn:oasis:names:tc:ebxml-msg:service" and ["MessageError", "Ping", "Pong", "StatusRequest", "StatusResponse", "Acknowledgment"].include? ebMS_info['action']) ? true : false 
    753       end 
    754844 
    755845      ################################## 
    756846      ## EBMessage2 
    757847      ################################## 
     848      # This is the constructor of the ebXML Message Version 2.0 class. 
    758849      # currently it is possible to load the ebXML message from a file, string 
    759850      # TODO add as load type URI 
    760851      def initialize config, ebXML_message_path, load_type = "file" 
     852        @ebXML_message_path = ebXML_message_path 
    761853        @config = config 
    762854        @logger = @config['LOGGER'] 
     
    776868        end 
    777869 
     870        require @config['LIB_DIR'].strip + "/hefeweizen_library_utils" 
    778871        @raw_message_file_path = "#{@config['TEMP_FILE_DIR']}/raw_message_#{EBMessage2.get_good_message_id}" 
    779872         
     
    799892        end 
    800893 
     894        # ############################################################# 
     895        # TASKER SMELL 
     896        # o seems like this should be done in a takser ... as the size 
     897        #   and number of the payloads are not known. 
     898        # ############################################################# 
    801899        @soap_only = EBMessage2.raw_message_to_soap_only @raw_message_file_path 
    802900        @payloads = EBMessage2.raw_message_to_payloads @raw_message_file_path 
     
    832930          @has_manifest = false 
    833931        end 
    834  
    835932 
    836933=begin 
     
    854951 
    855952      # This method determines whether there is an action required for this ebXML message. 
     953      # Typically a pong follows a ping or for a message with an AckRequested element an  
     954      # Acknowledgement is required. 
    856955      def get_required_action 
    857956        if self.is_pig? then 
     
    866965          create_ack = self.has_ack_requested? 
    867966           
    868           if create_ack then  
    869             create_signed_ack = self.has_ack_signature_requested? 
    870           end 
     967          create_signed_ack = self.has_ack_signature_requested? if create_ack 
    871968           
    872969          if create_ack == true and create_signed_ack == false then 
     
    897994       
    898995 
    899  
    900  
     996      # This method returns the signature references as a string. 
    901997      def get_signature_references_as_string 
    902          
    903998        if @has_signature then 
    904999          doc = REXML::Document.new(@soap_only) 
     
    9111006          return "" 
    9121007        end 
    913  
    9141008      end 
    9151009 
     
    11421236      # This is very slow and only good for prototyping. 
    11431237      # TODO Fix this for performance. Use low level IO or a tasker 
     1238      # ############################################################# 
     1239      # TASKER SMELL 
     1240      # o seems like this should be done in a takser ... as the size 
     1241      #   and number of the payloads are not known. 
     1242      # ############################################################# 
    11441243      def EBMessage2.raw_message_to_soap_only raw_message_file_path 
    11451244        soap_only = "" 
     
    11771276      # This method reads the multipart mime message and retrieves the payload mime parts and creates 
    11781277      # a payload object of each. 
     1278      # ############################################################# 
     1279      # TASKER SMELL 
     1280      # o seems like this should be done in a takser ... as the size 
     1281      #   and number of the payloads are not known. 
     1282      # ############################################################# 
    11791283      def EBMessage2.raw_message_to_payloads raw_message_file_path 
    11801284        payloads = Hash.new