Rally - HP ALM - QC-RallyUsernameToQcUser.pxml
search cancel

Rally - HP ALM - QC-RallyUsernameToQcUser.pxml

book

Article ID: 125051

calendar_today

Updated On:

Products

Rally On-Premise Rally SaaS

Issue/Introduction

An example of a custom field handler (we called it <RallyUsernameToQcUserFieldHandler) which can be used by the QC connector to map CA Agile Central's "SubmittedBy" and " Owner" fields on a Defect to QC's fields "BG_DETECTED_BY" and "BG_RESPONSIBLE" (respectively), when the only difference between the Rally's Username field and QC's User field is the at-sign (@domain.com) in Rally, versus no domain in QC.

Environment

Release:
Component: ACSAAS

Resolution

Below are the 5 sections relating to this QC connector example:



  1. This configuration file: x090-rally_username_to_qc_user_field_handler.pxml
  2. The encode credentials include file for Rally: Encoded-Credentials-Rally-user.xml
  3. The encode credentials include file for QC: Encoded-Credentials-QC11.xml
  4. The Ruby code for the field handler: x090-rally_username_to_qc_user_field_handler.rb





1. Configuration file x090-rally_username_to_qc_user_field_handler.pxml




<?xml version="1.0"?>
<!DOCTYPE config SYSTEM "config.dtd" [
<!ENTITY Encoded-Credentials-Rally SYSTEM "Encoded-Credentials-Rally-user.xml">
<!ENTITY Encoded-Credentials-QC11 SYSTEM "Encoded-Credentials-QC11.xml">
]>
<!-- **********************************************************************
FILE: RallyUsernameToQcUser.pxml

PURPOSE: An example of a custom field handler which can be used by the QC
connector to map QC's fields "BG_DETECTED_BY" and "BG_RESPONSIBLE"
to Rally's "SubmittedBy" and "Owner" fields on a Defect
(respectively). For example, this mapping will do a translation
as follows:

Rally to QC: "[email protected]" to "user"
QC to Rally: "User" to "[email protected]"

For this to work, one must put the Ruby code (below) into a file
named "rally_username_to_qc_user_field_handler.rb", within a
folder named "field_handlers", which must be in your working
folder (i.e. the folder from where the connector is invoked).

USAGE: Replace all the "Your-..." strings below with values appropriate
for your environment.
*********************************************************************** -->
<Config>
<RallyConnection>
<Url>rally1.rallydev.com</Url>
<WorkspaceName>JPKole-Test-WS</WorkspaceName>
<Projects>
<Project>JPKole-Test-Proj</Project>
</Projects>
<!-- <User>...</User>
<Password>...</Password> -->
&Encoded-Credentials-Rally;
<ArtifactType>Defect</ArtifactType>
<ExternalIDField>QCPR01ExtID</ExternalIDField>
<CopySelectors>
<CopySelector>FormattedID = DE372</CopySelector>
</CopySelectors>
</RallyConnection>

<QCConnection>
<Url>SomeVM.f4tech.com:8080</Url>
<Domain>DEFAULT</Domain>
<Project>JPproject11</Project>
<!-- <User>...</User>
<Password>...</Password> -->
&Encoded-Credentials-QC11;
<ArtifactType>BUG</ArtifactType>
<IDField>BG_BUG_ID</IDField>
<ExternalIDField>BG_USER_01</ExternalIDField>
<ExternalEndUserIDField>BG_USER_03</ExternalEndUserIDField>
<FieldDefaults>
<Field><Name>BG_DETECTION_DATE</Name> <Default>2014-11-04</Default></Field>
<Field><Name>BG_SEVERITY</Name> <Default>1-Low</Default></Field>
</FieldDefaults>
<CopySelectors>
<CopySelector>BG_BUG_ID = 94</CopySelector>
</CopySelectors>
</QCConnection>

<Connector>
<FieldMapping>
<Field><Rally>Name</Rally> <Other>BG_SUMMARY</Other></Field>
<Field><Rally>Description</Rally> <Other>BG_DESCRIPTION</Other></Field>
<Field><Rally>SubmittedBy</Rally> <Other>BG_DETECTED_BY</Other></Field>
<Field><Rally>Owner</Rally> <Other>BG_RESPONSIBLE</Other></Field>
</FieldMapping>
<RallyFieldHandlers>
<RallyUsernameToQcUserFieldHandler>
<FieldName>SubmittedBy</FieldName>
</RallyUsernameToQcUserFieldHandler>
<RallyUsernameToQcUserFieldHandler>
<FieldName>Owner</FieldName>
</RallyUsernameToQcUserFieldHandler>
</RallyFieldHandlers>
</Connector>

<ConnectorRunner>
<Preview>false</Preview>
<LogLevel>Debug</LogLevel>
<Services>COPY_QC_TO_RALLY, COPY_RALLY_TO_QC</Services>
</ConnectorRunner>
</Config>





2. The encode credentials include file for Rally: Encoded-Credentials-Rally-user.xml




<User>[email protected]</User>
<Password>encoded-s-e-c-r-e-t-p-w-=-</Password>





3. The encode credentials include file for QC: Encoded-Credentials-QC11.xml




<User>user</User>
<Password>encoded-s-e-c-r-e-t-p-w-=-</Password>






4. The Ruby code for the field handler: x090-rally_username_to_qc_user_field_handler.rb




require 'rallyeif/wrk/field_handlers/field_handler'

module RallyEIF
module WRK
module FieldHandlers

class RallyUsernameToQcUserFieldHandler < RallyFieldHandler #{

VALID_REFERENCES = [:Owner, :SubmittedBy]

def initialize(field_name = nil)
super(field_name)
end

def transform_out(artifact)
# "artifact" is a Rally Artifact object
value = @connection.get_value(artifact, @field_name.to_s)
if !value.nil?
usrobj = value.read
RallyLogger.debug(self, "usrobj.UserName: #{usrobj.UserName}")
RallyLogger.debug(self, "usrobj.DisplayName: #{usrobj.DisplayName}")
RallyLogger.debug(self, "usrobj.FirstName: #{usrobj.FirstName}")
RallyLogger.debug(self, "usrobj.MiddleName: #{usrobj.MiddleName}")
RallyLogger.debug(self, "usrobj.LastName: #{usrobj.LastName}")
RallyLogger.debug(self, "usrobj.NickName: #{usrobj.NickName}")
RallyLogger.debug(self, "usrobj.EmailAddress: #{usrobj.EmailAddress}")

# "value" is a "RallyObject" in QC connector versions after 2.8.8
# puts "DEBUG(RallyUsernameToQcUserFieldHandler.transform_out): value.to_s=#{value.to_s}"
myusername = usrobj.UserName
else
myusername = nil
end

if !myusername.nil?
retval = myusername.split("@").first
else
retval = myusername
end
return retval
end

def transform_in(value)
# The parameter "value" is a string containing the QC user name
RallyLogger.debug(self, "value.class=#{value.class}, value=#{value}")
if !value.nil?
retval = value.dup.concat("@rallydev.com")
else
retval = value
end
return retval
end

def read_config(fh_element)
super(fh_element)
fieldname_element_check(fh_element)

if (VALID_REFERENCES.index(@field_name) == nil)
raise UnrecoverableException.new("Field name for RallyUsernameToQcUserFieldHandler must be from " +
"the following set #{VALID_REFERENCES}", self)
end
end

end #} end of "class RallyUsernameToQcUserFieldHandler < RallyFieldHandler"

end
end
end