Package: DefaultDataManagerPresentationControl
DefaultDataManagerPresentationControl
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
createPredicate(DataManagerPresentationControl.ManagedFileOptions) |
|
|
|
|
|
||||||||||||||||||||
lambda$createPredicate$4(ManagedFile) |
|
|
|
|
|
||||||||||||||||||||
lambda$createPredicate$5(String, ManagedFile) |
|
|
|
|
|
||||||||||||||||||||
lambda$createPredicate$6(Predicate, String) |
|
|
|
|
|
||||||||||||||||||||
lambda$createPredicate$7(ManagedFile) |
|
|
|
|
|
||||||||||||||||||||
lambda$renderBackups$2(DataManagerPresentationControl.BackupOptions, Backup) |
|
|
|
|
|
||||||||||||||||||||
lambda$renderBackups$3(RoleFactory, Backup) |
|
|
|
|
|
||||||||||||||||||||
lambda$renderManagedFiles$0(DataManagerPresentationControl.ManagedFileOptions, ManagedFile) |
|
|
|
|
|
||||||||||||||||||||
lambda$renderManagedFiles$1(RoleFactory, ManagedFile) |
|
|
|
|
|
||||||||||||||||||||
renderBackups(DataManagerPresentationControl.BackupOptions) |
|
|
|
|
|
||||||||||||||||||||
renderManagedFiles(DataManagerPresentationControl.ManagedFileOptions) |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * SolidBlue 3: Data safety
5: * http://tidalwave.it/projects/solidblue3
6: *
7: * Copyright (C) 2023 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/solidblue3j-src
23: * git clone https://github.com/tidalwave-it/solidblue3j-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.datamanager.application.nogui.impl;
28:
29: import jakarta.annotation.Nonnull;
30: import java.util.List;
31: import java.util.function.Predicate;
32: import java.nio.file.Files;
33: import org.springframework.stereotype.Component;
34: import it.tidalwave.util.RoleFactory;
35: import it.tidalwave.role.SimpleComposite;
36: import it.tidalwave.role.ui.PresentationModel;
37: import it.tidalwave.datamanager.model.Backup;
38: import it.tidalwave.datamanager.model.DataManager;
39: import it.tidalwave.datamanager.model.ManagedFile;
40: import it.tidalwave.datamanager.application.nogui.DataManagerPresentation;
41: import it.tidalwave.datamanager.application.nogui.DataManagerPresentationControl;
42: import lombok.RequiredArgsConstructor;
43: import static it.tidalwave.datamanager.model.DataManager.BackupFinder.SortingKeys.LABEL;
44: import static it.tidalwave.datamanager.model.DataManager.ManagedFileFinder.SortingKeys.PATH;
45: import static it.tidalwave.util.Finder.SortDirection.ASCENDING;
46: import static it.tidalwave.util.spring.jpa.JpaSpecificationFinder.by;
47: import static it.tidalwave.role.ui.spi.PresentationModelCollectors.toCompositePresentationModel;
48:
49: /***********************************************************************************************************************
50: *
51: * The default implementation of {@link DataManagerPresentationControl}.
52: *
53: * @stereotype Presentation Control
54: * @author Fabrizio Giudici
55: *
56: **********************************************************************************************************************/
57: @Component @RequiredArgsConstructor
58: public class DefaultDataManagerPresentationControl implements DataManagerPresentationControl
59: {
60: @Nonnull
61: private final DataManager dataManager;
62:
63: @Nonnull
64: private final DataManagerPresentation presentation;
65:
66: /*******************************************************************************************************************
67: * {@inheritDoc}
68: ******************************************************************************************************************/
69: @Override
70: public void renderManagedFiles (@Nonnull final ManagedFileOptions options)
71: {
72: final RoleFactory<ManagedFile> rf =
73:• o -> SimpleComposite.ofCloned(options.renderFingerprints ? o.getFingerprints() : List.of());
74:
75: final var pm = dataManager.findManagedFiles()
76: .withFingerprint(options.fingerprint)
77: .sort(by(PATH), ASCENDING)
78: .max(options.max)
79: .stream()
80: .filter(createPredicate(options))
81: .map(m -> PresentationModel.of(m, rf))
82: // .map(m -> m.as(_Presentable_).createPresentationModel(rf)) TODO breaks test
83: .collect(toCompositePresentationModel());
84: presentation.renderManagedFiles(pm);
85: }
86:
87: /*******************************************************************************************************************
88: * {@inheritDoc}
89: ******************************************************************************************************************/
90: @Override
91: public void renderBackups (@Nonnull final BackupOptions options)
92: {
93: final RoleFactory<Backup> rf =
94:• o -> SimpleComposite.ofCloned(options.renderFiles ? o.getBackupFiles() : List.of());
95:
96: final var pm = dataManager.findBackups()
97: .withLabel(options.label)
98: .withVolumeId(options.volumeId)
99: .withFileId(options.fileId)
100: .sort(by(LABEL), ASCENDING)
101: .stream()
102: .map(m -> PresentationModel.of(m, rf))
103: // .map(m -> m.as(_Presentable_).createPresentationModel(rf)) TODO breaks test
104: .collect(toCompositePresentationModel());
105: presentation.renderBackups(pm);
106: }
107:
108: /*******************************************************************************************************************
109: *
110: ******************************************************************************************************************/
111: @Nonnull
112: private static Predicate<ManagedFile> createPredicate (@Nonnull final ManagedFileOptions options)
113: {
114: final Predicate<ManagedFile> filter1 = __ -> true;
115: final var filter2 =
116: options.regex.map(r -> filter1.and(mf -> mf.getPath().toString().matches(r))).orElse(filter1);
117:• return !options.missingFiles ? filter2 : filter2.and(mf -> !Files.exists(mf.getPath()));
118: }
119: }