diff --git a/Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs b/Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs index 37e8bbba70..91670ee6d0 100644 --- a/Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs +++ b/Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs @@ -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; @@ -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 ExternalFields = ConvertExternalFieldsToACLDataContractfields(originalExternalFields); result = string.Empty; string bfExportedID = GetExportedIDString(businessFlow.ExternalIdCalCulated, "RQMID"); if (string.IsNullOrEmpty(bfExportedID) || bfExportedID.Equals("0")) @@ -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); @@ -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}"); @@ -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 ExternalFields = null) { try { @@ -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); } } @@ -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 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 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)) @@ -786,7 +786,7 @@ public bool ExportBusinessFlowToRQM(BusinessFlow businessFlow, ObservableList f.ID == field.ID)) + { + // Add it if it doesn't already exist fieldsToReturn.Add(field); + } } - return fieldsToReturn; } @@ -1131,7 +1139,10 @@ private Dictionary 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); + } } } } diff --git a/Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs b/Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs index e231e79108..b446f6978d 100644 --- a/Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs +++ b/Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs @@ -1274,7 +1274,6 @@ private static ObservableList GetCustomAttributes(Backgro } //TODO: Get 'next' and 'last links XmlNodeList CustomAttributelinkList_ = CustomAttributeList.GetElementsByTagName("link"); - if (CustomAttributelinkList_.Count > 0) { XmlNode selfPage = CustomAttributelinkList_.Item(1); @@ -1352,8 +1351,6 @@ private static ObservableList 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 @@ -1364,7 +1361,24 @@ private static ObservableList 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"; + } @@ -1372,6 +1386,31 @@ private static ObservableList GetCustomAttributes(Backgro 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"; @@ -1442,28 +1481,60 @@ private static ObservableList 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); @@ -1537,7 +1608,6 @@ private static ObservableList GetCustomAttributes(Backgro catch (Exception e) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}", e); - } return fields; } diff --git a/Ginger/GingerCoreNET/DLLS/RQMExportStd.dll b/Ginger/GingerCoreNET/DLLS/RQMExportStd.dll index ab8efd3f4b..f86eb9731c 100644 Binary files a/Ginger/GingerCoreNET/DLLS/RQMExportStd.dll and b/Ginger/GingerCoreNET/DLLS/RQMExportStd.dll differ diff --git a/Ginger/GingerCoreNET/DLLS/RQM_RepositoryStd.dll b/Ginger/GingerCoreNET/DLLS/RQM_RepositoryStd.dll index 02d0750820..74290350c3 100644 Binary files a/Ginger/GingerCoreNET/DLLS/RQM_RepositoryStd.dll and b/Ginger/GingerCoreNET/DLLS/RQM_RepositoryStd.dll differ diff --git a/Ginger/GingerCoreNET/GeneralLib/General.cs b/Ginger/GingerCoreNET/GeneralLib/General.cs index 4f897acff2..be753da5b2 100644 --- a/Ginger/GingerCoreNET/GeneralLib/General.cs +++ b/Ginger/GingerCoreNET/GeneralLib/General.cs @@ -727,7 +727,11 @@ public static ObservableList GetExternalFields() } foreach (var externalItemField in externalOnlineItemsFields) { - originalExternalFields.Add(MapExternalField(externalItemField)); + ExternalItemFieldBase item = MapExternalField(externalItemField); + if(item != null) + { + originalExternalFields.Add(item); + } } } else @@ -740,19 +744,68 @@ public static ObservableList GetExternalFields() private static ExternalItemFieldBase MapExternalField(ExternalItemFieldBase externalItemField) { - var existingField = WorkSpace.Instance.Solution.ExternalItemsFields - .FirstOrDefault(x => x.Name.Equals(externalItemField.Name, StringComparison.CurrentCultureIgnoreCase)); + try + { + var existingField = WorkSpace.Instance.Solution.ExternalItemsFields + .FirstOrDefault(x => x.Name.Equals(externalItemField.Name, StringComparison.CurrentCultureIgnoreCase) && x.ProjectGuid == externalItemField.ProjectGuid); - return new ExternalItemFieldBase + string value = ""; + + if (existingField == null) + { + if (externalItemField.Mandatory) + { + if (!string.IsNullOrEmpty(externalItemField.SelectedValue)) + { + value = externalItemField.SelectedValue; + } + else + { + value = GetDefaultValue(externalItemField); + } + } + } + else + { + if (externalItemField.Mandatory) + { + if (!string.IsNullOrEmpty(existingField.SelectedValue)) + { + value = existingField.SelectedValue; + } + else + { + value = GetDefaultValue(externalItemField); + } + } + } + return new ExternalItemFieldBase + { + Name = externalItemField.Name, + ID = externalItemField.ID, + ItemType = externalItemField.ItemType, + Type = externalItemField.Type, + Guid = externalItemField.Guid, + IsCustomField = externalItemField.IsCustomField, + SelectedValue = value + }; + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR,"Failed to Map External Fields",ex.InnerException); + return null; + } + } + + private static string GetDefaultValue(ExternalItemFieldBase externalItemField) + { + // Return default values based on the field type. + return (externalItemField.Type.ToUpperInvariant()) switch { - Name = externalItemField.Name, - ID = externalItemField.ID, - ItemType = externalItemField.ItemType, - Guid = externalItemField.Guid, - IsCustomField = externalItemField.IsCustomField, - SelectedValue = existingField != null && !string.IsNullOrEmpty(existingField.SelectedValue) - ? existingField.SelectedValue - : externalItemField.SelectedValue + "INTEGER" => "1", + "MEDIUMSTRING" => "Dummy", + "SMALLSTRING" => "Dummy", + _ => externalItemField.SelectedValue }; } }