1) fix bug when tags don't show after saving the dataset

2) save the email when user logs in with orcid
3) refactor unlink, delete credential of user to be unlinked
This commit is contained in:
Bernaldo Mihasi 2023-07-03 11:40:35 +03:00
parent 1c0562d7e7
commit 000882cbdb
3 changed files with 26 additions and 30 deletions

View File

@ -289,14 +289,6 @@ public class DatasetManager {
.stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
.collect(Collectors.toList()).size() == 0 && !datasetEntity.getDmp().isPublic())
throw new UnauthorisedException();
eu.eudat.elastic.entities.Dataset datasetElastic;
try {
datasetElastic = datasetRepository.exists() ?
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
} catch (Exception ex) {
logger.warn(ex.getMessage());
datasetElastic = null;
}
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
dataset.fromDataModel(datasetEntity);
@ -336,6 +328,14 @@ public class DatasetManager {
boolean latestVersion = profile.getVersion().toString().equals(datasetEntity.getProfile().getVersion().toString());
dataset.setIsProfileLatestVersion(latestVersion);
eu.eudat.elastic.entities.Dataset datasetElastic;
try {
datasetElastic = datasetRepository.exists() ?
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
} catch (Exception ex) {
logger.warn(ex.getMessage());
datasetElastic = null;
}
if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
dataset.setTags(datasetElastic.getTags());
}
@ -1034,14 +1034,6 @@ public class DatasetManager {
public DatasetWizardModel datasetUpdateProfile(String id) {
DatasetWizardModel dataset = new DatasetWizardModel();
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
eu.eudat.elastic.entities.Dataset datasetElastic;
try {
datasetElastic = datasetRepository.exists() ?
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
} catch (Exception ex) {
logger.warn(ex.getMessage());
datasetElastic = null;
}
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
dataset.fromDataModel(datasetEntity);
@ -1062,6 +1054,14 @@ public class DatasetManager {
// Now at latest version.
dataset.setIsProfileLatestVersion(true);
eu.eudat.elastic.entities.Dataset datasetElastic;
try {
datasetElastic = datasetRepository.exists() ?
datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset();
} catch (Exception ex) {
logger.warn(ex.getMessage());
datasetElastic = null;
}
if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
dataset.setTags(datasetElastic.getTags());
}

View File

@ -48,6 +48,9 @@ public class EmailConfirmationManager {
// Checks if mail is used by another user. If it is, merges the new the old.
Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
if (existingUsers > 0) {
Credential credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.equal(root.get("userInfo"), user)).getSingle();
credential.setEmail(loginConfirmationEmail.getEmail());
databaseRepository.getCredentialDao().createOrUpdate(credential);
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
mergeNewUserToOld(user, oldUser);
expireUserToken(user);
@ -57,6 +60,12 @@ public class EmailConfirmationManager {
user.setEmail(loginConfirmationEmail.getEmail());
databaseRepository.getUserInfoDao().createOrUpdate(user);
Credential credential = databaseRepository.getCredentialDao().asQueryable()
.where((builder, root) -> builder.equal(root.get("userInfo"), user)).getSingle();
if(credential.getEmail() == null){
credential.setEmail(user.getEmail());
databaseRepository.getCredentialDao().createOrUpdate(credential);
}
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
}

View File

@ -72,20 +72,7 @@ public class UnlinkEmailConfirmationManager {
Credential credential = databaseRepository.getCredentialDao().asQueryable()
.where((builder, root) -> builder.and(builder.equal(root.get("email"), emailTobeUnlinked), builder.equal(root.get("provider"), provider))).getSingle();
if(credential != null) {
UserInfo userTobeUnlinked = databaseRepository.getUserInfoDao().asQueryable()
.where((builder, root) -> builder.and(builder.equal(root.get("userStatus"), 1), builder.equal(root.get("name"), credential.getPublicValue()))).getSingle();
userTobeUnlinked.setEmail(emailTobeUnlinked);
userTobeUnlinked.setUserStatus((short) 0);
databaseRepository.getUserInfoDao().createOrUpdate(userTobeUnlinked);
credential.setUserInfo(userTobeUnlinked);
databaseRepository.getCredentialDao().createOrUpdate(credential);
UserToken userToken = this.apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserTokenBuilder.class)
.token(UUID.randomUUID()).user(userTobeUnlinked)
.expiresAt(Timestamp.valueOf(LocalDateTime.now().plusDays(10))).issuedAt(new Date())
.build();
apiContext.getOperationsContext().getDatabaseRepository().getUserTokenDao().createOrUpdate(userToken);
databaseRepository.getCredentialDao().delete(credential);
}
}