Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new Item Version (basic Items only) #1318

Merged
merged 51 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5b036e8
[CST-4499] Version history module (WIP)
alemarte Sep 2, 2021
a1e3124
[CST-4499] Version history (WIP) - Buttons added to history, form rep…
Sep 6, 2021
6f24b31
[CST-4499] Version history (WIP) - Removed summary page (with routing…
Sep 7, 2021
95ffc7a
[CST-4499] Version history (WIP) - Added in-row editing in version hi…
Sep 7, 2021
72bfab1
[CST-4499] Version history (WIP) - Changes to in-row editing, code cl…
Sep 8, 2021
d402ab7
[CST-4499] Version history (WIP) - New version modal and other changes
Sep 8, 2021
05385f3
[CST-4499] Version history (WIP) - Fixes to API calls
Sep 10, 2021
dd2df91
[CST-4499] Version history (WIP) - Fixes to API calls
Sep 10, 2021
ad5ace7
Changes by alex
Sep 10, 2021
44d3558
[CST-4499] Version history (WIP) - 'Create version' button in item pa…
Sep 10, 2021
ce399cb
[CST-4499] Version history (WIP) - Missing tests and auth features
alemarte Sep 2, 2021
b4111fe
[CST-4499] Version history (WIP) - Version page added (redirecting to…
Sep 13, 2021
f10f25d
Merge remote-tracking branch 'bb/CST-4499' into CST-4499
Sep 13, 2021
5d8f625
[CST-4499] Version history (WIP) - Refactoring
Sep 13, 2021
60bbb9a
[CST-4499] Version history (WIP) - Redirect after deleting a version
Sep 14, 2021
77ff774
[CST-4499] Version history (WIP) - Minor fixes and code cleanup
Sep 14, 2021
f858eee
[CST-4499] Version history (WIP) - Authorization features - Deleting …
Sep 15, 2021
cf1c73b
[CST-4499] Version history (WIP) - Authorization features - Deleting
Sep 16, 2021
b1b2bd4
[CST-4499] Version history (WIP) - Authorization features - Cache iss…
Sep 16, 2021
025e7f5
[CST-4499] Version history (WIP) - Cache issue fixed
Sep 17, 2021
55a1a1c
[CST-4499] Version history (WIP) - Refactoring
Sep 17, 2021
97ed08e
[CST-4499] Version history - Test TBD
Sep 17, 2021
a547030
[CST-4499] Version history - LGTM fixes - Test TBD
Sep 17, 2021
fbc6983
[CST-4499] Version history - Tests WIP
Sep 20, 2021
3255a29
[CST-4499] Version history - Tests WIP
Sep 20, 2021
62fea1f
[CST-4499] Version history - Tests WIP
Sep 21, 2021
aee612e
[CST-4499] Version history - Old tests fixed
Sep 21, 2021
468ad70
[CST-4499] Version history - Old tests fixed
Sep 21, 2021
c816b97
[CST-4499] Version history - Old tests fixed
Sep 21, 2021
f60755b
[CST-4499] Version history - New version refactored - Test TBD
Sep 24, 2021
4f2697b
[CST-4499] Version history - New version refactored (with tests)
Sep 27, 2021
ca9ca01
[CST-4499] Version history - Redirect to Edit Item
Sep 29, 2021
8a38d06
[CST-4499] Version history - Fixes and tests
Sep 29, 2021
e111f7c
[CST-4499] Version history - Minor fixes
Sep 29, 2021
b7d6c8e
[CST-4499] Version history - SSR bug fixed
Oct 4, 2021
850970e
[CST-4499] Version history - Code refactoring (WIP) and "Edit workspa…
Oct 15, 2021
e4d468b
[CST-4499] Version history - Changes to version history table
Oct 15, 2021
dfeee78
Merge branch 'main' into CST-4499
Oct 15, 2021
7c40c3b
[CST-4499] Version history - Pagination fixed
Oct 18, 2021
bee6289
[CST-4499] Version history - Test
Oct 18, 2021
8f541c3
[CST-4499] Add tests to workspaceitem-data.service and workflowitem-d…
atarix83 Oct 18, 2021
e142a49
[CST-4499] Add tests to version-data.service
atarix83 Oct 18, 2021
376d803
[CST-4499] Version history - Test item-data.service and item-versions…
Oct 19, 2021
6dac829
Merge branch 'main' of github.com:4science/dspace-angular into CST-4499
Oct 19, 2021
3cc302b
[CST-4499] Version history - Test version-history-data.service
Oct 19, 2021
82f6a78
Merge branch 'main' into CST-4499
Oct 19, 2021
75fffe2
[CST-4499] Version history - Test version-history-data.service
Oct 19, 2021
d12f932
[CST-4499] Version history - Test version-history-data.service
Oct 19, 2021
52baa81
[CST-4499] Version history - Test versioned-item.component
Oct 19, 2021
3b0e1db
[CST-4499] Version history - Test item-versions.component
Oct 20, 2021
fd61ac0
[CST-4499] Version history - Test item-versions.component
Oct 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/core/data/feature-authorization/feature-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ export enum FeatureID {
CanManagePolicies = 'canManagePolicies',
CanMakePrivate = 'canMakePrivate',
CanMove = 'canMove',
CanEditVersion = 'canEditVersion',
CanDeleteVersion = 'canDeleteVersion',
CanCreateVersion = 'canCreateVersion',
}
12 changes: 11 additions & 1 deletion src/app/core/data/item-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ItemDataService', () => {
},
removeByHrefSubstring(href: string) {
// Do nothing
}
},
}) as RequestService;
const rdbService = getMockRemoteDataBuildService();

