public string Create(string projectId, string title, string expression) { Logger.DebugFormat("BEGIN MandatoryUserFilter.Create ProjectId={0}, Title={1}, Expression={2}", projectId, title, expression); CheckAuthentication(); var url = Url.Combine(Config.ServiceUrl, Constants.MD_URI, projectId, "obj"); var request = new UserFilterRequest { UserFilter = new UserFilter { Content = new UserFilterContent {Expression = expression}, Meta = new UserFilterMeta {Title = title} } }; var response = JsonPostRequest(url, request); var filterResponse = JsonConvert.DeserializeObject<UriResponse>(response); Logger.DebugFormat("END MandatoryUserFilter.Create"); return filterResponse.Uri; }
public string CreateUserFilterUsingAttributeUris(string projectId, string filterTitle, Dictionary<string, List<string>> attributeUrisWithElementTitles, bool inclusive = true) { var items = new Dictionary<string, List<string>>(); foreach (var item in attributeUrisWithElementTitles) { var attribute = GetAttributeByUri(item.Key); if (attribute == null) { throw new GoodDataApiException(String.Format("No attribute found with title {0}", item.Key), GoodDataErrorType.AttributeNotFound); } var elements = new List<Element>(); foreach (var elementTitle in item.Value) { var fullAttribute = FindAttributeElementByTitle(projectId, attribute, elementTitle); if (fullAttribute != null) { elements.Add(fullAttribute); } } if (elements.Count == 0) { throw new GoodDataApiException(String.Format("No element {0} found for attribute {1}", string.Join(",", item.Value), attribute.Meta.Identifier) ,GoodDataErrorType.ElementNotFound); } items.Add(attribute.Meta.Uri, elements.Select(element => element.Uri).ToList()); } var url = Url.Combine(Config.ServiceUrl, Constants.MD_URI, projectId, "obj"); var payload = new UserFilterRequest(filterTitle, items, inclusive); var response = JsonPostRequest(url, payload); var filterResponse = JsonConvert.DeserializeObject(response, typeof(UriResponse)) as UriResponse; return filterResponse.Uri; }