コード例 #1
0
        /// <summary>
        /// Builds this instance for specified executor type.
        /// </summary>
        /// <typeparam name="TExecutor">The type of the executor.</typeparam>
        public static TExecutor Build <TExecutor>(
            ILoggerFactory logger, IConfigurationStore configStore, IServiceExceptionHandler serviceExceptionHandler,
            string customerUid = null, string userId = null, string userEmailAddress = null, IHeaderDictionary headers = null,
            IProductivity3dV1ProxyCoord productivity3dV1ProxyCoord = null, IProductivity3dV2ProxyCompaction productivity3dV2ProxyCompaction = null,
            ITransferProxyFactory persistantTransferProxyFactory   = null, IFilterServiceProxy filterServiceProxy = null, ITRexImportFileProxy tRexImportFileProxy = null,
            IProjectRepository projectRepo        = null, IHttpContextAccessor httpContextAccessor = null, IDataOceanClient dataOceanClient = null,
            ITPaaSApplicationAuthentication authn = null, ISchedulerProxy schedulerProxy           = null, IPegasusClient pegasusClient     = null,
            ICwsProjectClient cwsProjectClient    = null, ICwsDeviceClient cwsDeviceClient         = null,
            ICwsProfileSettingsClient cwsProfileSettingsClient = null,
            IWebRequest gracefulClient = null, INotificationHubClient notificationHubClient = null
            )
            where TExecutor : RequestExecutorContainer, new()
        {
            ILogger log = null;

            if (logger != null)
            {
                log = logger.CreateLogger <RequestExecutorContainer>();
            }

            var executor = new TExecutor();

            executor.Initialise(
                log, configStore, serviceExceptionHandler, customerUid, userId, userEmailAddress, headers,
                productivity3dV1ProxyCoord, productivity3dV2ProxyCompaction,
                persistantTransferProxyFactory, filterServiceProxy, tRexImportFileProxy, projectRepo,
                httpContextAccessor, dataOceanClient, authn, schedulerProxy, pegasusClient, cwsProjectClient, cwsDeviceClient,
                cwsProfileSettingsClient, gracefulClient, notificationHubClient
                );

            return(executor);
        }
コード例 #2
0
        public ExecutorTestFixture()
        {
            var loggerFactory     = new LoggerFactory().AddSerilog(SerilogExtensions.Configure("IntegrationTests.ExecutorTests.log", null));
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging()
            .AddSingleton(loggerFactory)
            .AddHttpClient()
            .AddSingleton <IConfigurationStore, GenericConfiguration>()
            .AddTransient <IRepository <IProjectEvent>, ProjectRepository>()
            .AddTransient <ICwsProjectClient, CwsProjectClient>()
            .AddTransient <IServiceExceptionHandler, ServiceExceptionHandler>()

            // for serviceDiscovery
            .AddServiceDiscovery()
            .AddTransient <IWebRequest, GracefulWebRequest>()
            .AddMemoryCache()
            .AddSingleton <IDataCache, InMemoryDataCache>()

            .AddTransient <IProductivity3dV1ProxyCoord, Productivity3dV1ProxyCoord>()
            .AddTransient <IProductivity3dV2ProxyNotification, Productivity3dV2ProxyNotification>()
            .AddTransient <IProductivity3dV2ProxyCompaction, Productivity3dV2ProxyCompaction>()
            .AddTransient <IErrorCodesProvider, ProjectErrorCodesProvider>();


            _serviceProvider                = serviceCollection.BuildServiceProvider();
            ConfigStore                     = _serviceProvider.GetRequiredService <IConfigurationStore>();
            Logger                          = _serviceProvider.GetRequiredService <ILoggerFactory>();
            ServiceExceptionHandler         = _serviceProvider.GetRequiredService <IServiceExceptionHandler>();
            ProjectRepo                     = _serviceProvider.GetRequiredService <IRepository <IProjectEvent> >() as ProjectRepository;
            CwsProjectClient                = _serviceProvider.GetRequiredService <ICwsProjectClient>();
            Productivity3dV2ProxyCompaction = _serviceProvider.GetRequiredService <IProductivity3dV2ProxyCompaction>();
        }