Expand Down Expand Up @@ -184,4 +184,14 @@ describe('ItemDataService', () => {
});
});

describe('when cache is invalidated', () => {
beforeEach(() => {
service = initTestService();
});
it('should call setStaleByHrefSubstring', () => {
service.invalidateItemCache('uuid');
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith('item/uuid');
});
});

});
10 changes: 10 additions & 0 deletions src/app/core/data/item-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class ItemDataService extends DataService<Item> {
* Get the endpoint for browsing items
* (When options.sort.field is empty, the default field to browse by will be 'dc.date.issued')
* @param {FindListOptions} options
* @param linkPath
* @returns {Observable<string>}
*/
public getBrowseEndpoint(options: FindListOptions = {}, linkPath: string = this.linkPath): Observable<string> {
Expand Down Expand Up @@ -287,4 +288,13 @@ export class ItemDataService extends DataService<Item> {
switchMap((url: string) => this.halService.getEndpoint('bitstreams', `${url}/${itemId}`))
);
}

/**
* Invalidate the cache of the item
* @param itemUUID
*/
invalidateItemCache(itemUUID: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New method missing specs

this.requestService.setStaleByHrefSubstring('item/' + itemUUID);
}

}
181 changes: 181 additions & 0 deletions src/app/core/data/version-data.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import { HttpClient } from '@angular/common/http';
import { of as observableOf } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';

import { NotificationsService } from '../../shared/notifications/notifications.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RequestService } from './request.service';
import { PageInfo } from '../shared/page-info.model';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { RequestEntry } from './request.reducer';
import { HrefOnlyDataService } from './href-only-data.service';
import { getMockHrefOnlyDataService } from '../../shared/mocks/href-only-data.service.mock';

import { Store } from '@ngrx/store';
import { CoreState } from '../core.reducers';
import { RestResponse } from '../cache/response.models';
import { cold, getTestScheduler, hot } from 'jasmine-marbles';
import { Item } from '../shared/item.model';
import { VersionDataService } from './version-data.service';
import { Version } from '../shared/version.model';
import { VersionHistory } from '../shared/version-history.model';
import { followLink } from '../../shared/utils/follow-link-config.model';


