diff --git a/src/app/core/shared/collection.model.ts b/src/app/core/shared/collection.model.ts index c1464d7d39..1505359cfd 100644 --- a/src/app/core/shared/collection.model.ts +++ b/src/app/core/shared/collection.model.ts @@ -1,4 +1,4 @@ -import { autoserialize, deserialize, inheritSerialization } from 'cerialize'; +import { autoserialize, deserialize, deserializeAs, inheritSerialization } from 'cerialize'; import { Observable } from 'rxjs'; import { link, typedObject } from '../cache/builders/build-decorators'; import { PaginatedList } from '../data/paginated-list'; @@ -15,17 +15,16 @@ import { RESOURCE_POLICY } from '../resource-policy/models/resource-policy.resou import { COMMUNITY } from './community.resource-type'; import { Community } from './community.model'; import { ChildHALResource } from './child-hal-resource.model'; +import { excludeFromEquals } from '../utilities/equals.decorators'; @typedObject @inheritSerialization(DSpaceObject) export class Collection extends DSpaceObject implements ChildHALResource { static type = COLLECTION; - /** - * A string representing the unique handle of this Collection - */ - @autoserialize - handle: string; + @excludeFromEquals + @deserializeAs('handle') + private _handle: string; /** * The {@link HALLink}s for this Collection @@ -75,6 +74,18 @@ export class Collection extends DSpaceObject implements ChildHALResource { @link(COMMUNITY, false) parentCommunity?: Observable>; + /** + * A string representing the unique handle of this Collection + */ + get handle(): string { + const metadataValue = this.firstMetadataValue('dc.identifier.uri'); + return metadataValue ? metadataValue : this._handle; + } + + set handle(value: string) { + this._handle = value; + } + /** * The introductory text of this Collection * Corresponds to the metadata field dc.description diff --git a/src/app/core/shared/community.model.ts b/src/app/core/shared/community.model.ts index 796aaa8ece..06f7b70c01 100644 --- a/src/app/core/shared/community.model.ts +++ b/src/app/core/shared/community.model.ts @@ -1,4 +1,4 @@ -import { autoserialize, deserialize, inheritSerialization } from 'cerialize'; +import { autoserialize, deserialize, deserializeAs, inheritSerialization } from 'cerialize'; import { Observable } from 'rxjs'; import { link, typedObject } from '../cache/builders/build-decorators'; import { PaginatedList } from '../data/paginated-list'; @@ -11,17 +11,16 @@ import { COMMUNITY } from './community.resource-type'; import { DSpaceObject } from './dspace-object.model'; import { HALLink } from './hal-link.model'; import { ChildHALResource } from './child-hal-resource.model'; +import { excludeFromEquals } from '../utilities/equals.decorators'; @typedObject @inheritSerialization(DSpaceObject) export class Community extends DSpaceObject implements ChildHALResource { static type = COMMUNITY; - /** - * A string representing the unique handle of this Community - */ - @autoserialize - handle: string; + @excludeFromEquals + @deserializeAs('handle') + private _handle: string; /** * The {@link HALLink}s for this Community @@ -64,6 +63,18 @@ export class Community extends DSpaceObject implements ChildHALResource { @link(COMMUNITY, false) parentCommunity?: Observable>; + /** + * A string representing the unique handle of this Community + */ + get handle(): string { + const metadataValue = this.firstMetadataValue('dc.identifier.uri'); + return metadataValue ? metadataValue : this._handle; + } + + set handle(value: string) { + this._handle = value; + } + /** * The introductory text of this Community * Corresponds to the metadata field dc.description diff --git a/src/app/shared/comcol-page-handle/comcol-page-handle.component.spec.ts b/src/app/shared/comcol-page-handle/comcol-page-handle.component.spec.ts new file mode 100644 index 0000000000..e059cb7044 --- /dev/null +++ b/src/app/shared/comcol-page-handle/comcol-page-handle.component.spec.ts @@ -0,0 +1,62 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { TranslateModule } from '@ngx-translate/core'; +import { By } from '@angular/platform-browser'; +import { UIURLCombiner } from 'src/app/core/url-combiner/ui-url-combiner'; +import { ComcolPageHandleComponent } from './comcol-page-handle.component'; + +const handleWithProtocol = 'http://localhost:4000/handle/123456789/2'; + +const handleWithoutProtocol = '123456789/2'; +const handleWithoutProtocolUIURLCombined = new UIURLCombiner('/handle/', '123456789/2').toString(); + +describe('ComcolPageHandleComponent', () => { + let component: ComcolPageHandleComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [TranslateModule.forRoot()], + declarations: [ ComcolPageHandleComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ComcolPageHandleComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should be empty if no content is passed', () => { + component.content = undefined; + fixture.detectChanges(); + const div = fixture.debugElement.query(By.css('div')); + expect(div).toBeNull(); + }); + + describe('should create a link pointing the handle', () => { + + it('should use the content if it includes the http protocol', () => { + component.content = handleWithProtocol; + fixture.detectChanges(); + + const link = fixture.debugElement.query(By.css('a')); + expect(link.nativeElement.getAttribute('href')).toBe(handleWithProtocol); + expect(link.nativeElement.innerHTML).toBe(handleWithProtocol); + }); + + it('should combine the base uri to the content if it doesnt include the http protocol', () => { + component.content = handleWithoutProtocol; + fixture.detectChanges(); + const link = fixture.debugElement.query(By.css('a')); + expect(link.nativeElement.getAttribute('href')).toBe(handleWithoutProtocolUIURLCombined); + expect(link.nativeElement.innerHTML).toBe(handleWithoutProtocolUIURLCombined); + }); + + }); + +}); \ No newline at end of file diff --git a/src/app/shared/comcol-page-handle/comcol-page-handle.component.ts b/src/app/shared/comcol-page-handle/comcol-page-handle.component.ts index bf403e9e88..bea3f51e28 100644 --- a/src/app/shared/comcol-page-handle/comcol-page-handle.component.ts +++ b/src/app/shared/comcol-page-handle/comcol-page-handle.component.ts @@ -21,6 +21,7 @@ export class ComcolPageHandleComponent { @Input() content: string; public getHandle(): string { - return new UIURLCombiner('/handle/', this.content).toString(); - } -} + return this.content.includes('http') ? this.content + : new UIURLCombiner('/handle/', this.content).toString(); + }} +