use of se.inera.intyg.webcert.persistence.anvandarmetadata.model.AnvandarPreference in project webcert by sklintyg.
the class AnvandarPreferenceRepositoryImpl method getAnvandarPreference.
@Override
public Map<String, String> getAnvandarPreference(String hsaId) {
List<AnvandarPreference> anvandarMetadataList = entityManager.createQuery("SELECT am FROM AnvandarPreference am WHERE am.hsaId = :hsaId", AnvandarPreference.class).setParameter("hsaId", hsaId).getResultList();
Map<String, String> map = new HashMap<>();
for (AnvandarPreference am : anvandarMetadataList) {
map.put(am.getKey(), am.getValue());
}
return map;
}
use of se.inera.intyg.webcert.persistence.anvandarmetadata.model.AnvandarPreference in project webcert by sklintyg.
the class WebCertUserServiceImpl method storeUserPreference.
@Override
public void storeUserPreference(String key, String value) {
WebCertUser user = getUser();
String hsaId = user.getHsaId();
AnvandarPreference am = anvandarPreferenceRepository.findByHsaIdAndKey(hsaId, key);
if (am == null) {
anvandarPreferenceRepository.save(new AnvandarPreference(hsaId, key, value));
} else {
am.setValue(value);
anvandarPreferenceRepository.save(am);
}
user.getAnvandarPreference().put(key, value);
}
use of se.inera.intyg.webcert.persistence.anvandarmetadata.model.AnvandarPreference in project webcert by sklintyg.
the class WebCertUserServiceImpl method deleteUserPreferences.
@Override
public void deleteUserPreferences() {
WebCertUser user = getUser();
String hsaId = user.getHsaId();
Map<String, String> anvandarPreferences = anvandarPreferenceRepository.getAnvandarPreference(hsaId);
int deleteCount = 0;
for (Map.Entry<String, String> preference : anvandarPreferences.entrySet()) {
AnvandarPreference toDelete = anvandarPreferenceRepository.findByHsaIdAndKey(hsaId, preference.getKey());
if (toDelete != null) {
anvandarPreferenceRepository.delete(toDelete);
deleteCount++;
}
}
if (deleteCount > 0) {
user.getAnvandarPreference().clear();
LOG.info("Successfully deleted " + deleteCount + " user preferences for user " + hsaId);
}
}
Aggregations