Commits
Art Lowel authored and Alexandre Vryghem committed 17d1f2e6acb
148 148 | return this.getBrowseEndpoint().pipe( |
149 149 | map((href: string) => `${href}/${uuid}`), |
150 150 | ); |
151 151 | } |
152 152 | |
153 153 | /** |
154 154 | * Send a delete request for a relationship by ID |
155 155 | * @param id the ID of the relationship to delete |
156 156 | * @param copyVirtualMetadata whether to copy this relationship's virtual metadata to the related Items |
157 157 | * accepted values: none, all, left, right, configured |
158 + | * @param shouldRefresh refresh the cache for the items in the relationship after creating |
159 + | * it. Disable this if you want to add relationships in bulk, and |
160 + | * want to refresh the cachemanually at the end |
158 161 | */ |
159 - | deleteRelationship(id: string, copyVirtualMetadata: string): Observable<RemoteData<NoContent>> { |
162 + | deleteRelationship(id: string, copyVirtualMetadata: string, shouldRefresh = true): Observable<RemoteData<NoContent>> { |
160 163 | return this.getRelationshipEndpoint(id).pipe( |
161 164 | isNotEmptyOperator(), |
162 165 | take(1), |
163 166 | distinctUntilChanged(), |
164 167 | map((endpointURL: string) => |
165 168 | new DeleteRequest(this.requestService.generateRequestId(), endpointURL + '?copyVirtualMetadata=' + copyVirtualMetadata), |
166 169 | ), |
167 170 | sendRequest(this.requestService), |
168 171 | switchMap((restRequest: RestRequest) => this.rdbService.buildFromRequestUUID(restRequest.uuid)), |
169 172 | getFirstCompletedRemoteData(), |
170 - | tap(() => this.refreshRelationshipItemsInCacheByRelationship(id)), |
173 + | tap(() => { |
174 + | if (shouldRefresh) { |
175 + | this.refreshRelationshipItemsInCacheByRelationship(id); |
176 + | } |
177 + | }), |
171 178 | ); |
172 179 | } |
173 180 | |
174 181 | /** |
175 182 | * Method to create a new relationship |
176 183 | * @param typeId The identifier of the relationship type |
177 184 | * @param item1 The first item of the relationship |
178 185 | * @param item2 The second item of the relationship |
179 186 | * @param leftwardValue The leftward value of the relationship |
180 187 | * @param rightwardValue The rightward value of the relationship |
188 + | * @param shouldRefresh refresh the cache for the items in the relationship after creating it. |
189 + | * Disable this if you want to add relationships in bulk, and want to refresh |
190 + | * the cache manually at the end |
181 191 | */ |
182 - | addRelationship(typeId: string, item1: Item, item2: Item, leftwardValue?: string, rightwardValue?: string): Observable<RemoteData<Relationship>> { |
192 + | addRelationship(typeId: string, item1: Item, item2: Item, leftwardValue?: string, rightwardValue?: string, shouldRefresh = true): Observable<RemoteData<Relationship>> { |
183 193 | const options: HttpOptions = Object.create({}); |
184 194 | let headers = new HttpHeaders(); |
185 195 | headers = headers.append('Content-Type', 'text/uri-list'); |
186 196 | options.headers = headers; |
187 197 | return this.halService.getEndpoint(this.linkPath).pipe( |
188 198 | isNotEmptyOperator(), |
189 199 | take(1), |
190 200 | map((endpointUrl: string) => `${endpointUrl}?relationshipType=${typeId}`), |
191 201 | map((endpointUrl: string) => isNotEmpty(leftwardValue) ? `${endpointUrl}&leftwardValue=${leftwardValue}` : endpointUrl), |
192 202 | map((endpointUrl: string) => isNotEmpty(rightwardValue) ? `${endpointUrl}&rightwardValue=${rightwardValue}` : endpointUrl), |
193 203 | map((endpointURL: string) => new PostRequest(this.requestService.generateRequestId(), endpointURL, `${item1.self} \n ${item2.self}`, options)), |
194 204 | sendRequest(this.requestService), |
195 205 | switchMap((restRequest: RestRequest) => this.rdbService.buildFromRequestUUID(restRequest.uuid)), |
196 206 | getFirstCompletedRemoteData(), |
197 - | tap(() => this.refreshRelationshipItemsInCache(item1)), |
198 - | tap(() => this.refreshRelationshipItemsInCache(item2)), |
207 + | tap(() => { |
208 + | if (shouldRefresh) { |
209 + | this.refreshRelationshipItemsInCache(item1); |
210 + | this.refreshRelationshipItemsInCache(item2); |
211 + | } |
212 + | }), |
199 213 | ) as Observable<RemoteData<Relationship>>; |
200 214 | } |
201 215 | |
202 216 | /** |
203 217 | * Method to remove two items of a relationship from the cache using the identifier of the relationship |
204 218 | * @param relationshipId The identifier of the relationship |
205 219 | */ |
206 220 | private refreshRelationshipItemsInCacheByRelationship(relationshipId: string) { |
207 221 | this.findById(relationshipId, true, false, followLink('leftItem'), followLink('rightItem')).pipe( |
208 222 | getFirstSucceededRemoteData(), |