describe('VersionDataService test', () => {
let scheduler: TestScheduler;
let service: VersionDataService;
let requestService: RequestService;
let rdbService: RemoteDataBuildService;
let objectCache: ObjectCacheService;
let halService: HALEndpointService;
let hrefOnlyDataService: HrefOnlyDataService;
let responseCacheEntry: RequestEntry;

const item = Object.assign(new Item(), {
id: '1234-1234',
uuid: '1234-1234',
bundles: observableOf({}),
metadata: {
'dc.title': [
{
language: 'en_US',
value: 'This is just another title'
}
],
'dc.type': [
{
language: null,
value: 'Article'
}
],
'dc.contributor.author': [
{
language: 'en_US',
value: 'Smith, Donald'
}
],
'dc.date.issued': [
{
language: null,
value: '2015-06-26'
}
]
}
});
const itemRD = createSuccessfulRemoteDataObject(item);

const versionHistory = Object.assign(new VersionHistory(), {
id: '1',
draftVersion: true,
});

const mockVersion: Version = Object.assign(new Version(), {
item: createSuccessfulRemoteDataObject$(item),
versionhistory: createSuccessfulRemoteDataObject$(versionHistory),
version: 1,
});
const mockVersionRD = createSuccessfulRemoteDataObject(mockVersion);

const endpointURL = `https://rest.api/rest/api/versioning/versions`;
const findByIdRequestURL = `https://rest.api/rest/api/versioning/versions/${mockVersion.id}`;
const findByIdRequestURL$ = observableOf(findByIdRequestURL);

const requestUUID = '8b3c613a-5a4b-438b-9686-be1d5b4a1c5a';

objectCache = {} as ObjectCacheService;
const notificationsService = {} as NotificationsService;
const http = {} as HttpClient;
const comparator = {} as any;
const comparatorEntry = {} as any;
const store = {} as Store<CoreState>;
const pageInfo = new PageInfo();

function initTestService() {
hrefOnlyDataService = getMockHrefOnlyDataService();
return new VersionDataService(
requestService,
rdbService,
store,
objectCache,
halService,
notificationsService,
http,
comparatorEntry
);
}

describe('', () => {
beforeEach(() => {

scheduler = getTestScheduler();

halService = jasmine.createSpyObj('halService', {
getEndpoint: cold('a', { a: endpointURL })
});
responseCacheEntry = new RequestEntry();
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
responseCacheEntry.response = new RestResponse(true, 200, 'Success');

requestService = jasmine.createSpyObj('requestService', {
generateRequestId: requestUUID,
send: true,
removeByHrefSubstring: {},
getByHref: observableOf(responseCacheEntry),
getByUUID: observableOf(responseCacheEntry),
});
rdbService = jasmine.createSpyObj('rdbService', {
buildSingle: hot('(a|)', {
a: mockVersionRD
})
});

service = initTestService();

spyOn((service as any), 'findByHref').and.callThrough();
spyOn((service as any), 'getIDHrefObs').and.returnValue(findByIdRequestURL$);
});

afterEach(() => {
service = null;
});

describe('getHistoryFromVersion', () => {
it('should proxy the call to DataService.findByHref', () => {
scheduler.schedule(() => service.getHistoryFromVersion(mockVersion, true, true));
scheduler.flush();

expect((service as any).findByHref).toHaveBeenCalledWith(findByIdRequestURL$, true, true, followLink('versionhistory'));
});

it('should return a VersionHistory', () => {
const result = service.getHistoryFromVersion(mockVersion, true, true);
const expected = cold('(a|)', {
a: versionHistory
});
expect(result).toBeObservable(expected);
});

it('should return an EMPTY observable when version is not given', () => {
const result = service.getHistoryFromVersion(null);
const expected = cold('|');
expect(result).toBeObservable(expected);
});
});

describe('getHistoryIdFromVersion', () => {
it('should return the version history id', () => {
spyOn((service as any), 'getHistoryFromVersion').and.returnValue(observableOf(versionHistory));

const result = service.getHistoryIdFromVersion(mockVersion);
const expected = cold('(a|)', {
a: versionHistory.id
});
expect(result).toBeObservable(expected);
});
});
});

});
34 changes: 29 additions & 5 deletions src/app/core/data/version-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { HttpClient } from '@angular/common/http';
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
import { FindListOptions } from './request.models';
import { Observable } from 'rxjs';
import { EMPTY, Observable } from 'rxjs';
import { dataService } from '../cache/builders/build-decorators';
import { VERSION } from '../shared/version.resource-type';
import { VersionHistory } from '../shared/version-history.model';
import { followLink } from '../../shared/utils/follow-link-config.model';
import { getFirstSucceededRemoteDataPayload } from '../shared/operators';
import { map, switchMap } from 'rxjs/operators';
import { isNotEmpty } from '../../shared/empty.util';

/**
* Service responsible for handling requests related to the Version object
Expand All @@ -36,9 +40,29 @@ export class VersionDataService extends DataService<Version> {
}

/**
* Get the endpoint for browsing versions
* Get the version history for the given version
* @param version
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* no valid cached version. Defaults to true
* @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
*/
getBrowseEndpoint(options: FindListOptions = {}, linkPath?: string): Observable<string> {
return this.halService.getEndpoint(this.linkPath);
getHistoryFromVersion(version: Version, useCachedVersionIfAvailable = false, reRequestOnStale = true): Observable<VersionHistory> {
return isNotEmpty(version) ? this.findById(version.id, useCachedVersionIfAvailable, reRequestOnStale, followLink('versionhistory')).pipe(
getFirstSucceededRemoteDataPayload(),
switchMap((res: Version) => res.versionhistory),
getFirstSucceededRemoteDataPayload(),
) : EMPTY;
}

/**
* Get the ID of the version history for the given version
* @param version
*/
getHistoryIdFromVersion(version: Version): Observable<string> {
return this.getHistoryFromVersion(version).pipe(
map((versionHistory: VersionHistory) => versionHistory.id),
);
}

}
Loading