示例#1
0
 /// <summary>
 /// Given a boolean defined and a ParsedAxis, returns a List of List of CubeObjects.
 /// The indexes in the outer list repressents each tag on an axis.
 /// The indexes in the inner list reppressents the cube objects tagged with the tag.
 /// </summary>
 /// <param name="defined"></param>
 /// <param name="parsedAxis"></param>
 /// <returns></returns>
 private List <List <CubeObject> > getAllCubeObjectsFromAxis(bool defined, ParsedAxis parsedAxis)
 {
     if (defined)
     {
         if (parsedAxis.AxisType.Equals("Tagset"))
         {
             return(getAllCubeObjectsFrom_Tagset_Axis(parsedAxis));
         }
         else if (parsedAxis.AxisType.Equals("Hierarchy"))
         {
             return(getAllCubeObjectsFrom_Hierarchy_Axis(parsedAxis));
         }
         else if (parsedAxis.AxisType.Equals("HierarchyLeaf")) //A HierarchyLeaf is a Node with no children.
         {
             return(getAllCubeObjectsFrom_HierarchyLeaf_Axis(parsedAxis));
         }
         else
         {
             throw new Exception("AxisType: " + parsedAxis.AxisType + " was not recognized!");
         }
     }
     else
     {
         return(null);
     }
 }
示例#2
0
        /// <summary>
        /// Returns list of cubeObjects per tag. Called with ParsedAxis of type "HierarchyLeaf".
        /// </summary>
        /// <param name="parsedAxis"></param>
        /// <returns></returns>
        private List <List <CubeObject> > getAllCubeObjectsFrom_HierarchyLeaf_Axis(ParsedAxis parsedAxis)
        {
            Node currentNode = fetchWholeHierarchyFromRootNode(parsedAxis.HierarchyNodeId);
            List <CubeObject> cubeObjectsTaggedWithTagFromNode = getAllCubeObjectsTaggedWith(currentNode.TagId);

            return(new List <List <CubeObject> >()
            {
                cubeObjectsTaggedWithTagFromNode
            });
        }
示例#3
0
        /// <summary>
        /// Returns list of cubeObjects per tag. Called with ParsedAxis of type "Hierarchy".
        /// </summary>
        /// <param name="parsedAxis"></param>
        /// <returns></returns>
        private List <List <CubeObject> > getAllCubeObjectsFrom_Hierarchy_Axis(ParsedAxis parsedAxis)
        {
            List <Node> hierarchyNodes;
            Node        rootNode = fetchWholeHierarchyFromRootNode(parsedAxis.HierarchyNodeId);

            hierarchyNodes = rootNode.Children;
            return(hierarchyNodes
                   .Select(n => getAllCubeObjectsTaggedWith(extractTagsFromHieararchy(n))       //Map hierarchy nodes to list of cube objects
                           .GroupBy(co => co.Id).Select(grouping => grouping.First()).ToList()) //Getting unique cubeobjects
                   .ToList());
        }
示例#4
0
        /// <summary>
        /// Returns list of cubeObjects per tag. Called with ParsedAxis of type "Tagset".
        /// </summary>
        /// <param name="parsedAxis"></param>
        /// <returns></returns>
        private List <List <CubeObject> > getAllCubeObjectsFrom_Tagset_Axis(ParsedAxis parsedAxis)
        {
            //Getting tags from database:
            List <Tag> tags;

            using (var context = new ObjectContext())
            {
                var Tagset = context.Tagsets
                             .Include(ts => ts.Tags)
                             //.Include(co => co.ObjectTagRelations)
                             .Where(ts => ts.Id == parsedAxis.TagsetId)
                             .FirstOrDefault();
                tags = Tagset.Tags.OrderBy(t => t.Name).ToList();
            }
            return(tags
                   .Select(t => getAllCubeObjectsTaggedWith(t.Id))
                   .ToList());
        }
