Commits

Art Lowel authored 6b0f76c0123
fix nullpointer
No tags

src/app/submission/objects/submission-objects.effects.ts

Modified
5 5 import { union } from 'lodash';
6 6
7 7 import { from as observableFrom, Observable, of as observableOf } from 'rxjs';
8 8 import { catchError, map, mergeMap, switchMap, take, tap, withLatestFrom } from 'rxjs/operators';
9 9 import { SubmissionObject } from '../../core/submission/models/submission-object.model';
10 10 import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
11 11 import { WorkspaceitemSectionUploadObject } from '../../core/submission/models/workspaceitem-section-upload.model';
12 12 import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model';
13 13 import { WorkspaceItem } from '../../core/submission/models/workspaceitem.model';
14 14 import { SubmissionJsonPatchOperationsService } from '../../core/submission/submission-json-patch-operations.service';
15 -import { isEmpty, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
15 +import { isEmpty, isNotEmpty, isNotUndefined, hasValue } from '../../shared/empty.util';
16 16 import { NotificationsService } from '../../shared/notifications/notifications.service';
17 17 import { SectionsType } from '../sections/sections-type';
18 18 import { SectionsService } from '../sections/sections.service';
19 19 import { SubmissionState } from '../submission.reducers';
20 20 import { SubmissionService } from '../submission.service';
21 21 import parseSectionErrors from '../utils/parseSectionErrors';
22 22
23 23 import {
24 24 CompleteInitSubmissionFormAction,
25 25 DepositSubmissionAction,
322 322 // to avoid dispatching an action for every error, create an array of errors per section
323 323 errorsList = parseSectionErrors(errors);
324 324 if (notify) {
325 325 this.notificationsService.warning(null, this.translate.get('submission.sections.general.sections_not_valid'));
326 326 }
327 327 }
328 328
329 329 const sections: WorkspaceitemSectionsObject = (item.sections && isNotEmpty(item.sections)) ? item.sections : {};
330 330 const sectionsKeys: string[] = union(Object.keys(sections), Object.keys(errorsList));
331 331 const metadata = (item.item as Item).metadata;
332 - const metadataKeys = Object.keys(metadata);
332 + const metadataKeys = hasValue(metadata) ? Object.keys(metadata) : undefined;
333 333
334 334 for (const sectionId of sectionsKeys) {
335 335 const sectionErrors = errorsList[sectionId] || [];
336 336 let sectionData = sections[sectionId] || {};
337 337
338 338 // When Upload section is disabled, add to submission only if there are files
339 339 if (currentState.sections[sectionId].sectionType === SectionsType.Upload
340 340 && isEmpty((sectionData as WorkspaceitemSectionUploadObject).files)
341 341 && !currentState.sections[sectionId].enabled) {
342 342 continue;
343 343 }
344 344
345 - const sectionKeys = Object.keys(sectionData);
346 - if (sectionKeys.every((key: string) => metadataKeys.includes(key))) {
347 - sectionData = metadata as any;
348 - }
349 -
350 - console.log('sectionData', sectionData);
345 + if (isNotEmpty(metadataKeys)) {
346 + const sectionKeys = Object.keys(sectionData);
347 + if (sectionKeys.every((key: string) => metadataKeys.includes(key))) {
348 + sectionData = metadata as any;
349 + console.log('sectionData', sectionData);
350 + //TODO het werkt op deze branch dus ook niet voor andere relaties, zorg er dus voor dat de state opnieuw wordt opgehaald na een change
351 + // of gewoon rechtstreeks naar het submission item kijkt.
351 352
353 + }
354 + }
352 355
353 356 if (notify && !currentState.sections[sectionId].enabled) {
354 357 this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType);
355 358 }
356 359 mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, sectionErrors));
357 360 }
358 361 });
359 362 }
360 363 return mappedActions;
361 364 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut