Skip to content

Package: JpaManagedFileFinder

JpaManagedFileFinder

nameinstructionbranchcomplexitylinemethod
JpaManagedFileFinder(JpaManagedFileFinder, Object)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
JpaManagedFileFinder(ManagedFileEntityJpaRepository, Function)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
JpaManagedFileFinder(ManagedFileEntityJpaRepository, Function, Optional)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
composeSpecification(Root, CriteriaBuilder, List)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$composeSpecification$0(List, CriteriaBuilder, Root, String)
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%
withFingerprint(Optional)
M: 0 C: 13
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.function.Function;
33: import java.io.Serial;
34: import jakarta.persistence.criteria.CriteriaBuilder;
35: import jakarta.persistence.criteria.Predicate;
36: import jakarta.persistence.criteria.Root;
37: import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
38: import it.tidalwave.util.spring.jpa.JpaSpecificationFinder;
39: import it.tidalwave.datamanager.model.DataManager.ManagedFileFinder;
40: import it.tidalwave.datamanager.model.ManagedFile;
41:
42: /***********************************************************************************************************************
43: *
44: * A specialised {@link it.tidalwave.util.Finder} for {@link ManagedFileEntity}.
45: *
46: * @stereotype Finder
47: * @author Fabrizio Giudici
48: *
49: **********************************************************************************************************************/
50: @SuppressFBWarnings("SE_BAD_FIELD")
51: public class JpaManagedFileFinder
52: extends JpaSpecificationFinder<ManagedFile, ManagedFileEntity, ManagedFileFinder, ManagedFileEntityJpaRepository>
53: implements ManagedFileFinder
54: {
55: @Serial private static final long serialVersionUID = 0L;
56:
57: private final Optional<String> fingerprint;
58:
59: /*******************************************************************************************************************
60: *
61: ******************************************************************************************************************/
62: public JpaManagedFileFinder (@Nonnull final ManagedFileEntityJpaRepository repository,
63: @Nonnull final Function<ManagedFileEntity, ManagedFile> transformer)
64: {
65: this(repository, transformer, Optional.empty());
66: }
67:
68: /*******************************************************************************************************************
69: *
70: ******************************************************************************************************************/
71: private JpaManagedFileFinder (@Nonnull final ManagedFileEntityJpaRepository repository,
72: @Nonnull final Function<ManagedFileEntity, ManagedFile> transformer,
73: @Nonnull final Optional<String> fingerprint)
74: {
75: super(repository, transformer);
76: this.fingerprint = fingerprint;
77: }
78:
79: /*******************************************************************************************************************
80: * The copy constructor required by {@link it.tidalwave.util.spi.HierarchicFinderSupport}.
81: ******************************************************************************************************************/
82: public JpaManagedFileFinder (@Nonnull final JpaManagedFileFinder other, @Nonnull final Object override)
83: {
84: super(other, override);
85: final var source = getSource(JpaManagedFileFinder.class, other, override);
86: this.fingerprint = source.fingerprint;
87: }
88:
89: /*******************************************************************************************************************
90: * {@inheritDoc}
91: ******************************************************************************************************************/
92: @Override @Nonnull
93: public ManagedFileFinder withFingerprint (@Nonnull final Optional<String> fingerprint)
94: {
95: return clonedWith(new JpaManagedFileFinder(repository, entityToModel, fingerprint));
96: }
97:
98: /*******************************************************************************************************************
99: * {@inheritDoc}
100: ******************************************************************************************************************/
101: protected void composeSpecification (@Nonnull final Root<ManagedFileEntity> root,
102: @Nonnull final CriteriaBuilder criteriaBuilder,
103: @Nonnull final List<? super Predicate> predicates)
104: {
105: fingerprint.ifPresent(f -> predicates.add(criteriaBuilder.equal(root.join("fingerprints").get("value"), f)));
106: }
107: }
108: