mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CSTPER-222] handle metadata reading for communities and collections
This commit is contained in:
@@ -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<RemoteData<Community>>;
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@@ -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<RemoteData<Community>>;
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@@ -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<ComcolPageHandleComponent>;
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@@ -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();
|
||||
}}
|
||||
|
||||
|
Reference in New Issue
Block a user