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:
parent
1c0562d7e7
commit
000882cbdb
|
@ -289,14 +289,6 @@ public class DatasetManager {
|
||||||
.stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
|
.stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
|
||||||
.collect(Collectors.toList()).size() == 0 && !datasetEntity.getDmp().isPublic())
|
.collect(Collectors.toList()).size() == 0 && !datasetEntity.getDmp().isPublic())
|
||||||
throw new UnauthorisedException();
|
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.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
||||||
dataset.fromDataModel(datasetEntity);
|
dataset.fromDataModel(datasetEntity);
|
||||||
|
|
||||||
|
@ -336,6 +328,14 @@ public class DatasetManager {
|
||||||
boolean latestVersion = profile.getVersion().toString().equals(datasetEntity.getProfile().getVersion().toString());
|
boolean latestVersion = profile.getVersion().toString().equals(datasetEntity.getProfile().getVersion().toString());
|
||||||
dataset.setIsProfileLatestVersion(latestVersion);
|
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()) {
|
if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
|
||||||
dataset.setTags(datasetElastic.getTags());
|
dataset.setTags(datasetElastic.getTags());
|
||||||
}
|
}
|
||||||
|
@ -1034,14 +1034,6 @@ public class DatasetManager {
|
||||||
public DatasetWizardModel datasetUpdateProfile(String id) {
|
public DatasetWizardModel datasetUpdateProfile(String id) {
|
||||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||||
eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
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.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity));
|
||||||
dataset.fromDataModel(datasetEntity);
|
dataset.fromDataModel(datasetEntity);
|
||||||
|
|
||||||
|
@ -1062,6 +1054,14 @@ public class DatasetManager {
|
||||||
// Now at latest version.
|
// Now at latest version.
|
||||||
dataset.setIsProfileLatestVersion(true);
|
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()) {
|
if (datasetElastic != null && datasetElastic.getTags() != null && !datasetElastic.getTags().isEmpty()) {
|
||||||
dataset.setTags(datasetElastic.getTags());
|
dataset.setTags(datasetElastic.getTags());
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,9 @@ public class EmailConfirmationManager {
|
||||||
// Checks if mail is used by another user. If it is, merges the new the old.
|
// 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();
|
Long existingUsers = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).count();
|
||||||
if (existingUsers > 0) {
|
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();
|
UserInfo oldUser = databaseRepository.getUserInfoDao().asQueryable().where((builder, root) -> builder.equal(root.get("email"), loginConfirmationEmail.getEmail())).getSingle();
|
||||||
mergeNewUserToOld(user, oldUser);
|
mergeNewUserToOld(user, oldUser);
|
||||||
expireUserToken(user);
|
expireUserToken(user);
|
||||||
|
@ -57,6 +60,12 @@ public class EmailConfirmationManager {
|
||||||
|
|
||||||
user.setEmail(loginConfirmationEmail.getEmail());
|
user.setEmail(loginConfirmationEmail.getEmail());
|
||||||
databaseRepository.getUserInfoDao().createOrUpdate(user);
|
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);
|
databaseRepository.getLoginConfirmationEmailDao().createOrUpdate(loginConfirmationEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,20 +72,7 @@ public class UnlinkEmailConfirmationManager {
|
||||||
Credential credential = databaseRepository.getCredentialDao().asQueryable()
|
Credential credential = databaseRepository.getCredentialDao().asQueryable()
|
||||||
.where((builder, root) -> builder.and(builder.equal(root.get("email"), emailTobeUnlinked), builder.equal(root.get("provider"), provider))).getSingle();
|
.where((builder, root) -> builder.and(builder.equal(root.get("email"), emailTobeUnlinked), builder.equal(root.get("provider"), provider))).getSingle();
|
||||||
if(credential != null) {
|
if(credential != null) {
|
||||||
UserInfo userTobeUnlinked = databaseRepository.getUserInfoDao().asQueryable()
|
databaseRepository.getCredentialDao().delete(credential);
|
||||||
.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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue