예제 #1
0
        public async Task <IActionResult> CompleteAndSendIn(string org, string service, Guid instanceId)
        {
            // Dependency Injection: Getting the Service Specific Implementation based on the service parameter data store
            // Will compile code and load DLL in to memory for AltinnCore
            IServiceImplementation serviceImplementation = _execution.GetServiceImplementation(org, service, false);

            // Create and populate the RequestContext object and make it available for the service implementation so
            // service developer can implement logic based on information about the request and the user performing
            // the request
            RequestContext requestContext = RequestHelper.GetRequestContext(Request.Query, instanceId);

            requestContext.UserContext = await _userHelper.GetUserContext(HttpContext);

            requestContext.Reportee = requestContext.UserContext.Reportee;

            // Get the serviceContext containing all metadata about current service
            ServiceContext serviceContext = _execution.GetServiceContext(org, service, false);

            serviceImplementation.SetPlatformServices(_platformSI);

            // Identify the correct view
            // Getting the Form Data from database
            object serviceModel = _form.GetFormModel(instanceId, serviceImplementation.GetServiceModelType(), org, service, requestContext.UserContext.ReporteeId, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            serviceImplementation.SetServiceModel(serviceModel);
            serviceImplementation.SetContext(requestContext, serviceContext, null, ModelState);

            ViewBag.FormID         = instanceId;
            ViewBag.ServiceContext = serviceContext;

            await serviceImplementation.RunServiceEvent(ServiceEventType.Validation);

            return(View());
        }
        public async Task <IActionResult> Index(string org, string service, string edition, int instanceId)
        {
            // Getting the Service Specific Implementation contained in external DLL migrated from TUL
            IServiceImplementation serviceImplementation = _execution.GetServiceImplementation(org, service, edition);

            // Create and populate the RequestContext object and make it available for the service implementation so
            // service developer can implement logic based on information about the request and the user performing
            // the request
            RequestContext requestContext = RequestHelper.GetRequestContext(Request.Query, instanceId);

            requestContext.UserContext = _userHelper.GetUserContext(HttpContext);
            requestContext.Reportee    = requestContext.UserContext.Reportee;

            // Get the serviceContext containing all metadata about current service
            ServiceContext serviceContext = _execution.GetServiceContext(org, service, edition);

            // Assign data to the ViewBag so it is available to the service views or service implementation
            ViewBag.ServiceContext = serviceContext;
            ViewBag.RequestContext = requestContext;
            ViewBag.Org            = org;
            ViewBag.Service        = service;
            ViewBag.Edition        = edition;
            ViewBag.FormID         = instanceId;

            // Assign the RequestContext and ViewBag to the serviceImplementation so
            // service developer can use the information in any of the service events that is called
            serviceImplementation.SetContext(requestContext, ViewBag, serviceContext, null, ModelState);

            // Set the platform services to the ServiceImplementation so the AltinnCore service can take
            // use of the plattform services
            PlatformServices platformServices = new PlatformServices(_authorization, _repository, _execution, org, service, edition);

            serviceImplementation.SetPlatformServices(platformServices);

            ViewBag.PlatformServices = platformServices;

            // Getting the Form Data from datastore
            object serviceModel = this._form.GetFormModel(
                instanceId,
                serviceImplementation.GetServiceModelType(),
                org,
                service,
                edition,
                requestContext.UserContext.ReporteeId);

            // Assing the populated service model to the service implementation
            serviceImplementation.SetServiceModel(serviceModel);

            // ServiceEvent 1: HandleGetDataEvent
            // Runs the event where the service developer can implement functionality to retrieve data from internal/external sources
            // based on the data in the service model
            await serviceImplementation.RunServiceEvent(AltinnCore.ServiceLibrary.Enums.ServiceEventType.DataRetrieval);

            // ServiceEvent 2: HandleCalculationEvent
            // Perform Calculation defined by the service developer
            await serviceImplementation.RunServiceEvent(AltinnCore.ServiceLibrary.Enums.ServiceEventType.Calculation);

            return(Ok(serviceModel));
        }
예제 #3
0
        /// <summary>
        /// Prepares the service implementation for a given dataElement, that has an xsd or json-schema.
        /// </summary>
        /// <param name="org">unique identifier of the organisation responsible for the app</param>
        /// <param name="app">application identifier which is unique within an organisation</param>
        /// <param name="elementType">the data element type</param>
        /// <param name="startApp">indicates if the app should be started or just opened</param>
        /// <returns>the serviceImplementation object which represents the application business logic</returns>
        private async Task <IServiceImplementation> PrepareServiceImplementation(string org, string app, string elementType, bool startApp = false)
        {
            logger.LogInformation($"Preparing data element instantiation for {elementType}");

            IServiceImplementation serviceImplementation = executionService.GetServiceImplementation(org, app, startApp);

            RequestContext requestContext = RequestHelper.GetRequestContext(Request.Query, Guid.Empty);

            requestContext.UserContext = await userHelper.GetUserContext(HttpContext);

            requestContext.Party = requestContext.UserContext.Party;

            ServiceContext serviceContext = executionService.GetServiceContext(org, app, startApp);

            serviceImplementation.SetContext(requestContext, serviceContext, null, ModelState);
            serviceImplementation.SetPlatformServices(platformService);

            return(serviceImplementation);
        }
예제 #4
0
        public async Task <IActionResult> Gindex(string org, string service, int partyId, Guid instanceId)
        {
            // Getting the Service Specific Implementation contained in external DLL migrated from TUL
            IServiceImplementation serviceImplementation = _execution.GetServiceImplementation(org, service, false);

            // Create and populate the RequestContext object and make it available for the service implementation so
            // service developer can implement logic based on information about the request and the user performing
            // the request
            RequestContext requestContext = RequestHelper.GetRequestContext(Request.Query, instanceId);

            requestContext.UserContext = await _userHelper.GetUserContext(HttpContext);

            requestContext.Party = requestContext.UserContext.Party;

            // Get the serviceContext containing all metadata about current service
            ServiceContext serviceContext = _execution.GetServiceContext(org, service, false);

            // Assign data to the ViewBag so it is available to the service views or service implementation
            ViewBag.ServiceContext = serviceContext;
            ViewBag.RequestContext = requestContext;
            ViewBag.Org            = org;
            ViewBag.Service        = service;
            ViewBag.FormID         = instanceId;

            // Assign the RequestContext to the serviceImplementation so
            // service developer can use the information in any of the service events that is called
            serviceImplementation.SetContext(requestContext, serviceContext, null, ModelState);

            // Set the platform services to the ServiceImplementation so the AltinnCore service can take
            // use of the plattform services
            serviceImplementation.SetPlatformServices(_platformSI);

            ViewBag.PlatformServices = _platformSI;

            Instance instance = await _instance.GetInstance(service, org, requestContext.UserContext.PartyId, instanceId);

            Guid dataId = Guid.Parse(instance.Data.Find(m => m.ElementType.Equals(FORM_ID)).Id);

            // Getting the Form Data from datastore
            object serviceModel = this._data.GetFormData(
                instanceId,
                serviceImplementation.GetServiceModelType(),
                org,
                service,
                requestContext.UserContext.PartyId,
                dataId);

            // Assing the populated service model to the service implementation
            serviceImplementation.SetServiceModel(serviceModel);

            // ServiceEvent 1: HandleGetDataEvent
            // Runs the event where the service developer can implement functionality to retrieve data from internal/external sources
            // based on the data in the service model
            await serviceImplementation.RunServiceEvent(AltinnCore.ServiceLibrary.Enums.ServiceEventType.DataRetrieval);

            // ServiceEvent 2: HandleCalculationEvent
            // Perform Calculation defined by the service developer
            await serviceImplementation.RunServiceEvent(AltinnCore.ServiceLibrary.Enums.ServiceEventType.Calculation);

            return(Ok(serviceModel));
        }
예제 #5
0
        public async Task <IActionResult> CompleteAndSendIn(string org, string service, int partyId, Guid instanceGuid, string view)
        {
            // Dependency Injection: Getting the Service Specific Implementation based on the service parameter data store
            // Will compile code and load DLL in to memory for AltinnCore
            IServiceImplementation serviceImplementation = _execution.GetServiceImplementation(org, service, false);

            // Get the serviceContext containing all metadata about current service
            ServiceContext serviceContext = _execution.GetServiceContext(org, service, false);

            // Create and populate the RequestContext object and make it available for the service implementation so
            // service developer can implement logic based on information about the request and the user performing
            // the request
            RequestContext requestContext = await PopulateRequestContext(instanceGuid);

            serviceImplementation.SetPlatformServices(_platformSI);

            // Assign data to the ViewBag so it is available to the service views or service implementation
            PopulateViewBag(org, service, instanceGuid, 0, requestContext, serviceContext, _platformSI);

            // Getting the Form Data
            Instance instance = await _instance.GetInstance(service, org, requestContext.UserContext.PartyId, instanceGuid);

            Guid.TryParse(instance.Data.Find(m => m.ElementType == FORM_ID).Id, out Guid dataId);
            object serviceModel = _data.GetFormData(instanceGuid, serviceImplementation.GetServiceModelType(), org, service, requestContext.UserContext.PartyId, dataId);

            serviceImplementation.SetServiceModel(serviceModel);

            ViewBag.FormID         = instanceGuid;
            ViewBag.ServiceContext = serviceContext;

            serviceImplementation.SetContext(requestContext, serviceContext, null, ModelState);
            await serviceImplementation.RunServiceEvent(ServiceEventType.Validation);

            ApiResult apiResult = new ApiResult();

            if (ModelState.IsValid)
            {
                ServiceState currentState = _workflowSI.MoveServiceForwardInWorkflow(instanceGuid, org, service, requestContext.UserContext.PartyId);

                if (currentState.State == WorkflowStep.Archived)
                {
                    await _instance.ArchiveInstance(serviceModel, serviceImplementation.GetServiceModelType(), service, org, requestContext.UserContext.PartyId, instanceGuid);

                    apiResult.NextState = currentState.State;
                }

                // Create and store the instance submitted event
                InstanceEvent instanceEvent = new InstanceEvent
                {
                    AuthenticationLevel = requestContext.UserContext.AuthenticationLevel,
                    EventType           = InstanceEventType.Submited.ToString(),
                    InstanceId          = instance.Id,
                    InstanceOwnerId     = instance.InstanceOwnerId.ToString(),
                    UserId       = requestContext.UserContext.UserId,
                    WorkflowStep = instance.Process.CurrentTask,
                };

                await _event.SaveInstanceEvent(instanceEvent, org, service);
            }

            ModelHelper.MapModelStateToApiResult(ModelState, apiResult, serviceContext);

            if (apiResult.Status.Equals(ApiStatusType.ContainsError))
            {
                Response.StatusCode = 202;
            }
            else
            {
                Response.StatusCode = 200;
            }

            return(new ObjectResult(apiResult));
        }