@@ -17,10 +17,13 @@ import { isNullOrUndef } from 'chart.js/helpers';
17
17
import { HALEndpointService } from '../core/shared/hal-endpoint.service' ;
18
18
import { RemoteDataBuildService } from '../core/cache/builders/remote-data-build.service' ;
19
19
import { RequestService } from '../core/data/request.service' ;
20
- import { PostRequest } from '../core/data/request.models' ;
20
+ import { GetRequest } from '../core/data/request.models' ;
21
21
import { RemoteData } from '../core/data/remote-data' ;
22
22
import { NotificationsService } from '../shared/notifications/notifications.service' ;
23
23
import { TranslateService } from '@ngx-translate/core' ;
24
+ import { HttpHeaders } from '@angular/common/http' ;
25
+ import { HttpOptions } from '../core/dspace-rest/dspace-rest.service' ;
26
+ import { Item } from '../core/shared/item.model' ;
24
27
25
28
@Component ( {
26
29
selector : 'ds-change-submitter-page' ,
@@ -34,11 +37,22 @@ export class ChangeSubmitterPageComponent implements OnInit {
34
37
*/
35
38
private shareToken = '' ;
36
39
40
+ /**
41
+ * WorkspaceItem id from the url.
42
+ * This id is used to get authorization rights to call REST API to change the submitter.
43
+ */
44
+ private workspaceitemid = '' ;
45
+
37
46
/**
38
47
* BehaviorSubject that contains the submitter of the WorkspaceItem.
39
48
*/
40
49
submitter : BehaviorSubject < EPerson > = new BehaviorSubject ( null ) ;
41
50
51
+ /**
52
+ * BehaviorSubject that contains the Item.
53
+ */
54
+ item : BehaviorSubject < Item > = new BehaviorSubject ( null ) ;
55
+
42
56
/**
43
57
* BehaviorSubject that contains the WorkspaceItem.
44
58
*/
@@ -61,6 +75,8 @@ export class ChangeSubmitterPageComponent implements OnInit {
61
75
ngOnInit ( ) : void {
62
76
// Load `share_token` param value from the url
63
77
this . shareToken = this . route . snapshot . queryParams . share_token ;
78
+ // Load `workspaceitem_id` param value from the url
79
+ this . workspaceitemid = this . route . snapshot . queryParams . workspaceitemid ;
64
80
this . loadWorkspaceItemAndAssignSubmitter ( this . shareToken ) ;
65
81
}
66
82
@@ -70,17 +86,36 @@ export class ChangeSubmitterPageComponent implements OnInit {
70
86
loadWorkspaceItemAndAssignSubmitter ( shareToken : string ) {
71
87
this . findWorkspaceItemByShareToken ( shareToken ) ?. subscribe ( ( workspaceItem : WorkspaceItem ) => {
72
88
this . workspaceItem . next ( workspaceItem ) ;
89
+ this . loadItemFromWorkspaceItem ( workspaceItem ) ;
73
90
this . loadAndAssignSubmitter ( workspaceItem ) ;
74
91
} ) ;
75
92
}
76
93
94
+ /**
95
+ * Load the Item from the WorkspaceItem and assign it to the item BehaviorSubject.
96
+ */
97
+ loadItemFromWorkspaceItem ( workspaceItem : WorkspaceItem ) {
98
+ if ( workspaceItem . item instanceof Observable < Item > ) {
99
+ workspaceItem . item
100
+ . pipe ( getFirstSucceededRemoteDataPayload ( ) )
101
+ . subscribe ( ( item : Item ) => {
102
+ this . item . next ( item ) ;
103
+ } ) ;
104
+ }
105
+ }
106
+
77
107
/**
78
108
* Find a WorkspaceItem by its shareToken.
79
109
*/
80
110
findWorkspaceItemByShareToken ( shareToken : string ) : Observable < WorkspaceItem > {
111
+ let requestHeaders = new HttpHeaders ( ) ;
112
+ const requestOptions : HttpOptions = Object . create ( { } ) ;
113
+ requestHeaders = requestHeaders . append ( 'shareToken' , shareToken ) ;
114
+ requestOptions . headers = requestHeaders ;
115
+
81
116
return this . workspaceItemService . searchBy ( 'shareToken' , {
82
117
searchParams : [ Object . assign ( new RequestParam ( 'shareToken' , shareToken ) ) ]
83
- } , false , false , followLink ( 'submitter' ) ) . pipe ( getFirstSucceededRemoteListPayload ( ) ,
118
+ } , false , false , followLink ( 'item' ) , followLink ( ' submitter') ) . pipe ( getFirstSucceededRemoteListPayload ( ) ,
84
119
map ( ( workspaceItems : WorkspaceItem [ ] ) => workspaceItems ?. [ 0 ] ) ) ;
85
120
}
86
121
@@ -112,27 +147,28 @@ export class ChangeSubmitterPageComponent implements OnInit {
112
147
}
113
148
114
149
/**
115
- * Get the name of the submitter using the DSONameService.
116
- * @param submitter
150
+ * Get the name of the submitter or item using the DSONameService.
117
151
*/
118
- getSubmitterName ( submitter : EPerson ) : string {
119
- if ( isNullOrUndef ( submitter ) ) {
152
+ getName ( object : EPerson | Item ) {
153
+ if ( isNullOrUndef ( object ) ) {
120
154
return '' ;
121
155
}
122
- return this . dsoNameService . getName ( submitter ) ;
156
+ return this . dsoNameService . getName ( object ) ;
123
157
}
124
158
125
159
/**
126
- * Change the submitter of the WorkspaceItem using the shareToken. This will send a POST request to the backend when
160
+ * Change the submitter of the WorkspaceItem using the shareToken. This will send a GET request to the backend when
127
161
* the submitter of the Item is changed.
128
162
*/
129
163
changeSubmitter ( ) {
130
164
const requestId = this . requestService . generateRequestId ( ) ;
131
165
132
- const url = this . halService . getRootHref ( ) + '/submission/setOwner?shareToken=' + this . shareToken ;
133
- const postRequest = new PostRequest ( requestId , url ) ;
134
- // Send POST request
135
- this . requestService . send ( postRequest ) ;
166
+ const url = this . halService . getRootHref ( ) + '/submission/setOwner?shareToken=' + this . shareToken +
167
+ '&workspaceitemid=' + this . workspaceitemid ;
168
+
169
+ const getRequest = new GetRequest ( requestId , url ) ;
170
+ // Send GET request
171
+ this . requestService . send ( getRequest ) ;
136
172
this . changeSubmitterSpinner = true ;
137
173
// Get response
138
174
const response = this . rdbService . buildFromRequestUUID ( requestId ) ;
0 commit comments