mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Moved normalizeSectionData function to SubmissionResponseParsingService
This commit is contained in:
@@ -14,10 +14,55 @@ import { NormalizedSubmissionObjectFactory } from './normalized-submission-objec
|
||||
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||
import { SubmissionResourceType } from './submission-resource-type';
|
||||
import { NormalizedWorkspaceItem } from './models/normalized-workspaceitem.model';
|
||||
import { normalizeSectionData } from './models/workspaceitem-sections.model';
|
||||
import { NormalizedWorkflowItem } from './models/normalized-workflowitem.model';
|
||||
import { NormalizedEditItem } from './models/normalized-edititem.model';
|
||||
import { FormFieldMetadataValueObject } from '../../shared/form/builder/models/form-field-metadata-value.model';
|
||||
|
||||
export function isServerFormValue(obj: any): boolean {
|
||||
return (typeof obj === 'object'
|
||||
&& obj.hasOwnProperty('value')
|
||||
&& obj.hasOwnProperty('language')
|
||||
&& obj.hasOwnProperty('authority')
|
||||
&& obj.hasOwnProperty('confidence')
|
||||
&& obj.hasOwnProperty('place'))
|
||||
}
|
||||
|
||||
export function normalizeSectionData(obj: any) {
|
||||
let result: any = obj;
|
||||
if (isNotNull(obj)) {
|
||||
// If is an Instance of FormFieldMetadataValueObject normalize it
|
||||
if (typeof obj === 'object' && isServerFormValue(obj)) {
|
||||
// If authority property is set normalize as a FormFieldMetadataValueObject object
|
||||
/* NOTE: Data received from server could have authority property equal to null, but into form
|
||||
field's model is required a FormFieldMetadataValueObject object as field value, so instantiate it */
|
||||
result = new FormFieldMetadataValueObject(
|
||||
obj.value,
|
||||
obj.language,
|
||||
obj.authority,
|
||||
(obj.display || obj.value),
|
||||
obj.place,
|
||||
obj.confidence,
|
||||
obj.otherInformation
|
||||
);
|
||||
} else if (Array.isArray(obj)) {
|
||||
result = [];
|
||||
obj.forEach((item, index) => {
|
||||
result[index] = normalizeSectionData(item);
|
||||
});
|
||||
} else if (typeof obj === 'object') {
|
||||
result = Object.create({});
|
||||
Object.keys(obj)
|
||||
.forEach((key) => {
|
||||
result[key] = normalizeSectionData(obj[key]);
|
||||
});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides methods to parse response for a submission request.
|
||||
*/
|
||||
@Injectable()
|
||||
export class SubmissionResponseParsingService extends BaseResponseParsingService implements ResponseParsingService {
|
||||
|
||||
|
Reference in New Issue
Block a user