Search in sources :

Example 11 with AnvandarPreference

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;
}
Also used : AnvandarPreference(se.inera.intyg.webcert.persistence.anvandarmetadata.model.AnvandarPreference) HashMap(java.util.HashMap)

Example 12 with AnvandarPreference

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);
}
Also used : AnvandarPreference(se.inera.intyg.webcert.persistence.anvandarmetadata.model.AnvandarPreference) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 13 with AnvandarPreference

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);
    }
}
Also used : AnvandarPreference(se.inera.intyg.webcert.persistence.anvandarmetadata.model.AnvandarPreference) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Aggregations

AnvandarPreference (se.inera.intyg.webcert.persistence.anvandarmetadata.model.AnvandarPreference)13 Test (org.junit.Test)8 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)6 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1