ConfigurationHbmDAO.java

1
package org.europa.together.application;
2
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7
import jakarta.persistence.TypedQuery;
8
import jakarta.persistence.criteria.CriteriaBuilder;
9
import jakarta.persistence.criteria.CriteriaQuery;
10
import jakarta.persistence.criteria.ParameterExpression;
11
import jakarta.persistence.criteria.Root;
12
import org.europa.together.business.ConfigurationDAO;
13
import org.europa.together.business.CryptoTools;
14
import org.europa.together.business.Logger;
15
import org.europa.together.domain.ConfigurationDO;
16
import org.europa.together.domain.HashAlgorithm;
17
import org.europa.together.domain.JpaPagination;
18
import org.europa.together.domain.LogLevel;
19
import org.europa.together.exceptions.DAOException;
20
import org.europa.together.utils.StringUtils;
21
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.stereotype.Repository;
23
import org.springframework.transaction.annotation.Transactional;
24
25
/**
26
 * Implementation of the ConfigurationDAO.
27
 */
28
@Repository
29
@Transactional
30
public class ConfigurationHbmDAO extends GenericHbmDAO<ConfigurationDO, String>
31
        implements ConfigurationDAO {
32
33
    private static final long serialVersionUID = 5L;
34
    private static final Logger LOGGER = new LogbackLogger(ConfigurationHbmDAO.class);
35
36
    @Autowired
37
    private transient CryptoTools cryptoTools;
38
39
    /**
40
     * Constructor.
41
     */
42
    public ConfigurationHbmDAO() {
43
        super();
44
        LOGGER.log("instance class", LogLevel.INFO);
45
    }
46
47
    @Override
48
    public void updateConfigurationEntries(final List<ConfigurationDO> configuration)
49
            throws DAOException {
50
        try {
51
            for (ConfigurationDO entry : configuration) {
52 1 1. updateConfigurationEntries : removed call to org/europa/together/application/ConfigurationHbmDAO::update → KILLED
                this.update(entry.getUuid(), entry);
53
            }
54
        } catch (DAOException ex) {
55
            LOGGER.catchException(ex);
56
            throw new DAOException("EntityNotFound: " + ex.getMessage());
57
        }
58
    }
59
60
    @Override
61
    @Transactional(readOnly = true)
62
    public ConfigurationDO getConfigurationByKey(final String key,
63
            final String module, final String version) {
64
        ConfigurationDO entry;
65
        String hash = cryptoTools.calculateHash(key, HashAlgorithm.SHA256);
66
        CriteriaBuilder builder = mainEntityManagerFactory.getCriteriaBuilder();
67
        CriteriaQuery<ConfigurationDO> query = builder.createQuery(ConfigurationDO.class);
68
        // create Criteria
69
        Root<ConfigurationDO> root = query.from(ConfigurationDO.class);
70
        //Criteria SQL Parameters
71
        ParameterExpression<String> paramKey = builder.parameter(String.class);
72
        ParameterExpression<String> paramModulName = builder.parameter(String.class);
73
        ParameterExpression<String> paramVersion = builder.parameter(String.class);
74
75
        query.where(builder.equal(root.get("key"), paramKey),
76
                builder.equal(root.get("modulName"), paramModulName),
77
                builder.equal(root.get("version"), paramVersion));
78
        query.orderBy(builder.asc(root.get("uuid")));
79
        // wire queries tog parametersether with parameters
80
        TypedQuery<ConfigurationDO> result = mainEntityManagerFactory.createQuery(query);
81
        result.setParameter(paramKey, hash);
82
        result.setParameter(paramModulName, module);
83
        result.setParameter(paramVersion, version);
84
85
        entry = result.getSingleResult();
86
        LOGGER.log("getValueByKey() : " + entry.toString(), LogLevel.DEBUG);
87 1 1. getConfigurationByKey : replaced return value with null for org/europa/together/application/ConfigurationHbmDAO::getConfigurationByKey → KILLED
        return entry;
88
    }
89
90
    @Override
91
    @Transactional(readOnly = true)
92
    public List<ConfigurationDO> getAllConfigurationSetEntries(final String module,
93
            final String version, final String configSet) {
94
        List<ConfigurationDO> result = new ArrayList<>();
95
        Map<String, String> filter = new HashMap<>();
96
        filter.put("modulName", module);
97
        filter.put("version", version);
98
        filter.put("configurationSet", configSet);
99
100
        JpaPagination pagination = new JpaPagination("uuid");
101 1 1. getAllConfigurationSetEntries : removed call to org/europa/together/domain/JpaPagination::setFilterStringCriteria → KILLED
        pagination.setFilterStringCriteria(filter);
102
        result.addAll(listAllElements(pagination));
103 1 1. getAllConfigurationSetEntries : replaced return value with Collections.emptyList for org/europa/together/application/ConfigurationHbmDAO::getAllConfigurationSetEntries → KILLED
        return result;
104
    }
105
106
    @Override
107
    @Transactional(readOnly = true)
108
    public List<ConfigurationDO> getAllModuleEntries(final String module) {
109
        List<ConfigurationDO> result = new ArrayList<>();
110
        Map<String, String> filter = new HashMap<>();
111
        filter.put("modulName", module);
112
113
        JpaPagination pagination = new JpaPagination("uuid");
114 1 1. getAllModuleEntries : removed call to org/europa/together/domain/JpaPagination::setFilterStringCriteria → KILLED
        pagination.setFilterStringCriteria(filter);
115 1 1. getAllModuleEntries : removed call to org/europa/together/domain/JpaPagination::setAdditionalOrdering → SURVIVED
        pagination.setAdditionalOrdering("version");
116
        result.addAll(listAllElements(pagination));
117 1 1. getAllModuleEntries : replaced return value with Collections.emptyList for org/europa/together/application/ConfigurationHbmDAO::getAllModuleEntries → KILLED
        return result;
118
    }
119
120
    @Override
121
    @Transactional(readOnly = true)
122
    public List<ConfigurationDO> getAllDeprecatedEntries() {
123
        List<ConfigurationDO> result = new ArrayList<>();
124
        Map<String, Boolean> filter = new HashMap<>();
125
        filter.put("deprecated", Boolean.TRUE);
126
127
        JpaPagination pagination = new JpaPagination("uuid");
128 1 1. getAllDeprecatedEntries : removed call to org/europa/together/domain/JpaPagination::setFilterBooleanCriteria → KILLED
        pagination.setFilterBooleanCriteria(filter);
129 1 1. getAllDeprecatedEntries : removed call to org/europa/together/domain/JpaPagination::setAdditionalOrdering → SURVIVED
        pagination.setAdditionalOrdering("version");
130
        result.addAll(listAllElements(pagination));
131 1 1. getAllDeprecatedEntries : replaced return value with Collections.emptyList for org/europa/together/application/ConfigurationHbmDAO::getAllDeprecatedEntries → KILLED
        return result;
132
    }
133
134
    @Override
135
    @Transactional(readOnly = true)
136
    public List<ConfigurationDO> getHistoryOfAEntry(final String module,
137
            final String key, final String configSet) {
138
        List<ConfigurationDO> result = new ArrayList<>();
139
        String hash = cryptoTools.calculateHash(key, HashAlgorithm.SHA256);
140
        Map<String, String> filter = new HashMap<>();
141
        filter.put("key", hash);
142
        filter.put("modulName", module);
143
        filter.put("configurationSet", configSet);
144
145
        JpaPagination pagination = new JpaPagination("uuid");
146 1 1. getHistoryOfAEntry : removed call to org/europa/together/domain/JpaPagination::setFilterStringCriteria → KILLED
        pagination.setFilterStringCriteria(filter);
147 1 1. getHistoryOfAEntry : removed call to org/europa/together/domain/JpaPagination::setAdditionalOrdering → SURVIVED
        pagination.setAdditionalOrdering("version");
148
        result.addAll(listAllElements(pagination));
149 1 1. getHistoryOfAEntry : replaced return value with Collections.emptyList for org/europa/together/application/ConfigurationHbmDAO::getHistoryOfAEntry → KILLED
        return result;
150
    }
151
152
    @Override
153
    @Transactional(readOnly = true)
154
    public String getValueByKey(final String key, final String module, final String version) {
155
        String value = "";
156
        LOGGER.log("Module: " + module + " :: Version: " + version + " :: Key: " + key,
157
                LogLevel.DEBUG);
158
        ConfigurationDO entry = getConfigurationByKey(key, module, version);
159
        value = entry.getValue();
160 1 1. getValueByKey : negated conditional → KILLED
        if (StringUtils.isEmpty(value)) {
161
            value = entry.getDefaultValue();
162
            LOGGER.log("getValueByKey() returns the defaultValue " + value, LogLevel.DEBUG);
163
        }
164 1 1. getValueByKey : replaced return value with "" for org/europa/together/application/ConfigurationHbmDAO::getValueByKey → KILLED
        return value;
165
    }
166
167
    @Override
168
    public void restoreKeyToDefault(final ConfigurationDO entry)
169
            throws DAOException {
170
        ConfigurationDO change = this.find(entry.getUuid());
171 1 1. restoreKeyToDefault : negated conditional → KILLED
        if (change != null) {
172 1 1. restoreKeyToDefault : removed call to org/europa/together/domain/ConfigurationDO::setValue → KILLED
            change.setValue(change.getDefaultValue());
173 1 1. restoreKeyToDefault : removed call to org/europa/together/application/ConfigurationHbmDAO::update → SURVIVED
            this.update(change.getUuid(), change);
174
            LOGGER.log(change.getKey() + " reset to default.", LogLevel.DEBUG);
175
        } else {
176
            LOGGER.log("EntityNotFound " + entry.toString(), LogLevel.WARN);
177
            throw new DAOException("EntityNotFound: " + entry.toString());
178
        }
179
    }
180
}

