Skip to content

Commit 1abb169

Browse files
[DURACOM-501] add export item menu and functionalities, add dso-public menu to items
1 parent 0000da2 commit 1abb169

66 files changed

Lines changed: 2999 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/app.menus.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { EditCMSMetadataMenuProvider } from './shared/menu/providers/edit-cms-me
2626
import { EditItemMenuProvider } from './shared/menu/providers/edit-item-details.menu';
2727
import { EditUserAgreementMenuProvider } from './shared/menu/providers/edit-user-agreement.menu';
2828
import { ExportMenuProvider } from './shared/menu/providers/export.menu';
29+
import { ExportItemMenuProvider } from './shared/menu/providers/export-item.menu';
2930
import { HealthMenuProvider } from './shared/menu/providers/health.menu';
3031
import { ImportMenuProvider } from './shared/menu/providers/import.menu';
3132
import { ClaimMenuProvider } from './shared/menu/providers/item-claim.menu';
@@ -120,5 +121,8 @@ export const MENUS = buildMenuStructure({
120121
]),
121122
],
122123
[MenuID.DSO_PUBLIC]: [
124+
ExportItemMenuProvider.onRoute(
125+
MenuRoute.ITEM_PAGE,
126+
),
123127
],
124128
});

src/app/core/data/collection-data.service.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,55 @@ export class CollectionDataService extends ComColDataService<Collection> {
151151
);
152152
}
153153

