private static XmlAction ToXmlModel(IeBaseAction ieAction, WorkflowDataMaps dataMaps) { if (ieAction == null) { return(null); } switch (ieAction.ActionType) { case ActionTypes.EmailNotification: return(ToXmlModel(ieAction as IeEmailNotificationAction, dataMaps.PropertyTypeMap)); case ActionTypes.PropertyChange: return(ToXmlModel(ieAction as IePropertyChangeAction, dataMaps)); case ActionTypes.Generate: return(ToXmlModel(ieAction as IeGenerateAction, dataMaps.ArtifactTypeMap)); case ActionTypes.Webhook: return(ToXmlModel(ieAction as IeWebhookAction, dataMaps)); default: throw new ArgumentOutOfRangeException(nameof(ieAction.ActionType)); } }
private static XmlUsersGroups ToXmlModel(IeUsersGroups ieUsersGroups, WorkflowDataMaps dataMaps) { if (ieUsersGroups == null) { return(null); } var xmlUsersGroups = new XmlUsersGroups { IncludeCurrentUser = ieUsersGroups.IncludeCurrentUser, UsersGroups = !ieUsersGroups.UsersGroups.IsEmpty() ? new List <XmlUserGroup>() : null }; ieUsersGroups.UsersGroups?.ForEach(ug => { var isGroup = ug.IsGroup.GetValueOrDefault(); int ugId; if (isGroup) { if (!dataMaps.GroupMap.TryGetValue(Tuple.Create(ug.Name, ug.GroupProjectId), out ugId)) { throw new ExceptionWithErrorCode(I18NHelper.FormatInvariant("Id of Group '{1}' is not found.", ug.Name), ErrorCodes.UnexpectedError); } } else { if (!dataMaps.UserMap.TryGetValue(ug.Name, out ugId)) { throw new ExceptionWithErrorCode(I18NHelper.FormatInvariant("Id of User '{0}' is not found.", ug.Name), ErrorCodes.UnexpectedError); } } xmlUsersGroups.UsersGroups.Add(new XmlUserGroup { IsGroup = isGroup, Id = ugId }); }); return(xmlUsersGroups); }
private static XmlWebhookAction ToXmlModel(IeWebhookAction ieWebhookAction, WorkflowDataMaps dataMaps) { if (ieWebhookAction == null) { return(null); } if (!dataMaps.WebhooksByActionObj.ContainsKey(ieWebhookAction)) { return(null); } return(new XmlWebhookAction { Name = ieWebhookAction.Name, WebhookId = dataMaps.WebhooksByActionObj[ieWebhookAction] }); }
public void ToXmlModel_PropertyChangeAction_ChoiceProperty_DuplicateValidValue_ResultHasCorrectIds() { // Arrange const string propertyName = "Choice Property"; var converter = new TriggerConverter(); var trigger = new IeTrigger { Action = new IePropertyChangeAction { PropertyName = propertyName, ValidValues = new List <IeValidValue> { new IeValidValue { Id = 1, Value = "test" }, new IeValidValue { Id = 2, Value = "test" } } } }; var dataMaps = new WorkflowDataMaps(); dataMaps.PropertyTypeMap.Add(propertyName, 1); dataMaps.ValidValuesById.Add(1, new Dictionary <int, string> { { 1, "test" }, { 2, "test" } }); dataMaps.ValidValuesByValue.Add(1, new Dictionary <string, int> { { "test", 1 } }); // Act var xmlModel = converter.ToXmlModel(new[] { trigger }, dataMaps); // Assert var xmlAction = (XmlPropertyChangeAction)xmlModel.Triggers[0].Action; Assert.AreEqual(2, xmlAction.ValidValues.Count); Assert.IsTrue(xmlAction.ValidValues.Contains(1)); Assert.IsTrue(xmlAction.ValidValues.Contains(2)); }
private static XmlWorkflowEventTrigger ToXmlModel(IeTrigger ieTrigger, WorkflowDataMaps dataMaps) { if (ieTrigger == null) { return(null); } var xmlTrigger = new XmlWorkflowEventTrigger { Name = ieTrigger.Name }; if (ieTrigger.Condition != null) { xmlTrigger.Condition = ToXmlModel(ieTrigger.Condition, dataMaps.StateMap); } // Triggers must have an action. xmlTrigger.Action = ToXmlModel(ieTrigger.Action, dataMaps); return(xmlTrigger); }
private static void ToXmlModel(List <IeValidValue> validValues, int propertyTypeId, string propertyName, WorkflowDataMaps dataMaps, XmlPropertyChangeAction xmlAction) { if (validValues == null || !validValues.Any()) { return; } IDictionary <int, string> validValuesById = null; IDictionary <string, int> validValuesByValue = null; validValues.ForEach(validValue => { int validValueId; if (validValue.Id.HasValue) { if (validValuesById == null) { if (!dataMaps.ValidValuesById.TryGetValue(propertyTypeId, out validValuesById)) { throw new ExceptionWithErrorCode( I18NHelper.FormatInvariant( "Valid Values of Choice Standard Property Type '{0}' are not found.", propertyName), ErrorCodes.UnexpectedError); } } if (!validValuesById.ContainsKey(validValue.Id.Value)) { throw new ExceptionWithErrorCode( I18NHelper.FormatInvariant( "Valid Value with id '{0}' of Choice Standard Property Type '{1}' is not found.", validValue.Id.Value, propertyName), ErrorCodes.UnexpectedError); } validValueId = validValue.Id.Value; } else { if (validValuesByValue == null) { if (!dataMaps.ValidValuesByValue.TryGetValue(propertyTypeId, out validValuesByValue)) { throw new ExceptionWithErrorCode( I18NHelper.FormatInvariant( "Valid Values of Choice Standard Property Type '{0}' are not found.", propertyName), ErrorCodes.UnexpectedError); } } if (!validValuesByValue.TryGetValue(validValue.Value, out validValueId)) { throw new ExceptionWithErrorCode( I18NHelper.FormatInvariant( "Valid Value '{0}' of Choice Standard Property Type '{1}' is not found.", validValue.Value, propertyName), ErrorCodes.UnexpectedError); } } (xmlAction.ValidValues ?? (xmlAction.ValidValues = new List <int>())).Add(validValueId); }); }
private static XmlPropertyChangeAction ToXmlModel(IePropertyChangeAction ieAction, WorkflowDataMaps dataMaps) { if (ieAction == null) { return(null); } var xmlAction = new XmlPropertyChangeAction { Name = ieAction.Name, PropertyValue = ieAction.PropertyValue, UsersGroups = ToXmlModel(ieAction.UsersGroups, dataMaps) }; int propertyTypeId; if (!dataMaps.PropertyTypeMap.TryGetValue(ieAction.PropertyName, out propertyTypeId) && !WorkflowHelper.TryGetNameOrDescriptionPropertyTypeId(ieAction.PropertyName, out propertyTypeId)) { throw new ExceptionWithErrorCode(I18NHelper.FormatInvariant("Id of Standard Property Type '{0}' is not found.", ieAction.PropertyName), ErrorCodes.UnexpectedError); } xmlAction.PropertyTypeId = propertyTypeId; ToXmlModel(ieAction.ValidValues, propertyTypeId, ieAction.PropertyName, dataMaps, xmlAction); return(xmlAction); }
public XmlWorkflowEventTriggers ToXmlModel(IEnumerable <IeTrigger> ieTriggers, WorkflowDataMaps dataMaps) { if (ieTriggers == null) { return(null); } var xmlTriggers = new XmlWorkflowEventTriggers(); ieTriggers.ForEach(t => xmlTriggers.Triggers.Add(ToXmlModel(t, dataMaps))); return(xmlTriggers); }