コード例 #3
0
 private ValidateProjectExecutor CreateExecutor(
     IProductivity3dV1ProxyCoord productivity3dV1ProxyCoord = null,
     ICwsProjectClient cwsProjectClient = null,
     IProductivity3dV2ProxyCompaction productivity3dV2ProxyCompaction = null) =>
 RequestExecutorContainerFactory.Build <ValidateProjectExecutor>
     (_loggerFactory, _configStore, ServiceExceptionHandler,
     _customerUid.ToString(), _userUid.ToString(), null, _customHeaders,
     productivity3dV1ProxyCoord, cwsProjectClient: cwsProjectClient,
     productivity3dV2ProxyCompaction: productivity3dV2ProxyCompaction);
コード例 #4
0
        public async Task <CreateProjectResponseModel> CreateCustomerProject(ICwsProjectClient cwsProjectClient, string customerUid,
                                                                             string boundary = "POLYGON((172.595831670724 -43.5427038560109,172.594630041089 -43.5438859356773,172.59329966542 -43.542486101965, 172.595831670724 -43.5427038560109))")
        {
            var createProjectRequestModel = new CreateProjectRequestModel
            {
                AccountId   = customerUid,
                ProjectName = "wotever",
                Boundary    = GeometryConversion.MapProjectBoundary(boundary)
            };

            var response = await cwsProjectClient.CreateProject(createProjectRequestModel);

            return(response);
        }
コード例 #5
0
        /// <summary>
        /// Gets intersecting projects from cws
        ///   called from e.g. TFA, so uses applicationContext i.e. no customer.
        ///   if projectUid is provided, this is a manual import so don't consider itself as potentially overlapping
        /// </summary>
        public static async Task <List <ProjectDatabaseModel> > GetIntersectingProjects(
            string customerUid, double latitude, double longitude, string projectUid,
            ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, IHeaderDictionary customHeaders)
        {
            // get projects for customer using application token i.e. no user
            // todo what are the rules e.g. active, for manual import?
            var projectDatabaseModelList = (await GetProjectListForCustomer(new Guid(customerUid), null,
                                                                            log, serviceExceptionHandler, cwsProjectClient, CwsProjectType.AcceptsTagFiles, ProjectStatus.Active, false, true, customHeaders))
                                           .Where(p => string.IsNullOrEmpty(projectUid) || !p.IsArchived);

            // return a list at this stage to be used for logging in TFA, but other potential use in future.
            var projects = projectDatabaseModelList.Where(project => !string.IsNullOrEmpty(project.Boundary))
                           .Where(project => PolygonUtils.PointInPolygon(project.Boundary, latitude, longitude)).ToList();

            log.LogInformation($"{nameof(GetIntersectingProjects)}: Overlapping projects for customerUid: {customerUid} projects: {JsonConvert.SerializeObject(projects)}");
            return(projects);
        }
