to_dataHashObject

in app/models/provenance.rb [211:600]


  def to_dataHashObject(bundle_filepath)

    nodes = []
    links = []

    linkValue = 50
    processorTrimCount = "Processor execution ".length
    workflowRunTrimCount = "Workflow run of ".length

    
    getAllWorkflowRuns.each do |result|

      
      workflowRunURI = result["workflowRun"].to_s
      workflowRunLabel = result["workflowRunLabel"].to_s
      if workflowRunLabel[0] == "W"
        workflowRunLabel = workflowRunLabel[workflowRunTrimCount, workflowRunLabel.length]
      elsif workflowRunLabel[0] == "P"
        workflowRunLabel = workflowRunLabel[processorTrimCount, workflowRunLabel.length]
      end

      
      workflowRun = {:name => workflowRunURI, :type => "Workflow Run", 
                     :label => workflowRunLabel}

      
      indexSource = nodes.find_index(workflowRun)

      
      if indexSource.blank?
        indexSource = nodes.count
        nodes << workflowRun
      end

      
      if result["wasPartOfWorkflowRun"].present?

        secondWorkflowRunLabel = result["wasPartOfWorkflowRunLabel"].to_s
        if secondWorkflowRunLabel[0] == "W"
          secondWorkflowRunLabel = secondWorkflowRunLabel[workflowRunTrimCount, secondWorkflowRunLabel.length]
        elsif secondWorkflowRunLabel[0] == "P"
          secondWorkflowRunLabel = secondWorkflowRunLabel[processorTrimCount, secondWorkflowRunLabel.length]
        end
        secondWorkflowRun = {:name => result["wasPartOfWorkflowRun"].to_s, :type => "Workflow Run",
                             :label => secondWorkflowRunLabel}

        indexTarget = nodes.find_index(secondWorkflowRun)

        if indexTarget.blank?
          indexTarget = nodes.count
          nodes << secondWorkflowRun
        end

        
        linkWfToWf = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkWfToWf).blank?
          links << linkWfToWf
        end
      end

      
      if result["usedArtifactInput"].present?
        artifact = {:name => result["usedArtifactInput"].to_s, :type => "Artifact" }

        indexTarget = nodes.find_index(artifact)

        if indexTarget.blank?
          indexTarget = nodes.count
          nodes << artifact
        end

        
        linkProcessToArtifact = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkProcessToArtifact).blank?
          links << linkProcessToArtifact
        end
      end

      
      if result["usedDictionaryInput"].present?
        dictionary = {:name => result["usedDictionaryInput"].to_s, :type => "Dictionary" }

        indexTarget = nodes.find_index(artifact)

        if indexTarget.blank?
          indexTarget = nodes.count
          nodes << dictionary
        end

        
        linkProcessToArtifact = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkProcessToArtifact).blank?
          links << linkProcessToArtifact
        end
      end

    end

    
    
    getAllProcessRuns.each do |result|
      
      processRunURI = result["processURI"].to_s
      processRunLabel = result["processLabel"].to_s

      
      processRun = {:name => processRunURI, :type => "Process Run", 
                    :startedAtTime => result["startedAtTime"].to_s, :endedAtTime =>result["endedAtTime"].to_s,
                    :label => processRunLabel[processorTrimCount, processRunLabel.length]}
                    

      
      indexSource = nodes.find_index(processRun)

      
      if indexSource.blank?
        indexSource = nodes.count
        nodes << processRun
      end

      
      if result["wasPartOfWorkflow"].present?

        workflowRunLabel = result["wasPartOfWorkflowLabel"].to_s
        if workflowRunLabel[0] == "W"
          workflowRunLabel = workflowRunLabel[workflowRunTrimCount, workflowRunLabel.length]
        elsif workflowRunLabel[0] == "P"
          workflowRunLabel = workflowRunLabel[processorTrimCount, workflowRunLabel.length]
        end


        workflowRun = {:name => result["wasPartOfWorkflow"].to_s, :type => "Workflow Run", 
                       :label => workflowRunLabel}

        indexTarget = nodes.find_index(workflowRun)

        if indexTarget.blank?
          indexTarget = nodes.count
          nodes << workflowRun
        end

        
        linkProcessToWf = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkProcessToWf).blank?
          links << linkProcessToWf
        end
      end

      
      if result["usedArtifactInput"].present?
        artifact = {:name => result["usedArtifactInput"].to_s, :type => "Artifact" }

        indexTarget = nodes.find_index(artifact)

        if indexTarget.blank?
          indexTarget = nodes.count
          nodes << artifact
        end

        
        linkProcessToArtifact = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkProcessToArtifact).blank?
          links << linkProcessToArtifact
        end
      end

      
      if result["usedDictionaryInput"].present?
        dictionary = {:name => result["usedDictionaryInput"].to_s, :type => "Dictionary" }

        indexTarget = nodes.find_index(artifact)

        if indexTarget.blank?
          indexTarget = nodes.count
          nodes << dictionary
        end

        
        linkProcessToArtifact = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkProcessToArtifact).blank?
          links << linkProcessToArtifact
        end
      end



      
      
      

      

      
      
      
      

    
      
      
      
      
      

    end


    
    getAllArtifacts.each do |result|
      
      if result["artifactURI"].present?
        
        artifactURI = result["artifactURI"].to_s

        
        artifact = {:name => artifactURI, :type => "Artifact"}
      else
        
        artifactURI = result["dictionary"].to_s

        
        artifact = {:name => artifactURI, :type => "Dictionary"}
      end

      
      indexSource = -1

      nodes.each_with_index do |node, index|
        if node[:type].to_s == artifact[:type].to_s
          if node[:name].to_s == artifact[:name].to_s
            indexSource = index
            artifactLabel = "List"
            if result["comment"].present?
              artifactLabel = result["comment"].to_s
            end

            if node[:label].present? and node[:label] != "List"
              node[:label] = node[:label] + "\\n" + artifactLabel
              
            else
              node.merge!(:label => artifactLabel)
            end

            if !(node[:content].present?) and result["filepath"].present?
                artifactContent = getContentOf("#{bundle_filepath}#{result["filepath"].to_s}")
                node[:content] = artifactContent
            end
          end
        end
      end

      
      if indexSource == -1
        indexSource = nodes.count
        artifactLabel = "List"
        if result["comment"].present?
          artifactLabel = result["comment"].to_s
        end
        artifact[:label] = artifactLabel

        artifactContent = ""
        if result["filepath"].present?
          artifactContent = getContentOf("#{bundle_filepath}#{result["filepath"].to_s}")
          artifact[:content] = artifactContent
        end
        nodes << artifact
      end

      
      if result["outputFromProcessRun"].present?
        processRunLabel = result["outputFromProcessRunLabel"].to_s

        processRun = {:name => result["outputFromProcessRun"].to_s, :type => "Process Run", 
                      :startedAtTime => result["startedAtTime"].to_s, :endedAtTime =>result["endedAtTime"].to_s,
                      :label => processRunLabel[processorTrimCount, processRunLabel.length]}
    
        indexTarget = nodes.find_index(processRun)

        if indexTarget.blank?
          indexTarget = nodes.count
          nodes << processRun
        end

        
        linkArtifactToProcess = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkArtifactToProcess).blank?
          links << linkArtifactToProcess
        end
      end

      if result["outputFromWorkflowRun"].present?
        workflowRunLabel = result["outputFromWorkflowRunLabel"].to_s

        if workflowRunLabel[0] == "W"
          workflowRunLabel = workflowRunLabel[workflowRunTrimCount, workflowRunLabel.length]
        elsif workflowRunLabel[0] == "P"
          workflowRunLabel = workflowRunLabel[processorTrimCount, workflowRunLabel.length]
        end

        workflowRun = {:name => result["outputFromWorkflowRun"].to_s, :type => "Workflow Run",
                       :label => workflowRunLabel}
    
        indexTarget = nodes.find_index(workflowRun)

        if indexTarget.blank?
          indexTarget = nodes.count
          nodes << workflowRun
        end

        
        linkArtifactToWorkflow = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkArtifactToWorkflow).blank?
          links << linkArtifactToWorkflow
        end
      end

      if result["hadMemberArtifact"].present?
        memberArtifact = {:name => result["hadMemberArtifact"].to_s, :type => "Artifact"}
        
        indexTarget = -1

        nodes.each_with_index do |node, index|
          if node[:type].to_s == memberArtifact[:type].to_s
            if node[:name].to_s == memberArtifact[:name].to_s
              indexTarget = index
            end
          end
        end

        if indexTarget == -1
          if result["comment"].present?
            artifactLabel = result["comment"].to_s
            memberArtifact.merge!(:label => artifactLabel)
          end
          indexTarget = nodes.count
          nodes << memberArtifact
        end

        
        if result["outputFromProcessRun"].present?
          linkDictToArtifact = {:source => indexSource, :target => indexTarget, :value => linkValue}
          if links.find_index(linkDictToArtifact).blank?
            links << linkDictToArtifact
          end
        else
          linkDictToArtifact = {:source => indexTarget, :target => indexSource, :value => linkValue}
          if links.find_index(linkDictToArtifact).blank?
            links << linkDictToArtifact
          end
        end
      
      end

      if result["hadMemberDictionary"].present?
        dictionary = {:name => result["hadMemberDictionary"].to_s, :type => "Dictionary"}
    
        indexTarget = -1

        nodes.each_with_index do |node, index|
          if node[:type].to_s == dictionary[:type].to_s
            if node[:name].to_s == dictionary[:name].to_s
              indexTarget = index
            end
          end
        end

        if indexTarget == -1
          
          
          
          
          indexTarget = nodes.count
          nodes << dictionary
        end

        
        linkDictToDict = {:source => indexTarget, :target => indexSource, :value => linkValue}
        if links.find_index(linkDictToDict).blank?
          links << linkDictToDict
        end
      end
    end

    
    stream = {:nodes => nodes, :links => links }

    
    stream
  end