コード例 #1
0
        public void GetAssets_UsingSearchandFilter()
        {
            int pageSizeInt;
            int pageNumberInt;

            _controllerUtilities.ValidatePageParameters(Arg.Any <string>(), Arg.Any <string>(), out pageSizeInt, out pageNumberInt);
            _assetServices.GetCustomersForApplication(Arg.Any <string>()).Returns(x => null);

            _controllerUtilities.ValidateAssetUIDParameters(Arg.Any <string[]>()).Returns(x => new Guid[] { Guid.NewGuid() });
            _searchAndFilterClient.QueryFleet(Arg.Any <AssetFleetQueryParameters>()).Returns(x => new AssetFleetResponseParameters()
            {
                AssetUIDs = new Guid[] { Guid.NewGuid() }
            });

            _assetServices.GetAssets(Arg.Any <Guid[]>(), Arg.Any <Guid>()).Returns(x =>
                                                                                   new List <VSS.MasterData.WebAPI.DbModel.Asset>()
            {
                new VSS.MasterData.WebAPI.DbModel.Asset {
                    AssetUID = "ceea76f5-84de-49c2-b3fb-7463b9697f9c", SerialNumber = "2FMPK4J96HBB29959", MakeCode = "FA1", AssetName = "", AssetTypeName = "qwe", EquipmentVIN = "45", IconKey = 1, LegacyAssetID = 0, Model = "rt", ModelYear = 2017, StatusInd = true
                },
                new VSS.MasterData.WebAPI.DbModel.Asset {
                    AssetUID = "f29ec652-7e35-464a-a246-d869ad233e69", SerialNumber = "2FMPK4J96HBB29950", MakeCode = "FA2", AssetName = "", AssetTypeName = "erw", EquipmentVIN = "345", IconKey = 1, LegacyAssetID = 0, Model = "rtt", ModelYear = 2017, StatusInd = true
                }
            });

            var response = _controller.GetAssets(null, "7a0d9d17-b55c-4a59-af43-579e2588d9ba", null, null, null, null, "57d", "10", "1", null, null);

            Assert.Equal(200, ((Microsoft.AspNetCore.Mvc.ObjectResult)response).StatusCode);


            _controllerUtilities.ValidateAssetUIDParameters(Arg.Any <string[]>()).Returns(x => new Guid[] { });
            response = _controller.GetAssets(null, "7a0d9d17-b55c-4a59-af43-579e2588d9ba", null, null, null, null, "57d", "10", "1", null, null);
            Assert.Equal(200, ((Microsoft.AspNetCore.Mvc.ObjectResult)response).StatusCode);
        }
コード例 #2
0
        public ActionResult GetAssetsForSupportUser(
            [FromQuery] string searchString = null,
            [FromQuery] string pageSize     = "10",
            [FromQuery] string pageNumber   = "1")
        {
            if (!String.IsNullOrEmpty(searchString))
            {
                try
                {
                    int pageSizeInt;
                    int pageNumberInt;

                    try
                    {
                        _controllerUtilities.ValidatePageParameters(pageSize, pageNumber, out pageSizeInt, out pageNumberInt);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError("Get Assets for support user parameter validation threw an exception", ex);
                        return(BadRequest(ex.Message));
                    }
                    var assets = _assetRepository.GetAssetsforSupportUser(searchString, pageNumberInt, pageSizeInt);
                    return(Ok(assets));
                }
                catch (Exception ex)
                {
                    _logger.LogError("Get Assets for Support User threw an exception", ex);
                    return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
                }
            }

            else
            {
                return(Ok(new AssetDeviceForSupportUserListD {
                    TotalNumberOfPages = 0, PageNumber = 0, AssetDevices = null
                }));
            }
        }