コード例 #6
0
 public void Initialise(ILogger logger, IConfigurationStore configStore,
                        IServiceExceptionHandler serviceExceptionHandler,
                        string customerUid, string userId = null, string userEmailAddress = null,
                        IHeaderDictionary headers         = null,
                        IProductivity3dV1ProxyCoord productivity3dV1ProxyCoord           = null,
                        IProductivity3dV2ProxyCompaction productivity3dV2ProxyCompaction = null,
                        ITransferProxyFactory persistantTransferProxyFactory             = null, IFilterServiceProxy filterServiceProxy = null,
                        ITRexImportFileProxy tRexImportFileProxy           = null, IProjectRepository projectRepo = null,
                        IHttpContextAccessor httpContextAccessor           = null,
                        IDataOceanClient dataOceanClient                   = null, ITPaaSApplicationAuthentication authn = null,
                        ISchedulerProxy schedulerProxy                     = null, IPegasusClient pegasusClient          = null,
                        ICwsProjectClient cwsProjectClient                 = null, ICwsDeviceClient cwsDeviceClient      = null,
                        ICwsProfileSettingsClient cwsProfileSettingsClient = null,
                        IWebRequest gracefulClient = null, INotificationHubClient notificationHubClient = null)
 {
     log = logger;
     this.configStore             = configStore;
     this.serviceExceptionHandler = serviceExceptionHandler;
     this.customerUid             = customerUid;
     this.userId                          = userId;
     this.userEmailAddress                = userEmailAddress;
     this.customHeaders                   = headers;
     this.productivity3dV1ProxyCoord      = productivity3dV1ProxyCoord;
     this.productivity3dV2ProxyCompaction = productivity3dV2ProxyCompaction;
     this.persistantTransferProxyFactory  = persistantTransferProxyFactory;
     this.filterServiceProxy              = filterServiceProxy;
     this.tRexImportFileProxy             = tRexImportFileProxy;
     this.projectRepo                     = projectRepo;
     this.httpContextAccessor             = httpContextAccessor;
     this.dataOceanClient                 = dataOceanClient;
     this.authn                    = authn;
     this.schedulerProxy           = schedulerProxy;
     this.pegasusClient            = pegasusClient;
     this.cwsProjectClient         = cwsProjectClient;
     this.cwsDeviceClient          = cwsDeviceClient;
     this.cwsProfileSettingsClient = cwsProfileSettingsClient;
     this.gracefulClient           = gracefulClient;
     this.notificationHubClient    = notificationHubClient;
 }
コード例 #7
0
        /// <summary>
        /// Gets a Project for a shortProjectId for TBC
        ///  Regardless of archived state and user role
        /// </summary>
        public static async Task <ProjectDetailResponseModel> GetProjectForCustomer(Guid customerUid, Guid?userUid, long projectShortId,
                                                                                    ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, IHeaderDictionary customHeaders)
        {
            log.LogDebug($"{nameof(GetProjectForCustomer)} customerUid {customerUid}, userUid {userUid} projectShortId {projectShortId}");
            var projects = await cwsProjectClient.GetProjectsForCustomer(customerUid, userUid,
                                                                         type : CwsProjectType.AcceptsTagFiles, customHeaders : customHeaders);

            var projectMatches = projects.Projects.Where(p => (Guid.TryParse(p.ProjectId, out var g) ? g.ToLegacyId() : 0) == projectShortId).ToList();

            log.LogDebug($"{nameof(GetProjectForCustomer)} Found {projectMatches.Count} projects");
            if (projectMatches.Count != 1)
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, (projectMatches.Count == 0 ? 1 : 139));
            }

            log.LogDebug($"{nameof(GetProjectForCustomer)} Project matched {JsonConvert.SerializeObject(projectMatches[0])}");
            return(projectMatches[0]);
        }
コード例 #8
0
 /// <summary>
 /// Used internally, if a step fails, after a project has been CREATED,
 ///    then  what to do - delete from cws?
 ///    CCSSSCON-417
 /// </summary>
 private static async Task RollbackProjectCreation(Guid customerUid, Guid projectUid, ILogger log,
                                                   ICwsProjectClient projectClient)
 {
     log.LogError($"RollbackProjectCreation: NOT IMPLEMENTED YET customerUid {customerUid} projectUid {projectUid}");
 }
コード例 #9
0
        /// <summary>
        /// Gets a Project list for customer uid.
        ///  Includes all projects, regardless of archived state and user role
        /// </summary>
        public static async Task <List <ProjectDatabaseModel> > GetProjectListForCustomer(Guid customerUid, Guid?userUid,
                                                                                          ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, CwsProjectType?projectType,
                                                                                          ProjectStatus?status, bool onlyAdmin, bool includeBoundaries, IHeaderDictionary customHeaders)
        {
            log.LogDebug($"{nameof(GetProjectListForCustomer)} customerUid {customerUid}, userUid {userUid}");
            var projects = await cwsProjectClient.GetProjectsForCustomer(customerUid, userUid, includeBoundaries, projectType, status, onlyAdmin, customHeaders);

            var projectDatabaseModelList = new List <ProjectDatabaseModel>();

            if (projects.Projects != null)
            {
                foreach (var project in projects.Projects)
                {
                    var projectDatabaseModel = ConvertCwsToWorksOSProject(project, log);
                    if (projectDatabaseModel != null)
                    {
                        projectDatabaseModelList.Add(projectDatabaseModel);
                    }
                }
            }

            log.LogDebug($"{nameof(GetProjectListForCustomer)} Project list contains {projectDatabaseModelList.Count} projects");
            return(projectDatabaseModelList);
        }
