|
13 | 13 | import java.util.HashMap; |
14 | 14 | import java.util.List; |
15 | 15 | import java.util.Map; |
| 16 | +import java.util.Optional; |
16 | 17 | import java.util.concurrent.CompletableFuture; |
17 | 18 | import java.util.stream.Collectors; |
18 | 19 |
|
|
37 | 38 | import org.roda.core.data.v2.ip.RepresentationLink; |
38 | 39 | import org.roda.wui.client.browse.tabs.BrowseDIPTabs; |
39 | 40 | import org.roda.wui.client.common.ActionsToolbar; |
40 | | -import org.roda.wui.client.common.BrowseDIPActionsToolbar; |
41 | | -import org.roda.wui.client.common.BrowseDIPFileActionsToolbar; |
42 | | -import org.roda.wui.client.common.BrowseObjectActionsToolbar; |
| 41 | +import org.roda.wui.client.common.BrowseDIPContentActionsToolbar; |
43 | 42 | import org.roda.wui.client.common.NavigationToolbar; |
44 | 43 | import org.roda.wui.client.common.NoAsyncCallback; |
45 | 44 | import org.roda.wui.client.common.UserLogin; |
|
49 | 48 | import org.roda.wui.client.common.utils.JavascriptUtils; |
50 | 49 | import org.roda.wui.client.services.ConfigurationRestService; |
51 | 50 | import org.roda.wui.client.services.Services; |
| 51 | +import org.roda.wui.common.client.ClientLogger; |
52 | 52 | import org.roda.wui.common.client.HistoryResolver; |
53 | 53 | import org.roda.wui.common.client.tools.HistoryUtils; |
54 | 54 | import org.roda.wui.common.client.tools.ListUtils; |
@@ -77,6 +77,7 @@ public class BrowseDIP extends Composite { |
77 | 77 |
|
78 | 78 | public static final Sorter DEFAULT_DIPFILE_SORTER = new Sorter(new SortParameter(RodaConstants.DIPFILE_ID, false)); |
79 | 79 | private static final ClientMessages messages = GWT.create(ClientMessages.class); |
| 80 | + private static final ClientLogger logger = new ClientLogger(BrowseDIP.class.getName()); |
80 | 81 | public static final HistoryResolver RESOLVER = new HistoryResolver() { |
81 | 82 |
|
82 | 83 | @Override |
@@ -169,14 +170,22 @@ private void applyWhenIndexedAIP(Services services, String historyDipUUID, Strin |
169 | 170 | return response; |
170 | 171 | }).whenComplete((response, throwable1) -> { |
171 | 172 | if (response.getDipFile() != null) { |
172 | | - List<CompletableFuture<DIPFile>> dipFileAncestors = response.getDipFile().getAncestorsUUIDs().stream() |
173 | | - .map(m -> services.dipFileResource(s -> s.findByUuid(m, LocaleInfo.getCurrentLocale().getLocaleName()))) |
| 173 | + List<CompletableFuture<Optional<DIPFile>>> dipFileAncestors = response.getDipFile().getAncestorsUUIDs() |
| 174 | + .stream() |
| 175 | + .map( |
| 176 | + uuid -> services.dipFileResource(s -> s.findByUuid(uuid, LocaleInfo.getCurrentLocale().getLocaleName())) |
| 177 | + .handle((file, e) -> { |
| 178 | + if (e != null) { |
| 179 | + logger.warn("Failed to retrieve DIP file for DIP ID " + uuid + ": " + e.getMessage()); |
| 180 | + return Optional.<DIPFile> empty(); |
| 181 | + } else |
| 182 | + return Optional.ofNullable(file); |
| 183 | + })) |
174 | 184 | .collect(Collectors.toList()); |
175 | 185 | CompletableFuture<?>[] futuresArray = dipFileAncestors.toArray(new CompletableFuture<?>[0]); |
176 | 186 | CompletableFuture.allOf(futuresArray).thenApply(v -> { |
177 | | - for (CompletableFuture<DIPFile> dipFileAncestor : dipFileAncestors) { |
178 | | - DIPFile file = dipFileAncestor.join(); |
179 | | - response.getDipFileAncestors().add(file); |
| 187 | + for (CompletableFuture<Optional<DIPFile>> dipFileAncestor : dipFileAncestors) { |
| 188 | + dipFileAncestor.join().ifPresent(response.getDipFileAncestors()::add); |
180 | 189 | } |
181 | 190 | return response; |
182 | 191 | }).whenComplete((o, throwable) -> render(o, viewers, callback, services)); |
@@ -243,13 +252,21 @@ private void applyWhenIndexedRepresentation(Services services, String historyDip |
243 | 252 | }).whenComplete((response, throwable1) -> { |
244 | 253 | if (response.getDipFile() != null) { |
245 | 254 | List<CompletableFuture<DIPFile>> dipFileAncestors = response.getDipFile().getAncestorsUUIDs().stream() |
246 | | - .map(m -> services.dipFileResource(s -> s.findByUuid(m, LocaleInfo.getCurrentLocale().getLocaleName()))) |
| 255 | + .map( |
| 256 | + uuid -> services.dipFileResource(s -> s.findByUuid(uuid, LocaleInfo.getCurrentLocale().getLocaleName())) |
| 257 | + .handle((file, e) -> { |
| 258 | + if (e != null) |
| 259 | + return null; |
| 260 | + else |
| 261 | + return file; |
| 262 | + })) |
247 | 263 | .collect(Collectors.toList()); |
248 | 264 | CompletableFuture<?>[] futuresArray = dipFileAncestors.toArray(new CompletableFuture<?>[0]); |
249 | 265 | CompletableFuture.allOf(futuresArray).thenApply(v -> { |
250 | 266 | for (CompletableFuture<DIPFile> dipFileAncestor : dipFileAncestors) { |
251 | 267 | DIPFile file = dipFileAncestor.join(); |
252 | | - response.getDipFileAncestors().add(file); |
| 268 | + if (file != null) |
| 269 | + response.getDipFileAncestors().add(file); |
253 | 270 | } |
254 | 271 | return response; |
255 | 272 | }).whenComplete((o, throwable) -> render(o, viewers, callback, services)); |
@@ -306,13 +323,22 @@ private void applyWhenIndexedFile(Services services, String historyDipUUID, Stri |
306 | 323 | }).whenComplete((response, throwable1) -> { |
307 | 324 | if (response.getDipFile() != null) { |
308 | 325 | List<CompletableFuture<DIPFile>> dipFileAncestors = response.getDipFile().getAncestorsUUIDs().stream() |
309 | | - .map(m -> services.dipFileResource(s -> s.findByUuid(m, LocaleInfo.getCurrentLocale().getLocaleName()))) |
| 326 | + .map( |
| 327 | + uuid -> services.dipFileResource(s -> s.findByUuid(uuid, LocaleInfo.getCurrentLocale().getLocaleName())) |
| 328 | + .handle((file, e) -> { |
| 329 | + if (e != null) |
| 330 | + return null; |
| 331 | + else |
| 332 | + return file; |
| 333 | + })) |
310 | 334 | .collect(Collectors.toList()); |
| 335 | + |
311 | 336 | CompletableFuture<?>[] futuresArray = dipFileAncestors.toArray(new CompletableFuture<?>[0]); |
312 | 337 | CompletableFuture.allOf(futuresArray).thenApply(v -> { |
313 | 338 | for (CompletableFuture<DIPFile> dipFileAncestor : dipFileAncestors) { |
314 | 339 | DIPFile file = dipFileAncestor.join(); |
315 | | - response.getDipFileAncestors().add(file); |
| 340 | + if (file != null) |
| 341 | + response.getDipFileAncestors().add(file); |
316 | 342 | } |
317 | 343 | return response; |
318 | 344 | }).whenComplete((o, throwable) -> render(o, viewers, callback, services)); |
@@ -358,34 +384,25 @@ public BrowseDIP(Viewers viewers, BrowseDIPResponse response, Services services) |
358 | 384 | IndexedDIP dip = response.getDip(); |
359 | 385 | DIPFile dipFile = response.getDipFile(); |
360 | 386 |
|
361 | | - if (dipFile != null) { |
362 | | - BrowseObjectActionsToolbar<DIPFile> toolbar = new BrowseDIPFileActionsToolbar(); |
363 | | - toolbar.setObjectAndBuild(dipFile, response.getPermissions(), handler); |
364 | | - objectToolbar = toolbar; |
365 | | - |
366 | | - } else { |
367 | | - BrowseObjectActionsToolbar<IndexedDIP> toolbar = new BrowseDIPActionsToolbar(); |
368 | | - toolbar.setObjectAndBuild(dip, dip.getPermissions(), handler); |
369 | | - objectToolbar = toolbar; |
370 | | - } |
| 387 | + BrowseDIPContentActionsToolbar toolbar = new BrowseDIPContentActionsToolbar(); |
| 388 | + toolbar.setObjectsAndBuild(dip, dipFile, response.getPermissions(), handler); |
| 389 | + objectToolbar = toolbar; |
371 | 390 |
|
372 | 391 | initWidget(uiBinder.createAndBindUi(this)); |
373 | 392 |
|
374 | 393 | navigationToolbar.withObject(dipFile != null ? dipFile : dip); |
375 | 394 |
|
376 | 395 | handlers.put(Actionable.ActionImpact.DESTROYED, () -> { |
377 | | - if (dipFile == null) { |
378 | | - // dip was removed |
379 | | - if (!dip.getFileIds().isEmpty()) { |
380 | | - FileLink link = dip.getFileIds().get(0); |
381 | | - HistoryUtils.openBrowse(link.getAipId(), link.getRepresentationId(), link.getPath(), link.getFileId()); |
382 | | - } else if (!dip.getRepresentationIds().isEmpty()) { |
383 | | - RepresentationLink link = dip.getRepresentationIds().get(0); |
384 | | - HistoryUtils.openBrowse(link.getAipId(), link.getRepresentationId()); |
385 | | - } else if (!dip.getAipIds().isEmpty()) { |
386 | | - AIPLink link = dip.getAipIds().get(0); |
387 | | - HistoryUtils.openBrowse(link.getAipId()); |
388 | | - } |
| 396 | + // dip was removed |
| 397 | + if (!dip.getAipIds().isEmpty()) { |
| 398 | + AIPLink link = dip.getAipIds().get(0); |
| 399 | + HistoryUtils.openBrowse(link.getAipId()); |
| 400 | + } else if (!dip.getRepresentationIds().isEmpty()) { |
| 401 | + RepresentationLink link = dip.getRepresentationIds().get(0); |
| 402 | + HistoryUtils.openBrowse(link.getAipId()); |
| 403 | + } else if (!dip.getFileIds().isEmpty()) { |
| 404 | + AIPLink link = dip.getFileIds().get(0); |
| 405 | + HistoryUtils.openBrowse(link.getAipId()); |
389 | 406 | } |
390 | 407 | }); |
391 | 408 |
|
|
0 commit comments