2023-10-18 09:31:57 +02:00
|
|
|
package eu.eudat.service.supportivematerial;
|
|
|
|
|
|
|
|
|
2024-02-19 16:28:46 +01:00
|
|
|
import eu.eudat.commons.enums.SupportiveMaterialFieldType;
|
2023-10-18 09:31:57 +02:00
|
|
|
import gr.cite.tools.cache.CacheService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class SupportiveMaterialCacheService extends CacheService<SupportiveMaterialCacheService.SupportiveMaterialCacheValue> {
|
|
|
|
|
|
|
|
public static class SupportiveMaterialCacheValue {
|
|
|
|
|
|
|
|
public SupportiveMaterialCacheValue() {}
|
|
|
|
|
2024-02-19 16:28:46 +01:00
|
|
|
public SupportiveMaterialCacheValue(String language, SupportiveMaterialFieldType type, byte[] content) {
|
|
|
|
this.language = language;
|
|
|
|
this.type = type;
|
2023-10-18 09:31:57 +02:00
|
|
|
this.content = content;
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:28:46 +01:00
|
|
|
private String language;
|
|
|
|
private SupportiveMaterialFieldType type;
|
2023-10-18 09:31:57 +02:00
|
|
|
|
|
|
|
private byte[] content;
|
|
|
|
|
|
|
|
public byte[] getContent() {
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setContent(byte[] content) {
|
|
|
|
this.content = content;
|
|
|
|
}
|
2024-02-19 16:28:46 +01:00
|
|
|
|
|
|
|
public String getLanguage() {
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLanguage(String language) {
|
|
|
|
this.language = language;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SupportiveMaterialFieldType getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setType(SupportiveMaterialFieldType type) {
|
|
|
|
this.type = type;
|
|
|
|
}
|
2023-10-18 09:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public SupportiveMaterialCacheService(SupportiveMaterialCacheOptions options) {
|
|
|
|
super(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Class<SupportiveMaterialCacheValue> valueClass() {return SupportiveMaterialCacheValue.class;}
|
|
|
|
|
|
|
|
|
|
|
|
public String keyOf(SupportiveMaterialCacheValue value) {
|
2024-02-19 16:28:46 +01:00
|
|
|
return this.buildKey(value.getLanguage(), value.getType());
|
2023-10-18 09:31:57 +02:00
|
|
|
}
|
|
|
|
|
2024-02-19 16:28:46 +01:00
|
|
|
public String buildKey(String language, SupportiveMaterialFieldType type) {
|
2023-10-18 09:31:57 +02:00
|
|
|
HashMap<String, String> keyParts = new HashMap<>();
|
|
|
|
|
2024-02-19 16:28:46 +01:00
|
|
|
keyParts.put("$lang$", language.toLowerCase(Locale.ROOT));
|
|
|
|
keyParts.put("$type$", type.name().toLowerCase(Locale.ROOT));
|
2023-10-18 09:31:57 +02:00
|
|
|
|
|
|
|
return this.generateKey(keyParts);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|