示例#5
0
        /* EXAMPLES:
         * GET: /api/cell?xAxis={jsonObject}
         * GET: /api/cell?yAxis={jsonObject}
         * GET: /api/cell?zAxis={jsonObject}
         * GET: /api/cell?xAxis={jsonObject}&yAxis={jsonObject}
         * GET: /api/cell?xAxis={jsonObject}&zAxis={jsonObject}
         * GET: /api/cell?yAxis={jsonObject}&zAxis={jsonObject}
         * GET: /api/cell?xAxis={jsonObject}&yAxis={jsonObject}&zAxis={jsonObject}
         *
         * Where an axis showing a Hierarchy could be:
         *  {"AxisDirection":"X","AxisType":"Hierarchy","TagsetId":0,"HierarchyNodeId":1}
         * Or an axis showing a Tagset could be:
         *  {"AxisDirection":"X","AxisType":"Tagset","TagsetId":1,"HierarchyNodeId":0}
         *
         * The same way, filters can also be added:
         * Hierarchy filter:
         *     &filters=[{"type":"hierarchy","tagId":0,"nodeId":116}]
         * Tag filter:
         *     &filters=[{"type":"tag","tagId":42,"nodeId":0}]
         *
         */
        public IActionResult Get(string xAxis, string yAxis, string zAxis, string filters)
        {
            bool xDefined       = xAxis != null;
            bool yDefined       = yAxis != null;
            bool zDefined       = zAxis != null;
            bool filtersDefined = filters != null;
            //Parsing:
            ParsedAxis          axisX       = xDefined ? JsonConvert.DeserializeObject <ParsedAxis>(xAxis) : null;
            ParsedAxis          axisY       = yDefined ? JsonConvert.DeserializeObject <ParsedAxis>(yAxis) : null;
            ParsedAxis          axisZ       = zDefined ? JsonConvert.DeserializeObject <ParsedAxis>(zAxis) : null;
            List <ParsedFilter> filtersList = filtersDefined ? JsonConvert.DeserializeObject <List <ParsedFilter> >(filters) : null;
            //Extracting cubeObjects:
            List <List <CubeObject> > xAxisCubeObjects = getAllCubeObjectsFromAxis(xDefined, axisX);
            List <List <CubeObject> > yAxisCubeObjects = getAllCubeObjectsFromAxis(yDefined, axisY);
            List <List <CubeObject> > zAxisCubeObjects = getAllCubeObjectsFromAxis(zDefined, axisZ);
            //Creating Cells:
            List <Cell> cells = new List <Cell>();

            if (xDefined && yDefined && zDefined) //XYZ
            {
                cells =
                    xAxisCubeObjects.SelectMany((colist1, index1) =>
                                                yAxisCubeObjects.SelectMany((colist2, index2) =>
                                                                            zAxisCubeObjects.Select((colist3, index3) => new Cell()
                {
                    x           = index1 + 1,
                    y           = index2 + 1,
                    z           = index3 + 1,
                    CubeObjects = colist1
                                  .Where(co => colist2.Exists(co2 => co2.Id == co.Id) && //Where co is in colist2 and in colist3
                                         colist3.Exists(co3 => co3.Id == co.Id))
                                  .ToList()
                }))).ToList();
            }
            else if (xDefined && yDefined)  //XY
            {
                cells =
                    xAxisCubeObjects.SelectMany((colist1, index1) =>
                                                yAxisCubeObjects.Select((colist2, index2) =>
                                                                        new Cell()
                {
                    x           = index1 + 1,
                    y           = index2 + 1,
                    z           = 0,
                    CubeObjects = colist1
                                  .Where(co => colist2.Exists(co2 => co2.Id == co.Id)) //Where co is in colist2 as well
                                  .ToList()
                })).ToList();
            }
            else if (xDefined && zDefined)  //XZ
            {
                cells =
                    xAxisCubeObjects.SelectMany((colist1, index1) =>
                                                zAxisCubeObjects.Select((colist2, index2) =>
                                                                        new Cell()
                {
                    x           = index1 + 1,
                    y           = 0,
                    z           = index2 + 1,
                    CubeObjects = colist1
                                  .Where(co => colist2.Exists(co2 => co2.Id == co.Id)) //Where co is in colist2 as well
                                  .ToList()
                })).ToList();
            }
            else if (yDefined && zDefined)  //YZ
            {
                cells =
                    yAxisCubeObjects.SelectMany((colist1, index1) =>
                                                zAxisCubeObjects.Select((colist2, index2) =>
                                                                        new Cell()
                {
                    x           = 0,
                    y           = index1 + 1,
                    z           = index2 + 1,
                    CubeObjects = colist1
                                  .Where(co => colist2.Exists(co2 => co2.Id == co.Id)) //Where co is in colist2 as well
                                  .ToList()
                })).ToList();
            }
            else if (xDefined)               //X
            {
                cells =
                    xAxisCubeObjects.Select((colist1, index1) =>
                                            new Cell()
                {
                    x           = index1 + 1,
                    y           = 1,
                    z           = 0,
                    CubeObjects = colist1
                }).ToList();
            }
            else if (yDefined)                //Y
            {
                cells =
                    yAxisCubeObjects.Select((colist1, index1) =>
                                            new Cell()
                {
                    x           = 1,
                    y           = index1 + 1,
                    z           = 0,
                    CubeObjects = colist1
                }).ToList();
            }
            else if (zDefined)                //Z
            {
                cells =
                    zAxisCubeObjects.Select((colist1, index1) =>
                                            new Cell()
                {
                    x           = 0,
                    y           = 1,
                    z           = index1 + 1,
                    CubeObjects = colist1
                }).ToList();
            }
            else if (!xDefined && !yDefined && !zDefined) //If X Y and Z are not defined, show all:
            {
                cells = new List <Cell>()
                {
                    new Cell()
                    {
                        x           = 1,
                        y           = 1,
                        z           = 1,
                        CubeObjects = getAllCubeObjects()
                    }
                };
            }
            //If cells have no cubeObjects, remove them:
            cells.RemoveAll(c => c.CubeObjects.Count == 0);

            //Filtering:
            if (filtersDefined && filtersList.Count > 0)
            {
                //Devide filters:
                List <ParsedFilter> tagFilters       = filtersList.Where(f => f.type.Equals("tag")).ToList();
                List <ParsedFilter> hierarchyFilters = filtersList.Where(f => f.type.Equals("hierarchy")).ToList();

                //Apply filters:
                if (tagFilters.Count > 0)
                {
                    cells.ForEach(c => c.CubeObjects = filterCubeObjectsWithTagFilters(c.CubeObjects, tagFilters));
                }
                if (hierarchyFilters.Count > 0)
                {
                    cells.ForEach(c => c.CubeObjects = filterCubeObjectsWithHierarchyFilters(c.CubeObjects, hierarchyFilters));
                }
            }

            //Return OK with json result:
            return(Ok(JsonConvert.SerializeObject(cells,
                                                  new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            })));
        }