コード例 #3
0
        public ActionResult GetAssets(
            [FromQuery] string[] assetUIDs    = null, [FromQuery] string customerUid = null,
            [FromQuery] string[] assetType    = null, [FromQuery] string[] status    = null,
            [FromQuery] string[] manufacturer = null, [FromQuery] string[] model     = null,
            [FromQuery] string snContains     = null,
            [FromQuery] string pageSize       = "10", [FromQuery] string pageNumber = "1",
            Guid?userGuid = null, Guid?accountSelectionGuid = null)
        {
            bool isIntegrator = false;

            try
            {
                int         pageSizeInt;
                int         pageNumberInt;
                Guid?       customerGuid;
                List <Guid> customerGuids = new List <Guid>()
                {
                };

                _logger.LogDebug("Before JWT Call.Requestheaders:" + String.Join(",", Request.Headers.Select(x => x.Key + ":" + x.Value)));

                if (!Request.Headers.TryGetValue("X-JWT-Assertion", out StringValues headerValues))
                {
                    return(BadRequest("Could not validate X-VisionLink-UserUid or X-JWT-Assertion Headers in Request"));
                }

                TPaaSJWT jwt;
                try
                {
                    jwt = new TPaaSJWT(headerValues);
                }
                catch
                {
                    jwt = null;
                }


                if (jwt != null)
                {
                    if (userGuid == null || !userGuid.HasValue)
                    {
                        userGuid = jwt.UserUid;
                    }

                    _logger.LogDebug(string.Format("ApplicationName:{0},uuid:{1},encodedjwt:{2}", jwt.ApplicationName, jwt.UserUid, jwt.EncodedJWT));

                    if (!string.IsNullOrEmpty(jwt.ApplicationName))
                    {
                        _logger.LogInformation("JWT has an appname " + jwt.ApplicationName);
                        var customers = _assetService.GetCustomersForApplication(jwt.ApplicationName);                         // new List<Guid>() { new Guid("07D4A55244C5E311AA7700505688274D") };//

                        if (customers != null && customers.Count > 0)
                        {
                            _logger.LogInformation("CustomerCount>0" + new Guid(customers[0].ToString()));
                            customerGuid = !string.IsNullOrEmpty(customerUid) ? new Guid(customerUid) : (Guid?)null;
                            if (customerGuid.HasValue)
                            {
                                if (customers.Contains((Guid)customerGuid))
                                {
                                    customerGuids.Add((Guid)customerGuid);
                                    isIntegrator = true;
                                }
                                else
                                {
                                    return(BadRequest("Application does not have this customer mapped. Please contact your API administrator."));
                                }
                            }
                            else
                            {
                                customerGuids = customers;
                                isIntegrator  = true;
                            }
                        }
                        if (isIntegrator)
                        {
                            try
                            {
                                _controllerUtilities.ValidatePageParameters(pageSize, pageNumber, out pageSizeInt, out pageNumberInt);
                            }
                            catch (Exception ex)
                            {
                                _logger.LogError("Get Assets parameter validation threw an exception", ex);
                                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));                               //BadRequest("Assets parameter validation failed.");
                            }
                            if (customerGuids != null && customerGuids.Any())
                            {
                                CustomerAssetsListData assets = _assetService.GetAssetsForCustomer(customerGuids, pageNumberInt, pageSizeInt);
                                return(Ok(assets));
                            }
                        }
                        else
                        {
                            if (!userGuid.HasValue)
                            {
                                return(BadRequest("UserUID has not been provided"));
                            }

                            Guid[]          assetGuids;
                            WildcardMatches wildcardMatches;
                            try
                            {
                                assetGuids      = _controllerUtilities.ValidateAssetUIDParameters(assetUIDs);
                                wildcardMatches = ValidateWildcardMatches(null, snContains);
                                _controllerUtilities.ValidatePageParameters(pageSize, pageNumber, out pageSizeInt, out pageNumberInt);
                                customerGuid = !string.IsNullOrEmpty(customerUid) ? new Guid(customerUid) : (Guid?)null;
                            }
                            catch (Exception ex)
                            {
                                _logger.LogError("Get Assets parameter validation threw an exception", ex);
                                return(BadRequest(" Assets parameter validation " + ex.Message));                                //StatusCode((int)HttpStatusCode.InternalServerError, ex.Message);//
                            }

                            if (!assetGuids.Any())
                            {
                                assetGuids = GetAssetUIDsFromFilters(
                                    userGuid.Value, accountSelectionGuid, customerGuid, assetType, status, manufacturer, model,
                                    wildcardMatches, pageSizeInt, pageNumberInt);
                            }

                            if (assetGuids != null && assetGuids.Any())
                            {
                                var assets = GetAssetsFromAssetGuids(assetGuids, userGuid.Value);
                                return(Ok(assets));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Get AssetLists encountered an error", ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
            return(Ok(isIntegrator ? (object)new List <DataModels.CustomerAsset>() : (object)new List <DataModels.Asset>()));
        }