forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathitem-export.service.ts
More file actions
118 lines (107 loc) · 3.78 KB
/
Copy pathitem-export.service.ts
File metadata and controls
118 lines (107 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { Injectable } from '@angular/core';
import { map, take } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { ItemExportFormat } from '../../../core/itemexportformat/model/item-export-format.model';
import { Item } from '../../../core/shared/item.model';
import { isEmpty } from '../../empty.util';
import {
ItemExportFormatMolteplicity,
ItemExportFormatService
} from '../../../core/itemexportformat/item-export-format.service';
import { SearchOptions } from '../models/search-options.model';
export interface ItemExportFormConfiguration {
entityType: string;
format: ItemExportFormat;
entityTypes: string[];
formats: ItemExportFormat[];
}
@Injectable({
providedIn: 'root'
})
export class ItemExportService {
constructor(private itemExportFormatService: ItemExportFormatService) {
}
/**
* Initialize the item export form configuration.
* @param molteplicity
* @param item
*/
public initialItemExportFormConfiguration(item: Item): Observable<ItemExportFormConfiguration> {
if (item) {
return this.initialItemExportFormConfigurationSingle(item);
}
return this.initialItemExportFormConfigurationMultiple();
}
/**
* A new item export form configuration when a specific entityType is selected.
* @param entityTypes
* @param entityType
*/
public onSelectEntityType(entityTypes: string[], entityType): Observable<ItemExportFormConfiguration> {
return this.itemExportFormatService.byEntityTypeAndMolteplicity(entityType, ItemExportFormatMolteplicity.MULTIPLE).pipe(
take(1),
map(values => this.buildConfiguration(entityTypes, entityType, values[entityType]))
);
}
/**
* Perform the export operation.
* @param molteplicity
* @param item
* @param searchOptions
* @param entityType
* @param format
* @param itemList
*/
public submitForm(
molteplicity: ItemExportFormatMolteplicity,
item: Item,
searchOptions: SearchOptions,
entityType: string,
format: ItemExportFormat,
itemList: string[] = []
): Observable<number> {
if (molteplicity === ItemExportFormatMolteplicity.SINGLE) {
return this.itemExportFormatService.doExport(item.uuid, format);
} else {
return this.itemExportFormatService.doExportMulti(entityType, format, searchOptions, itemList);
}
}
protected initialItemExportFormConfigurationSingle(item: Item): Observable<ItemExportFormConfiguration> {
const entityType = item.firstMetadataValue('dspace.entity.type');
if (isEmpty(entityType)) {
throw Error('cannot get item entityType');
}
return this.itemExportFormatService.byEntityTypeAndMolteplicity(entityType, ItemExportFormatMolteplicity.SINGLE).pipe(
take(1),
map(values => this.buildConfiguration(null, entityType, values[entityType]))
);
}
protected initialItemExportFormConfigurationMultiple(): Observable<ItemExportFormConfiguration> {
return this.itemExportFormatService.byEntityTypeAndMolteplicity(null, ItemExportFormatMolteplicity.MULTIPLE).pipe(
take(1),
map(values => this.buildConfiguration(Object.keys(values), null, []))
);
}
protected buildConfiguration(entityTypes: string[], entityType: string, formats: ItemExportFormat[]): ItemExportFormConfiguration {
const _formats = formats ? formats : [];
return {
entityType,
format: _formats.length > 0 ? _formats[0] : null,
entityTypes: entityTypes,
formats: _formats
};
}
/**
* Get the UUID from a searchOptions
* @param searchOptions
*/
public getScopeUUID(searchOptions: SearchOptions): string {
if (searchOptions.fixedFilter) {
const fixedFilter = searchOptions.fixedFilter.split('=');
if (fixedFilter.length === 2 && fixedFilter[0] === 'scope') {
return fixedFilter[1];
}
}
return null;
}
}