Mutations

52

1.1
Location : updateConfigurationEntries
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:failUpdateConfigurationEntries()]
removed call to org/europa/together/application/ConfigurationHbmDAO::update → KILLED

87

1.1
Location : getConfigurationByKey
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getValueByKeyFallbackToDefault()]
replaced return value with null for org/europa/together/application/ConfigurationHbmDAO::getConfigurationByKey → KILLED

101

1.1
Location : getAllConfigurationSetEntries
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getAllSetEntries()]
removed call to org/europa/together/domain/JpaPagination::setFilterStringCriteria → KILLED

103

1.1
Location : getAllConfigurationSetEntries
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getAllSetEntries()]
replaced return value with Collections.emptyList for org/europa/together/application/ConfigurationHbmDAO::getAllConfigurationSetEntries → KILLED

114

1.1
Location : getAllModuleEntries
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getAllModuleEntries()]
removed call to org/europa/together/domain/JpaPagination::setFilterStringCriteria → KILLED

115

1.1
Location : getAllModuleEntries
Killed by : none
removed call to org/europa/together/domain/JpaPagination::setAdditionalOrdering → SURVIVED
Covering tests

117

1.1
Location : getAllModuleEntries
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getAllModuleEntries()]
replaced return value with Collections.emptyList for org/europa/together/application/ConfigurationHbmDAO::getAllModuleEntries → KILLED

