Skip to content

Commit 6e97375

Browse files
committed
[DSC-1565][CST-13645] Fix issue with type-bind when using controlled vocabulary for dc.type
1 parent ff3d4c8 commit 6e97375

4 files changed

Lines changed: 33 additions & 18 deletions

File tree

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.spec.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import {
1111
REQUIRED_MATCHER_PROVIDER,
1212
} from '@ng-dynamic-forms/core';
1313

14-
import {
15-
mockInputWithTypeBindModel, MockRelationModel
16-
} from '../../../mocks/form-models.mock';
14+
import { mockInputWithTypeBindModel, MockRelationModel } from '../../../mocks/form-models.mock';
1715
import { DsDynamicTypeBindRelationService } from './ds-dynamic-type-bind-relation.service';
1816
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
19-
import {UntypedFormControl, ReactiveFormsModule} from '@angular/forms';
17+
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
2018
import { FormBuilderService } from '../form-builder.service';
2119
import { getMockFormBuilderService } from '../../../mocks/form-builder-service.mock';
2220
import { Injector } from '@angular/core';
21+
import { VocabularyEntryDetail } from '../../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
2322

2423
describe('DSDynamicTypeBindRelationService test suite', () => {
2524
let service: DsDynamicTypeBindRelationService;
@@ -42,17 +41,17 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
4241
(relationService: DsDynamicTypeBindRelationService,
4342
formRelationService: DynamicFormRelationService,
4443
) => {
45-
service = relationService;
46-
dynamicFormRelationService = formRelationService;
47-
}));
44+
service = relationService;
45+
dynamicFormRelationService = formRelationService;
46+
}));
4847

4948
describe('Test getTypeBindValue method', () => {
5049
it('Should get type bind "boundType" from the given metadata object value', () => {
51-
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
52-
'boundType', null, null, null,'Bound Type'
53-
);
54-
const bindType = service.getTypeBindValue(mockMetadataValueObject);
55-
expect(bindType).toBe('boundType');
50+
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
51+
'boundType', null, null, null, 'Bound Type'
52+
);
53+
const bindType = service.getTypeBindValue(mockMetadataValueObject);
54+
expect(bindType).toBe('boundType');
5655
});
5756
it('Should get type authority key "bound-auth-key" from the given metadata object value', () => {
5857
const mockMetadataValueObject: FormFieldMetadataValueObject = new FormFieldMetadataValueObject(
@@ -61,6 +60,19 @@ describe('DSDynamicTypeBindRelationService test suite', () => {
6160
const bindType = service.getTypeBindValue(mockMetadataValueObject);
6261
expect(bindType).toBe('bound-auth-key');
6362
});
63+
it('Should get type bind "boundType" from the given vocabulary entry object value', () => {
64+
const vocabularyEntry = new VocabularyEntryDetail();
65+
vocabularyEntry.value = vocabularyEntry.display = 'boundType';
66+
const bindType = service.getTypeBindValue(vocabularyEntry);
67+
expect(bindType).toBe('boundType');
68+
});
69+
it('Should get type authority key "bound-auth-key" from the given vocabulary entry object value', () => {
70+
const vocabularyEntry = new VocabularyEntryDetail();
71+
vocabularyEntry.id = vocabularyEntry.authority = 'bound-auth-key';
72+
vocabularyEntry.value = vocabularyEntry.display = 'boundType';
73+
const bindType = service.getTypeBindValue(vocabularyEntry);
74+
expect(bindType).toBe('bound-auth-key');
75+
});
6476
it('Should get passed string returned directly as string passed instead of metadata', () => {
6577
const bindType = service.getTypeBindValue('rawString');
6678
expect(bindType).toBe('rawString');

src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import {
1111
DynamicFormControlMatcher,
1212
DynamicFormControlModel,
1313
DynamicFormControlRelation,
14-
DynamicFormRelationService, MATCH_VISIBLE,
14+
DynamicFormRelationService,
15+
MATCH_VISIBLE,
1516
OR_OPERATOR
1617
} from '@ng-dynamic-forms/core';
1718

18-
import {hasNoValue, hasValue} from '../../../empty.util';
19+
import { hasNoValue, hasValue } from '../../../empty.util';
1920
import { FormBuilderService } from '../form-builder.service';
2021
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
2122
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './ds-dynamic-form-constants';
23+
import { VocabularyEntry } from '../../../../core/submission/vocabularies/models/vocabulary-entry.model';
2224

2325
/**
2426
* Service to manage type binding for submission input fields
@@ -38,11 +40,11 @@ export class DsDynamicTypeBindRelationService {
3840
* @param bindModelValue
3941
* @private
4042
*/
41-
public getTypeBindValue(bindModelValue: string | FormFieldMetadataValueObject): string {
43+
public getTypeBindValue(bindModelValue: string | FormFieldMetadataValueObject | VocabularyEntry): string {
4244
let value;
4345
if (hasNoValue(bindModelValue) || typeof bindModelValue === 'string') {
4446
value = bindModelValue;
45-
} else if (bindModelValue instanceof FormFieldMetadataValueObject
47+
} else if ((bindModelValue instanceof FormFieldMetadataValueObject || bindModelValue instanceof VocabularyEntry)
4648
&& bindModelValue.hasAuthority()) {
4749
value = bindModelValue.authority;
4850
} else {

src/config/config.util.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('Config Util', () => {
2121
'dc.identifier.scopus',
2222
'dc.identifier.isi',
2323
'dcterms.dateSubmitted',
24-
'dc.identifier.applicationnumber'
24+
'dc.identifier.applicationnumber',
25+
'dc.type'
2526
]);
2627

2728
expect(appConfig.themes.length).toEqual(1);

src/config/default-app-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class DefaultAppConfig implements AppConfig {
157157
submission: SubmissionConfig = {
158158
autosave: {
159159
// NOTE: which metadata trigger an autosave
160-
metadata: ['dc.title', 'dc.identifier.doi', 'dc.identifier.pmid', 'dc.identifier.arxiv', 'dc.identifier.patentno', 'dc.identifier.scopus', 'dc.identifier.isi', 'dcterms.dateSubmitted', 'dc.identifier.applicationnumber'],
160+
metadata: ['dc.title', 'dc.identifier.doi', 'dc.identifier.pmid', 'dc.identifier.arxiv', 'dc.identifier.patentno', 'dc.identifier.scopus', 'dc.identifier.isi', 'dcterms.dateSubmitted', 'dc.identifier.applicationnumber', 'dc.type'],
161161
/**
162162
* NOTE: after how many time (milliseconds) submission is saved automatically
163163
* eg. timer: 5 * (1000 * 60); // 5 minutes

0 commit comments

Comments
 (0)