public GetTreeNodesResponse GetTreeNodes(GetTreeNodesRequest request) { var response = new GetTreeNodes().Execute(request) as GetTreeNodesResponse; if (response == null) { throw new InvalidOperationException("Response is null or wrong response type. Expected: GetTreeNodesResponse"); } return(response); }
/// <summary> /// Retrieves the nodes of the current level of the project tree. /// </summary> /// <param name="request">Request.</param> /// <param name="parentIds">Parent ids.</param> /// <param name="path">Path elements.</param> /// <param name="pageSize">Page size.</param> /// <param name="pageNumber">Page number.</param> /// <returns>Nodes of the current level of the project tree.</returns> public HttpResponseMessage Post(HttpRequestMessage request, string parentIds, string path, int pageSize = 10, int pageNumber = 0) { // Parse and validate input parameters string[] parentIdsParsed = ParseAndValidateParentIds(request, parentIds); TreeNodePath pathParsed = ParseAndValidatePath(request, path); if (parentIdsParsed.Length != pathParsed.Length) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, String.Format("Parent ids ('{0}') length ({1}) is not equal to path ('{2}') length ({3}).", parentIds, parentIdsParsed.Length, path, pathParsed.Length))); } // Process path by retrieving the object for every path element with the corresponding id from id chain var linkBuilder = new LinkBuilder(Url); Project project = null; Database database = null; BaseEnum baseEnum = null; Entity entity = null; Relation relation = null; Guid lastId = Guid.Empty; int i = 0; foreach (var element in pathParsed) { lastId = this.ParseAndValidateId(request, parentIdsParsed[i]); switch (element) { case Element.Project: VerifyProjectId(request, parentIdsParsed[i], project); break; case Element.Database: database = RetrieveDatabase(request, linkBuilder, parentIdsParsed[i], project); break; case Element.Folder_Diagrams: RetrieveFolder(request, parentIdsParsed[i], database.Id); break; case Element.Folder_BaseEnums: RetrieveFolder(request, parentIdsParsed[i], database.Id); break; case Element.Folder_DataTypes: RetrieveFolder(request, parentIdsParsed[i], database.Id); break; case Element.Folder_Entities: RetrieveFolder(request, parentIdsParsed[i], database.Id); break; case Element.Diagram: throw new NotImplementedException(); // TODO: implement case Element.BaseEnum: baseEnum = RetrieveBaseEnum(request, linkBuilder, parentIdsParsed[i], database); break; case Element.Entity: entity = RetrieveEntity(request, linkBuilder, parentIdsParsed[i], database); break; case Element.Folder_EntityAttributes: RetrieveFolder(request, parentIdsParsed[i], entity.Id); break; case Element.Folder_EntityRelations: RetrieveFolder(request, parentIdsParsed[i], entity.Id); break; case Element.Relation: relation = RetrieveRelation(request, linkBuilder, parentIdsParsed[i], entity); break; default: if (element != TreeNodePath.Root) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, String.Format("Element '{0}' is not expected at position {1} of the path '{2}'.", element, i, path))); } project = RetrieveProject(request, linkBuilder, parentIdsParsed[i]); break; } i++; } // Retrieve nodes var getTreeNodes = new GetTreeNodes(); QueryResult <TreeNode> treeNodes = getTreeNodes.Execute(ObjectTreeDataSource.ProjectTreeView, lastId, pathParsed, pageSize, pageNumber); // Add links foreach (var node in treeNodes.ResultSet) { node.AddLinks(linkBuilder, parentIds + IdSeparator + node.ObjectId, pathParsed); } // Wrap into the collection var collection = this.WrapQueryResultIntoCollection <TreeNode>(treeNodes); // Return the object return(request.CreateResponse(HttpStatusCode.OK, collection)); }