Skip to content

Package: JpaDataManagerDao

JpaDataManagerDao

nameinstructionbranchcomplexitylinemethod
backupEntityToModel(BackupEntity)
M: 0 C: 55
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
backupFileEntitiesToModel(Backup, List)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
backupFileEntityToModel(BackupFileEntity, Backup)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
findBackups()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
findManagedFiles()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
fingerprintEntitiesToModel(List)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
fingerprintEntityToModel(FingerprintEntity)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
lambda$backupEntityToModel$2(AtomicReference, BackupEntity)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$backupEntityToModel$3(AtomicReference, BackupEntity)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$backupFileEntitiesToModel$4(Backup, BackupFileEntity)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$managedFileEntityToModel$0(ManagedFileEntity)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$managedFileEntityToModel$1(ManagedFileEntity)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
managedFileEntityToModel(ManagedFileEntity)
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

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.dao.impl.jpa;
28:
29: import jakarta.annotation.Nonnull;
30: import java.util.List;
31: import java.util.Optional;
32: import java.util.concurrent.atomic.AtomicReference;
33: import java.nio.file.Path;
34: import org.springframework.stereotype.Component;
35: import it.tidalwave.util.Id;
36: import it.tidalwave.util.spring.jpa.impl.Fetcher;
37: import it.tidalwave.datamanager.model.Backup;
38: import it.tidalwave.datamanager.model.BackupFile;
39: import it.tidalwave.datamanager.model.DataManager.BackupFinder;
40: import it.tidalwave.datamanager.model.DataManager.ManagedFileFinder;
41: import it.tidalwave.datamanager.model.Fingerprint;
42: import it.tidalwave.datamanager.model.ManagedFile;
43: import it.tidalwave.datamanager.dao.DataManagerDao;
44: import lombok.AllArgsConstructor;
45: import lombok.extern.slf4j.Slf4j;
46:
47: /***********************************************************************************************************************
48: *
49: * The DAO for the application.
50: *
51: * @stereotype DAO
52: * @author Fabrizio Giudici
53: *
54: **********************************************************************************************************************/
55: @Component @AllArgsConstructor @Slf4j
56: public class JpaDataManagerDao implements DataManagerDao
57: {
58: @Nonnull
59: private final ManagedFileEntityJpaRepository managedFileRepo;
60:
61: @Nonnull
62: private final BackupEntityJpaRepository backupRepo;
63:
64: @Nonnull
65: private final Fetcher fetcher;
66:
67: /*******************************************************************************************************************
68: * {@inheritDoc}
69: ******************************************************************************************************************/
70: @Override @Nonnull
71: public ManagedFileFinder findManagedFiles()
72: {
73: return new JpaManagedFileFinder(managedFileRepo, this::managedFileEntityToModel);
74: }
75:
76: /*******************************************************************************************************************
77: * {@inheritDoc}
78: ******************************************************************************************************************/
79: @Override @Nonnull
80: public BackupFinder findBackups()
81: {
82: return new JpaBackupFinder(backupRepo, this::backupEntityToModel);
83: }
84:
85: /*******************************************************************************************************************
86: * {@inheritDoc}
87: ******************************************************************************************************************/
88: @Nonnull
89: public ManagedFile managedFileEntityToModel (@Nonnull final ManagedFileEntity entity)
90: {
91: return new ManagedFile(Id.of(entity.getId()),
92: Path.of(entity.getPath()),
93:• entity.isInitialized()
94: ? () -> fingerprintEntitiesToModel(entity.getFingerprints())
95: : () -> fingerprintEntitiesToModel(fetcher.fetch(entity, ManagedFileEntity::getFingerprints)));
96: }
97:
98: /*******************************************************************************************************************
99: *
100: ******************************************************************************************************************/
101: @Nonnull
102: private static List<Fingerprint> fingerprintEntitiesToModel (@Nonnull final List<? extends FingerprintEntity> entities)
103: {
104: return entities.stream().map(JpaDataManagerDao::fingerprintEntityToModel).toList();
105: }
106:
107: /*******************************************************************************************************************
108: *
109: ******************************************************************************************************************/
110: @Nonnull
111: private static Fingerprint fingerprintEntityToModel (@Nonnull final FingerprintEntity entity)
112: {
113: return Fingerprint.builder()
114: .id(Id.of(entity.getId()))
115: .name(entity.getName())
116: .algorithm(entity.getAlgorithm())
117: .fingerprint(entity.getValue())
118: .timestamp(entity.getTimestamp())
119: .build();
120: }
121:
122: /*******************************************************************************************************************
123: * {@inheritDoc}
124: ******************************************************************************************************************/
125: @Nonnull
126: public Backup backupEntityToModel (@Nonnull final BackupEntity entity)
127: {
128: final var ref = new AtomicReference<Backup>();
129: final var backup = Backup.builder()
130: .id(Id.of(entity.getId()))
131: .label(entity.getLabel())
132: .volumeId(Id.of(entity.getVolumeId()))
133: .encrypted(entity.isEncrypted())
134: .basePath(Path.of(entity.getBasePath()))
135: .creationDate(entity.getCreationDate())
136: .registrationDate(entity.getRegistrationDate())
137: .latestCheckDate(Optional.ofNullable(entity.getLatestCheckDate()))
138:• .backupFiles(entity.isInitialized()
139: ? () -> backupFileEntitiesToModel(ref.get(), entity.getBackupFiles())
140: : () -> backupFileEntitiesToModel(ref.get(), fetcher.fetch(entity, BackupEntity::getBackupFiles)))
141: .build();
142: ref.set(backup);
143: return backup;
144: }
145:
146: /*******************************************************************************************************************
147: *
148: ******************************************************************************************************************/
149: @Nonnull
150: private List<BackupFile> backupFileEntitiesToModel (@Nonnull final Backup backup,
151: @Nonnull final List<? extends BackupFileEntity> entities)
152: {
153: return entities.stream().map(e -> backupFileEntityToModel(e, backup)).toList();
154: }
155:
156: /*******************************************************************************************************************
157: *
158: ******************************************************************************************************************/
159: @Nonnull
160: private BackupFile backupFileEntityToModel (@Nonnull final BackupFileEntity entity,
161: @Nonnull final Backup backup)
162: {
163: return new BackupFile(Id.of(entity.getId()),
164: Path.of(entity.getPath()),
165: managedFileEntityToModel(entity.getManagedFile()), // TODO: use flyweight? Needed?
166: backup); // TODO: use flyweight? Needed?
167: }
168: }