database enum handle implementation

This commit is contained in:
Efstratios Giannopoulos 2023-10-17 12:39:29 +03:00
parent 6443654343
commit 925f195f5a
6 changed files with 31 additions and 18 deletions

View File

@ -26,4 +26,15 @@ public enum ProviderType implements DatabaseEnum<Integer> {
}
public Integer getValue() { return this.value; }
private static final Map<Integer, ProviderType> map;
static {
map = new HashMap<>();
for (ProviderType v : ProviderType.values()) {
map.put(v.getValue(), v);
}
}
public static ProviderType of(Integer i) {
return map.get(i);
}
}

View File

@ -2,6 +2,9 @@ package eu.eudat.commons.enums;
import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.HashMap;
import java.util.Map;
public enum Status implements DatabaseEnum<Integer> {
Inactive(0),
@ -16,4 +19,17 @@ public enum Status implements DatabaseEnum<Integer> {
public Integer getValue() {
return value;
}
private static final Map<Integer, Status> map;
static {
map = new HashMap<>();
for (Status v : Status.values()) {
map.put(v.getValue(), v);
}
}
public static Status of(Integer i) {
return map.get(i);
}
}

View File

@ -9,14 +9,7 @@ import java.util.Map;
@Converter
public class ProviderTypeConverter extends DatabaseEnumConverter<ProviderType, Integer> {
private static final Map<Integer, ProviderType> map;
static {
map = new HashMap<>();
for (ProviderType v : ProviderType.values()) {
map.put(v.getValue(), v);
}
}
public ProviderType of(Integer i) {
return map.get(i);
return ProviderType.of(i);
}
}

View File

@ -9,14 +9,7 @@ import java.util.Map;
@Converter
public class StatusConverter extends DatabaseEnumConverter<Status, Integer> {
private static final Map<Integer, Status> map;
static {
map = new HashMap<>();
for (Status v : Status.values()) {
map.put(v.getValue(), v);
}
}
public Status of(Integer i) {
return map.get(i);
return Status.of(i);
}
}

View File

@ -58,7 +58,7 @@ public class EmailConfirmationManager {
user.setEmail(loginConfirmationEmail.getEmail());
databaseRepository.getUserInfoDao().createOrUpdate(user);
CredentialEntity credential = databaseRepository.getCredentialDao().asQueryable()
.where((builder, root) -> builder.equal(root.get("userInfo"), user)).getSingle();
.where((builder, root) -> builder.equal(root.get("userId"), user.getId())).getSingle();
if(credential.getEmail() == null){
credential.setEmail(user.getEmail());
databaseRepository.getCredentialDao().createOrUpdate(credential);

View File

@ -90,7 +90,7 @@ public class UserManager {
public List<UserCredential> getCredentials(UUID userId) {
List<UserCredential> results = new ArrayList<>();
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
List<CredentialEntity> credentials = apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), user)).toList();
List<CredentialEntity> credentials = apiContext.getOperationsContext().getDatabaseRepository().getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userId"), user.getId())).toList();
credentials.forEach(credential -> {
UserCredential userCredential = new UserCredential();
userCredential.setEmail(credential.getEmail());