Exemple #1
0
        /// <summary>
        /// Processes the PutFilter Request
        /// </summary>
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = CastRequestObjectTo <FilterRequestFull>(item, 38);
            FilterDescriptorSingleResult result;

            // Hydrate the polygon filter if present.
            request.FilterJson = await ValidationUtil.HydrateJsonWithBoundary(/* GeofenceProxy,*/ auxRepository as GeofenceRepository, log, serviceExceptionHandler, request);

            // Perform any required combination of filters of the request to create a new filter lists a set of filter UIDs and combination roles
            request.FilterJson = await CombineFilters(request);

            if (request.FilterType == FilterType.Transient)
            {
                result = await ProcessTransient(request);
            }
            else
            {
                // Hydrate the alignment and design filenames if present (persistent filters only).
                FilterFilenameUtil.GetFilterFileNames(log, serviceExceptionHandler, fileImportProxy, request);
                result = await ProcessPersistent(request);
            }

            await FilterJsonHelper.ParseFilterJson(request.ProjectData, result.FilterDescriptor, Productivity3dV2ProxyCompaction, request.CustomHeaders);

            return(result);
        }
Exemple #2
0
        public void Should_return_project_extents_for_project_extents(DateRangeType dateRangeType, bool useNullDate)
        {
            var startUtc = useNullDate ? (DateTime?)null : new DateTime(2017, 11, 5);
            var endUtc   = useNullDate ? (DateTime?)null : new DateTime(2017, 11, 6);

            //Json deserialize interprets date as mm/dd/yyyy so format date that way
            var startUtcStr      = startUtc?.ToString("MM/dd/yyyy");
            var endUtcStr        = endUtc?.ToString("MM/dd/yyyy");
            var filterDescriptor = new FilterDescriptor
            {
                FilterJson =
                    $"{{\"dateRangeType\":\"{dateRangeType}\",\"asAtDate\":\"false\",\"startUTC\":\"{startUtcStr}\",\"endUTC\":\"{endUtcStr}\",\"elevationType\":null}}"
            };

            FilterJsonHelper.ParseFilterJson(
                new ProjectData {
                IanaTimeZone = "America/Los_Angeles", ProjectUID = _projectGuid.ToString()
            }, filterDescriptor,
                productivity3dV2ProxyCompaction: _mockedProductivity3dV2ProxyCompaction.Object, customHeaders: new HeaderDictionary());

            Abstractions.Models.Filter filterObj =
                JsonConvert.DeserializeObject <Abstractions.Models.Filter>(filterDescriptor.FilterJson);
            Assert.Equal(MockedStartTime, filterObj.StartUtc);
            Assert.Equal(_mockedEndTime, filterObj.EndUtc);
        }
Exemple #3
0
        public void Should_match_contributingMachines_contains_legacyId_noMatch_using_FilterDescriptor()
        {
            var dateRangeType = DateRangeType.CurrentMonth;
            var asAtDate      = true;

            long legacyAssetId = 999;
            var  machineName   = "the machine name";
            var  isJohnDoe     = false;
            Guid?assetUid      = null;

            var contributingMachinesString =
                $",\"contributingMachines\":[{{\"assetID\":\"{legacyAssetId}\",\"machineName\":\"{machineName}\",\"isJohnDoe\":{(isJohnDoe ? "true" : "false")}}}]";
            var filterDescriptor = new FilterDescriptor
            {
                FilterJson =
                    $"{{\"dateRangeType\":\"{dateRangeType}\",\"asAtDate\":\"{asAtDate}\",\"elevationType\":null{contributingMachinesString}}}"
            };

            var expectedResult = new List <MachineDetails> {
                new MachineDetails(legacyAssetId, machineName, isJohnDoe, assetUid)
            };

            FilterJsonHelper.ParseFilterJson(
                new ProjectData {
                IanaTimeZone = "America/Los_Angeles", ProjectUID = _projectGuid.ToString()
            }, filterDescriptor,
                _mockedProductivity3dV2ProxyCompaction.Object, new HeaderDictionary());

            var actualResult = JsonConvert.DeserializeObject <Abstractions.Models.Filter>(filterDescriptor.FilterJson);

            Assert.Single(actualResult.ContributingMachines);
            Assert.Equal(expectedResult[0], actualResult.ContributingMachines[0]);
        }
