mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
refactory for metadata and collection params
This commit is contained in:
@@ -8,28 +8,14 @@ export class VocabularyOptions {
|
||||
*/
|
||||
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
|
||||
*/
|
||||
closed: boolean;
|
||||
|
||||
constructor(name: string,
|
||||
metadata?: string,
|
||||
scope?: string,
|
||||
closed: boolean = false) {
|
||||
this.name = name;
|
||||
this.metadata = metadata;
|
||||
this.scope = scope;
|
||||
this.closed = closed;
|
||||
}
|
||||
}
|
||||
|
@@ -175,8 +175,6 @@ describe('VocabularyService', () => {
|
||||
const entryByIDRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?entryID=${entryID}`;
|
||||
const vocabularyOptions: VocabularyOptions = {
|
||||
name: vocabularyId,
|
||||
metadata: metadata,
|
||||
scope: collectionUUID,
|
||||
closed: false
|
||||
}
|
||||
const pageInfo = new PageInfo();
|
||||
@@ -316,24 +314,6 @@ describe('VocabularyService', () => {
|
||||
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('', () => {
|
||||
|
@@ -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},
|
||||
* to automatically resolve {@link HALLink}s of the {@link VocabularyEntryDetail}
|
||||
|
@@ -78,10 +78,8 @@ import { FormBuilderService } from '../form-builder.service';
|
||||
describe('DsDynamicFormControlContainerComponent test suite', () => {
|
||||
|
||||
const vocabularyOptions: VocabularyOptions = {
|
||||
closed: false,
|
||||
metadata: 'list',
|
||||
name: 'type_programme',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
closed: false
|
||||
};
|
||||
const formModel = [
|
||||
new DynamicCheckboxModel({ id: 'checkbox' }),
|
||||
|
@@ -36,10 +36,8 @@ export const LIST_TEST_GROUP = new FormGroup({
|
||||
|
||||
export const LIST_CHECKBOX_TEST_MODEL_CONFIG = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'listCheckbox',
|
||||
name: 'type_programme',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
closed: false
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
id: 'listCheckbox',
|
||||
@@ -53,10 +51,8 @@ export const LIST_CHECKBOX_TEST_MODEL_CONFIG = {
|
||||
|
||||
export const LIST_RADIO_TEST_MODEL_CONFIG = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'listRadio',
|
||||
name: 'type_programme',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
closed: false
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
id: 'listRadio',
|
||||
|
@@ -25,10 +25,8 @@ import { ObjNgFor } from '../../../../../utils/object-ngfor.pipe';
|
||||
|
||||
let LOOKUP_TEST_MODEL_CONFIG: DynamicLookupModelConfig = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'lookup',
|
||||
name: 'RPAuthority',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
closed: false
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
errorMessages: { required: 'Required field.' },
|
||||
@@ -49,10 +47,8 @@ let LOOKUP_TEST_MODEL_CONFIG: DynamicLookupModelConfig = {
|
||||
|
||||
let LOOKUP_NAME_TEST_MODEL_CONFIG = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'lookup-name',
|
||||
name: 'RPAuthority',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
closed: false
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
errorMessages: { required: 'Required field.' },
|
||||
@@ -80,10 +76,8 @@ describe('Dynamic Lookup component', () => {
|
||||
function init() {
|
||||
LOOKUP_TEST_MODEL_CONFIG = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'lookup',
|
||||
name: 'RPAuthority',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
closed: false
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
errorMessages: { required: 'Required field.' },
|
||||
@@ -104,10 +98,8 @@ describe('Dynamic Lookup component', () => {
|
||||
|
||||
LOOKUP_NAME_TEST_MODEL_CONFIG = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'lookup-name',
|
||||
name: 'RPAuthority',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
closed: false
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
errorMessages: { required: 'Required field.' },
|
||||
|
@@ -50,9 +50,7 @@ function init() {
|
||||
ONEBOX_TEST_MODEL_CONFIG = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'onebox',
|
||||
name: 'vocabulary',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
name: 'vocabulary'
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
id: 'onebox',
|
||||
|
@@ -24,9 +24,7 @@ export const SD_TEST_GROUP = new FormGroup({
|
||||
export const SD_TEST_MODEL_CONFIG = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'dropdown',
|
||||
name: 'common_iso_languages',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
name: 'common_iso_languages'
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
errorMessages: { required: 'Required field.' },
|
||||
|
@@ -46,9 +46,7 @@ function init() {
|
||||
TAG_TEST_MODEL_CONFIG = {
|
||||
vocabularyOptions: {
|
||||
closed: false,
|
||||
metadata: 'tag',
|
||||
name: 'common_iso_languages',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
name: 'common_iso_languages'
|
||||
} as VocabularyOptions,
|
||||
disabled: false,
|
||||
id: 'tag',
|
||||
|
@@ -79,10 +79,8 @@ describe('FormBuilderService test suite', () => {
|
||||
});
|
||||
|
||||
const vocabularyOptions: VocabularyOptions = {
|
||||
closed: false,
|
||||
metadata: 'list',
|
||||
name: 'type_programme',
|
||||
scope: 'c1c16450-d56f-41bc-bb81-27f1d1eb5c23'
|
||||
closed: false
|
||||
};
|
||||
|
||||
testModel = [
|
||||
|
@@ -32,7 +32,7 @@ export class DropdownFieldParser extends FieldParser {
|
||||
let layout: DynamicFormControlLayout;
|
||||
|
||||
if (isNotEmpty(this.configData.selectableMetadata[0].controlledVocabulary)) {
|
||||
this.setVocabularyOptions(dropdownModelConfig, this.parserOptions.collectionUUID);
|
||||
this.setVocabularyOptions(dropdownModelConfig);
|
||||
if (isNotEmpty(fieldValue)) {
|
||||
dropdownModelConfig.value = fieldValue;
|
||||
}
|
||||
|
@@ -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)) {
|
||||
controlModel.vocabularyOptions = new VocabularyOptions(
|
||||
this.configData.selectableMetadata[0].controlledVocabulary,
|
||||
this.configData.selectableMetadata[0].metadata,
|
||||
scope,
|
||||
this.configData.selectableMetadata[0].closed
|
||||
)
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ export class ListFieldParser extends FieldParser {
|
||||
}
|
||||
});
|
||||
}
|
||||
this.setVocabularyOptions(listModelConfig, this.parserOptions.collectionUUID);
|
||||
this.setVocabularyOptions(listModelConfig);
|
||||
}
|
||||
|
||||
let listModel;
|
||||
|
@@ -8,7 +8,7 @@ export class LookupFieldParser extends FieldParser {
|
||||
if (this.configData.selectableMetadata[0].controlledVocabulary) {
|
||||
const lookupModelConfig: DynamicLookupModelConfig = this.initModel(null, label);
|
||||
|
||||
this.setVocabularyOptions(lookupModelConfig, this.parserOptions.collectionUUID);
|
||||
this.setVocabularyOptions(lookupModelConfig);
|
||||
|
||||
this.setValues(lookupModelConfig, fieldValue, true);
|
||||
|
||||
|
@@ -11,7 +11,7 @@ export class LookupNameFieldParser extends FieldParser {
|
||||
if (this.configData.selectableMetadata[0].controlledVocabulary) {
|
||||
const lookupModelConfig: DynamicLookupNameModelConfig = this.initModel(null, label);
|
||||
|
||||
this.setVocabularyOptions(lookupModelConfig, this.parserOptions.collectionUUID);
|
||||
this.setVocabularyOptions(lookupModelConfig);
|
||||
|
||||
this.setValues(lookupModelConfig, fieldValue, true);
|
||||
|
||||
|
@@ -77,7 +77,7 @@ export class OneboxFieldParser extends FieldParser {
|
||||
return new DynamicQualdropModel(inputSelectGroup, clsGroup);
|
||||
} else if (this.configData.selectableMetadata[0].controlledVocabulary) {
|
||||
const oneboxModelConfig: DsDynamicOneboxModelConfig = this.initModel(null, label);
|
||||
this.setVocabularyOptions(oneboxModelConfig, this.parserOptions.collectionUUID);
|
||||
this.setVocabularyOptions(oneboxModelConfig);
|
||||
this.setValues(oneboxModelConfig, fieldValue, true);
|
||||
|
||||
return new DynamicOneboxModel(oneboxModelConfig);
|
||||
|
@@ -8,7 +8,7 @@ export class TagFieldParser extends FieldParser {
|
||||
const tagModelConfig: DynamicTagModelConfig = this.initModel(null, label);
|
||||
if (this.configData.selectableMetadata[0].controlledVocabulary
|
||||
&& this.configData.selectableMetadata[0].controlledVocabulary.length > 0) {
|
||||
this.setVocabularyOptions(tagModelConfig, this.parserOptions.collectionUUID);
|
||||
this.setVocabularyOptions(tagModelConfig);
|
||||
}
|
||||
|
||||
this.setValues(tagModelConfig, fieldValue, null, true);
|
||||
|
@@ -152,7 +152,7 @@ const relationGroupConfig = {
|
||||
export const MockRelationModel: DynamicRelationGroupModel = new DynamicRelationGroupModel(relationGroupConfig);
|
||||
|
||||
export const inputWithLanguageAndAuthorityConfig = {
|
||||
vocabularyOptions: new VocabularyOptions('testAuthority', 'testWithAuthority', 'scope'),
|
||||
vocabularyOptions: new VocabularyOptions('testAuthority', false),
|
||||
languageCodes: [
|
||||
{
|
||||
display: 'English',
|
||||
@@ -207,7 +207,7 @@ export const inputWithLanguageConfig = {
|
||||
export const mockInputWithLanguageModel = new DsDynamicInputModel(inputWithLanguageConfig);
|
||||
|
||||
export const inputWithLanguageAndAuthorityArrayConfig = {
|
||||
vocabularyOptions: new VocabularyOptions('testAuthority', 'testWithAuthority', 'scope'),
|
||||
vocabularyOptions: new VocabularyOptions('testAuthority', false),
|
||||
languageCodes: [
|
||||
{
|
||||
display: 'English',
|
||||
|
@@ -31,7 +31,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
||||
const emptyNodeMap = new Map<string, TreeviewFlatNode>();
|
||||
const storedNodeMap = new Map<string, TreeviewFlatNode>().set('test', new TreeviewFlatNode(item2));
|
||||
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 vocabularyTreeviewServiceStub = jasmine.createSpyObj('VocabularyTreeviewService', {
|
||||
initialize: jasmine.createSpy('initialize'),
|
||||
@@ -224,7 +224,7 @@ describe('VocabularyTreeviewComponent test suite', () => {
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
vocabularyOptions: VocabularyOptions = new VocabularyOptions('vocabularyTest', 'metadata.test', '123456');
|
||||
vocabularyOptions: VocabularyOptions = new VocabularyOptions('vocabularyTest', false);
|
||||
preloadLevel = 2;
|
||||
|
||||
}
|
||||
|
@@ -156,7 +156,7 @@ describe('VocabularyTreeviewService test suite', () => {
|
||||
searchNodeMap = new Map<string, TreeviewNode>([
|
||||
[item.id, searchItemNode],
|
||||
]);
|
||||
vocabularyOptions = new VocabularyOptions('vocabularyTest', 'metadata.test', '123456');
|
||||
vocabularyOptions = new VocabularyOptions('vocabularyTest', false);
|
||||
}
|
||||
|
||||
beforeEach(async(() => {
|
||||
|
Reference in New Issue
Block a user