| 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 |
|
|
| 27 |
|
|
| 28 |
|
@Repository |
| 29 |
|
@Transactional |
| |
|
| 100% |
Uncovered Elements: 0 (88) |
Complexity: 12 |
Complexity Density: 0.16 |
|
| 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 |
|
|
| 41 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 42 |
1 |
public ConfigurationHbmDAO() {... |
| 43 |
1 |
super(); |
| 44 |
1 |
LOGGER.log("instance class", LogLevel.INFO); |
| 45 |
|
} |
| 46 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 47 |
2 |
@Override... |
| 48 |
|
public void updateConfigurationEntries(final List<ConfigurationDO> configuration) |
| 49 |
|
throws DAOException { |
| 50 |
2 |
try { |
| 51 |
2 |
for (ConfigurationDO entry : configuration) { |
| 52 |
4 |
this.update(entry.getUuid(), entry); |
| 53 |
|
} |
| 54 |
|
} catch (DAOException ex) { |
| 55 |
1 |
LOGGER.catchException(ex); |
| 56 |
1 |
throw new DAOException("EntityNotFound: " + ex.getMessage()); |
| 57 |
|
} |
| 58 |
|
} |
| 59 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
|
| 60 |
7 |
@Override... |
| 61 |
|
@Transactional(readOnly = true) |
| 62 |
|
public ConfigurationDO getConfigurationByKey(final String key, |
| 63 |
|
final String module, final String version) { |
| 64 |
7 |
ConfigurationDO entry; |
| 65 |
7 |
String hash = cryptoTools.calculateHash(key, HashAlgorithm.SHA256); |
| 66 |
7 |
CriteriaBuilder builder = mainEntityManagerFactory.getCriteriaBuilder(); |
| 67 |
7 |
CriteriaQuery<ConfigurationDO> query = builder.createQuery(ConfigurationDO.class); |
| 68 |
|
|
| 69 |
7 |
Root<ConfigurationDO> root = query.from(ConfigurationDO.class); |
| 70 |
|
|
| 71 |
7 |
ParameterExpression<String> paramKey = builder.parameter(String.class); |
| 72 |
7 |
ParameterExpression<String> paramModulName = builder.parameter(String.class); |
| 73 |
7 |
ParameterExpression<String> paramVersion = builder.parameter(String.class); |
| 74 |
|
|
| 75 |
7 |
query.where(builder.equal(root.get("key"), paramKey), |
| 76 |
|
builder.equal(root.get("modulName"), paramModulName), |
| 77 |
|
builder.equal(root.get("version"), paramVersion)); |
| 78 |
7 |
query.orderBy(builder.asc(root.get("uuid"))); |
| 79 |
|
|
| 80 |
7 |
TypedQuery<ConfigurationDO> result = mainEntityManagerFactory.createQuery(query); |
| 81 |
7 |
result.setParameter(paramKey, hash); |
| 82 |
7 |
result.setParameter(paramModulName, module); |
| 83 |
7 |
result.setParameter(paramVersion, version); |
| 84 |
|
|
| 85 |
7 |
entry = result.getSingleResult(); |
| 86 |
5 |
LOGGER.log("getValueByKey() : " + entry.toString(), LogLevel.DEBUG); |
| 87 |
5 |
return entry; |
| 88 |
|
} |
| 89 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
| 90 |
32 |
@Override... |
| 91 |
|
@Transactional(readOnly = true) |
| 92 |
|
public List<ConfigurationDO> getAllConfigurationSetEntries(final String module, |
| 93 |
|
final String version, final String configSet) { |
| 94 |
32 |
List<ConfigurationDO> result = new ArrayList<>(); |
| 95 |
32 |
Map<String, String> filter = new HashMap<>(); |
| 96 |
32 |
filter.put("modulName", module); |
| 97 |
32 |
filter.put("version", version); |
| 98 |
32 |
filter.put("configurationSet", configSet); |
| 99 |
|
|
| 100 |
32 |
JpaPagination pagination = new JpaPagination("uuid"); |
| 101 |
32 |
pagination.setFilterStringCriteria(filter); |
| 102 |
32 |
result.addAll(listAllElements(pagination)); |
| 103 |
32 |
return result; |
| 104 |
|
} |
| 105 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 106 |
3 |
@Override... |
| 107 |
|
@Transactional(readOnly = true) |
| 108 |
|
public List<ConfigurationDO> getAllModuleEntries(final String module) { |
| 109 |
3 |
List<ConfigurationDO> result = new ArrayList<>(); |
| 110 |
3 |
Map<String, String> filter = new HashMap<>(); |
| 111 |
3 |
filter.put("modulName", module); |
| 112 |
|
|
| 113 |
3 |
JpaPagination pagination = new JpaPagination("uuid"); |
| 114 |
3 |
pagination.setFilterStringCriteria(filter); |
| 115 |
3 |
pagination.setAdditionalOrdering("version"); |
| 116 |
3 |
result.addAll(listAllElements(pagination)); |
| 117 |
3 |
return result; |
| 118 |
|
} |
| 119 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 120 |
1 |
@Override... |
| 121 |
|
@Transactional(readOnly = true) |
| 122 |
|
public List<ConfigurationDO> getAllDeprecatedEntries() { |
| 123 |
1 |
List<ConfigurationDO> result = new ArrayList<>(); |
| 124 |
1 |
Map<String, Boolean> filter = new HashMap<>(); |
| 125 |
1 |
filter.put("deprecated", Boolean.TRUE); |
| 126 |
|
|
| 127 |
1 |
JpaPagination pagination = new JpaPagination("uuid"); |
| 128 |
1 |
pagination.setFilterBooleanCriteria(filter); |
| 129 |
1 |
pagination.setAdditionalOrdering("version"); |
| 130 |
1 |
result.addAll(listAllElements(pagination)); |
| 131 |
1 |
return result; |
| 132 |
|
} |
| 133 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
| 134 |
1 |
@Override... |
| 135 |
|
@Transactional(readOnly = true) |
| 136 |
|
public List<ConfigurationDO> getHistoryOfAEntry(final String module, |
| 137 |
|
final String key, final String configSet) { |
| 138 |
1 |
List<ConfigurationDO> result = new ArrayList<>(); |
| 139 |
1 |
String hash = cryptoTools.calculateHash(key, HashAlgorithm.SHA256); |
| 140 |
1 |
Map<String, String> filter = new HashMap<>(); |
| 141 |
1 |
filter.put("key", hash); |
| 142 |
1 |
filter.put("modulName", module); |
| 143 |
1 |
filter.put("configurationSet", configSet); |
| 144 |
|
|
| 145 |
1 |
JpaPagination pagination = new JpaPagination("uuid"); |
| 146 |
1 |
pagination.setFilterStringCriteria(filter); |
| 147 |
1 |
pagination.setAdditionalOrdering("version"); |
| 148 |
1 |
result.addAll(listAllElements(pagination)); |
| 149 |
1 |
return result; |
| 150 |
|
} |
| 151 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 152 |
3 |
@Override... |
| 153 |
|
@Transactional(readOnly = true) |
| 154 |
|
public String getValueByKey(final String key, final String module, final String version) { |
| 155 |
3 |
String value = ""; |
| 156 |
3 |
LOGGER.log("Module: " + module + " :: Version: " + version + " :: Key: " + key, |
| 157 |
|
LogLevel.DEBUG); |
| 158 |
3 |
ConfigurationDO entry = getConfigurationByKey(key, module, version); |
| 159 |
2 |
value = entry.getValue(); |
| 160 |
2 |
if (StringUtils.isEmpty(value)) { |
| 161 |
1 |
value = entry.getDefaultValue(); |
| 162 |
1 |
LOGGER.log("getValueByKey() returns the defaultValue " + value, LogLevel.DEBUG); |
| 163 |
|
} |
| 164 |
2 |
return value; |
| 165 |
|
} |
| 166 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 167 |
12 |
@Override... |
| 168 |
|
public void restoreKeyToDefault(final ConfigurationDO entry) |
| 169 |
|
throws DAOException { |
| 170 |
12 |
ConfigurationDO change = this.find(entry.getUuid()); |
| 171 |
12 |
if (change != null) { |
| 172 |
11 |
change.setValue(change.getDefaultValue()); |
| 173 |
11 |
this.update(change.getUuid(), change); |
| 174 |
11 |
LOGGER.log(change.getKey() + " reset to default.", LogLevel.DEBUG); |
| 175 |
|
} else { |
| 176 |
1 |
LOGGER.log("EntityNotFound " + entry.toString(), LogLevel.WARN); |
| 177 |
1 |
throw new DAOException("EntityNotFound: " + entry.toString()); |
| 178 |
|
} |
| 179 |
|
} |
| 180 |
|
} |