Rename halResourceTypesStorage to halResourceFactory

pull/4734/head
Alex Dik 8 years ago
parent 07f6eafc53
commit b5038a8a22
  1. 4
      frontend/app/components/api/api-v3/hal-resource-factory/hal-resource-factory.service.ts
  2. 16
      frontend/app/components/api/api-v3/hal-resource-types/hal-resource-types.service.test.ts
  3. 12
      frontend/app/components/api/api-v3/hal-resource-types/hal-resource-types.service.ts
  4. 14
      frontend/app/components/api/api-v3/hal-resources/hal-resource.service.test.ts
  5. 14
      frontend/app/components/api/api-v3/hal-resources/hal-resource.service.ts

@ -30,7 +30,7 @@
import {opApiModule} from '../../../../angular-modules'; import {opApiModule} from '../../../../angular-modules';
import {HalResource} from '../hal-resources/hal-resource.service'; import {HalResource} from '../hal-resources/hal-resource.service';
export class HalResourceTypesStorageService { export class HalResourceFactoryService {
private config:any = {}; private config:any = {};
public get defaultClass() { public get defaultClass() {
@ -80,4 +80,4 @@ export class HalResourceTypesStorageService {
} }
} }
opApiModule.service('halResourceTypesStorage', HalResourceTypesStorageService); opApiModule.service('halResourceFactory', HalResourceFactoryService);

@ -28,11 +28,11 @@
import {opApiModule} from '../../../../angular-modules'; import {opApiModule} from '../../../../angular-modules';
import {HalResourceTypesService} from './hal-resource-types.service'; import {HalResourceTypesService} from './hal-resource-types.service';
import {HalResourceTypesStorageService} from '../hal-resource-types-storage/hal-resource-types-storage.service'; import {HalResourceFactoryService} from '../hal-resource-factory/hal-resource-factory.service';
describe('halResourceTypes service', () => { describe('halResourceTypes service', () => {
var halResourceTypes:HalResourceTypesService; var halResourceTypes:HalResourceTypesService;
var halResourceTypesStorage:HalResourceTypesStorageService; var halResourceFactory:HalResourceFactoryService;
var config:any; var config:any;
var compareCls:typeof HalResource; var compareCls:typeof HalResource;
@ -49,20 +49,20 @@ describe('halResourceTypes service', () => {
$provide.value('FooResource', FooResource); $provide.value('FooResource', FooResource);
})); }));
beforeEach(angular.mock.inject(function (_halResourceTypes_, _halResourceTypesStorage_) { beforeEach(angular.mock.inject(function (_halResourceTypes_, _halResourceFactory_) {
[halResourceTypes, halResourceTypesStorage] = _.toArray(arguments); [halResourceTypes, halResourceFactory] = _.toArray(arguments);
})); }));
const expectResourceClassAdded = () => { const expectResourceClassAdded = () => {
it('should add the respective class object to the storage', () => { it('should add the respective class object to the storage', () => {
const cls = halResourceTypesStorage.getResourceClassOfType('Other'); const cls = halResourceFactory.getResourceClassOfType('Other');
expect(cls).to.equal(compareCls); expect(cls).to.equal(compareCls);
}); });
}; };
const expectAttributeClassAdded = () => { const expectAttributeClassAdded = () => {
it('should add the attribute type config to the storage', () => { it('should add the attribute type config to the storage', () => {
const cls = halResourceTypesStorage.getResourceClassOfAttribute('Other', 'attr'); const cls = halResourceFactory.getResourceClassOfAttribute('Other', 'attr');
expect(cls).to.equal(compareCls); expect(cls).to.equal(compareCls);
}); });
}; };
@ -72,7 +72,7 @@ describe('halResourceTypes service', () => {
}); });
it('should have added HalResource as the default type', () => { it('should have added HalResource as the default type', () => {
expect(halResourceTypesStorage.defaultClass).to.equal(HalResource); expect(halResourceFactory.defaultClass).to.equal(HalResource);
}); });
describe('when configuring the type with class and attributes', () => { describe('when configuring the type with class and attributes', () => {
@ -107,7 +107,7 @@ describe('halResourceTypes service', () => {
describe('when configuring the type with only the attribute types', () => { describe('when configuring the type with only the attribute types', () => {
beforeEach(() => { beforeEach(() => {
compareCls = halResourceTypesStorage.defaultClass; compareCls = halResourceFactory.defaultClass;
config = { config = {
Other: { Other: {
attr: 'Other' attr: 'Other'

@ -27,13 +27,13 @@
// ++ // ++
import {opApiModule} from '../../../../angular-modules'; import {opApiModule} from '../../../../angular-modules';
import {HalResourceTypesStorageService} from '../hal-resource-types-storage/hal-resource-types-storage.service'; import {HalResourceFactoryService} from '../hal-resource-factory/hal-resource-factory.service';
export class HalResourceTypesService { export class HalResourceTypesService {
constructor(protected $injector, constructor(protected $injector,
protected halResourceTypesStorage:HalResourceTypesStorageService, protected halResourceFactory:HalResourceFactoryService,
HalResource) { HalResource) {
halResourceTypesStorage.defaultClass = HalResource; halResourceFactory.defaultClass = HalResource;
} }
public setResourceTypeConfig(config) { public setResourceTypeConfig(config) {
@ -41,7 +41,7 @@ export class HalResourceTypesService {
const value = config[typeName]; const value = config[typeName];
const result = { const result = {
typeName: typeName, typeName: typeName,
className: value.className || this.getClassName(this.halResourceTypesStorage.defaultClass), className: value.className || this.getClassName(this.halResourceFactory.defaultClass),
attrTypes: value.attrTypes || {} attrTypes: value.attrTypes || {}
}; };
@ -57,13 +57,13 @@ export class HalResourceTypesService {
}); });
types.forEach(typeConfig => { types.forEach(typeConfig => {
this.halResourceTypesStorage this.halResourceFactory
.setResourceType(typeConfig.typeName, this.$injector.get(typeConfig.className)); .setResourceType(typeConfig.typeName, this.$injector.get(typeConfig.className));
}); });
types types
.forEach(typeConfig => { .forEach(typeConfig => {
this.halResourceTypesStorage.setResourceTypeAttributes(typeConfig.typeName, typeConfig.attrTypes); this.halResourceFactory.setResourceTypeAttributes(typeConfig.typeName, typeConfig.attrTypes);
}); });
} }

@ -28,11 +28,11 @@
import {opApiModule, opServicesModule} from '../../../../angular-modules'; import {opApiModule, opServicesModule} from '../../../../angular-modules';
import {HalResource} from './hal-resource.service'; import {HalResource} from './hal-resource.service';
import {HalResourceTypesStorageService} from '../hal-resource-types-storage/hal-resource-types-storage.service'; import {HalResourceFactoryService} from '../hal-resource-factory/hal-resource-factory.service';
describe('HalResource service', () => { describe('HalResource service', () => {
var $httpBackend:ng.IHttpBackendService; var $httpBackend:ng.IHttpBackendService;
var halResourceTypesStorage:HalResourceTypesStorageService; var halResourceFactory:HalResourceFactoryService;
var resource; var resource;
var source; var source;
@ -43,9 +43,9 @@ describe('HalResource service', () => {
$provide.value('OtherResource', OtherResource); $provide.value('OtherResource', OtherResource);
})); }));
beforeEach(angular.mock.inject(function (_$httpBackend_, beforeEach(angular.mock.inject(function (_$httpBackend_,
_halResourceTypesStorage_, _halResourceFactory_,
apiV3) { apiV3) {
[$httpBackend, halResourceTypesStorage] = _.toArray(arguments); [$httpBackend, halResourceFactory] = _.toArray(arguments);
apiV3.setDefaultHttpFields({cache: false}); apiV3.setDefaultHttpFields({cache: false});
})); }));
@ -54,7 +54,7 @@ describe('HalResource service', () => {
}); });
it('should be instantiable using a default object', () => { it('should be instantiable using a default object', () => {
expect(new HalResource().href).to.equal(null); expect(new HalResource().$href).to.equal(null);
}); });
it('should set its source to _plain if _plain is a property of the source', () => { it('should set its source to _plain if _plain is a property of the source', () => {
@ -87,8 +87,8 @@ describe('HalResource service', () => {
} }
}; };
halResourceTypesStorage.setResourceType('Other', OtherResource); halResourceFactory.setResourceType('Other', OtherResource);
halResourceTypesStorage.setResourceTypeAttributes('Other', { halResourceFactory.setResourceTypeAttributes('Other', {
someResource: 'Other' someResource: 'Other'
}); });

@ -28,20 +28,20 @@
import {opApiModule} from '../../../../angular-modules'; import {opApiModule} from '../../../../angular-modules';
import {HalLinkInterface} from '../hal-link/hal-link.service'; import {HalLinkInterface} from '../hal-link/hal-link.service';
import {HalResourceTypesStorageService} from '../hal-resource-types-storage/hal-resource-types-storage.service'; import {HalResourceFactoryService} from '../hal-resource-factory/hal-resource-factory.service';
const ObservableArray:any = require('observable-array'); const ObservableArray:any = require('observable-array');
var $q:ng.IQService; var $q:ng.IQService;
var lazy; var lazy;
var HalLink; var HalLink;
var halResourceTypesStorage:HalResourceTypesStorageService; var halResourceFactory:HalResourceFactoryService;
export class HalResource { export class HalResource {
public static _type:string; public static _type:string;
public static init(source:any) { public static init(source:any) {
const resourceClass = halResourceTypesStorage.getResourceClassOfType(source._type); const resourceClass = halResourceFactory.getResourceClassOfType(source._type);
return new resourceClass(source); return new resourceClass(source);
} }
@ -50,7 +50,7 @@ export class HalResource {
return element; return element;
} }
const resourceClass = halResourceTypesStorage.getResourceClassOfType(element._type); const resourceClass = halResourceFactory.getResourceClassOfType(element._type);
return new resourceClass(element); return new resourceClass(element);
} }
@ -274,7 +274,7 @@ function initializeResource(halResource:HalResource) {
var resource = HalResource.getEmptyResource(); var resource = HalResource.getEmptyResource();
resource._links.self = link; resource._links.self = link;
const resourceClass = halResourceTypesStorage const resourceClass = halResourceFactory
.getResourceClassOfAttribute(halResource.constructor._type, linkName); .getResourceClassOfAttribute(halResource.constructor._type, linkName);
return new resourceClass(resource, false); return new resourceClass(resource, false);
@ -297,7 +297,7 @@ function initializeResource(halResource:HalResource) {
} }
function halResourceService(...args) { function halResourceService(...args) {
[$q, lazy, HalLink, halResourceTypesStorage] = args; [$q, lazy, HalLink, halResourceFactory] = args;
return HalResource; return HalResource;
} }
@ -305,7 +305,7 @@ halResourceService.$inject = [
'$q', '$q',
'lazy', 'lazy',
'HalLink', 'HalLink',
'halResourceTypesStorage' 'halResourceFactory'
]; ];
opApiModule.factory('HalResource', halResourceService); opApiModule.factory('HalResource', halResourceService);

Loading…
Cancel
Save