Exemple #4
0
        public void Should_not_set_dates_based_on_DateRangeType_When_using_Custom(DateRangeType dateRangeType,
                                                                                  bool asAtDate)
        {
            var startUtc = dateRangeType == DateRangeType.Custom ? new DateTime(2017, 11, 5) : (DateTime?)null;
            var endUtc   = dateRangeType == DateRangeType.Custom ? new DateTime(2017, 11, 6) : (DateTime?)null;


            //Json deserialize interprets date as mm/dd/yyyy so format date that way
            var startUtcStr      = startUtc?.ToString("MM/dd/yyyy");
            var endUtcStr        = endUtc?.ToString("MM/dd/yyyy");
            var filterDescriptor = new FilterDescriptor
            {
                FilterJson =
                    $"{{\"dateRangeType\":\"{dateRangeType}\",\"asAtDate\":\"{asAtDate}\",\"startUTC\":\"{startUtcStr}\",\"endUTC\":\"{endUtcStr}\",\"elevationType\":null}}"
            };

            FilterJsonHelper.ParseFilterJson(
                new ProjectData {
                IanaTimeZone = "America/Los_Angeles", ProjectUID = _projectGuid.ToString()
            }, filterDescriptor,
                _mockedProductivity3dV2ProxyCompaction.Object, new HeaderDictionary());

            Abstractions.Models.Filter filterObj =
                JsonConvert.DeserializeObject <Abstractions.Models.Filter>(filterDescriptor.FilterJson);
            Assert.Equal(asAtDate ? MockedStartTime : startUtc, filterObj.StartUtc);
            Assert.Equal(endUtc, filterObj.EndUtc);
        }
Exemple #5
0
        public async Task Should_not_set_dates_based_on_DateRangeType(DateRangeType dateRangeType, bool asAtDate)
        {
            var startUtc = dateRangeType == DateRangeType.Custom ? new DateTime(2017, 11, 5) : (DateTime?)null;
            var endUtc   = dateRangeType == DateRangeType.Custom ? new DateTime(2017, 11, 6) : (DateTime?)null;
            //Json deserialize interprets date as mm/dd/yyyy so format date that way
            var startUtcStr = startUtc?.ToString("MM/dd/yyyy");
            var endUtcStr   = endUtc?.ToString("MM/dd/yyyy");
            var filter      = new MasterData.Repositories.DBModels.Filter
            {
                FilterJson =
                    $"{{\"dateRangeType\":\"{dateRangeType}\",\"asAtDate\":\"{asAtDate}\",\"startUTC\":\"{startUtcStr}\",\"endUTC\":\"{endUtcStr}\",\"elevationType\":null}}"
            };

            await FilterJsonHelper.ParseFilterJson(
                new ProjectData { IanaTimeZone = "America/Los_Angeles", ProjectUID = _projectGuid.ToString() }, filter,
                productivity3dV2ProxyCompaction : _mockedProductivity3dV2ProxyCompaction.Object, customHeaders : new HeaderDictionary());

            Abstractions.Models.Filter filterObj =
                JsonConvert.DeserializeObject <Abstractions.Models.Filter>(filter.FilterJson);
            Assert.Equal(dateRangeType, filterObj.DateRangeType);
            if (asAtDate)
            {
                Assert.Equal(MockedStartTime, filterObj.StartUtc);
            }
            else
            {
                Assert.Equal(startUtc, filterObj.StartUtc);
            }
            Assert.Equal(endUtc, filterObj.EndUtc);
        }
Exemple #6
0
 public async Task Should_return_When_filters_collection_is_null()
 {
     try
     {
         await FilterJsonHelper.ParseFilterJson(new ProjectData(), filters : null, productivity3dV2ProxyCompaction : _mockedProductivity3dV2ProxyCompaction.Object, customHeaders : new HeaderDictionary());
     }
     catch (Exception exception)
     {
         Assert.True(false, $"Expected no exception, but got: {exception.Message}");
     }
 }