154+
/**
155+
* Get all collections the user is admin
156+
*
157+
* @param query limit the returned collection to those with metadata values matching the query terms.
158+
* @param options The [[FindListOptions]] object
159+
* @param reRequestOnStale Whether or not the request should automatically be re-requested after
160+
* the response becomes stale
161+
* @param linksToFollow The array of [[FollowLinkConfig]]
162+
* @return Observable<RemoteData<PaginatedList<Collection>>>
163+
* collection list
164+
*/
165+
getAdministeredCollection(query: string, options: FindListOptions = {}, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
166+
const searchHref = 'findAdministered';
167+
options = Object.assign({}, options, {
168+
searchParams: [new RequestParam('query', query)],
169+
});
170+
171+
return this.searchBy(searchHref, options, true, reRequestOnStale, ...linksToFollow).pipe(
172+
getAllCompletedRemoteData(),
173+
);
174+
}
175+
176+
/**
177+
* Get all collections the user is admin selected by entityType
178+
*
179+
* @param query limit the returned collection to those with metadata values matching the query terms.
180+
* @param entityType mandatory, the label of the entity type field the collection must have.
181+
* @param options The [[FindListOptions]] object
182+
* @param reRequestOnStale Whether or not the request should automatically be re-requested after
183+
* the response becomes stale
184+
* @param linksToFollow The array of [[FollowLinkConfig]]
185+
* @return Observable<RemoteData<PaginatedList<Collection>>>
186+
* collection list
187+
*/
188+
getAdministeredCollectionByEntityType(query: string, entityType: string, options: FindListOptions = {}, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Collection>[]): Observable<RemoteData<PaginatedList<Collection>>> {
189+
190+
const searchHref = 'findAdminAuthorizedByEntityType';
191+
options = Object.assign({}, options, {
192+
searchParams: [
193+
new RequestParam('query', query),
194+
new RequestParam('entityType', entityType),
195+
],
196+
});
197+
198+
return this.searchBy(searchHref, options, true, reRequestOnStale, ...linksToFollow).pipe(
199+
getAllCompletedRemoteData(),
200+
);
201+
}
202+
154203
/**
155204
* Get all collections the user is authorized to submit to
156205
*
@@ -251,8 +300,8 @@ export class CollectionDataService extends ComColDataService<Collection> {
251300
options.elementsPerPage = 1;
252301

253302
return this.searchBy(searchHref, options).pipe(
254-
getFirstCompletedRemoteData(),
255-
map((collections: RemoteData<PaginatedList<Collection>>) => collections?.payload?.totalElements > 0),
303+
getAllCompletedRemoteData(),
304+
map((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.totalElements > 0),
256305
);
257306
}
258307

src/app/core/data/processes/script-data.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export const METADATA_EXPORT_SCRIPT_NAME = 'metadata-export';
3232
export const BATCH_IMPORT_SCRIPT_NAME = 'import';
3333
export const BATCH_EXPORT_SCRIPT_NAME = 'export';
3434
export const DSPACE_OBJECT_DELETION_SCRIPT_NAME = 'object-deletion';
35+
export const ITEM_EXPORT_SCRIPT_NAME = 'item-export';
36+
export const BULK_ITEM_EXPORT_SCRIPT_NAME = 'bulk-item-export';
3537

3638
@Injectable({ providedIn: 'root' })
3739
export class ScriptDataService extends IdentifiableDataService<Script> implements FindAllData<Script> {
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
import { EventEmitter } from '@angular/core';
2+
import { TranslateService } from '@ngx-translate/core';
3+
import { of } from 'rxjs';
4+
5+
import { RequestParam } from '../cache/models/request-param.model';
6+
import {
7+
SortDirection,
8+
SortOptions,
9+
} from '../cache/models/sort-options.model';
10+
import { PaginatedList } from '../data/paginated-list.model';
11+
import {
12+
BULK_ITEM_EXPORT_SCRIPT_NAME,
13+
ITEM_EXPORT_SCRIPT_NAME,
14+
ScriptDataService,
15+
} from '../data/processes/script-data.service';
16+
import { NotificationsService } from '../notification-system/notifications.service';
17+
import { Process } from '../processes/process.model';
18+
import { ProcessParameter } from '../processes/process-parameter.model';
19+
import { PaginatedSearchOptions } from '../shared/search/models/paginated-search-options.model';
20+
import { SearchFilter } from '../shared/search/models/search-filter.model';
21+
import { NotificationsServiceStub } from '../testing/notifications-service.stub';
22+
import { createPaginatedList } from '../testing/utils.test';
23+
import { createSuccessfulRemoteDataObject$ } from '../utilities/remote-data.utils';
24+
import {
25+
ItemExportFormatMolteplicity,
26+
ItemExportFormatService,
27+
} from './item-export-format.service';
28+
import { ItemExportFormat } from './model/item-export-format.model';
29+
import createSpyObj = jasmine.createSpyObj;
30+
31+
const ItemExportFormatsMap = {
32+
Publication: [
33+
Object.assign(new ItemExportFormat(), { id: 'publication-xml', entityType: 'Publication', molteplicity: 'MULTIPLE' }),
34+
Object.assign(new ItemExportFormat(), { id: 'publication-csv', entityType: 'Publication', molteplicity: 'MULTIPLE' }),
35+
],
36+
Project: [
37+
Object.assign(new ItemExportFormat(), { id: 'project-xml', entityType: 'Project', molteplicity: 'MULTIPLE' }),
38+
],
39+
};
40+
41+
describe('ItemExportFormatService', () => {
42+
43+
let service: ItemExportFormatService;
44+
const notificationsService: NotificationsService = new NotificationsServiceStub() as any;
45+
const translateService: TranslateService = {
46+
get: () => of('test-message'),
47+
onLangChange: new EventEmitter(),
48+
onTranslationChange: new EventEmitter(),
49+
onDefaultLangChange: new EventEmitter(),
50+
} as any;
51+
let scriptDataService: ScriptDataService;
52+
const TheProcess = Object.assign(new Process(), {
53+
processId: 1234,
54+
resourceSelfLinks: ['process/1234'],
55+
});
56+
57+
beforeEach(() => {
58+
scriptDataService = createSpyObj('scriptDataService', ['invoke']);
59+
service = new ItemExportFormatService(
60+
null,
61+
null,
62+
null,
63+
null,
64+
notificationsService,
65+
null,
66+
null,
67+
translateService,
68+
scriptDataService);
69+
});
70+
71+
describe('byEntityTypeAndMolteplicity', () => {
72+
73+
beforeEach(() => {
74+
const searchResult: any = [...ItemExportFormatsMap.Publication, ...ItemExportFormatsMap.Project];
75+
const paginatedList: PaginatedList<ItemExportFormat> = createPaginatedList(searchResult);
76+
spyOn((service as any).searchData, 'searchBy').and.returnValue(createSuccessfulRemoteDataObject$(paginatedList));
77+
});
78+
79+
it('should configure and call dataService.searchBy and map results by entityType', (done) => {
80+
const entityTypeId = 'Publication';
81+
const molteplicity = ItemExportFormatMolteplicity.MULTIPLE;
82+
83+
const searchParams = [
84+
new RequestParam('molteplicity', molteplicity),
85+
new RequestParam('entityTypeId', entityTypeId),
86+
];
87+
88+
service.byEntityTypeAndMolteplicity(entityTypeId, molteplicity).subscribe((result) => {
89+
expect((service as any).searchData.searchBy).toHaveBeenCalledWith('byEntityTypeAndMolteplicity', { searchParams, elementsPerPage: 100 });
90+
expect(result).toEqual(ItemExportFormatsMap);
91+
done();
92+
});
93+
94+
expect(service).toBeTruthy();
95+
});
96+
97+
});
98+
99+
describe('doExport', () => {
100+
101+
beforeEach(() => {
102+
(scriptDataService as any).invoke.and.returnValue(createSuccessfulRemoteDataObject$(TheProcess));
103+
});
104+
105+
it('should invoke a configured single item export', (done) => {
106+
const format = Object.assign(new ItemExportFormat(), { id: 'publication-xml' });
107+
const uuid = 'itemUUID';
108+
const expectedParameters = [
109+
Object.assign(new ProcessParameter(), { name: '-i', value: 'itemUUID' }),
110+
Object.assign(new ProcessParameter(), { name: '-f', value: 'publication-xml' }),
111+
];
112+
service.doExport(uuid, format).subscribe((result) => {
113+
expect(result).toEqual(1234);
114+
expect((service as any).scriptDataService.invoke).toHaveBeenCalledWith(ITEM_EXPORT_SCRIPT_NAME, expectedParameters, []);
115+
done();
116+
});
117+
118+
});
119+
120+
});
121+
122+
describe('doExportMulti', () => {
123+
124+
beforeEach(() => {
125+
(scriptDataService as any).invoke.and.returnValue(createSuccessfulRemoteDataObject$(TheProcess));
126+
});
127+
128+
it('should invoke a configured bulk item export', (done) => {
129+
const entityType = 'Publication';
130+
const format = Object.assign(new ItemExportFormat(), { id: 'publication-xml' });
131+
const searchOptions = new PaginatedSearchOptions({
132+
query: 'queryX',
133+
filters: [
134+
new SearchFilter('f.name', ['nameX', 'nameY']),
135+
new SearchFilter('f.type', ['typeX']),
136+
new SearchFilter('other.name', ['nameY']),
137+
],
138+
fixedFilter: 'scope=scopeX',
139+
configuration: 'configurationX',
140+
sort: new SortOptions('fieldX', SortDirection.ASC),
141+
});
142+
143+
const expectedParameters = [
144+
Object.assign(new ProcessParameter(), { name: '-f', value: 'publication-xml' }),
145+
Object.assign(new ProcessParameter(), { name: '-t', value: 'Publication' }),
146+
Object.assign(new ProcessParameter(), { name: '-q', value: 'queryX' }),
147+
Object.assign(new ProcessParameter(), { name: '-sf', value: 'name=nameX&name=nameY&type=typeX' }),
148+
Object.assign(new ProcessParameter(), { name: '-s', value: 'scopeX' }),
149+
Object.assign(new ProcessParameter(), { name: '-c', value: 'configurationX' }),
150+
Object.assign(new ProcessParameter(), { name: '-so', value: 'fieldX,ASC' }),
151+
];
152+
153+
service.doExportMulti(entityType, format, searchOptions).subscribe((result) => {
154+
expect(result).toEqual(1234);
155+
expect((service as any).scriptDataService.invoke).toHaveBeenCalledWith(BULK_ITEM_EXPORT_SCRIPT_NAME, expectedParameters, []);
156+
done();
157+
});
158+
159+
});
160+
161+
it('should invoke a configured bulk item export with a list', (done) => {
162+
const entityType = 'Publication';
163+
const format = Object.assign(new ItemExportFormat(), { id: 'publication-xml' });
164+
const searchOptions = new PaginatedSearchOptions({
165+
query: 'queryX',
166+
filters: [
167+
new SearchFilter('f.name', ['nameX']),
168+
new SearchFilter('f.type', ['typeX']),
169+
new SearchFilter('other.name', ['nameY']),
170+
],
171+
fixedFilter: 'scope=scopeX',
172+
configuration: 'configurationX',
173+
sort: new SortOptions('fieldX', SortDirection.ASC),
174+
});
175+
176+
const expectedParameters = [
177+
Object.assign(new ProcessParameter(), { name: '-f', value: 'publication-xml' }),
178+
Object.assign(new ProcessParameter(), { name: '-si', value: 'item1;item2' }),
179+
];
180+
181+
service.doExportMulti(entityType, format, searchOptions, ['item1', 'item2']).subscribe((result) => {
182+
expect(result).toEqual(1234);
183+
expect((service as any).scriptDataService.invoke).toHaveBeenCalledWith(BULK_ITEM_EXPORT_SCRIPT_NAME, expectedParameters, []);
184+
done();
185+
});
186+
187+
});
188+
189+
});
190+
191+
});

0 commit comments

Comments
 (0)