Skip to content

Commit

Permalink
Merge pull request #3997 from Ginger-Automation/Beta/BugFix/RQMChanges
Browse files Browse the repository at this point in the history
RQM fixes for custom Attributes
  • Loading branch information
Maheshkale447 authored Nov 14, 2024
2 parents 570e01d + 97e3be2 commit e35d8dc
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 40 deletions.
43 changes: 27 additions & 16 deletions Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
using ACL_Data_Contract;
using ACL_Data_Contract.Abstraction;
using ALM_CommonStd.DataContracts;
using amdocs.ginger.GingerCoreNET;
using Amdocs.Ginger.Common;
using Amdocs.Ginger.Common.InterfacesLib;
using Amdocs.Ginger.IO;
Expand Down Expand Up @@ -109,6 +108,14 @@ private void GetRQMProjectListConfiguration()
RQMTestPlan testPlan;
public bool ExportExecutionDetailsToRQM(BusinessFlow businessFlow, ref string result, bool exectutedFromAutomateTab = false, PublishToALMConfig publishToALMConfig = null, ProjEnvironment projEnvironment = null)
{
var originalExternalFields = General.GetExternalFields();

if (!originalExternalFields.Any(x => x.ItemType == "TestCase"))
{
Reporter.ToUser(eUserMsgKey.StaticInfoMessage, "Current solution have no predefined values for RQM's mandatory fields. Please configure before doing export. ('ALM'-'ALM Items Fields Configuration')");
return false;
}
List<ACL_Data_Contract.ExternalItemFieldBase> ExternalFields = ConvertExternalFieldsToACLDataContractfields(originalExternalFields);
result = string.Empty;
string bfExportedID = GetExportedIDString(businessFlow.ExternalIdCalCulated, "RQMID");
if (string.IsNullOrEmpty(bfExportedID) || bfExportedID.Equals("0"))
Expand Down Expand Up @@ -194,7 +201,7 @@ public bool ExportExecutionDetailsToRQM(BusinessFlow businessFlow, ref string re
|| publishToALMConfig.FilterStatus == FilterByStatus.All)
{
testPlan.Name = !string.IsNullOrEmpty(publishToALMConfig.VariableForTCRunNameCalculated) ? publishToALMConfig.VariableForTCRunNameCalculated : testPlan.Name;
ExecutionResult exeResult = GetExeResultforActivityGroup(businessFlow, bfExportedID, activGroup, ref result, testPlan, currentRQMProjectMapping, loginData, publishToALMConfig);
ExecutionResult exeResult = GetExeResultforActivityGroup(businessFlow, bfExportedID, activGroup, ref result, testPlan, currentRQMProjectMapping, loginData, publishToALMConfig, ExternalFields);
if (exeResult != null)
{
exeResultList.Add(exeResult);
Expand Down Expand Up @@ -242,7 +249,7 @@ public bool ExportExecutionDetailsToRQM(BusinessFlow businessFlow, ref string re
}
valuelist.Add(exeResultList.FirstOrDefault().TestCaseExportID);

resultInfo = RQMConnect.Instance.RQMRep.ExportExecutionResult(loginData, exeResultList, RQMCore.ALMProjectGuid, ALMCore.DefaultAlmConfig.ALMProjectName, RQMCore.ALMProjectGroupName);
resultInfo = RQMConnect.Instance.RQMRep.ExportExecutionResult(loginData, exeResultList, RQMCore.ALMProjectGuid, ALMCore.DefaultAlmConfig.ALMProjectName, RQMCore.ALMProjectGroupName,null, ExternalFields);
if (!resultInfo.IsSuccess)
{
Reporter.ToLog(eLogLevel.ERROR, $"Failed to Update Execution Record Results for {businessFlow.Name} and testplan {bfExportedID}, execution record id {exeResultList.FirstOrDefault().ExecutionRecordExportID} Error: {resultInfo.ErrorDesc}");
Expand Down Expand Up @@ -374,7 +381,7 @@ public bool ExportExecutionDetailsToRQM(BusinessFlow businessFlow, ref string re
// get data about execution records per current test plan - finish
return false;
}
private ExecutionResult GetExeResultforActivityGroup(BusinessFlow businessFlow, string bfExportedID, ActivitiesGroup activGroup, ref string result, RQMTestPlan testPlan, RQMProject currentRQMProjectMapping, LoginDTO loginData, PublishToALMConfig publishToALMConfig)
private ExecutionResult GetExeResultforActivityGroup(BusinessFlow businessFlow, string bfExportedID, ActivitiesGroup activGroup, ref string result, RQMTestPlan testPlan, RQMProject currentRQMProjectMapping, LoginDTO loginData, PublishToALMConfig publishToALMConfig, List<ACL_Data_Contract.ExternalItemFieldBase> ExternalFields = null)
{
try
{
Expand Down Expand Up @@ -507,7 +514,7 @@ private ExecutionResult GetExeResultforActivityGroup(BusinessFlow businessFlow,
if (string.IsNullOrEmpty(exeRecordId) || exeRecordId.Equals("0"))
{
Reporter.ToLog(eLogLevel.DEBUG, $"Record id not found for {businessFlow.Name}, creating new record");
result = CreateExecutionRecord(bfExportedID, activGroup, testPlan, loginData, testCaseId, testScriptId, ref exeRecordId);
result = CreateExecutionRecord(bfExportedID, activGroup, testPlan, loginData, testCaseId, testScriptId, ref exeRecordId,ExternalFields);
}
}

Expand Down Expand Up @@ -650,20 +657,13 @@ private ExecutionResult GetExeResultforActivityGroup(BusinessFlow businessFlow,
}
}

private string CreateExecutionRecord(string bfExportedID, ActivitiesGroup activGroup, RQMTestPlan testPlan, LoginDTO loginData, string txExportID, string tsExportID, ref string erExportID)
private string CreateExecutionRecord(string bfExportedID, ActivitiesGroup activGroup, RQMTestPlan testPlan, LoginDTO loginData, string txExportID, string tsExportID, ref string erExportID, List<ACL_Data_Contract.ExternalItemFieldBase> ExternalFields = null)
{
string result = string.Empty;
ACL_Data_Contract.Activity currentActivity = GetTestCaseFromActivityGroup(activGroup);
try
{
var originalExternalFields = General.GetExternalFields();

if (!originalExternalFields.Any(x => x.ItemType == "TestCase"))
{
Reporter.ToUser(eUserMsgKey.StaticInfoMessage, "Current solution have no predefined values for RQM's mandatory fields. Please configure before doing export. ('ALM'-'ALM Items Fields Configuration')");
return null;
}
List<ACL_Data_Contract.ExternalItemFieldBase> ExternalFields = ConvertExternalFieldsToACLDataContractfields(originalExternalFields);
// if executionRecord not updated and not exists - so create one in RQM and update BussinesFlow object (this may be not saved due not existed "autosave" functionality)
var resultInfo = RQMConnect.Instance.RQMRep.CreateExecutionRecordPerActivity(loginData, RQMCore.ALMProjectGuid, ALMCore.DefaultAlmConfig.ALMProjectName, RQMCore.ALMProjectGroupName, currentActivity, bfExportedID, testPlan.Name, ExternalFields);
if (resultInfo != null && !string.IsNullOrEmpty(resultInfo.ErrorDesc))
Expand Down Expand Up @@ -786,7 +786,7 @@ public bool ExportBusinessFlowToRQM(BusinessFlow businessFlow, ObservableList<Ex

}

ResultInfo resultInfo;
ALM_CommonStd.DataContracts.ResultInfo resultInfo;
try
{
//Create (RQM)TestCase for each Ginger ActivityGroup and add it to RQM TestCase List
Expand Down Expand Up @@ -925,9 +925,17 @@ public bool ExportBusinessFlowToRQM(BusinessFlow businessFlow, ObservableList<Ex
field.ItemType = fields[indx].ItemType;
field.Name = fields[indx].Name;
field.SelectedValue = fields[indx].SelectedValue;
field.ID = fields[indx].ID;
field.Type = fields[indx].Type;
field.TypeIdentifier = fields[indx].TypeIdentifier;
field.IsMultiple = fields[indx].IsMultiple;

if (!fieldsToReturn.Any(f => f.ID == field.ID))
{
// Add it if it doesn't already exist
fieldsToReturn.Add(field);
}
}

return fieldsToReturn;
}

Expand Down Expand Up @@ -1131,7 +1139,10 @@ private Dictionary<string, string> GetCustomProperties(string ItemType)
{
if (itemField.Mandatory == true || itemField.ToUpdate == true)
{
propertiesList.Add(itemField.Name, itemField.SelectedValue);
if (!propertiesList.ContainsKey(itemField.Name))
{
propertiesList.Add(itemField.Name, itemField.SelectedValue);
}
}
}
}
Expand Down
94 changes: 82 additions & 12 deletions Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,6 @@ private static ObservableList<ExternalItemFieldBase> GetCustomAttributes(Backgro
}
//TODO: Get 'next' and 'last links
XmlNodeList CustomAttributelinkList_ = CustomAttributeList.GetElementsByTagName("link");

if (CustomAttributelinkList_.Count > 0)
{
XmlNode selfPage = CustomAttributelinkList_.Item(1);
Expand Down Expand Up @@ -1352,8 +1351,6 @@ private static ObservableList<ExternalItemFieldBase> GetCustomAttributes(Backgro
{
CustomAttributeListing.LoadXml(CustomAttributeDetail.responseText);
}


string CustomAttributeName = string.Empty; // -->itemfield.Name
string CustomAttributeItemType = string.Empty; //-->itemfield.ItemType
string CustomAttributeMandatory = string.Empty; // --> itemfield.Mandatory & initial value for : --> itemfield.ToUpdate
Expand All @@ -1364,14 +1361,56 @@ private static ObservableList<ExternalItemFieldBase> GetCustomAttributes(Backgro
CustomAttributeName = CustomAttributeListing.GetElementsByTagName("ns4:title").Item(0).InnerText;
CustomAttributeItemType = CustomAttributeListing.GetElementsByTagName("ns2:scope").Item(0).InnerText;
string CustomAttributefieldType = CustomAttributeListing.GetElementsByTagName("ns2:type").Item(0).InnerText;
CustomAttributeMandatory = "false";
// Define the namespace manager for the XML document
XmlNamespaceManager nsManager = new XmlNamespaceManager(CustomAttributeListing.NameTable);
nsManager.AddNamespace("ns2", "http://jazz.net/xmlns/alm/qm/v0.1/");

// XPath query to find ns2:required
string xpath = "//ns2:required";

// Use SelectSingleNode to check if ns2:required element exists
XmlNode requiredNode = CustomAttributeListing.SelectSingleNode(xpath, nsManager);

if (requiredNode != null)
{
CustomAttributeMandatory = requiredNode.InnerText;
}
else
{
CustomAttributeMandatory = "false";
}



itemfield.ItemType = CustomAttributeItemType;
itemfield.ID = CustomAttributeID;
itemfield.Name = CustomAttributeName;
itemfield.Type = CustomAttributefieldType;
itemfield.TypeIdentifier = typeIdentifier;
if (CustomAttributeMandatory.Equals("true", StringComparison.CurrentCultureIgnoreCase))
{
itemfield.ToUpdate = true;
itemfield.Mandatory = true;
if (itemfield.Type.Equals("INTEGER", StringComparison.CurrentCultureIgnoreCase))
{
itemfield.SelectedValue = "1";
}
else if (itemfield.Type.Equals("MEDIUMSTRING", StringComparison.CurrentCultureIgnoreCase) || itemfield.Type.Equals("SMALLSTRING", StringComparison.CurrentCultureIgnoreCase))
{
itemfield.SelectedValue = "dummy";
}
else if (itemfield.Type.Equals("TIMESTAMP", StringComparison.CurrentCultureIgnoreCase))
{
itemfield.SelectedValue = DateTime.Now.ToString("yyyy-MM-dd");
}
Reporter.ToLog(eLogLevel.INFO, $" CustomAttributeMandatory {CustomAttributeMandatory} itemfield.Name {itemfield.Name} itemfield.Type {itemfield.Type} itemfield..SelectedValue {itemfield.SelectedValue}");
}
else
{
itemfield.ToUpdate = false;
itemfield.Mandatory = false;
}

if (itemfield.SelectedValue == null)
{
itemfield.SelectedValue = "Unassigned";
Expand Down Expand Up @@ -1442,28 +1481,60 @@ private static ObservableList<ExternalItemFieldBase> GetCustomAttributes(Backgro
CustomAttributeName = CustomAttributeListing.GetElementsByTagName("ns4:title").Item(0).InnerText;
CustomAttributeItemType = CustomAttributeListing.GetElementsByTagName("ns2:scope").Item(0).InnerText;
string CustomAttributefieldType = CustomAttributeListing.GetElementsByTagName("ns2:type").Item(0).InnerText;
CustomAttributeMandatory = "false";
// Define the namespace manager for the XML document
XmlNamespaceManager nsManager = new XmlNamespaceManager(CustomAttributeListing.NameTable);
nsManager.AddNamespace("ns2", "http://jazz.net/xmlns/alm/qm/v0.1/");

// XPath query to find ns2:required
string xpath = "//ns2:required";

// Use SelectSingleNode to check if ns2:required element exists
XmlNode requiredNode = CustomAttributeListing.SelectSingleNode(xpath, nsManager);

if (requiredNode != null)
{
CustomAttributeMandatory = requiredNode.InnerText;
}
else
{
CustomAttributeMandatory = "false";
}


itemfield.ItemType = CustomAttributeItemType;
itemfield.ID = CustomAttributeID;
itemfield.TypeIdentifier = typeIdentifier;
itemfield.Name = CustomAttributeName;
itemfield.Type = CustomAttributefieldType;
if (itemfield.SelectedValue == null)
{
itemfield.SelectedValue = "Unassigned";
}

if (CustomAttributeMandatory == "true")
if (CustomAttributeMandatory.Equals("true",StringComparison.CurrentCultureIgnoreCase))
{
itemfield.ToUpdate = true;
itemfield.Mandatory = true;
if(itemfield.Type.Equals("INTEGER",StringComparison.CurrentCultureIgnoreCase))
{
itemfield.SelectedValue = "1";
}
else if(itemfield.Type.Equals("MEDIUMSTRING", StringComparison.CurrentCultureIgnoreCase) || itemfield.Type.Equals("SMALLSTRING", StringComparison.CurrentCultureIgnoreCase))
{
itemfield.SelectedValue = "dummy";
}
else if(itemfield.Type.Equals("TIMESTAMP", StringComparison.CurrentCultureIgnoreCase))
{
itemfield.SelectedValue = DateTime.Now.ToString("yyyy-MM-dd");
}
Reporter.ToLog(eLogLevel.INFO, $" CustomAttributeMandatory {CustomAttributeMandatory} itemfield.Name {itemfield.Name} itemfield.Type {itemfield.Type} itemfield..SelectedValue {itemfield.SelectedValue}");
}
else
{
itemfield.ToUpdate = false;
itemfield.Mandatory = false;
}
if (itemfield.SelectedValue == null)
{
itemfield.SelectedValue = "Unassigned";
}


itemfield.IsCustomField = true;
itemfield.ProjectGuid = ALMCore.DefaultAlmConfig.ALMProjectGUID;
CustomAttributeRsult.Add(itemfield);
Expand Down Expand Up @@ -1537,7 +1608,6 @@ private static ObservableList<ExternalItemFieldBase> GetCustomAttributes(Backgro
catch (Exception e)
{
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}", e);

}
return fields;
}
Expand Down
Binary file modified Ginger/GingerCoreNET/DLLS/RQMExportStd.dll
Binary file not shown.
Binary file modified Ginger/GingerCoreNET/DLLS/RQM_RepositoryStd.dll
Binary file not shown.
Loading

0 comments on commit e35d8dc

Please sign in to comment.