Exemple #7
0
        public async Task Should_set_dates_based_on_DateRangeType_When_using_Filter(DateRangeType dateRangeType, bool asAtDate)
        {
            var filter = new MasterData.Repositories.DBModels.Filter
            {
                FilterJson = $"{{\"dateRangeType\":\"{dateRangeType}\",\"asAtDate\":\"{asAtDate}\",\"elevationType\":null}}"
            };

            await FilterJsonHelper.ParseFilterJson(
                new ProjectData { IanaTimeZone = "America/Los_Angeles", ProjectUID = _projectGuid.ToString() }, filter,
                _mockedProductivity3dV2ProxyCompaction.Object, new HeaderDictionary());

            ValidateDates(filter.FilterJson, asAtDate);
        }
Exemple #8
0
        public void Should_match_contributingMachines_contains_assetUid_using_FilterDescriptor()
        {
            var dateRangeType = DateRangeType.CurrentMonth;
            var asAtDate      = true;

            var nullLegacyAssetId = -1;
            var machineName       = "the machine name";
            var isJohnDoe         = false;
            var assetUid          = Guid.NewGuid();
            var assetId           = assetUid.ToLegacyId();

            var contributingMachinesString =
                $",\"contributingMachines\":[{{\"assetID\":\"{nullLegacyAssetId}\",\"machineName\":\"{machineName}\",\"isJohnDoe\":{(isJohnDoe ? "true" : "false")},\"assetUid\":\"{assetUid}\"}}]";
            var filterDescriptor = new FilterDescriptor
            {
                FilterJson =
                    $"{{\"dateRangeType\":\"{dateRangeType}\",\"asAtDate\":\"{asAtDate}\",\"elevationType\":null{contributingMachinesString}}}"
            };

            var expectedResult = new List <MachineDetails> {
                new MachineDetails(assetId, machineName, isJohnDoe, assetUid)
            };

            var getMachinesExecutionResult = new MachineExecutionResult
                                             (
                new List <MachineStatus>(1)
            {
                new MachineStatus(assetId, machineName, isJohnDoe,
                                  string.Empty, 0, null, null, null, null, null,
                                  assetUid: assetUid)
            }
                                             );

            _mockedProductivity3dV2ProxyCompaction.Setup(x =>
                                                         x.ExecuteGenericV2Request <MachineExecutionResult>(It.IsAny <String>(), It.IsAny <HttpMethod>(), It.IsAny <Stream>(), It.IsAny <IHeaderDictionary>()))
            .ReturnsAsync(getMachinesExecutionResult);

            FilterJsonHelper.ParseFilterJson(
                new ProjectData {
                IanaTimeZone = "America/Los_Angeles", ProjectUID = _projectGuid.ToString()
            }, filterDescriptor,
                _mockedProductivity3dV2ProxyCompaction.Object, new HeaderDictionary());

            var actualResult = JsonConvert.DeserializeObject <Abstractions.Models.Filter>(filterDescriptor.FilterJson);

            Assert.Single(actualResult.ContributingMachines);
            Assert.Equal(expectedResult[0], actualResult.ContributingMachines[0]);
        }
Exemple #9
0
        /// <summary>
        /// Gets all filters for the project.
        /// </summary>
        /// <returns>If successful returns a <see cref="FilterDescriptorListResult"/> containing a collection of filters for the project.</returns>
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = CastRequestObjectTo <FilterRequestFull>(item, 9);

            if (request == null)
            {
                return(null);
            }

            List <MasterData.Repositories.DBModels.Filter> filters = null;

            // get all for ProjectUid where !deleted
            //   must be ok for
            //      customer /project
            //      and UserUid: If the calling context is == Application, then get all
            //                     else get only those for the calling UserUid
            try
            {
                if (request.IsApplicationContext)
                {
                    filters = (List <MasterData.Repositories.DBModels.Filter>)await((IFilterRepository)this.Repository)
                              .GetFiltersForProject(request.ProjectUid)
                              .ConfigureAwait(false);
                }
                else
                {
                    filters = (List <MasterData.Repositories.DBModels.Filter>)await((IFilterRepository)this.Repository)
                              .GetFiltersForProjectUser(request.CustomerUid, request.ProjectUid, request.UserId)
                              .ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 10, e.Message);
            }

            await FilterJsonHelper.ParseFilterJson(request.ProjectData, filters, Productivity3dV2ProxyCompaction, request.CustomHeaders);

            // may be none, return success and empty list
            return(new FilterDescriptorListResult
            {
                FilterDescriptors = filters?
                                    .Select(filter => AutoMapperUtility.Automapper.Map <FilterDescriptor>(filter))
                                    .ToImmutableList()
            });
        }