128

1.1
Location : getAllDeprecatedEntries
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getDeprecatedEntries()]
removed call to org/europa/together/domain/JpaPagination::setFilterBooleanCriteria → KILLED

129

1.1
Location : getAllDeprecatedEntries
Killed by : none
removed call to org/europa/together/domain/JpaPagination::setAdditionalOrdering → SURVIVED
Covering tests

131

1.1
Location : getAllDeprecatedEntries
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getDeprecatedEntries()]
replaced return value with Collections.emptyList for org/europa/together/application/ConfigurationHbmDAO::getAllDeprecatedEntries → KILLED

146

1.1
Location : getHistoryOfAEntry
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getHistoryOfAEntry()]
removed call to org/europa/together/domain/JpaPagination::setFilterStringCriteria → KILLED

147

1.1
Location : getHistoryOfAEntry
Killed by : none
removed call to org/europa/together/domain/JpaPagination::setAdditionalOrdering → SURVIVED
Covering tests

149

1.1
Location : getHistoryOfAEntry
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getHistoryOfAEntry()]
replaced return value with Collections.emptyList for org/europa/together/application/ConfigurationHbmDAO::getHistoryOfAEntry → KILLED

160

1.1
Location : getValueByKey
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getValueByKeyFallbackToDefault()]
negated conditional → KILLED

164

1.1
Location : getValueByKey
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:getValueByKeyFallbackToDefault()]
replaced return value with "" for org/europa/together/application/ConfigurationHbmDAO::getValueByKey → KILLED

171

1.1
Location : restoreKeyToDefault
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:restoreKeyToDefault()]
negated conditional → KILLED

172

1.1
Location : restoreKeyToDefault
Killed by : org.europa.together.application.ConfigurationHbmDAOTest.[engine:junit-jupiter]/[class:org.europa.together.application.ConfigurationHbmDAOTest]/[method:restoreKeyToDefault()]
removed call to org/europa/together/domain/ConfigurationDO::setValue → KILLED

173

1.1
Location : restoreKeyToDefault
Killed by : none
removed call to org/europa/together/application/ConfigurationHbmDAO::update → SURVIVED
Covering tests

Active mutators

Tests examined


Report generated by PIT 1.22.0