refactory for metadata and collection params

This commit is contained in:
Danilo Di Nuzzo
2020-08-12 14:01:29 +02:00
parent 4a30e5d7d5
commit 66cabcb342
20 changed files with 23 additions and 101 deletions

View File

@@ -8,28 +8,14 @@ export class VocabularyOptions {
*/ */
name: string; name: string;
/**
* The metadata field name (e.g. "dc.type") for which the vocabulary is used:
*/
metadata?: string;
/**
* The uuid of the collection where the item is being submitted
*/
scope?: string;
/** /**
* A boolean representing if value is closely related to a vocabulary entry or not * A boolean representing if value is closely related to a vocabulary entry or not
*/ */
closed: boolean; closed: boolean;
constructor(name: string, constructor(name: string,
metadata?: string,
scope?: string,
closed: boolean = false) { closed: boolean = false) {
this.name = name; this.name = name;
this.metadata = metadata;
this.scope = scope;
this.closed = closed; this.closed = closed;
} }
} }

View File

@@ -175,8 +175,6 @@ describe('VocabularyService', () => {
const entryByIDRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?entryID=${entryID}`; const entryByIDRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?entryID=${entryID}`;
const vocabularyOptions: VocabularyOptions = { const vocabularyOptions: VocabularyOptions = {
name: vocabularyId, name: vocabularyId,
metadata: metadata,
scope: collectionUUID,
closed: false closed: false
} }
const pageInfo = new PageInfo(); const pageInfo = new PageInfo();
@@ -316,24 +314,6 @@ describe('VocabularyService', () => {
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });
}); });
describe('searchVocabularyByMetadataAndCollection', () => {
it('should proxy the call to vocabularyDataService.findVocabularyByHref', () => {
scheduler.schedule(() => service.searchVocabularyByMetadataAndCollection(vocabularyOptions).subscribe());
scheduler.flush();
expect((service as any).vocabularyDataService.findByHref).toHaveBeenCalledWith(searchRequestURL);
});
it('should return a RemoteData<Vocabulary> for the search', () => {
const result = service.searchVocabularyByMetadataAndCollection(vocabularyOptions);
const expected = cold('a|', {
a: vocabularyRD
});
expect(result).toBeObservable(expected);
});
});
}); });
describe('', () => { describe('', () => {

View File

@@ -255,26 +255,6 @@ export class VocabularyService {
); );
} }
/**
* Return the controlled {@link Vocabulary} configured for the specified metadata and collection if any.
*
* @param vocabularyOptions The {@link VocabularyOptions} for the request
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
* @return {Observable<RemoteData<PaginatedList<Vocabulary>>>}
* Return an observable that emits object list
*/
searchVocabularyByMetadataAndCollection(vocabularyOptions: VocabularyOptions, ...linksToFollow: Array<FollowLinkConfig<Vocabulary>>): Observable<RemoteData<Vocabulary>> {
const options: VocabularyFindOptions = new VocabularyFindOptions(
vocabularyOptions.scope,
vocabularyOptions.metadata
);
return this.vocabularyDataService.getSearchByHref(this.searchByMetadataAndCollectionMethod, options).pipe(
first((href: string) => hasValue(href)),
flatMap((href: string) => this.vocabularyDataService.findByHref(href))
)
}
/** /**
* Returns an observable of {@link RemoteData} of a {@link VocabularyEntryDetail}, based on an href, with a list of {@link FollowLinkConfig}, * Returns an observable of {@link RemoteData} of a {@link VocabularyEntryDetail}, based on an href, with a list of {@link FollowLinkConfig},
* to automatically resolve {@link HALLink}s of the {@link VocabularyEntryDetail} * to automatically resolve {@link HALLink}s of the {@link VocabularyEntryDetail}

View File

@@ -78,10 +78,8 @@ import { FormBuilderService } from '../form-builder.service';
describe('DsDynamicFormControlContainerComponent test suite', () => { describe('DsDynamicFormControlContainerComponent test suite', () => {
const vocabularyOptions: VocabularyOptions = { const vocabularyOptions: VocabularyOptions = {
closed: false,
metadata: 'list',
name: 'type_programme', name: 'type_programme',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23' closed: false
}; };
const formModel = [ const formModel = [
new DynamicCheckboxModel({ id: 'checkbox' }), new DynamicCheckboxModel({ id: 'checkbox' }),

View File

@@ -36,10 +36,8 @@ export const LIST_TEST_GROUP = new FormGroup({
export const LIST_CHECKBOX_TEST_MODEL_CONFIG = { export const LIST_CHECKBOX_TEST_MODEL_CONFIG = {
vocabularyOptions: { vocabularyOptions: {
closed: false,
metadata: 'listCheckbox',
name: 'type_programme', name: 'type_programme',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23' closed: false
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
id: 'listCheckbox', id: 'listCheckbox',
@@ -53,10 +51,8 @@ export const LIST_CHECKBOX_TEST_MODEL_CONFIG = {
export const LIST_RADIO_TEST_MODEL_CONFIG = { export const LIST_RADIO_TEST_MODEL_CONFIG = {
vocabularyOptions: { vocabularyOptions: {
closed: false,
metadata: 'listRadio',
name: 'type_programme', name: 'type_programme',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23' closed: false
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
id: 'listRadio', id: 'listRadio',

View File

@@ -25,10 +25,8 @@ import { ObjNgFor } from '../../../../../utils/object-ngfor.pipe';
let LOOKUP_TEST_MODEL_CONFIG: DynamicLookupModelConfig = { let LOOKUP_TEST_MODEL_CONFIG: DynamicLookupModelConfig = {
vocabularyOptions: { vocabularyOptions: {
closed: false,
metadata: 'lookup',
name: 'RPAuthority', name: 'RPAuthority',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23' closed: false
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
errorMessages: { required: 'Required field.' }, errorMessages: { required: 'Required field.' },
@@ -49,10 +47,8 @@ let LOOKUP_TEST_MODEL_CONFIG: DynamicLookupModelConfig = {
let LOOKUP_NAME_TEST_MODEL_CONFIG = { let LOOKUP_NAME_TEST_MODEL_CONFIG = {
vocabularyOptions: { vocabularyOptions: {
closed: false,
metadata: 'lookup-name',
name: 'RPAuthority', name: 'RPAuthority',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23' closed: false
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
errorMessages: { required: 'Required field.' }, errorMessages: { required: 'Required field.' },
@@ -80,10 +76,8 @@ describe('Dynamic Lookup component', () => {
function init() { function init() {
LOOKUP_TEST_MODEL_CONFIG = { LOOKUP_TEST_MODEL_CONFIG = {
vocabularyOptions: { vocabularyOptions: {
closed: false,
metadata: 'lookup',
name: 'RPAuthority', name: 'RPAuthority',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23' closed: false
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
errorMessages: { required: 'Required field.' }, errorMessages: { required: 'Required field.' },
@@ -104,10 +98,8 @@ describe('Dynamic Lookup component', () => {
LOOKUP_NAME_TEST_MODEL_CONFIG = { LOOKUP_NAME_TEST_MODEL_CONFIG = {
vocabularyOptions: { vocabularyOptions: {
closed: false,
metadata: 'lookup-name',
name: 'RPAuthority', name: 'RPAuthority',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23' closed: false
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
errorMessages: { required: 'Required field.' }, errorMessages: { required: 'Required field.' },

View File

@@ -50,9 +50,7 @@ function init() {
ONEBOX_TEST_MODEL_CONFIG = { ONEBOX_TEST_MODEL_CONFIG = {
vocabularyOptions: { vocabularyOptions: {
closed: false, closed: false,
metadata: 'onebox', name: 'vocabulary'
name: 'vocabulary',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
id: 'onebox', id: 'onebox',

View File

@@ -24,9 +24,7 @@ export const SD_TEST_GROUP = new FormGroup({
export const SD_TEST_MODEL_CONFIG = { export const SD_TEST_MODEL_CONFIG = {
vocabularyOptions: { vocabularyOptions: {
closed: false, closed: false,
metadata: 'dropdown', name: 'common_iso_languages'
name: 'common_iso_languages',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
errorMessages: { required: 'Required field.' }, errorMessages: { required: 'Required field.' },

View File

@@ -46,9 +46,7 @@ function init() {
TAG_TEST_MODEL_CONFIG = { TAG_TEST_MODEL_CONFIG = {
vocabularyOptions: { vocabularyOptions: {
closed: false, closed: false,
metadata: 'tag', name: 'common_iso_languages'
name: 'common_iso_languages',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
} as VocabularyOptions, } as VocabularyOptions,
disabled: false, disabled: false,
id: 'tag', id: 'tag',

View File

@@ -79,10 +79,8 @@ describe('FormBuilderService test suite', () => {
}); });
const vocabularyOptions: VocabularyOptions = { const vocabularyOptions: VocabularyOptions = {
closed: false,
metadata: 'list',
name: 'type_programme', name: 'type_programme',
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23' closed: false
}; };
testModel = [ testModel = [

View File

@@ -32,7 +32,7 @@ export class DropdownFieldParser extends FieldParser {
let layout: DynamicFormControlLayout; let layout: DynamicFormControlLayout;
if (isNotEmpty(this.configData.selectableMetadata[0].controlledVocabulary)) { if (isNotEmpty(this.configData.selectableMetadata[0].controlledVocabulary)) {
this.setVocabularyOptions(dropdownModelConfig, this.parserOptions.collectionUUID); this.setVocabularyOptions(dropdownModelConfig);
if (isNotEmpty(fieldValue)) { if (isNotEmpty(fieldValue)) {
dropdownModelConfig.value = fieldValue; dropdownModelConfig.value = fieldValue;
} }

View File

@@ -109,12 +109,10 @@ export abstract class FieldParser {
} }
} }
public setVocabularyOptions(controlModel, scope) { public setVocabularyOptions(controlModel) {
if (isNotEmpty(this.configData.selectableMetadata) && isNotEmpty(this.configData.selectableMetadata[0].controlledVocabulary)) { if (isNotEmpty(this.configData.selectableMetadata) && isNotEmpty(this.configData.selectableMetadata[0].controlledVocabulary)) {
controlModel.vocabularyOptions = new VocabularyOptions( controlModel.vocabularyOptions = new VocabularyOptions(
this.configData.selectableMetadata[0].controlledVocabulary, this.configData.selectableMetadata[0].controlledVocabulary,
this.configData.selectableMetadata[0].metadata,
scope,
this.configData.selectableMetadata[0].closed this.configData.selectableMetadata[0].closed
) )
} }

View File

@@ -24,7 +24,7 @@ export class ListFieldParser extends FieldParser {
} }
}); });
} }
this.setVocabularyOptions(listModelConfig, this.parserOptions.collectionUUID); this.setVocabularyOptions(listModelConfig);
} }
let listModel; let listModel;

View File

@@ -8,7 +8,7 @@ export class LookupFieldParser extends FieldParser {
if (this.configData.selectableMetadata[0].controlledVocabulary) { if (this.configData.selectableMetadata[0].controlledVocabulary) {
const lookupModelConfig: DynamicLookupModelConfig = this.initModel(null, label); const lookupModelConfig: DynamicLookupModelConfig = this.initModel(null, label);
this.setVocabularyOptions(lookupModelConfig, this.parserOptions.collectionUUID); this.setVocabularyOptions(lookupModelConfig);
this.setValues(lookupModelConfig, fieldValue, true); this.setValues(lookupModelConfig, fieldValue, true);

View File

@@ -11,7 +11,7 @@ export class LookupNameFieldParser extends FieldParser {
if (this.configData.selectableMetadata[0].controlledVocabulary) { if (this.configData.selectableMetadata[0].controlledVocabulary) {
const lookupModelConfig: DynamicLookupNameModelConfig = this.initModel(null, label); const lookupModelConfig: DynamicLookupNameModelConfig = this.initModel(null, label);
this.setVocabularyOptions(lookupModelConfig, this.parserOptions.collectionUUID); this.setVocabularyOptions(lookupModelConfig);
this.setValues(lookupModelConfig, fieldValue, true); this.setValues(lookupModelConfig, fieldValue, true);

View File

@@ -77,7 +77,7 @@ export class OneboxFieldParser extends FieldParser {
return new DynamicQualdropModel(inputSelectGroup, clsGroup); return new DynamicQualdropModel(inputSelectGroup, clsGroup);
} else if (this.configData.selectableMetadata[0].controlledVocabulary) { } else if (this.configData.selectableMetadata[0].controlledVocabulary) {
const oneboxModelConfig: DsDynamicOneboxModelConfig = this.initModel(null, label); const oneboxModelConfig: DsDynamicOneboxModelConfig = this.initModel(null, label);
this.setVocabularyOptions(oneboxModelConfig, this.parserOptions.collectionUUID); this.setVocabularyOptions(oneboxModelConfig);
this.setValues(oneboxModelConfig, fieldValue, true); this.setValues(oneboxModelConfig, fieldValue, true);
return new DynamicOneboxModel(oneboxModelConfig); return new DynamicOneboxModel(oneboxModelConfig);

View File

@@ -8,7 +8,7 @@ export class TagFieldParser extends FieldParser {
const tagModelConfig: DynamicTagModelConfig = this.initModel(null, label); const tagModelConfig: DynamicTagModelConfig = this.initModel(null, label);
if (this.configData.selectableMetadata[0].controlledVocabulary if (this.configData.selectableMetadata[0].controlledVocabulary
&& this.configData.selectableMetadata[0].controlledVocabulary.length > 0) { && this.configData.selectableMetadata[0].controlledVocabulary.length > 0) {
this.setVocabularyOptions(tagModelConfig, this.parserOptions.collectionUUID); this.setVocabularyOptions(tagModelConfig);
} }
this.setValues(tagModelConfig, fieldValue, null, true); this.setValues(tagModelConfig, fieldValue, null, true);

View File

@@ -152,7 +152,7 @@ const relationGroupConfig = {
export const MockRelationModel: DynamicRelationGroupModel = new DynamicRelationGroupModel(relationGroupConfig); export const MockRelationModel: DynamicRelationGroupModel = new DynamicRelationGroupModel(relationGroupConfig);
export const inputWithLanguageAndAuthorityConfig = { export const inputWithLanguageAndAuthorityConfig = {
vocabularyOptions: new VocabularyOptions('testAuthority', 'testWithAuthority', 'scope'), vocabularyOptions: new VocabularyOptions('testAuthority', false),
languageCodes: [ languageCodes: [
{ {
display: 'English', display: 'English',
@@ -207,7 +207,7 @@ export const inputWithLanguageConfig = {
export const mockInputWithLanguageModel = new DsDynamicInputModel(inputWithLanguageConfig); export const mockInputWithLanguageModel = new DsDynamicInputModel(inputWithLanguageConfig);
export const inputWithLanguageAndAuthorityArrayConfig = { export const inputWithLanguageAndAuthorityArrayConfig = {
vocabularyOptions: new VocabularyOptions('testAuthority', 'testWithAuthority', 'scope'), vocabularyOptions: new VocabularyOptions('testAuthority', false),
languageCodes: [ languageCodes: [
{ {
display: 'English', display: 'English',

View File

@@ -31,7 +31,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
const emptyNodeMap = new Map<string, TreeviewFlatNode>(); const emptyNodeMap = new Map<string, TreeviewFlatNode>();
const storedNodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item2)); const storedNodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item2));
const nodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item)); const nodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item));
const vocabularyOptions = new VocabularyOptions('vocabularyTest', 'metadata.test', '123456'); const vocabularyOptions = new VocabularyOptions('vocabularyTest', false);
const modalStub = jasmine.createSpyObj('modalStub', ['close']); const modalStub = jasmine.createSpyObj('modalStub', ['close']);
const vocabularyTreeviewServiceStub = jasmine.createSpyObj('VocabularyTreeviewService', { const vocabularyTreeviewServiceStub = jasmine.createSpyObj('VocabularyTreeviewService', {
initialize: jasmine.createSpy('initialize'), initialize: jasmine.createSpy('initialize'),
@@ -224,7 +224,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
}) })
class TestComponent { class TestComponent {
vocabularyOptions: VocabularyOptions = new VocabularyOptions('vocabularyTest', 'metadata.test', '123456'); vocabularyOptions: VocabularyOptions = new VocabularyOptions('vocabularyTest', false);
preloadLevel = 2; preloadLevel = 2;
} }

View File

@@ -156,7 +156,7 @@ describe('VocabularyTreeviewService test suite', () => {
searchNodeMap = new Map<string, TreeviewNode>([ searchNodeMap = new Map<string, TreeviewNode>([
[item.id, searchItemNode], [item.id, searchItemNode],
]); ]);
vocabularyOptions = new VocabularyOptions('vocabularyTest', 'metadata.test', '123456'); vocabularyOptions = new VocabularyOptions('vocabularyTest', false);
} }
beforeEach(async(() => { beforeEach(async(() => {