コード例 #10
0
        /// <summary>
        /// Used by Create/Update project to check if any new boundary overlaps any OTHER project
        /// </summary>
        public static async Task <bool> DoesProjectOverlap(Guid customerUid, Guid?projectUid, Guid userUid, string projectBoundary,
                                                           ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, IHeaderDictionary customHeaders)
        {
            // get all active projects for customer, excluding this projectUid (i.e. update)
            // todo what are the rules e.g. active, for manual import?

            var projectDatabaseModelList = (await GetProjectListForCustomer(customerUid, userUid,
                                                                            log, serviceExceptionHandler, cwsProjectClient, CwsProjectType.AcceptsTagFiles, ProjectStatus.Active, false, true, customHeaders))
                                           .Where(p => !p.IsArchived && p.ProjectType.HasFlag(CwsProjectType.AcceptsTagFiles) &&
                                                  (projectUid == null || string.Compare(p.ProjectUID.ToString(), projectUid.ToString(), StringComparison.OrdinalIgnoreCase) != 0));

            // return once we find any overlapping projects
            foreach (var project in projectDatabaseModelList)
            {
                if (string.IsNullOrEmpty(project.Boundary))
                {
                    continue;
                }
                if (PolygonUtils.OverlappingPolygons(projectBoundary, project.Boundary))
                {
                    return(true);
                }
            }

            log.LogDebug($"{nameof(DoesProjectOverlap)}: No overlapping projects.");
            return(false);
        }
コード例 #11
0
        /// <summary>
        /// Gets a Project, even if archived.
        ///    Return project even if null. This is called internally from TFA,
        ///      so don't want to throw exception other GetProjects do. Note that no UserUid available.
        ///
        /// Others are called from UI so can throw exception.
        /// </summary>
        public static async Task <ProjectDatabaseModel> GetProjectAndReturn(string projectUid,
                                                                            ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, IHeaderDictionary customHeaders)
        {
            var project = await cwsProjectClient.GetMyProject(new Guid(projectUid), null, customHeaders : customHeaders);

            if (project == null)
            {
                log.LogInformation($"{nameof(GetProjectAndReturn)} Project projectUid: {projectUid} not retrieved");
                return(null);
            }
            log.LogInformation($"{nameof(GetProjectAndReturn)} Project projectUid: {projectUid} project retrieved {JsonConvert.SerializeObject(project)}");
            return(ConvertCwsToWorksOSProject(project, log));
        }
コード例 #12
0
        /// <summary>
        /// Gets a Project and checks customerUid
        ///   Includes any project, regardless of archived state.
        ///   Temporary Note that this will return nothing if user doesn't have ADMIN role
        ///       WM team may change this behaviour in future
        /// </summary>
        public static async Task <ProjectDatabaseModel> GetProject(Guid projectUid, Guid customerUid, Guid userUid,
                                                                   ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, IHeaderDictionary customHeaders)
        {
            var project = await cwsProjectClient.GetMyProject(projectUid, userUid, customHeaders);

            if (project == null)
            {
                log.LogWarning($"Project not found: {projectUid}");
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.Forbidden, 1);
                return(null);
            }

            if (!string.Equals(project.AccountId, customerUid.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                log.LogWarning($"Customer doesn't have access to projectUid: {projectUid}");
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.Forbidden, 1);
            }

            log.LogInformation($"Project projectUid: {projectUid} retrieved");
            return(ConvertCwsToWorksOSProject(project, log));
        }