Merge pull request #3967 from FinnStutzenstein/collectionStringModelMapperServiceCleanup

Remove the deprecation warning in the CollectionStringModelMapperService
This commit is contained in:
Sean 2018-11-05 11:40:27 +01:00 committed by GitHub
commit 7bfb097f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 77 additions and 48 deletions

View File

@ -12,20 +12,7 @@ export class CollectionStringModelMapperService {
* Mapps collection strings to model constructors. Accessed by {@method registerCollectionElement} and * Mapps collection strings to model constructors. Accessed by {@method registerCollectionElement} and
* {@method getCollectionStringType}. * {@method getCollectionStringType}.
*/ */
private static collectionStringsTypeMapping: { [collectionString: string]: ModelConstructor<BaseModel> } = {}; private collectionStringsTypeMapping: { [collectionString: string]: ModelConstructor<BaseModel> } = {};
/**
* Returns the collection string of a given ModelConstructor or undefined, if it is not registered.
* @param ctor
* @deprecated Should inject this service and don't use the static functions.
*/
public static getCollectionString(ctor: ModelConstructor<BaseModel>): string {
return Object.keys(CollectionStringModelMapperService.collectionStringsTypeMapping).find(
(collectionString: string) => {
return ctor === CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString];
}
);
}
/** /**
* Constructor to create the NotifyService. Registers itself to the WebsocketService. * Constructor to create the NotifyService. Registers itself to the WebsocketService.
@ -39,7 +26,7 @@ export class CollectionStringModelMapperService {
* @param type * @param type
*/ */
public registerCollectionElement(collectionString: string, type: ModelConstructor<BaseModel>): void { public registerCollectionElement(collectionString: string, type: ModelConstructor<BaseModel>): void {
CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString] = type; this.collectionStringsTypeMapping[collectionString] = type;
} }
/** /**
@ -47,7 +34,7 @@ export class CollectionStringModelMapperService {
* @param collectionString the requested collection * @param collectionString the requested collection
*/ */
public getModelConstructor(collectionString: string): ModelConstructor<BaseModel> { public getModelConstructor(collectionString: string): ModelConstructor<BaseModel> {
return CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString]; return this.collectionStringsTypeMapping[collectionString];
} }
/** /**
@ -55,10 +42,8 @@ export class CollectionStringModelMapperService {
* @param ctor * @param ctor
*/ */
public getCollectionString(ctor: ModelConstructor<BaseModel>): string { public getCollectionString(ctor: ModelConstructor<BaseModel>): string {
return Object.keys(CollectionStringModelMapperService.collectionStringsTypeMapping).find( return Object.keys(this.collectionStringsTypeMapping).find((collectionString: string) => {
(collectionString: string) => { return ctor === this.collectionStringsTypeMapping[collectionString];
return ctor === CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString]; });
}
);
} }
} }

View File

@ -1,10 +1,12 @@
import { TestBed, inject } from '@angular/core/testing'; import { TestBed, inject } from '@angular/core/testing';
import { AgendaRepositoryService } from './agenda-repository.service'; import { AgendaRepositoryService } from './agenda-repository.service';
import { E2EImportsModule } from 'e2e-imports.module';
describe('AgendaRepositoryService', () => { describe('AgendaRepositoryService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [E2EImportsModule],
providers: [AgendaRepositoryService] providers: [AgendaRepositoryService]
}); });
}); });

View File