Exemple #10
0
        public async Task Should_return_When_project_is_null()
        {
            try
            {
                var filter = new MasterData.Repositories.DBModels.Filter
                {
                    FilterJson = "{\"dateRangeType\":\"0\",\"elevationType\":null}"
                };
                await FilterJsonHelper.ParseFilterJson(null, filter, _mockedProductivity3dV2ProxyCompaction.Object, new HeaderDictionary());

                var filterObj = JsonConvert.DeserializeObject <Abstractions.Models.Filter>(filter.FilterJson);
                Assert.Equal(DateRangeType.Today, filterObj.DateRangeType);
            }
            catch (Exception exception)
            {
                Assert.True(false, $"Expected no exception, but got: {exception.Message}");
            }
        }
Exemple #11
0
        public void Should_handle_nocontributingMachines_using_FilterDescriptor()
        {
            var dateRangeType = DateRangeType.CurrentMonth;
            var asAtDate      = true;
            var contributingMachinesString = String.Empty;
            var filterDescriptor           = new FilterDescriptor
            {
                FilterJson =
                    $"{{\"dateRangeType\":\"{dateRangeType}\",\"asAtDate\":\"{asAtDate}\",\"elevationType\":null{contributingMachinesString}}}"
            };
            List <MachineDetails> expectedResult = null;

            FilterJsonHelper.ParseFilterJson(
                new ProjectData {
                IanaTimeZone = "America/Los_Angeles", ProjectUID = _projectGuid.ToString()
            }, filterDescriptor,
                _mockedProductivity3dV2ProxyCompaction.Object, new HeaderDictionary());

            var actualResult = JsonConvert.DeserializeObject <Abstractions.Models.Filter>(filterDescriptor.FilterJson);

            Assert.Equal(expectedResult, actualResult.ContributingMachines);
        }
Exemple #12
0
        public async Task Should_set_dates_based_on_DateRangeType_When_using_collection_of_Filters(DateRangeType dateRangeType,
                                                                                                   bool asAtDate)
        {
            var filters = new List <MasterData.Repositories.DBModels.Filter>();

            for (int i = 0; i < 10; i++)
            {
                filters.Add(new MasterData.Repositories.DBModels.Filter
                {
                    FilterJson = $"{{\"dateRangeType\":\"{dateRangeType}\",\"asAtDate\":\"{asAtDate}\",\"elevationType\":null}}"
                });
            }

            await FilterJsonHelper.ParseFilterJson(
                new ProjectData { IanaTimeZone = "America/Los_Angeles", ProjectUID = _projectGuid.ToString() }, filters,
                _mockedProductivity3dV2ProxyCompaction.Object, new HeaderDictionary());

            foreach (var filter in filters)
            {
                ValidateDates(filter.FilterJson, asAtDate);
            }
        }
Exemple #13
0
        /// <summary>
        /// Processes the GetFilters Request
        /// </summary>
        /// <returns>If successful returns a <see cref="FilterDescriptorSingleResult"/> object containing the filter.</returns>
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = CastRequestObjectTo <FilterRequestFull>(item, 5);

            if (request == null)
            {
                return(null);
            }

            MasterData.Repositories.DBModels.Filter filter = null;
            // get FilterUid where !deleted
            //   must be ok for
            //      customer /project
            //      and UserUid: If the calling context is == Application, then get all
            //                     else get only those for the calling UserUid
            try
            {
                filter = await((IFilterRepository)Repository).GetFilter(request.FilterUid);
            }
            catch (Exception e)
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 6, e.Message);
            }

            if (filter == null ||
                !string.Equals(filter.CustomerUid, request.CustomerUid, StringComparison.OrdinalIgnoreCase) ||
                !string.Equals(filter.ProjectUid, request.ProjectUid, StringComparison.OrdinalIgnoreCase) ||
                !string.Equals(filter.UserId, request.UserId, StringComparison.OrdinalIgnoreCase) && !request.IsApplicationContext
                )
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 36);
            }


            await FilterJsonHelper.ParseFilterJson(request.ProjectData, filter, Productivity3dV2ProxyCompaction, request.CustomHeaders);

            return(new FilterDescriptorSingleResult(AutoMapperUtility.Automapper.Map <FilterDescriptor>(filter)));
        }