Commits
Art Lowel authored 44801701c97
9 9 | import { isEmpty, isNotEmpty, isNotNull } from '../../shared/empty.util'; |
10 10 | import { ConfigObject } from '../config/models/config.model'; |
11 11 | import { BaseResponseParsingService } from '../data/base-response-parsing.service'; |
12 12 | import { GLOBAL_CONFIG } from '../../../config'; |
13 13 | import { GlobalConfig } from '../../../config/global-config.interface'; |
14 14 | import { ObjectCacheService } from '../cache/object-cache.service'; |
15 15 | import { FormFieldMetadataValueObject } from '../../shared/form/builder/models/form-field-metadata-value.model'; |
16 16 | import { SubmissionObject } from './models/submission-object.model'; |
17 17 | import { WorkflowItem } from './models/workflowitem.model'; |
18 18 | import { WorkspaceItem } from './models/workspaceitem.model'; |
19 - | import { SubmissionDefinitionsModel } from '../config/models/config-submission-definitions.model'; |
20 - | import { SubmissionSectionModel } from '../config/models/config-submission-section.model'; |
21 - | import { SectionsType } from '../../submission/sections/sections-type'; |
22 - | import { SectionDataModel } from '../../submission/sections/models/section.model'; |
23 19 | |
24 20 | /** |
25 21 | * Export a function to check if object has same properties of FormFieldMetadataValueObject |
26 22 | * |
27 23 | * @param obj |
28 24 | */ |
29 25 | export function isServerFormValue(obj: any): boolean { |
30 26 | return (typeof obj === 'object' |
31 27 | && obj.hasOwnProperty('value') |
32 28 | && obj.hasOwnProperty('language') |
133 129 | * @param {RestRequest} request |
134 130 | * @returns {any[]} |
135 131 | */ |
136 132 | protected processResponse<ObjectDomain>(data: any, request: RestRequest): any[] { |
137 133 | const dataDefinition = this.process<ObjectDomain>(data, request); |
138 134 | const definition = Array.of(); |
139 135 | const processedList = Array.isArray(dataDefinition) ? dataDefinition : Array.of(dataDefinition); |
140 136 | |
141 137 | processedList.forEach((item) => { |
142 138 | |
139 + | item = Object.assign({}, item); |
143 140 | // In case data is an Instance of WorkspaceItem normalize field value of all the section of type form |
144 141 | if (item instanceof WorkspaceItem |
145 142 | || item instanceof WorkflowItem) { |
146 143 | if (item.sections) { |
147 - | const sectionConfigs = item.sections.page ? (item.submissionDefinition as SubmissionDefinitionsModel).sections.page : []; |
148 144 | const precessedSection = Object.create({}); |
149 145 | // Iterate over all workspaceitem's sections |
150 146 | Object.keys(item.sections) |
151 147 | .forEach((sectionId) => { |
152 - | const sectionConfig: SubmissionSectionModel = sectionConfigs.find((config) => config.id === sectionId); |
153 - | let sectionData = item.sections[sectionId]; |
154 - | if (sectionConfig && sectionConfig.sectionType === SectionsType.SubmissionForm) { |
155 - | sectionData = item.item.metadata; |
156 - | } |
157 - | if (typeof sectionData === 'object' && (isNotEmpty(sectionData) && |
148 + | if (typeof item.sections[sectionId] === 'object' && (isNotEmpty(item.sections[sectionId]) && |
158 149 | // When Upload section is disabled, add to submission only if there are files |
159 - | (!sectionData.hasOwnProperty('files') || isNotEmpty((sectionData as any).files)))) { |
150 + | (!item.sections[sectionId].hasOwnProperty('files') || isNotEmpty((item.sections[sectionId] as any).files)))) { |
160 151 | |
161 152 | const sectiondata = Object.create({}); |
162 153 | // Iterate over all sections property |
163 - | Object.keys(sectionData) |
154 + | Object.keys(item.sections[sectionId]) |
164 155 | .forEach((metdadataId) => { |
165 - | const entry = sectionData[metdadataId]; |
156 + | const entry = item.sections[sectionId][metdadataId]; |
166 157 | // If entry is not an array, for sure is not a section of type form |
167 158 | if (Array.isArray(entry)) { |
168 159 | sectiondata[metdadataId] = []; |
169 160 | entry.forEach((valueItem, index) => { |
170 161 | // Parse value and normalize it |
171 162 | const normValue = normalizeSectionData(valueItem, index); |
172 163 | if (isNotEmpty(normValue)) { |
173 164 | sectiondata[metdadataId].push(normValue); |
174 165 | } |
175 166 | }); |