public async Task <ActionResult> Get(
            [FromRoute] string org,
            [FromRoute] string app,
            [FromQuery] string dataType)
        {
            if (string.IsNullOrEmpty(dataType))
            {
                return(BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter."));
            }

            string classRef = _appResourcesService.GetClassRefForLogicDataType(dataType);

            if (string.IsNullOrEmpty(classRef))
            {
                return(BadRequest($"Invalid dataType {dataType} provided. Please provide a valid dataType as query parameter."));
            }

            if (GetPartyHeader(HttpContext).Count > 1)
            {
                return(BadRequest($"Invalid party. Only one allowed"));
            }

            InstanceOwner owner = await GetInstanceOwner(HttpContext);

            if (string.IsNullOrEmpty(owner.PartyId))
            {
                return(StatusCode((int)HttpStatusCode.Forbidden));
            }

            EnforcementResult enforcementResult = await AuthorizeAction(org, app, Convert.ToInt32(owner.PartyId), "read");

            if (!enforcementResult.Authorized)
            {
                return(Forbidden(enforcementResult));
            }

            object appModel = _altinnApp.CreateNewAppModel(classRef);

            // runs prefill from repo configuration if config exists
            await _prefillService.PrefillDataModel(owner.PartyId, dataType, appModel);

            Instance virutalInstance = new Instance()
            {
                InstanceOwner = owner
            };
            await _altinnApp.RunProcessDataRead(virutalInstance, null, appModel);

            return(Ok(appModel));
        }
Пример #2
0
        /// <summary>
        ///  Gets a data element (form data) from storage and performs business logic on it (e.g. to calculate certain fields) before it is returned.
        ///  If more there are more data elements of the same dataType only the first one is returned. In that case use the more spesific
        ///  GET method to fetch a particular data element.
        /// </summary>
        /// <returns>data element is returned in response body</returns>
        private async Task <ActionResult> GetFormData(
            string org,
            string app,
            int instanceOwnerId,
            Guid instanceGuid,
            Guid dataGuid,
            string dataType,
            Instance instance)
        {
            string appModelclassRef = _appResourcesService.GetClassRefForLogicDataType(dataType);

            // Get Form Data from data service. Assumes that the data element is form data.
            object appModel = await _dataService.GetFormData(
                instanceGuid,
                _altinnApp.GetAppModelType(appModelclassRef),
                org,
                app,
                instanceOwnerId,
                dataGuid);

            if (appModel == null)
            {
                return(BadRequest($"Did not find form data for data element {dataGuid}"));
            }

            try
            {
                await _altinnApp.RunProcessDataRead(instance, dataGuid, appModel);
            }
            catch (NotImplementedException)
            {
                // Trigger application business logic the old way. DEPRICATED
                await _altinnApp.RunCalculation(appModel);
            }

            string userOrgClaim = User.GetOrg();

            if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.InvariantCultureIgnoreCase))
            {
                await _instanceService.UpdateReadStatus(instanceOwnerId, instanceGuid, "read");
            }

            return(Ok(appModel));
        }