Refactored IntegrationService

This commit is contained in:
Giuseppe
2018-10-17 09:17:02 +02:00
parent b27e3d9e2f
commit 8bc7d31864
21 changed files with 121 additions and 56 deletions

View File

@@ -4,6 +4,7 @@ import { ResponseCacheService } from '../cache/response-cache.service';
import { RequestService } from '../data/request.service'; import { RequestService } from '../data/request.service';
import { IntegrationService } from './integration.service'; import { IntegrationService } from './integration.service';
import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
@Injectable() @Injectable()
export class AuthorityService extends IntegrationService { export class AuthorityService extends IntegrationService {
@@ -13,7 +14,9 @@ export class AuthorityService extends IntegrationService {
constructor( constructor(
protected responseCache: ResponseCacheService, protected responseCache: ResponseCacheService,
protected requestService: RequestService, protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected halService: HALEndpointService) { protected halService: HALEndpointService) {
super(); super();
} }
} }

View File

@@ -1,13 +1,13 @@
import { GenericConstructor } from '../shared/generic-constructor'; import { GenericConstructor } from '../shared/generic-constructor';
import { IntegrationType } from './intergration-type'; import { IntegrationType } from './intergration-type';
import { AuthorityValueModel } from './models/authority-value.model';
import { IntegrationModel } from './models/integration.model'; import { IntegrationModel } from './models/integration.model';
import { NormalizedAuthorityValue } from './models/normalized-authority-value.model';
export class IntegrationObjectFactory { export class IntegrationObjectFactory {
public static getConstructor(type): GenericConstructor<IntegrationModel> { public static getConstructor(type): GenericConstructor<IntegrationModel> {
switch (type) { switch (type) {
case IntegrationType.Authority: { case IntegrationType.Authority: {
return AuthorityValueModel; return NormalizedAuthorityValue;
} }
default: { default: {
return undefined; return undefined;

View File

@@ -7,7 +7,7 @@ import { Store } from '@ngrx/store';
import { CoreState } from '../core.reducers'; import { CoreState } from '../core.reducers';
import { IntegrationResponseParsingService } from './integration-response-parsing.service'; import { IntegrationResponseParsingService } from './integration-response-parsing.service';
import { IntegrationRequest } from '../data/request.models'; 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 { PageInfo } from '../shared/page-info.model';
import { PaginatedList } from '../data/paginated-list'; import { PaginatedList } from '../data/paginated-list';
@@ -151,36 +151,36 @@ describe('IntegrationResponseParsingService', () => {
statusText: 'Internal Server Error' statusText: 'Internal Server Error'
}; };
const pageinfo = Object.assign(new PageInfo(), { elementsPerPage: 5, totalElements: 5, totalPages: 1, currentPage: 1 }); const pageinfo = Object.assign(new PageInfo(), { elementsPerPage: 5, totalElements: 5, totalPages: 1, currentPage: 1 });
const definitions = new PaginatedList(pageinfo,[ definitions = new PaginatedList(pageinfo,[
Object.assign({}, new AuthorityValueModel(), { Object.assign(new AuthorityValue(), {
type: 'authority', type: 'authority',
display: 'One', display: 'One',
id: 'One', id: 'One',
otherInformation: undefined, otherInformation: undefined,
value: 'One' value: 'One'
}), }),
Object.assign({}, new AuthorityValueModel(), { Object.assign(new AuthorityValue(), {
type: 'authority', type: 'authority',
display: 'Two', display: 'Two',
id: 'Two', id: 'Two',
otherInformation: undefined, otherInformation: undefined,
value: 'Two' value: 'Two'
}), }),
Object.assign({}, new AuthorityValueModel(), { Object.assign(new AuthorityValue(), {
type: 'authority', type: 'authority',
display: 'Three', display: 'Three',
id: 'Three', id: 'Three',
otherInformation: undefined, otherInformation: undefined,
value: 'Three' value: 'Three'
}), }),
Object.assign({}, new AuthorityValueModel(), { Object.assign(new AuthorityValue(), {
type: 'authority', type: 'authority',
display: 'Four', display: 'Four',
id: 'Four', id: 'Four',
otherInformation: undefined, otherInformation: undefined,
value: 'Four' value: 'Four'
}), }),
Object.assign({}, new AuthorityValueModel(), { Object.assign(new AuthorityValue(), {
type: 'authority', type: 'authority',
display: 'Five', display: 'Five',
id: 'Five', id: 'Five',
@@ -206,6 +206,7 @@ describe('IntegrationResponseParsingService', () => {
it('should return a IntegrationSuccessResponse with data definition', () => { it('should return a IntegrationSuccessResponse with data definition', () => {
const response = service.parse(validRequest, validResponse); const response = service.parse(validRequest, validResponse);
console.log((response as any).dataDefinition);
expect((response as any).dataDefinition).toEqual(definitions); expect((response as any).dataDefinition).toEqual(definitions);
}); });

View File

@@ -16,12 +16,14 @@ import { GlobalConfig } from '../../../config/global-config.interface';
import { ObjectCacheService } from '../cache/object-cache.service'; import { ObjectCacheService } from '../cache/object-cache.service';
import { IntegrationModel } from './models/integration.model'; import { IntegrationModel } from './models/integration.model';
import { IntegrationType } from './intergration-type'; import { IntegrationType } from './intergration-type';
import { AuthorityValue } from './models/authority.value';
import { PaginatedList } from '../data/paginated-list';
@Injectable() @Injectable()
export class IntegrationResponseParsingService extends BaseResponseParsingService implements ResponseParsingService { export class IntegrationResponseParsingService extends BaseResponseParsingService implements ResponseParsingService {
protected objectFactory = IntegrationObjectFactory; protected objectFactory = IntegrationObjectFactory;
protected toCache = false; protected toCache = true;
constructor( constructor(
@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
@@ -33,7 +35,7 @@ export class IntegrationResponseParsingService extends BaseResponseParsingServic
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) { if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
const dataDefinition = this.process<IntegrationModel,IntegrationType>(data.payload, request.href); 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 { } else {
return new ErrorResponse( return new ErrorResponse(
Object.assign( 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;
}
} }

View File

@@ -9,6 +9,8 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub'; import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub';
import { IntegrationService } from './integration.service'; import { IntegrationService } from './integration.service';
import { IntegrationSearchOptions } from './models/integration-options.model'; 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 LINK_NAME = 'authorities';
const BROWSE = 'entries'; const BROWSE = 'entries';
@@ -20,6 +22,7 @@ class TestService extends IntegrationService {
constructor( constructor(
protected responseCache: ResponseCacheService, protected responseCache: ResponseCacheService,
protected requestService: RequestService, protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected halService: HALEndpointService) { protected halService: HALEndpointService) {
super(); super();
} }
@@ -30,6 +33,7 @@ describe('IntegrationService', () => {
let service: TestService; let service: TestService;
let responseCache: ResponseCacheService; let responseCache: ResponseCacheService;
let requestService: RequestService; let requestService: RequestService;
let rdbService: RemoteDataBuildService;
let halService: any; let halService: any;
let findOptions: IntegrationSearchOptions; let findOptions: IntegrationSearchOptions;
@@ -55,6 +59,7 @@ describe('IntegrationService', () => {
return new TestService( return new TestService(
responseCache, responseCache,
requestService, requestService,
rdbService,
halService halService
); );
} }
@@ -62,6 +67,7 @@ describe('IntegrationService', () => {
beforeEach(() => { beforeEach(() => {
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
requestService = getMockRequestService(); requestService = getMockRequestService();
rdbService = getMockRemoteDataBuildService();
scheduler = getTestScheduler(); scheduler = getTestScheduler();
halService = new HALEndpointServiceStub(integrationEndpoint); halService = new HALEndpointServiceStub(integrationEndpoint);
findOptions = new IntegrationSearchOptions(uuid, name, metadata, query); findOptions = new IntegrationSearchOptions(uuid, name, metadata, query);

View File

@@ -8,11 +8,13 @@ import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointService } from '../shared/hal-endpoint.service';
import { IntegrationData } from './integration-data'; import { IntegrationData } from './integration-data';
import { IntegrationSearchOptions } from './models/integration-options.model'; import { IntegrationSearchOptions } from './models/integration-options.model';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
export abstract class IntegrationService { export abstract class IntegrationService {
protected request: IntegrationRequest; protected request: IntegrationRequest;
protected abstract responseCache: ResponseCacheService; protected abstract responseCache: ResponseCacheService;
protected abstract requestService: RequestService; protected abstract requestService: RequestService;
protected abstract rdbService: RemoteDataBuildService;
protected abstract linkPath: string; protected abstract linkPath: string;
protected abstract browseEndpoint: string; protected abstract browseEndpoint: string;
protected abstract halService: HALEndpointService; protected abstract halService: HALEndpointService;
@@ -26,7 +28,12 @@ export abstract class IntegrationService {
Observable.throw(new Error(`Couldn't retrieve the integration data`))), Observable.throw(new Error(`Couldn't retrieve the integration data`))),
successResponse successResponse
.filter((response: IntegrationSuccessResponse) => isNotEmpty(response)) .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()); .distinctUntilChanged());
} }

View File

@@ -2,7 +2,7 @@ import { IntegrationModel } from './integration.model';
import { autoserialize } from 'cerialize'; import { autoserialize } from 'cerialize';
import { isNotEmpty } from '../../../shared/empty.util'; import { isNotEmpty } from '../../../shared/empty.util';
export class AuthorityValueModel extends IntegrationModel { export class AuthorityValue extends IntegrationModel {
@autoserialize @autoserialize
id: string; id: string;
@@ -19,6 +19,7 @@ export class AuthorityValueModel extends IntegrationModel {
@autoserialize @autoserialize
language: string; language: string;
@autoserialize
hasValue(): boolean { hasValue(): boolean {
return isNotEmpty(this.value); return isNotEmpty(this.value);
} }

View File

@@ -1,12 +1,20 @@
import { autoserialize } from 'cerialize'; import { autoserialize } from 'cerialize';
import { CacheableObject } from '../../cache/object-cache.reducer';
export abstract class IntegrationModel { export abstract class IntegrationModel implements CacheableObject{
@autoserialize @autoserialize
public type: string; self: string;
@autoserialize
uuid: string;
@autoserialize
public type: any;
@autoserialize @autoserialize
public _links: { public _links: {
[name: string]: string [name: string]: string
} }
} }

View File

@@ -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;
}

View File

@@ -29,7 +29,7 @@ import { FormGroup } from '@angular/forms';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { hasOnlyEmptyProperties } from '../../../../../object.util'; import { hasOnlyEmptyProperties } from '../../../../../object.util';
import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.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';
@Component({ @Component({
selector: 'ds-dynamic-group', selector: 'ds-dynamic-group',

View File

@@ -1,7 +1,7 @@
import { DynamicFormControlLayout, serializable } from '@ng-dynamic-forms/core'; import { DynamicFormControlLayout, serializable } from '@ng-dynamic-forms/core';
import { FormRowModel } from '../../../../../../core/shared/config/config-submission-forms.model'; import { FormRowModel } from '../../../../../../core/shared/config/config-submission-forms.model';
import { DsDynamicInputModel, DsDynamicInputModelConfig } from '../ds-dynamic-input.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'; import { isEmpty, isNull } from '../../../../../empty.util';
export const DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP = 'RELATION'; export const DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP = 'RELATION';

View File

@@ -5,7 +5,7 @@ import {
DynamicFormGroupModelConfig, DynamicFormGroupModelConfig,
serializable serializable
} from '@ng-dynamic-forms/core'; } 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 { AuthorityOptions } from '../../../../../../core/integration/models/authority-options.model';
import { hasValue } from '../../../../../empty.util'; import { hasValue } from '../../../../../empty.util';
@@ -21,7 +21,7 @@ export class DynamicListCheckboxGroupModel extends DynamicCheckboxGroupModel {
@serializable() authorityOptions: AuthorityOptions; @serializable() authorityOptions: AuthorityOptions;
@serializable() repeatable: boolean; @serializable() repeatable: boolean;
@serializable() groupLength: number; @serializable() groupLength: number;
@serializable() _value: AuthorityValueModel[]; @serializable() _value: AuthorityValue[];
isListGroup = true; isListGroup = true;
valueUpdates: Subject<any>; valueUpdates: Subject<any>;
@@ -34,7 +34,7 @@ export class DynamicListCheckboxGroupModel extends DynamicCheckboxGroupModel {
this.repeatable = config.repeatable; this.repeatable = config.repeatable;
this.valueUpdates = new Subject<any>(); 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); this.valueUpdates.next(config.value);
} }
@@ -46,13 +46,13 @@ export class DynamicListCheckboxGroupModel extends DynamicCheckboxGroupModel {
return this._value; return this._value;
} }
set value(value: AuthorityValueModel | AuthorityValueModel[]) { set value(value: AuthorityValue | AuthorityValue[]) {
if (value) { if (value) {
if (Array.isArray(value)) { if (Array.isArray(value)) {
this._value = value; this._value = value;
} else { } else {
// _value is non extendible so assign it a new array // _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 this._value = newValue
} }
} }

View File

@@ -15,7 +15,7 @@ import { AuthorityService } from '../../../../../../core/integration/authority.s
import { AuthorityServiceStub } from '../../../../../testing/authority-service-stub'; import { AuthorityServiceStub } from '../../../../../testing/authority-service-stub';
import { DynamicListRadioGroupModel } from './dynamic-list-radio-group.model'; import { DynamicListRadioGroupModel } from './dynamic-list-radio-group.model';
import { By } from '@angular/platform-browser'; 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'; import { createTestComponent } from '../../../../../testing/utils';
export const LAYOUT_TEST = { export const LAYOUT_TEST = {
@@ -155,7 +155,7 @@ describe('DsDynamicListComponent test suite', () => {
const de = listFixture.debugElement.queryAll(By.css('div.custom-checkbox')); const de = listFixture.debugElement.queryAll(By.css('div.custom-checkbox'));
const items = de[0].queryAll(By.css('input.custom-control-input')); const items = de[0].queryAll(By.css('input.custom-control-input'));
const item = items[0]; 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(); item.nativeElement.click();
@@ -182,7 +182,7 @@ describe('DsDynamicListComponent test suite', () => {
listComp = listFixture.componentInstance; // FormComponent test instance listComp = listFixture.componentInstance; // FormComponent test instance
listComp.group = LIST_TEST_GROUP; listComp.group = LIST_TEST_GROUP;
listComp.model = new DynamicListCheckboxGroupModel(LIST_CHECKBOX_TEST_MODEL_CONFIG, LAYOUT_TEST); 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; listComp.model.value = modelValue;
listFixture.detectChanges(); listFixture.detectChanges();
}); });
@@ -245,7 +245,7 @@ describe('DsDynamicListComponent test suite', () => {
const de = listFixture.debugElement.queryAll(By.css('div.custom-radio')); const de = listFixture.debugElement.queryAll(By.css('div.custom-radio'));
const items = de[0].queryAll(By.css('input.custom-control-input')); const items = de[0].queryAll(By.css('input.custom-control-input'));
const item = items[0]; 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(); item.nativeElement.click();
@@ -260,7 +260,7 @@ describe('DsDynamicListComponent test suite', () => {
listComp = listFixture.componentInstance; // FormComponent test instance listComp = listFixture.componentInstance; // FormComponent test instance
listComp.group = LIST_TEST_GROUP; listComp.group = LIST_TEST_GROUP;
listComp.model = new DynamicListRadioGroupModel(LIST_RADIO_TEST_MODEL_CONFIG, LAYOUT_TEST); 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; listComp.model.value = modelValue;
listFixture.detectChanges(); listFixture.detectChanges();
}); });

View File

@@ -8,7 +8,7 @@ import { hasValue, isNotEmpty } from '../../../../../empty.util';
import { DynamicListCheckboxGroupModel } from './dynamic-list-checkbox-group.model'; import { DynamicListCheckboxGroupModel } from './dynamic-list-checkbox-group.model';
import { FormBuilderService } from '../../../form-builder.service'; import { FormBuilderService } from '../../../form-builder.service';
import { DynamicCheckboxModel } from '@ng-dynamic-forms/core'; 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 { DynamicListRadioGroupModel } from './dynamic-list-radio-group.model';
import { IntegrationData } from '../../../../../../core/integration/integration-data'; import { IntegrationData } from '../../../../../../core/integration/integration-data';
@@ -36,7 +36,7 @@ export class DsDynamicListComponent implements OnInit {
@Output() focus: EventEmitter<any> = new EventEmitter<any>(); @Output() focus: EventEmitter<any> = new EventEmitter<any>();
public items: ListItem[][] = []; public items: ListItem[][] = [];
protected optionsList: AuthorityValueModel[]; protected optionsList: AuthorityValue[];
protected searchOptions: IntegrationSearchOptions; protected searchOptions: IntegrationSearchOptions;
constructor(private authorityService: AuthorityService, constructor(private authorityService: AuthorityService,
@@ -70,7 +70,7 @@ export class DsDynamicListComponent implements OnInit {
const target = event.target as any; const target = event.target as any;
if (this.model.repeatable) { if (this.model.repeatable) {
// Target tabindex coincide with the array index of the value into the authority list // 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) { if (target.checked) {
this.model.valueUpdates.next(authorityValue); this.model.valueUpdates.next(authorityValue);
} else { } else {
@@ -93,9 +93,9 @@ export class DsDynamicListComponent implements OnInit {
let groupCounter = 0; let groupCounter = 0;
let itemsPerGroup = 0; let itemsPerGroup = 0;
let tempList: ListItem[] = []; 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' // 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 value = option.id || option.value;
const checked: boolean = isNotEmpty(findKey( const checked: boolean = isNotEmpty(findKey(
this.model.value, this.model.value,

View File

@@ -19,7 +19,7 @@ import { FormService } from '../../../../form.service';
import { FormComponent } from '../../../../form.component'; import { FormComponent } from '../../../../form.component';
import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model'; import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.model';
import { By } from '@angular/platform-browser'; 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 { DynamicLookupNameModel } from './dynamic-lookup-name.model';
import { createTestComponent } from '../../../../../testing/utils'; import { createTestComponent } from '../../../../../testing/utils';
@@ -188,7 +188,7 @@ describe('Dynamic Lookup component', () => {
it('should select a results entry properly', fakeAsync(() => { it('should select a results entry properly', fakeAsync(() => {
let de = lookupFixture.debugElement.queryAll(By.css('button')); let de = lookupFixture.debugElement.queryAll(By.css('button'));
const btnEl = de[0].nativeElement; 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'); spyOn(lookupComp.change, 'emit');
lookupComp.firstInputValue = 'test'; lookupComp.firstInputValue = 'test';
@@ -278,12 +278,12 @@ describe('Dynamic Lookup component', () => {
it('should select a results entry properly', fakeAsync(() => { it('should select a results entry properly', fakeAsync(() => {
const payload = [ const payload = [
Object.assign(new AuthorityValueModel(), {id: 1, display: 'Name, Lastname', value: 1}), Object.assign(new AuthorityValue(), {id: 1, display: 'Name, Lastname', value: 1}),
Object.assign(new AuthorityValueModel(), {id: 2, display: 'NameTwo, LastnameTwo', value: 2}), Object.assign(new AuthorityValue(), {id: 2, display: 'NameTwo, LastnameTwo', value: 2}),
]; ];
let de = lookupFixture.debugElement.queryAll(By.css('button')); let de = lookupFixture.debugElement.queryAll(By.css('button'));
const btnEl = de[0].nativeElement; 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'); spyOn(lookupComp.change, 'emit');
authorityServiceStub.setNewPayload(payload); authorityServiceStub.setNewPayload(payload);

View File

@@ -9,7 +9,7 @@ import { IntegrationData } from '../../../../../../core/integration/integration-
import { PageInfo } from '../../../../../../core/shared/page-info.model'; import { PageInfo } from '../../../../../../core/shared/page-info.model';
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.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 { DynamicLookupNameModel } from './dynamic-lookup-name.model'; import { DynamicLookupNameModel } from './dynamic-lookup-name.model';
@Component({ @Component({
@@ -68,9 +68,7 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
return (typeof item === 'string') ? item : this.inputFormatter(item, field); return (typeof item === 'string') ? item : this.inputFormatter(item, field);
} }
// inputFormatter = (x: { display: string }) => x.display;
inputFormatter = (x: { display: string }, y: number) => { inputFormatter = (x: { display: string }, y: number) => {
// this.splitValues();
return y === 1 ? this.firstInputValue : this.secondInputValue; return y === 1 ? this.firstInputValue : this.secondInputValue;
}; };
@@ -95,7 +93,7 @@ export class DsDynamicLookupComponent implements OnDestroy, OnInit {
protected setInputsValue(value) { protected setInputsValue(value) {
if (hasValue(value)) { if (hasValue(value)) {
let displayValue = value; let displayValue = value;
if (value instanceof FormFieldMetadataValueObject || value instanceof AuthorityValueModel) { if (value instanceof FormFieldMetadataValueObject || value instanceof AuthorityValue) {
displayValue = value.display; displayValue = value.display;
} }

View File

@@ -18,7 +18,7 @@ import { DsDynamicTypeaheadComponent } from '../typeahead/dynamic-typeahead.comp
import { DynamicTypeaheadModel } from '../typeahead/dynamic-typeahead.model'; import { DynamicTypeaheadModel } from '../typeahead/dynamic-typeahead.model';
import { TYPEAHEAD_TEST_GROUP, TYPEAHEAD_TEST_MODEL_CONFIG } from '../typeahead/dynamic-typeahead.component.spec'; import { TYPEAHEAD_TEST_GROUP, TYPEAHEAD_TEST_MODEL_CONFIG } from '../typeahead/dynamic-typeahead.component.spec';
import { By } from '@angular/platform-browser'; 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'; import { hasClass, createTestComponent } from '../../../../../testing/utils';
export const SD_TEST_GROUP = new FormGroup({ 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(() => { 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 de: any = scrollableDropdownFixture.debugElement.query(By.css('button.ds-form-input-btn'));
let btnEl = de.nativeElement; let btnEl = de.nativeElement;
@@ -196,7 +196,7 @@ describe('Dynamic Dynamic Scrollable Dropdown component', () => {
scrollableDropdownFixture = TestBed.createComponent(DsDynamicScrollableDropdownComponent); scrollableDropdownFixture = TestBed.createComponent(DsDynamicScrollableDropdownComponent);
scrollableDropdownComp = scrollableDropdownFixture.componentInstance; // FormComponent test instance scrollableDropdownComp = scrollableDropdownFixture.componentInstance; // FormComponent test instance
scrollableDropdownComp.group = SD_TEST_GROUP; 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 = new DynamicScrollableDropdownModel(SD_TEST_MODEL_CONFIG);
scrollableDropdownComp.model.value = modelValue; scrollableDropdownComp.model.value = modelValue;
scrollableDropdownFixture.detectChanges(); scrollableDropdownFixture.detectChanges();

View File

@@ -10,7 +10,7 @@ import { isNull, isUndefined } from '../../../../../empty.util';
import { AuthorityService } from '../../../../../../core/integration/authority.service'; import { AuthorityService } from '../../../../../../core/integration/authority.service';
import { IntegrationSearchOptions } from '../../../../../../core/integration/models/integration-options.model'; import { IntegrationSearchOptions } from '../../../../../../core/integration/models/integration-options.model';
import { IntegrationData } from '../../../../../../core/integration/integration-data'; 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({ @Component({
selector: 'ds-dynamic-scrollable-dropdown', 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) { openDropdown(sdRef: NgbDropdown) {
if (!this.model.readOnly) { if (!this.model.readOnly) {

View File

@@ -18,7 +18,7 @@ import { GlobalConfig } from '../../../../../../../config/global-config.interfac
import { GLOBAL_CONFIG } from '../../../../../../../config'; import { GLOBAL_CONFIG } from '../../../../../../../config';
import { Chips } from '../../../../../chips/models/chips.model'; import { Chips } from '../../../../../chips/models/chips.model';
import { FormFieldMetadataValueObject } from '../../../models/form-field-metadata-value.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'; import { createTestComponent } from '../../../../../testing/utils';
function createKeyUpEvent(key: number) { function createKeyUpEvent(key: number) {
@@ -147,10 +147,10 @@ describe('DsDynamicTagComponent test suite', () => {
it('should select a results entry properly', fakeAsync(() => { it('should select a results entry properly', fakeAsync(() => {
modelValue = [ 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 = { 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: () => { preventDefault: () => {
return; return;
} }

View File

@@ -2,13 +2,13 @@ import { Observable } from 'rxjs/Observable';
import { IntegrationSearchOptions } from '../../core/integration/models/integration-options.model'; import { IntegrationSearchOptions } from '../../core/integration/models/integration-options.model';
import { IntegrationData } from '../../core/integration/integration-data'; import { IntegrationData } from '../../core/integration/integration-data';
import { PageInfo } from '../../core/shared/page-info.model'; 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 { export class AuthorityServiceStub {
private _payload = [ private _payload = [
Object.assign(new AuthorityValueModel(),{id: 1, display: 'one', value: 1}), Object.assign(new AuthorityValue(),{id: 1, display: 'one', value: 1}),
Object.assign(new AuthorityValueModel(),{id: 2, display: 'two', value: 2}), Object.assign(new AuthorityValue(),{id: 2, display: 'two', value: 2}),
]; ];
setNewPayload(payload) { setNewPayload(payload) {

View File

@@ -15,7 +15,7 @@ import { FormFieldPreviousValueObject } from '../../../shared/form/builder/model
import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder'; import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder';
import { FormFieldLanguageValueObject } from '../../../shared/form/builder/models/form-field-language-value.model'; 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 { 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 { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model'; 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'; 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 ((event.model as DsDynamicInputModel).hasAuthority) {
if (Array.isArray(value)) { if (Array.isArray(value)) {
value.forEach((authority, index) => { value.forEach((authority, index) => {
authority = Object.assign(new AuthorityValueModel(), authority, {language}); authority = Object.assign(new AuthorityValue(), authority, {language});
value[index] = authority; value[index] = authority;
}); });
fieldValue = value; fieldValue = value;
} else { } else {
fieldValue = Object.assign(new AuthorityValueModel(), value, {language}); fieldValue = Object.assign(new AuthorityValue(), value, {language});
} }
} else { } else {
// Language without Authority (input, textArea) // Language without Authority (input, textArea)
fieldValue = new FormFieldMetadataValueObject(value, language); 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; fieldValue = value;
} else { } else {
fieldValue = new FormFieldMetadataValueObject(value); fieldValue = new FormFieldMetadataValueObject(value);