@ -7,6 +7,7 @@ import { ViewItem } from '../models/view-item';
import { AgendaBaseModel } from '../../../shared/models/base/agenda-base-model'; import { AgendaBaseModel } from '../../../shared/models/base/agenda-base-model';
import { BaseModel } from '../../../shared/models/base/base-model'; import { BaseModel } from '../../../shared/models/base/base-model';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository service for users * Repository service for users
@ -17,8 +18,8 @@ import { Identifiable } from '../../../shared/models/base/identifiable';
providedIn: 'root' providedIn: 'root'
}) })
export class AgendaRepositoryService extends BaseRepository<ViewItem, Item> { export class AgendaRepositoryService extends BaseRepository<ViewItem, Item> {
public constructor(DS: DataStoreService) { public constructor(DS: DataStoreService, mapperService: CollectionStringModelMapperService) {
super(DS, Item); super(DS, mapperService, Item);
} }
/** /**

View File

@ -7,6 +7,7 @@ import { Item } from '../../../shared/models/agenda/item';
import { BaseRepository } from '../../base/base-repository'; import { BaseRepository } from '../../base/base-repository';
import { DataStoreService } from '../../../core/services/data-store.service'; import { DataStoreService } from '../../../core/services/data-store.service';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository Service for Assignments. * Repository Service for Assignments.
@ -21,8 +22,8 @@ export class AssignmentRepositoryService extends BaseRepository<ViewAssignment,
* Constructor for the Assignment Repository. * Constructor for the Assignment Repository.
* *
*/ */
public constructor(DS: DataStoreService) { public constructor(DS: DataStoreService, mapperService: CollectionStringModelMapperService) {
super(DS, Assignment, [User, Item, Tag]); super(DS, mapperService, Assignment, [User, Item, Tag]);
} }
public async update(assignment: Partial<Assignment>, viewAssignment: ViewAssignment): Promise<void> { public async update(assignment: Partial<Assignment>, viewAssignment: ViewAssignment): Promise<void> {

View File

@ -30,6 +30,7 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode
*/ */
public constructor( public constructor(
protected DS: DataStoreService, protected DS: DataStoreService,
protected collectionStringModelMapperService: CollectionStringModelMapperService,
protected baseModelCtor: ModelConstructor<M>, protected baseModelCtor: ModelConstructor<M>,
protected depsModelCtors?: ModelConstructor<BaseModel>[] protected depsModelCtors?: ModelConstructor<BaseModel>[]
) { ) {
@ -67,7 +68,7 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode
// Watch the Observables for deleting // Watch the Observables for deleting
this.DS.deletedObservable.subscribe(model => { this.DS.deletedObservable.subscribe(model => {
if (model.collection === CollectionStringModelMapperService.getCollectionString(this.baseModelCtor)) { if (model.collection === this.collectionStringModelMapperService.getCollectionString(this.baseModelCtor)) {
delete this.viewModelStore[model.id]; delete this.viewModelStore[model.id];
this.updateAllObservables(model.id); this.updateAllObservables(model.id);
} }

View File

@ -8,6 +8,7 @@ import { DataStoreService } from '../../../core/services/data-store.service';
import { ConstantsService } from '../../../core/services/constants.service'; import { ConstantsService } from '../../../core/services/constants.service';
import { HttpService } from '../../../core/services/http.service'; import { HttpService } from '../../../core/services/http.service';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Holds a single config item. * Holds a single config item.
@ -86,8 +87,13 @@ export class ConfigRepositoryService extends BaseRepository<ViewConfig, Config>
/** /**
* Constructor for ConfigRepositoryService. Requests the constants from the server and creates the config group structure. * Constructor for ConfigRepositoryService. Requests the constants from the server and creates the config group structure.
*/ */
public constructor(DS: DataStoreService, private constantsService: ConstantsService, private http: HttpService) { public constructor(
super(DS, Config); DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private constantsService: ConstantsService,
private http: HttpService
) {
super(DS, mapperService, Config);
this.constantsService.get('OpenSlidesConfigVariables').subscribe(constant => { this.constantsService.get('OpenSlidesConfigVariables').subscribe(constant => {
this.createConfigStructure(constant); this.createConfigStructure(constant);
@ -186,10 +192,7 @@ export class ConfigRepositoryService extends BaseRepository<ViewConfig, Config>
updatedConfig.patchValues(viewConfig.config); updatedConfig.patchValues(viewConfig.config);
updatedConfig.patchValues(config); updatedConfig.patchValues(config);
// TODO: Use datasendService, if it can switch correctly between put, post and patch // TODO: Use datasendService, if it can switch correctly between put, post and patch
await this.http.put( await this.http.put('rest/' + updatedConfig.collectionString + '/' + updatedConfig.key + '/', updatedConfig);
'rest/' + updatedConfig.collectionString + '/' + updatedConfig.key + '/',
updatedConfig
);
} }
/** /**

View File

@ -6,6 +6,7 @@ import { Mediafile } from '../../../shared/models/mediafiles/mediafile';
import { User } from '../../../shared/models/users/user'; import { User } from '../../../shared/models/users/user';
import { DataStoreService } from '../../../core/services/data-store.service'; import { DataStoreService } from '../../../core/services/data-store.service';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository for files * Repository for files
@ -18,8 +19,8 @@ export class MediafileRepositoryService extends BaseRepository<ViewMediafile, Me
* Consturctor for the file repo * Consturctor for the file repo
* @param DS the DataStore * @param DS the DataStore
*/ */
public constructor(DS: DataStoreService) { public constructor(DS: DataStoreService, mapperService: CollectionStringModelMapperService) {
super(DS, Mediafile, [User]); super(DS, mapperService, Mediafile, [User]);
} }
/** /**

View File

@ -8,6 +8,7 @@ import { Motion } from '../../../shared/models/motions/motion';
import { CategoryNumbering } from '../models/category-numbering'; import { CategoryNumbering } from '../models/category-numbering';
import { HttpService } from '../../../core/services/http.service'; import { HttpService } from '../../../core/services/http.service';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository Services for Categories * Repository Services for Categories
@ -31,10 +32,11 @@ export class CategoryRepositoryService extends BaseRepository<ViewCategory, Cate
*/ */
public constructor( public constructor(
protected DS: DataStoreService, protected DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService, private dataSend: DataSendService,
private httpService: HttpService private httpService: HttpService
) { ) {
super(DS, Category); super(DS, mapperService, Category);
} }
protected createViewModel(category: Category): ViewCategory { protected createViewModel(category: Category): ViewCategory {

View File

@ -11,6 +11,7 @@ import { DataStoreService } from '../../../core/services/data-store.service';
import { MotionChangeReco } from '../../../shared/models/motions/motion-change-reco'; import { MotionChangeReco } from '../../../shared/models/motions/motion-change-reco';
import { ViewChangeReco } from '../models/view-change-reco'; import { ViewChangeReco } from '../models/view-change-reco';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository Services for change recommendations * Repository Services for change recommendations
@ -34,8 +35,12 @@ export class ChangeRecommendationRepositoryService extends BaseRepository<ViewCh
* @param DS * @param DS
* @param dataSend * @param dataSend
*/ */
public constructor(DS: DataStoreService, private dataSend: DataSendService) { public constructor(
super(DS, MotionChangeReco, [Category, User, Workflow]); DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService
) {
super(DS, mapperService, MotionChangeReco, [Category, User, Workflow]);
} }
/** /**

View File

@ -6,6 +6,7 @@ import { ViewMotionCommentSection } from '../models/view-motion-comment-section'
import { MotionCommentSection } from '../../../shared/models/motions/motion-comment-section'; import { MotionCommentSection } from '../../../shared/models/motions/motion-comment-section';
import { Group } from '../../../shared/models/users/group'; import { Group } from '../../../shared/models/users/group';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository Services for Categories * Repository Services for Categories
@ -30,8 +31,12 @@ export class MotionCommentSectionRepositoryService extends BaseRepository<
* Handles CRUD using an observer to the DataStore * Handles CRUD using an observer to the DataStore
* @param DataSend * @param DataSend
*/ */
public constructor(protected DS: DataStoreService, private dataSend: DataSendService) { public constructor(
super(DS, MotionCommentSection, [Group]); protected DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService
) {
super(DS, mapperService, MotionCommentSection, [Group]);
} }
protected createViewModel(section: MotionCommentSection): ViewMotionCommentSection { protected createViewModel(section: MotionCommentSection): ViewMotionCommentSection {

View File

@ -15,6 +15,7 @@ import { ViewChangeReco } from '../models/view-change-reco';
import { MotionChangeReco } from '../../../shared/models/motions/motion-change-reco'; import { MotionChangeReco } from '../../../shared/models/motions/motion-change-reco';
import { ViewUnifiedChange } from '../models/view-unified-change'; import { ViewUnifiedChange } from '../models/view-unified-change';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository Services for motions (and potentially categories) * Repository Services for motions (and potentially categories)
@ -42,11 +43,12 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
*/ */
public constructor( public constructor(
DS: DataStoreService, DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService, private dataSend: DataSendService,
private readonly lineNumbering: LinenumberingService, private readonly lineNumbering: LinenumberingService,
private readonly diff: DiffService private readonly diff: DiffService
) { ) {
super(DS, Motion, [Category, User, Workflow]); super(DS, mapperService, Motion, [Category, User, Workflow]);
} }
/** /**

View File

@ -5,6 +5,7 @@ import { BaseRepository } from '../../base/base-repository';
import { ViewStatuteParagraph } from '../models/view-statute-paragraph'; import { ViewStatuteParagraph } from '../models/view-statute-paragraph';
import { StatuteParagraph } from '../../../shared/models/motions/statute-paragraph'; import { StatuteParagraph } from '../../../shared/models/motions/statute-paragraph';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository Services for statute paragraphs * Repository Services for statute paragraphs
@ -23,8 +24,12 @@ export class StatuteParagraphRepositoryService extends BaseRepository<ViewStatut
* Handles CRUD using an observer to the DataStore * Handles CRUD using an observer to the DataStore
* @param DataSend * @param DataSend
*/ */
public constructor(protected DS: DataStoreService, private dataSend: DataSendService) { public constructor(
super(DS, StatuteParagraph); DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService
) {
super(DS, mapperService, StatuteParagraph);
} }
protected createViewModel(statuteParagraph: StatuteParagraph): ViewStatuteParagraph { protected createViewModel(statuteParagraph: StatuteParagraph): ViewStatuteParagraph {

View File

@ -5,6 +5,7 @@ import { DataSendService } from '../../../core/services/data-send.service';
import { DataStoreService } from '../../../core/services/data-store.service'; import { DataStoreService } from '../../../core/services/data-store.service';
import { BaseRepository } from '../../base/base-repository'; import { BaseRepository } from '../../base/base-repository';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository Services for Tags * Repository Services for Tags
@ -26,8 +27,12 @@ export class TagRepositoryService extends BaseRepository<ViewTag, Tag> {
* Handles CRUD using an observer to the DataStore * Handles CRUD using an observer to the DataStore
* @param DataSend * @param DataSend
*/ */
public constructor(protected DS: DataStoreService, private dataSend: DataSendService) { public constructor(
super(DS, Tag); protected DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService
) {
super(DS, mapperService, Tag);
} }
protected createViewModel(tag: Tag): ViewTag { protected createViewModel(tag: Tag): ViewTag {

View File

@ -7,6 +7,7 @@ import { DataStoreService } from '../../../core/services/data-store.service';
import { DataSendService } from '../../../core/services/data-send.service'; import { DataSendService } from '../../../core/services/data-send.service';
import { ConstantsService } from '../../../core/services/constants.service'; import { ConstantsService } from '../../../core/services/constants.service';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Set rules to define the shape of an app permission * Set rules to define the shape of an app permission
@ -35,8 +36,13 @@ export class GroupRepositoryService extends BaseRepository<ViewGroup, Group> {
* @param DS Store * @param DS Store
* @param dataSend Sending Data * @param dataSend Sending Data
*/ */
public constructor(DS: DataStoreService, private dataSend: DataSendService, private constants: ConstantsService) { public constructor(
super(DS, Group); DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService,
private constants: ConstantsService
) {
super(DS, mapperService, Group);
this.sortPermsPerApp(); this.sortPermsPerApp();
} }

View File

@ -7,6 +7,7 @@ import { Group } from '../../../shared/models/users/group';
import { DataStoreService } from '../../../core/services/data-store.service'; import { DataStoreService } from '../../../core/services/data-store.service';
import { DataSendService } from '../../../core/services/data-send.service'; import { DataSendService } from '../../../core/services/data-send.service';
import { Identifiable } from '../../../shared/models/base/identifiable'; import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/** /**
* Repository service for users * Repository service for users
@ -20,8 +21,12 @@ export class UserRepositoryService extends BaseRepository<ViewUser, User> {
/** /**
* Constructor calls the parent constructor * Constructor calls the parent constructor
*/ */
public constructor(DS: DataStoreService, private dataSend: DataSendService) { public constructor(
super(DS, User, [Group]); DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService
) {
super(DS, mapperService, User, [Group]);
} }
/** /**