From 8bc7d318644afd892832d96015e4c25e5e60292f Mon Sep 17 00:00:00 2001 From: Giuseppe <giuseppe.digilio@4science.it> Date: Wed, 17 Oct 2018 09:17:02 +0200 Subject: [PATCH] Refactored IntegrationService --- src/app/core/integration/authority.service.ts | 3 ++ .../integration/integration-object-factory.ts | 4 +-- ...tegration-response-parsing.service.spec.ts | 15 +++++----- .../integration-response-parsing.service.ts | 17 +++++++++-- .../integration/integration.service.spec.ts | 6 ++++ .../core/integration/integration.service.ts | 9 +++++- ...rity-value.model.ts => authority.value.ts} | 3 +- .../integration/models/integration.model.ts | 12 ++++++-- .../normalized-authority-value.model.ts | 28 +++++++++++++++++++ .../dynamic-group/dynamic-group.components.ts | 2 +- .../dynamic-group/dynamic-group.model.ts | 2 +- .../list/dynamic-list-checkbox-group.model.ts | 10 +++---- .../list/dynamic-list.component.spec.ts | 10 +++---- .../models/list/dynamic-list.component.ts | 10 +++---- .../lookup/dynamic-lookup.component.spec.ts | 10 +++---- .../models/lookup/dynamic-lookup.component.ts | 6 ++-- ...amic-scrollable-dropdown.component.spec.ts | 6 ++-- .../dynamic-scrollable-dropdown.component.ts | 4 +-- .../models/tag/dynamic-tag.component.spec.ts | 6 ++-- .../shared/testing/authority-service-stub.ts | 6 ++-- .../sections/form/form-operations.service.ts | 8 +++--- 21 files changed, 121 insertions(+), 56 deletions(-) rename src/app/core/integration/models/{authority-value.model.ts => authority.value.ts} (85%) create mode 100644 src/app/core/integration/models/normalized-authority-value.model.ts diff --git a/src/app/core/integration/authority.service.ts b/src/app/core/integration/authority.service.ts index cb2595adc4..515a0da378 100644 --- a/src/app/core/integration/authority.service.ts +++ b/src/app/core/integration/authority.service.ts @@ -4,6 +4,7 @@ import { ResponseCacheService } from '../cache/response-cache.service'; import { RequestService } from '../data/request.service'; import { IntegrationService } from './integration.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; @Injectable() export class AuthorityService extends IntegrationService { @@ -13,7 +14,9 @@ export class AuthorityService extends IntegrationService { constructor( protected responseCache: ResponseCacheService, protected requestService: RequestService, + protected rdbService: RemoteDataBuildService, protected halService: HALEndpointService) { super(); } + } diff --git a/src/app/core/integration/integration-object-factory.ts b/src/app/core/integration/integration-object-factory.ts index 4f69dbd6fe..f66a070fdf 100644 --- a/src/app/core/integration/integration-object-factory.ts +++ b/src/app/core/integration/integration-object-factory.ts @@ -1,13 +1,13 @@ import { GenericConstructor } from '../shared/generic-constructor'; import { IntegrationType } from './intergration-type'; -import { AuthorityValueModel } from './models/authority-value.model'; import { IntegrationModel } from './models/integration.model'; +import { NormalizedAuthorityValue } from './models/normalized-authority-value.model'; export class IntegrationObjectFactory { public static getConstructor(type): GenericConstructor<IntegrationModel> { switch (type) { case IntegrationType.Authority: { - return AuthorityValueModel; + return NormalizedAuthorityValue; } default: { return undefined; diff --git a/src/app/core/integration/integration-response-parsing.service.spec.ts b/src/app/core/integration/integration-response-parsing.service.spec.ts index b16dd22947..a7f793cfef 100644 --- a/src/app/core/integration/integration-response-parsing.service.spec.ts +++ b/src/app/core/integration/integration-response-parsing.service.spec.ts @@ -7,7 +7,7 @@ import { Store } from '@ngrx/store'; import { CoreState } from '../core.reducers'; import { IntegrationResponseParsingService } from './integration-response-parsing.service'; import { IntegrationRequest } from '../data/request.models'; -import { AuthorityValueModel } from './models/authority-value.model'; +import { AuthorityValue } from './models/authority.value'; import { PageInfo } from '../shared/page-info.model'; import { PaginatedList } from '../data/paginated-list'; @@ -151,36 +151,36 @@ describe('IntegrationResponseParsingService', () => { statusText: 'Internal Server Error' }; const pageinfo = Object.assign(new PageInfo(), { elementsPerPage: 5, totalElements: 5, totalPages: 1, currentPage: 1 }); - const definitions = new PaginatedList(pageinfo,[ - Object.assign({}, new AuthorityValueModel(), { + definitions = new PaginatedList(pageinfo,[ + Object.assign(new AuthorityValue(), { type: 'authority', display: 'One', id: 'One', otherInformation: undefined, value: 'One' }), - Object.assign({}, new AuthorityValueModel(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'Two', id: 'Two', otherInformation: undefined, value: 'Two' }), - Object.assign({}, new AuthorityValueModel(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'Three', id: 'Three', otherInformation: undefined, value: 'Three' }), - Object.assign({}, new AuthorityValueModel(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'Four', id: 'Four', otherInformation: undefined, value: 'Four' }), - Object.assign({}, new AuthorityValueModel(), { + Object.assign(new AuthorityValue(), { type: 'authority', display: 'Five', id: 'Five', @@ -206,6 +206,7 @@ describe('IntegrationResponseParsingService', () => { it('should return a IntegrationSuccessResponse with data definition', () => { const response = service.parse(validRequest, validResponse); + console.log((response as any).dataDefinition); expect((response as any).dataDefinition).toEqual(definitions); }); diff --git a/src/app/core/integration/integration-response-parsing.service.ts b/src/app/core/integration/integration-response-parsing.service.ts index f85f49e240..a60337c78a 100644 --- a/src/app/core/integration/integration-response-parsing.service.ts +++ b/src/app/core/integration/integration-response-parsing.service.ts @@ -16,12 +16,14 @@ import { GlobalConfig } from '../../../config/global-config.interface'; import { ObjectCacheService } from '../cache/object-cache.service'; import { IntegrationModel } from './models/integration.model'; import { IntegrationType } from './intergration-type'; +import { AuthorityValue } from './models/authority.value'; +import { PaginatedList } from '../data/paginated-list'; @Injectable() export class IntegrationResponseParsingService extends BaseResponseParsingService implements ResponseParsingService { protected objectFactory = IntegrationObjectFactory; - protected toCache = false; + protected toCache = true; constructor( @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, @@ -33,7 +35,7 @@ export class IntegrationResponseParsingService extends BaseResponseParsingServic parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) { const dataDefinition = this.process<IntegrationModel,IntegrationType>(data.payload, request.href); - return new IntegrationSuccessResponse(dataDefinition, data.statusCode, data.statusText, this.processPageInfo(data.payload.page)); + return new IntegrationSuccessResponse(this.processResponse(dataDefinition), data.statusCode, data.statusText, this.processPageInfo(data.payload)); } else { return new ErrorResponse( Object.assign( @@ -44,4 +46,15 @@ export class IntegrationResponseParsingService extends BaseResponseParsingServic } } + protected processResponse(data: PaginatedList<IntegrationModel>): any { + const returnList = Array.of(); + data.page.forEach((item, index) => { + if (item.type === IntegrationType.Authority) { + data.page[index] = Object.assign(new AuthorityValue(), item); + } + }); + + return data; + } + } diff --git a/src/app/core/integration/integration.service.spec.ts b/src/app/core/integration/integration.service.spec.ts index b7f4e019f7..745bf8bb8e 100644 --- a/src/app/core/integration/integration.service.spec.ts +++ b/src/app/core/integration/integration.service.spec.ts @@ -9,6 +9,8 @@ import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub'; import { IntegrationService } from './integration.service'; import { IntegrationSearchOptions } from './models/integration-options.model'; +import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; +import { getMockRemoteDataBuildService } from '../../shared/mocks/mock-remote-data-build.service'; const LINK_NAME = 'authorities'; const BROWSE = 'entries'; @@ -20,6 +22,7 @@ class TestService extends IntegrationService { constructor( protected responseCache: ResponseCacheService, protected requestService: RequestService, + protected rdbService: RemoteDataBuildService, protected halService: HALEndpointService) { super(); } @@ -30,6 +33,7 @@ describe('IntegrationService', () => { let service: TestService; let responseCache: ResponseCacheService; let requestService: RequestService; + let rdbService: RemoteDataBuildService; let halService: any; let findOptions: IntegrationSearchOptions; @@ -55,6 +59,7 @@ describe('IntegrationService', () => { return new TestService( responseCache, requestService, + rdbService, halService ); } @@ -62,6 +67,7 @@ describe('IntegrationService', () => { beforeEach(() => { responseCache = initMockResponseCacheService(true); requestService = getMockRequestService(); + rdbService = getMockRemoteDataBuildService(); scheduler = getTestScheduler(); halService = new HALEndpointServiceStub(integrationEndpoint); findOptions = new IntegrationSearchOptions(uuid, name, metadata, query); diff --git a/src/app/core/integration/integration.service.ts b/src/app/core/integration/integration.service.ts index f1c770336a..8e39f2a82d 100644 --- a/src/app/core/integration/integration.service.ts +++ b/src/app/core/integration/integration.service.ts @@ -8,11 +8,13 @@ import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { IntegrationData } from './integration-data'; import { IntegrationSearchOptions } from './models/integration-options.model'; +import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; export abstract class IntegrationService { protected request: IntegrationRequest; protected abstract responseCache: ResponseCacheService; protected abstract requestService: RequestService; + protected abstract rdbService: RemoteDataBuildService; protected abstract linkPath: string; protected abstract browseEndpoint: string; protected abstract halService: HALEndpointService; @@ -26,7 +28,12 @@ export abstract class IntegrationService { Observable.throw(new Error(`Couldn't retrieve the integration data`))), successResponse .filter((response: IntegrationSuccessResponse) => isNotEmpty(response)) - .map((response: IntegrationSuccessResponse) => new IntegrationData(response.pageInfo, response.dataDefinition)) + .map((response: IntegrationSuccessResponse) => + new IntegrationData( + response.pageInfo, + (response.dataDefinition) ? response.dataDefinition.page : [] + ) + ) .distinctUntilChanged()); } diff --git a/src/app/core/integration/models/authority-value.model.ts b/src/app/core/integration/models/authority.value.ts similarity index 85% rename from src/app/core/integration/models/authority-value.model.ts rename to src/app/core/integration/models/authority.value.ts index 82c8099e9f..583356d011 100644 --- a/src/app/core/integration/models/authority-value.model.ts +++ b/src/app/core/integration/models/authority.value.ts @@ -2,7 +2,7 @@ import { IntegrationModel } from './integration.model'; import { autoserialize } from 'cerialize'; import { isNotEmpty } from '../../../shared/empty.util'; -export class AuthorityValueModel extends IntegrationModel { +export class AuthorityValue extends IntegrationModel { @autoserialize id: string; @@ -19,6 +19,7 @@ export class AuthorityValueModel extends IntegrationModel { @autoserialize language: string; + @autoserialize hasValue(): boolean { return isNotEmpty(this.value); } diff --git a/src/app/core/integration/models/integration.model.ts b/src/app/core/integration/models/integration.model.ts index d3383ab94a..9e54de2c07 100644 --- a/src/app/core/integration/models/integration.model.ts +++ b/src/app/core/integration/models/integration.model.ts @@ -1,12 +1,20 @@ import { autoserialize } from 'cerialize'; +import { CacheableObject } from '../../cache/object-cache.reducer'; -export abstract class IntegrationModel { +export abstract class IntegrationModel implements CacheableObject{ @autoserialize - public type: string; + self: string; + + @autoserialize + uuid: string; + + @autoserialize + public type: any; @autoserialize public _links: { [name: string]: string } + } diff --git a/src/app/core/integration/models/normalized-authority-value.model.ts b/src/app/core/integration/models/normalized-authority-value.model.ts new file mode 100644 index 0000000000..5ebb61281d --- /dev/null +++ b/src/app/core/integration/models/normalized-authority-value.model.ts @@ -0,0 +1,28 @@ +import { autoserialize, inheritSerialization } from 'cerialize'; +import { IntegrationModel } from './integration.model'; +import { mapsTo } from '../../cache/builders/build-decorators'; +import { AuthorityValue } from './authority.value'; + +/** + * Normalized model class for an Authority Value + */ +@mapsTo(AuthorityValue) +@inheritSerialization(IntegrationModel) +export class NormalizedAuthorityValue extends IntegrationModel { + + @autoserialize + id: string; + + @autoserialize + display: string; + + @autoserialize + value: string; + + @autoserialize + otherInformation: any; + + @autoserialize + language: string; + +} diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts index a954f58e99..1993492cf1 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts @@ -29,7 +29,7 @@ import { FormGroup } from '@angular/forms'; import { Subscription } from 'rxjs/Subscription'; import { hasOnlyEmptyProperties } from '../../../../../object.util'; import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; @Component({ selector: 'ds-dynamic-group', diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model.ts index 2048c41df8..dd419fd82d 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model.ts @@ -1,7 +1,7 @@ import { DynamicFormControlLayout, serializable } from '@ng-dynamic-forms/core'; import { FormRowModel } from '../../../../../../core/shared/config/config-submission-forms.model'; import { DsDynamicInputModel, DsDynamicInputModelConfig } from '../ds-dynamic-input.model'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; import { isEmpty, isNull } from '../../../../../empty.util'; export const DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP = 'RELATION'; diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model.ts index 5fdc530ebd..1b09c0896a 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model.ts @@ -5,7 +5,7 @@ import { DynamicFormGroupModelConfig, serializable } from '@ng-dynamic-forms/core'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; import { AuthorityOptions } from '../../../../../../core/integration/models/authority-options.model'; import { hasValue } from '../../../../../empty.util'; @@ -21,7 +21,7 @@ export class DynamicListCheckboxGroupModel extends DynamicCheckboxGroupModel { @serializable() authorityOptions: AuthorityOptions; @serializable() repeatable: boolean; @serializable() groupLength: number; - @serializable() _value: AuthorityValueModel[]; + @serializable() _value: AuthorityValue[]; isListGroup = true; valueUpdates: Subject<any>; @@ -34,7 +34,7 @@ export class DynamicListCheckboxGroupModel extends DynamicCheckboxGroupModel { this.repeatable = config.repeatable; this.valueUpdates = new Subject<any>(); - this.valueUpdates.subscribe((value: AuthorityValueModel | AuthorityValueModel[]) => this.value = value); + this.valueUpdates.subscribe((value: AuthorityValue | AuthorityValue[]) => this.value = value); this.valueUpdates.next(config.value); } @@ -46,13 +46,13 @@ export class DynamicListCheckboxGroupModel extends DynamicCheckboxGroupModel { return this._value; } - set value(value: AuthorityValueModel | AuthorityValueModel[]) { + set value(value: AuthorityValue | AuthorityValue[]) { if (value) { if (Array.isArray(value)) { this._value = value; } else { // _value is non extendible so assign it a new array - const newValue = (this.value as AuthorityValueModel[]).concat([value]); + const newValue = (this.value as AuthorityValue[]).concat([value]); this._value = newValue } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.spec.ts index 6a765eba4a..1962583890 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.spec.ts @@ -15,7 +15,7 @@ import { AuthorityService } from '../../../../../../core/integration/authority.s import { AuthorityServiceStub } from '../../../../../testing/authority-service-stub'; import { DynamicListRadioGroupModel } from './dynamic-list-radio-group.model'; import { By } from '@angular/platform-browser'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; import { createTestComponent } from '../../../../../testing/utils'; export const LAYOUT_TEST = { @@ -155,7 +155,7 @@ describe('DsDynamicListComponent test suite', () => { const de = listFixture.debugElement.queryAll(By.css('div.custom-checkbox')); const items = de[0].queryAll(By.css('input.custom-control-input')); const item = items[0]; - modelValue = [Object.assign(new AuthorityValueModel(), {id: 1, display: 'one', value: 1})]; + modelValue = [Object.assign(new AuthorityValue(), {id: 1, display: 'one', value: 1})]; item.nativeElement.click(); @@ -182,7 +182,7 @@ describe('DsDynamicListComponent test suite', () => { listComp = listFixture.componentInstance; // FormComponent test instance listComp.group = LIST_TEST_GROUP; listComp.model = new DynamicListCheckboxGroupModel(LIST_CHECKBOX_TEST_MODEL_CONFIG, LAYOUT_TEST); - modelValue = [Object.assign(new AuthorityValueModel(), {id: 1, display: 'one', value: 1})]; + modelValue = [Object.assign(new AuthorityValue(), {id: 1, display: 'one', value: 1})]; listComp.model.value = modelValue; listFixture.detectChanges(); }); @@ -245,7 +245,7 @@ describe('DsDynamicListComponent test suite', () => { const de = listFixture.debugElement.queryAll(By.css('div.custom-radio')); const items = de[0].queryAll(By.css('input.custom-control-input')); const item = items[0]; - modelValue = Object.assign(new AuthorityValueModel(), {id: 1, display: 'one', value: 1}); + modelValue = Object.assign(new AuthorityValue(), {id: 1, display: 'one', value: 1}); item.nativeElement.click(); @@ -260,7 +260,7 @@ describe('DsDynamicListComponent test suite', () => { listComp = listFixture.componentInstance; // FormComponent test instance listComp.group = LIST_TEST_GROUP; listComp.model = new DynamicListRadioGroupModel(LIST_RADIO_TEST_MODEL_CONFIG, LAYOUT_TEST); - modelValue = Object.assign(new AuthorityValueModel(), {id: 1, display: 'one', value: 1}); + modelValue = Object.assign(new AuthorityValue(), {id: 1, display: 'one', value: 1}); listComp.model.value = modelValue; listFixture.detectChanges(); }); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts index ec0d3e343a..7380421a0a 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts @@ -8,7 +8,7 @@ import { hasValue, isNotEmpty } from '../../../../../empty.util'; import { DynamicListCheckboxGroupModel } from './dynamic-list-checkbox-group.model'; import { FormBuilderService } from '../../../form-builder.service'; import { DynamicCheckboxModel } from '@ng-dynamic-forms/core'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; import { DynamicListRadioGroupModel } from './dynamic-list-radio-group.model'; import { IntegrationData } from '../../../../../../core/integration/integration-data'; @@ -36,7 +36,7 @@ export class DsDynamicListComponent implements OnInit { @Output() focus: EventEmitter<any> = new EventEmitter<any>(); public items: ListItem[][] = []; - protected optionsList: AuthorityValueModel[]; + protected optionsList: AuthorityValue[]; protected searchOptions: IntegrationSearchOptions; constructor(private authorityService: AuthorityService, @@ -70,7 +70,7 @@ export class DsDynamicListComponent implements OnInit { const target = event.target as any; if (this.model.repeatable) { // Target tabindex coincide with the array index of the value into the authority list - const authorityValue: AuthorityValueModel = this.optionsList[target.tabIndex]; + const authorityValue: AuthorityValue = this.optionsList[target.tabIndex]; if (target.checked) { this.model.valueUpdates.next(authorityValue); } else { @@ -93,9 +93,9 @@ export class DsDynamicListComponent implements OnInit { let groupCounter = 0; let itemsPerGroup = 0; let tempList: ListItem[] = []; - this.optionsList = authorities.payload as AuthorityValueModel[]; + this.optionsList = authorities.payload as AuthorityValue[]; // Make a list of available options (checkbox/radio) and split in groups of 'model.groupLength' - (authorities.payload as AuthorityValueModel[]).forEach((option, key) => { + (authorities.payload as AuthorityValue[]).forEach((option, key) => { const value = option.id || option.value; const checked: boolean = isNotEmpty(findKey( this.model.value, diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.spec.ts index ce45453bee..513208762a 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.spec.ts @@ -19,7 +19,7 @@ import { FormService } from '../../../../form.service'; import { FormComponent } from '../../../../form.component'; import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model'; import { By } from '@angular/platform-browser'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; import { DynamicLookupNameModel } from './dynamic-lookup-name.model'; import { createTestComponent } from '../../../../../testing/utils'; @@ -188,7 +188,7 @@ describe('Dynamic Lookup component', () => { it('should select a results entry properly', fakeAsync(() => { let de = lookupFixture.debugElement.queryAll(By.css('button')); const btnEl = de[0].nativeElement; - const selectedValue = Object.assign(new AuthorityValueModel(), {id: 1, display: 'one', value: 1}); + const selectedValue = Object.assign(new AuthorityValue(), {id: 1, display: 'one', value: 1}); spyOn(lookupComp.change, 'emit'); lookupComp.firstInputValue = 'test'; @@ -278,12 +278,12 @@ describe('Dynamic Lookup component', () => { it('should select a results entry properly', fakeAsync(() => { const payload = [ - Object.assign(new AuthorityValueModel(), {id: 1, display: 'Name, Lastname', value: 1}), - Object.assign(new AuthorityValueModel(), {id: 2, display: 'NameTwo, LastnameTwo', value: 2}), + Object.assign(new AuthorityValue(), {id: 1, display: 'Name, Lastname', value: 1}), + Object.assign(new AuthorityValue(), {id: 2, display: 'NameTwo, LastnameTwo', value: 2}), ]; let de = lookupFixture.debugElement.queryAll(By.css('button')); const btnEl = de[0].nativeElement; - const selectedValue = Object.assign(new AuthorityValueModel(), {id: 1, display: 'Name, Lastname', value: 1}); + const selectedValue = Object.assign(new AuthorityValue(), {id: 1, display: 'Name, Lastname', value: 1}); spyOn(lookupComp.change, 'emit'); authorityServiceStub.setNewPayload(payload); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.ts index 4e88e9c78e..0a0bb4b01a 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.ts @@ -9,7 +9,7 @@ import { IntegrationData } from '../../../../../../core/integration/integration- import { PageInfo } from '../../../../../../core/shared/page-info.model'; import { Subscription } from 'rxjs/Subscription'; import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; import { DynamicLookupNameModel } from './dynamic-lookup-name.model'; @Component({ @@ -68,9 +68,7 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit { return (typeof item === 'string') ? item : this.inputFormatter(item, field); } - // inputFormatter = (x: { display: string }) => x.display; inputFormatter = (x: { display: string }, y: number) => { - // this.splitValues(); return y === 1 ? this.firstInputValue : this.secondInputValue; }; @@ -95,7 +93,7 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit { protected setInputsValue(value) { if (hasValue(value)) { let displayValue = value; - if (value instanceof FormFieldMetadataValueObject || value instanceof AuthorityValueModel) { + if (value instanceof FormFieldMetadataValueObject || value instanceof AuthorityValue) { displayValue = value.display; } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.spec.ts index 49cdb5d890..96fbe925fd 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.spec.ts @@ -18,7 +18,7 @@ import { DsDynamicTypeaheadComponent } from '../typeahead/dynamic-typeahead.comp import { DynamicTypeaheadModel } from '../typeahead/dynamic-typeahead.model'; import { TYPEAHEAD_TEST_GROUP, TYPEAHEAD_TEST_MODEL_CONFIG } from '../typeahead/dynamic-typeahead.component.spec'; import { By } from '@angular/platform-browser'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; import { hasClass, createTestComponent } from '../../../../../testing/utils'; export const SD_TEST_GROUP = new FormGroup({ @@ -155,7 +155,7 @@ describe('Dynamic Dynamic Scrollable Dropdown component', () => { })); it('should select a results entry properly', fakeAsync(() => { - const selectedValue = Object.assign(new AuthorityValueModel(), {id: 1, display: 'one', value: 1}); + const selectedValue = Object.assign(new AuthorityValue(), {id: 1, display: 'one', value: 1}); let de: any = scrollableDropdownFixture.debugElement.query(By.css('button.ds-form-input-btn')); let btnEl = de.nativeElement; @@ -196,7 +196,7 @@ describe('Dynamic Dynamic Scrollable Dropdown component', () => { scrollableDropdownFixture = TestBed.createComponent(DsDynamicScrollableDropdownComponent); scrollableDropdownComp = scrollableDropdownFixture.componentInstance; // FormComponent test instance scrollableDropdownComp.group = SD_TEST_GROUP; - modelValue = Object.assign(new AuthorityValueModel(), {id: 1, display: 'one', value: 1}); + modelValue = Object.assign(new AuthorityValue(), {id: 1, display: 'one', value: 1}); scrollableDropdownComp.model = new DynamicScrollableDropdownModel(SD_TEST_MODEL_CONFIG); scrollableDropdownComp.model.value = modelValue; scrollableDropdownFixture.detectChanges(); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts index a043477d88..854094ca61 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts @@ -10,7 +10,7 @@ import { isNull, isUndefined } from '../../../../../empty.util'; import { AuthorityService } from '../../../../../../core/integration/authority.service'; import { IntegrationSearchOptions } from '../../../../../../core/integration/models/integration-options.model'; import { IntegrationData } from '../../../../../../core/integration/integration-data'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; @Component({ selector: 'ds-dynamic-scrollable-dropdown', @@ -55,7 +55,7 @@ export class DsDynamicScrollableDropdownComponent implements OnInit { }) } - inputFormatter = (x: AuthorityValueModel): string => x.display || x.value; + inputFormatter = (x: AuthorityValue): string => x.display || x.value; openDropdown(sdRef: NgbDropdown) { if (!this.model.readOnly) { diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts index 24959f4be4..696019252d 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts @@ -18,7 +18,7 @@ import { GlobalConfig } from '../../../../../../../config/global-config.interfac import { GLOBAL_CONFIG } from '../../../../../../../config'; import { Chips } from '../../../../../chips/models/chips.model'; import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model'; -import { AuthorityValueModel } from '../../../../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../../../../core/integration/models/authority.value'; import { createTestComponent } from '../../../../../testing/utils'; function createKeyUpEvent(key: number) { @@ -147,10 +147,10 @@ describe('DsDynamicTagComponent test suite', () => { it('should select a results entry properly', fakeAsync(() => { modelValue = [ - Object.assign(new AuthorityValueModel(), {id: 1, display: 'Name, Lastname', value: 1}) + Object.assign(new AuthorityValue(), {id: 1, display: 'Name, Lastname', value: 1}) ]; const event: NgbTypeaheadSelectItemEvent = { - item: Object.assign(new AuthorityValueModel(), {id: 1, display: 'Name, Lastname', value: 1}), + item: Object.assign(new AuthorityValue(), {id: 1, display: 'Name, Lastname', value: 1}), preventDefault: () => { return; } diff --git a/src/app/shared/testing/authority-service-stub.ts b/src/app/shared/testing/authority-service-stub.ts index 0bc8179fe3..a4f9e06d5c 100644 --- a/src/app/shared/testing/authority-service-stub.ts +++ b/src/app/shared/testing/authority-service-stub.ts @@ -2,13 +2,13 @@ import { Observable } from 'rxjs/Observable'; import { IntegrationSearchOptions } from '../../core/integration/models/integration-options.model'; import { IntegrationData } from '../../core/integration/integration-data'; import { PageInfo } from '../../core/shared/page-info.model'; -import { AuthorityValueModel } from '../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../core/integration/models/authority.value'; export class AuthorityServiceStub { private _payload = [ - Object.assign(new AuthorityValueModel(),{id: 1, display: 'one', value: 1}), - Object.assign(new AuthorityValueModel(),{id: 2, display: 'two', value: 2}), + Object.assign(new AuthorityValue(),{id: 1, display: 'one', value: 1}), + Object.assign(new AuthorityValue(),{id: 2, display: 'two', value: 2}), ]; setNewPayload(payload) { diff --git a/src/app/submission/sections/form/form-operations.service.ts b/src/app/submission/sections/form/form-operations.service.ts index e5add4bc6e..f79f824f77 100644 --- a/src/app/submission/sections/form/form-operations.service.ts +++ b/src/app/submission/sections/form/form-operations.service.ts @@ -15,7 +15,7 @@ import { FormFieldPreviousValueObject } from '../../../shared/form/builder/model import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder'; import { FormFieldLanguageValueObject } from '../../../shared/form/builder/models/form-field-language-value.model'; import { DsDynamicInputModel } from '../../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-input.model'; -import { AuthorityValueModel } from '../../../core/integration/models/authority-value.model'; +import { AuthorityValue } from '../../../core/integration/models/authority.value'; import { FormBuilderService } from '../../../shared/form/builder/form-builder.service'; import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model'; import { DynamicQualdropModel } from '../../../shared/form/builder/ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model'; @@ -141,18 +141,18 @@ export class FormOperationsService { if ((event.model as DsDynamicInputModel).hasAuthority) { if (Array.isArray(value)) { value.forEach((authority, index) => { - authority = Object.assign(new AuthorityValueModel(), authority, {language}); + authority = Object.assign(new AuthorityValue(), authority, {language}); value[index] = authority; }); fieldValue = value; } else { - fieldValue = Object.assign(new AuthorityValueModel(), value, {language}); + fieldValue = Object.assign(new AuthorityValue(), value, {language}); } } else { // Language without Authority (input, textArea) fieldValue = new FormFieldMetadataValueObject(value, language); } - } else if (value instanceof FormFieldLanguageValueObject || value instanceof AuthorityValueModel || isObject(value)) { + } else if (value instanceof FormFieldLanguageValueObject || value instanceof AuthorityValue || isObject(value)) { fieldValue = value; } else { fieldValue = new FormFieldMetadataValueObject(value); -- GitLab