add inapp notification events in main app

This commit is contained in:
amentis 2024-01-10 17:46:45 +02:00
parent 708fa69c53
commit 17d97bb3b3
7 changed files with 191 additions and 78 deletions

View File

@ -0,0 +1,78 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class UserRequestPersist {
private UUID userId;
public static final String _userId = "userId";
private String email;
public static final String _email = "email";
public UUID getUserId() {
return userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Component(UserRequestPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class UserRequestPersistValidator extends BaseValidator<UserRequestPersist> {
public static final String ValidatorName = "UserRequestPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected UserRequestPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<UserRequestPersist> modelClass() {
return UserRequestPersist.class;
}
@Override
protected List<Specification> specifications(UserRequestPersist item) {
return Arrays.asList(
this.spec()
.must(() -> this.isValidGuid(item.getUserId()))
.failOn(UserRequestPersist._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserRequestPersist._userId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEmail()))
.failOn(UserRequestPersist._email).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserRequestPersist._email}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -217,34 +217,39 @@ public class DescriptionServiceImpl implements DescriptionService {
if (!dmpUser.getUserId().equals(this.userScope.getUserIdSafe())){ if (!dmpUser.getUserId().equals(this.userScope.getUserIdSafe())){
UserEntity user = this.queryFactory.query(UserQuery.class).ids(dmpUser.getUserId()).first(); UserEntity user = this.queryFactory.query(UserQuery.class).ids(dmpUser.getUserId()).first();
if (user != null){ if (user != null){
NotificationIntegrationEvent event = new NotificationIntegrationEvent(); this.createDescriptionNotificationEvent(description, user, NotificationContactType.EMAIL);
event.setUserId(this.userScope.getUserId()); this.createDescriptionNotificationEvent(description, user, NotificationContactType.IN_APP);
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(user.getId());
query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal));
List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, query.first().getValue()));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(NotificationContactType.EMAIL);
event = this.applyNotificationType(description.getStatus(), event);
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
fieldInfoList.add(new FieldInfo("{reasonName}", DataType.String, this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).first().getName()));
fieldInfoList.add(new FieldInfo("{name}", DataType.String, description.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, description.getId().toString()));
data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event);
} }
} }
} }
} }
private void createDescriptionNotificationEvent(DescriptionEntity description, UserEntity user, NotificationContactType type) throws InvalidApplicationException {
NotificationIntegrationEvent event = new NotificationIntegrationEvent();
event.setUserId(this.userScope.getUserId());
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(user.getId());
query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal));
List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, query.first().getValue()));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(type);
event = this.applyNotificationType(description.getStatus(), event);
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
fieldInfoList.add(new FieldInfo("{reasonName}", DataType.String, this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).first().getName()));
fieldInfoList.add(new FieldInfo("{name}", DataType.String, description.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, description.getId().toString()));
data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event);
}
private NotificationIntegrationEvent applyNotificationType(DescriptionStatus status, NotificationIntegrationEvent event) { private NotificationIntegrationEvent applyNotificationType(DescriptionStatus status, NotificationIntegrationEvent event) {
switch (status) { switch (status) {
case Draft: case Draft:

View File

@ -227,7 +227,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
data.setUserId(user.getUserId()); data.setUserId(user.getUserId());
data.setRole(user.getRole()); data.setRole(user.getRole());
this.entityManager.persist(data); this.entityManager.persist(data);
this.sendJoinMail(data); this.sendDescriptionTemplateInvitationEvent(data, NotificationContactType.EMAIL);
this.sendDescriptionTemplateInvitationEvent(data, NotificationContactType.IN_APP);
} }
updatedCreatedIds.add(data.getId()); updatedCreatedIds.add(data.getId());
} }
@ -236,7 +237,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.deleterFactory.deleter(UserDescriptionTemplateDeleter.class).delete(toDelete); this.deleterFactory.deleter(UserDescriptionTemplateDeleter.class).delete(toDelete);
} }
private void sendJoinMail(UserDescriptionTemplateEntity userDescriptionTemplate) throws InvalidApplicationException { private void sendDescriptionTemplateInvitationEvent(UserDescriptionTemplateEntity userDescriptionTemplate, NotificationContactType type) throws InvalidApplicationException {
NotificationIntegrationEvent event = new NotificationIntegrationEvent(); NotificationIntegrationEvent event = new NotificationIntegrationEvent();
event.setTenant(tenantScope.getTenant()); event.setTenant(tenantScope.getTenant());
event.setUserId(userScope.getUserIdSafe()); event.setUserId(userScope.getUserIdSafe());
@ -251,7 +252,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
contactPairs.add(new ContactPair(ContactInfoType.Email, query.first().getValue())); contactPairs.add(new ContactPair(ContactInfoType.Email, query.first().getValue()));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null); NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData)); event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(NotificationContactType.EMAIL); event.setContactTypeHint(type);
event.setNotificationType(notificationProperties.getDescriptionTemplateInvitationType()); event.setNotificationType(notificationProperties.getDescriptionTemplateInvitationType());
NotificationFieldData data = new NotificationFieldData(); NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>(); List<FieldInfo> fieldInfoList = new ArrayList<>();
@ -261,7 +262,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
data.setFields(fieldInfoList); data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data)); event.setData(jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event); eventHandler.handle(event);
} }
private void addOwner(DescriptionTemplateEntity descriptionTemplateEntity) throws InvalidApplicationException { private void addOwner(DescriptionTemplateEntity descriptionTemplateEntity) throws InvalidApplicationException {

View File

@ -186,33 +186,38 @@ public class DmpServiceImpl implements DmpService {
if (!dmpUser.getUserId().equals(this.userScope.getUserIdSafe())){ if (!dmpUser.getUserId().equals(this.userScope.getUserIdSafe())){
UserEntity user = this.queryFactory.query(UserQuery.class).ids(dmpUser.getUserId()).first(); UserEntity user = this.queryFactory.query(UserQuery.class).ids(dmpUser.getUserId()).first();
if (user != null){ if (user != null){
NotificationIntegrationEvent event = new NotificationIntegrationEvent(); this.createDmpNotificationEvent(dmp, user, NotificationContactType.EMAIL);
event.setUserId(this.userScope.getUserId()); this.createDmpNotificationEvent(dmp, user, NotificationContactType.IN_APP);
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(user.getId());
query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal));
List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, query.first().getValue()));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(NotificationContactType.EMAIL);
event = this.applyNotificationType(dmp.getStatus(), event);
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
fieldInfoList.add(new FieldInfo("{reasonName}", DataType.String, this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).first().getName()));
fieldInfoList.add(new FieldInfo("{name}", DataType.String, dmp.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, dmp.getId().toString()));
data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event);
} }
} }
} }
} }
private void createDmpNotificationEvent(DmpEntity dmp, UserEntity user, NotificationContactType type) throws InvalidApplicationException {
NotificationIntegrationEvent event = new NotificationIntegrationEvent();
event.setUserId(this.userScope.getUserId());
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(user.getId());
query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal));
List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, query.first().getValue()));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(type);
event = this.applyNotificationType(dmp.getStatus(), event);
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
fieldInfoList.add(new FieldInfo("{reasonName}", DataType.String, this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserId()).first().getName()));
fieldInfoList.add(new FieldInfo("{name}", DataType.String, dmp.getLabel()));
fieldInfoList.add(new FieldInfo("{id}", DataType.String, dmp.getId().toString()));
data.setFields(fieldInfoList);
event.setData(jsonHandlingService.toJsonSafe(data));
eventHandler.handle(event);
}
private NotificationIntegrationEvent applyNotificationType(DmpStatus status, NotificationIntegrationEvent event) { private NotificationIntegrationEvent applyNotificationType(DmpStatus status, NotificationIntegrationEvent event) {
switch (status) { switch (status) {
case Draft: case Draft:
@ -737,6 +742,11 @@ public class DmpServiceImpl implements DmpService {
private void sendDmpInvitationExistingUser(UUID userId, DmpEntity dmp, DmpUserRole role) throws InvalidApplicationException { private void sendDmpInvitationExistingUser(UUID userId, DmpEntity dmp, DmpUserRole role) throws InvalidApplicationException {
UserEntity recipient = this.queryFactory.query(UserQuery.class).ids(userId).isActive(IsActive.Active).first(); UserEntity recipient = this.queryFactory.query(UserQuery.class).ids(userId).isActive(IsActive.Active).first();
String email = this.queryFactory.query(UserContactInfoQuery.class).userIds(recipient.getId()).first().getValue(); String email = this.queryFactory.query(UserContactInfoQuery.class).userIds(recipient.getId()).first().getValue();
this.createDmpInvitationExistingUserEvent(recipient, dmp, role, email, NotificationContactType.EMAIL);
this.createDmpInvitationExistingUserEvent(recipient, dmp, role, email, NotificationContactType.IN_APP);
}
private void createDmpInvitationExistingUserEvent(UserEntity recipient, DmpEntity dmp, DmpUserRole role, String email, NotificationContactType type) throws InvalidApplicationException {
NotificationIntegrationEvent event = new NotificationIntegrationEvent(); NotificationIntegrationEvent event = new NotificationIntegrationEvent();
event.setUserId(this.userScope.getUserIdSafe()); event.setUserId(this.userScope.getUserIdSafe());
@ -745,7 +755,7 @@ public class DmpServiceImpl implements DmpService {
contactPairs.add(new ContactPair(ContactInfoType.Email, email)); contactPairs.add(new ContactPair(ContactInfoType.Email, email));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null); NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData)); event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(NotificationContactType.EMAIL); event.setContactTypeHint(type);
event.setNotificationType(notificationProperties.getDmpInvitationExistingUserType()); event.setNotificationType(notificationProperties.getDmpInvitationExistingUserType());
NotificationFieldData data = new NotificationFieldData(); NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>(); List<FieldInfo> fieldInfoList = new ArrayList<>();

View File

@ -2,6 +2,7 @@ package eu.eudat.service.user;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.model.User; import eu.eudat.model.User;
import eu.eudat.model.persist.UserRequestPersist;
import eu.eudat.model.persist.UserPersist; import eu.eudat.model.persist.UserPersist;
import eu.eudat.model.persist.UserRolePatchPersist; import eu.eudat.model.persist.UserRolePatchPersist;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -31,9 +32,9 @@ public interface UserService {
User patchRoles(UserRolePatchPersist model, FieldSet fields) throws InvalidApplicationException; User patchRoles(UserRolePatchPersist model, FieldSet fields) throws InvalidApplicationException;
void sendMergeAccountConfirmation(String email) throws InvalidApplicationException, JAXBException; void sendMergeAccountConfirmation(UserRequestPersist model) throws InvalidApplicationException, JAXBException;
void sendRemoveCredentialConfirmation(String email) throws InvalidApplicationException, JAXBException; void sendRemoveCredentialConfirmation(UserRequestPersist model) throws InvalidApplicationException, JAXBException;
void confirmMergeAccount(String token) throws InvalidApplicationException; void confirmMergeAccount(String token) throws InvalidApplicationException;

View File

@ -343,20 +343,28 @@ public class UserServiceImpl implements UserService {
//endregion //endregion
//notifications //notifications
public void sendMergeAccountConfirmation(String email) throws InvalidApplicationException, JAXBException { public void sendMergeAccountConfirmation(UserRequestPersist model) throws InvalidApplicationException, JAXBException {
String token = this.createActionConfirmation(email, ActionConfirmationType.MergeAccount); UserEntity user = this.queryFactory.query(UserQuery.class).ids(model.getUserId()).isActive(IsActive.Active).first();
if (user == null){
throw new MyApplicationException("User don't exist");
}
String token = this.createActionConfirmation(model.getEmail(), ActionConfirmationType.MergeAccount);
createMergeNotificationEvent(token, user, model.getEmail(), NotificationContactType.EMAIL);
createMergeNotificationEvent(token, user, model.getEmail(), NotificationContactType.IN_APP);
}
private void createMergeNotificationEvent(String token, UserEntity user, String email, NotificationContactType type) throws InvalidApplicationException {
NotificationIntegrationEvent event = new NotificationIntegrationEvent(); NotificationIntegrationEvent event = new NotificationIntegrationEvent();
event.setUserId(this.userScope.getUserIdSafe()); event.setUserId(user.getId());
List<ContactPair> contactPairs = new ArrayList<>(); List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, email)); contactPairs.add(new ContactPair(ContactInfoType.Email, email));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null); NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData)); event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(NotificationContactType.EMAIL); event.setContactTypeHint(type);
event.setNotificationType(notificationProperties.getMergeAccountConfirmationType()); event.setNotificationType(notificationProperties.getMergeAccountConfirmationType());
NotificationFieldData data = new NotificationFieldData(); NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>(); List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{userName}", DataType.String, this.queryFactory.query(UserQuery.class).ids(this.userScope.getUserIdSafe()).first().getName())); fieldInfoList.add(new FieldInfo("{userName}", DataType.String, user.getName()));
fieldInfoList.add(new FieldInfo("{confirmationToken}", DataType.String, token)); fieldInfoList.add(new FieldInfo("{confirmationToken}", DataType.String, token));
fieldInfoList.add(new FieldInfo("{expiration_time}", DataType.String, this.secondsToTime(this.notificationProperties.getEmailExpirationTimeSeconds()))); fieldInfoList.add(new FieldInfo("{expiration_time}", DataType.String, this.secondsToTime(this.notificationProperties.getEmailExpirationTimeSeconds())));
data.setFields(fieldInfoList); data.setFields(fieldInfoList);
@ -364,26 +372,34 @@ public class UserServiceImpl implements UserService {
eventHandler.handle(event); eventHandler.handle(event);
} }
public void sendRemoveCredentialConfirmation(String email) throws InvalidApplicationException, JAXBException { public void sendRemoveCredentialConfirmation(UserRequestPersist model) throws InvalidApplicationException, JAXBException {
UserContactInfoEntity userContactInfo = this.queryFactory.query(UserContactInfoQuery.class).types(ContactInfoType.Email).userIds(this.userScope.getUserIdSafe()).values(email).first(); UserQuery userQuery = this.queryFactory.query(UserQuery.class).ids(model.getUserId()).isActive(IsActive.Active);
if (userQuery == null || userQuery.count() == 0){
throw new MyApplicationException("User don't exist");
}
UserContactInfoEntity userContactInfo = this.queryFactory.query(UserContactInfoQuery.class).types(ContactInfoType.Email).userIds(model.getUserId()).values(model.getEmail()).first();
if(userContactInfo == null){ if(userContactInfo == null){
throw new MyApplicationException("Email does not exist in this user!"); throw new MyApplicationException("Email does not exist in this user!");
} }
UserCredentialQuery query = this.queryFactory.query(UserCredentialQuery.class).userIds(this.userScope.getUserIdSafe()); UserCredentialQuery query = this.queryFactory.query(UserCredentialQuery.class).userIds(model.getUserId());
if (query == null || query.count() == 0){ if (query == null || query.count() == 0){
throw new MyApplicationException("This user don't have credential!"); throw new MyApplicationException("This user don't have credential!");
} }
String token = this.createActionConfirmation(email, ActionConfirmationType.RemoveCredential); String token = this.createActionConfirmation(model.getEmail(), ActionConfirmationType.RemoveCredential);
this.createRemoveCredentialNotificationEvent(token, model.getEmail(), model.getUserId(), NotificationContactType.EMAIL);
this.createRemoveCredentialNotificationEvent(token, model.getEmail(), model.getUserId(), NotificationContactType.IN_APP);
}
private void createRemoveCredentialNotificationEvent(String token, String email, UUID userId, NotificationContactType type) throws InvalidApplicationException {
NotificationIntegrationEvent event = new NotificationIntegrationEvent(); NotificationIntegrationEvent event = new NotificationIntegrationEvent();
event.setUserId(this.userScope.getUserIdSafe()); event.setUserId(userId);
List<ContactPair> contactPairs = new ArrayList<>(); List<ContactPair> contactPairs = new ArrayList<>();
contactPairs.add(new ContactPair(ContactInfoType.Email, email)); contactPairs.add(new ContactPair(ContactInfoType.Email, email));
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null); NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
event.setContactHint(jsonHandlingService.toJsonSafe(contactData)); event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(NotificationContactType.EMAIL); event.setContactTypeHint(type);
event.setNotificationType(notificationProperties.getRemoveCredentialConfirmationType()); event.setNotificationType(notificationProperties.getRemoveCredentialConfirmationType());
NotificationFieldData data = new NotificationFieldData(); NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>(); List<FieldInfo> fieldInfoList = new ArrayList<>();

View File

@ -14,6 +14,7 @@ import eu.eudat.model.builder.DmpAssociatedUserBuilder;
import eu.eudat.model.builder.UserBuilder; import eu.eudat.model.builder.UserBuilder;
import eu.eudat.model.censorship.DmpAssociatedUserCensor; import eu.eudat.model.censorship.DmpAssociatedUserCensor;
import eu.eudat.model.censorship.UserCensor; import eu.eudat.model.censorship.UserCensor;
import eu.eudat.model.persist.UserRequestPersist;
import eu.eudat.model.persist.UserPersist; import eu.eudat.model.persist.UserPersist;
import eu.eudat.model.persist.UserRolePatchPersist; import eu.eudat.model.persist.UserRolePatchPersist;
import eu.eudat.model.result.QueryResult; import eu.eudat.model.result.QueryResult;
@ -270,23 +271,24 @@ public class UserController {
this.auditService.track(AuditableAction.User_Delete, "id", id); this.auditService.track(AuditableAction.User_Delete, "id", id);
} }
@GetMapping("mine/merge-account-request/{email}") @PostMapping("mine/merge-account-request/{email}")
@Transactional @Transactional
public ResponseEntity<ResponseItem<String>> mergeAccount(@PathVariable("email") String email) throws InvalidApplicationException, JAXBException { @ValidationFilterAnnotation(validator = UserRequestPersist.UserRequestPersistValidator.ValidatorName, argumentName = "model")
logger.debug(new MapLogEntry("merge account to user").And("email", email)); public Boolean mergeAccount(@RequestBody UserRequestPersist model) throws InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("merge account to user").And("email", model));
this.userTypeService.sendMergeAccountConfirmation(email); this.userTypeService.sendMergeAccountConfirmation(model);
this.auditService.track(AuditableAction.User_MergeRequest, Map.ofEntries( this.auditService.track(AuditableAction.User_MergeRequest, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("email", email) new AbstractMap.SimpleEntry<String, Object>("model", model)
)); ));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).payload("Merge Account Request Success")); return true;
} }
@GetMapping("mine/confirm-merge-account/token/{token}") @GetMapping("mine/confirm-merge-account/token/{token}")
@Transactional @Transactional
public ResponseEntity<ResponseItem<String>> confirmMergeAccount(@PathVariable("token") String token) throws InvalidApplicationException, JAXBException { public Boolean confirmMergeAccount(@PathVariable("token") String token) throws InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("confirm merge account to user").And("token", token)); logger.debug(new MapLogEntry("confirm merge account to user").And("token", token));
this.userTypeService.confirmMergeAccount(token); this.userTypeService.confirmMergeAccount(token);
@ -295,26 +297,27 @@ public class UserController {
new AbstractMap.SimpleEntry<String, Object>("token", token) new AbstractMap.SimpleEntry<String, Object>("token", token)
)); ));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).payload("Merge Account Confirm Success")); return true;
} }
@GetMapping("mine/remove-credential-request/{email}") @GetMapping("mine/remove-credential-request/{email}")
@Transactional @Transactional
public ResponseEntity<ResponseItem<String>> removeCredentialAccount(@PathVariable("email") String email) throws InvalidApplicationException, JAXBException { @ValidationFilterAnnotation(validator = UserRequestPersist.UserRequestPersistValidator.ValidatorName, argumentName = "model")
logger.debug(new MapLogEntry("remove credential request to user").And("email", email)); public Boolean removeCredentialAccount(@RequestBody UserRequestPersist model) throws InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("remove credential request to user").And("model", model));
this.userTypeService.sendRemoveCredentialConfirmation(email); this.userTypeService.sendRemoveCredentialConfirmation(model);
this.auditService.track(AuditableAction.User_RemoveCredentialRequest, Map.ofEntries( this.auditService.track(AuditableAction.User_RemoveCredentialRequest, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("email", email) new AbstractMap.SimpleEntry<String, Object>("email", model)
)); ));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).payload("Remove Credential Request Success")); return true;
} }
@GetMapping("mine/confirm-remove-credential/token/{token}") @GetMapping("mine/confirm-remove-credential/token/{token}")
@Transactional @Transactional
public ResponseEntity<ResponseItem<String>> confirmRemoveCredentialAccount(@PathVariable("token") String token) throws InvalidApplicationException, JAXBException { public Boolean confirmRemoveCredentialAccount(@PathVariable("token") String token) throws InvalidApplicationException, JAXBException {
logger.debug(new MapLogEntry("confirm remove credential to user").And("token", token)); logger.debug(new MapLogEntry("confirm remove credential to user").And("token", token));
this.userTypeService.confirmRemoveCredential(token); this.userTypeService.confirmRemoveCredential(token);
@ -323,6 +326,6 @@ public class UserController {
new AbstractMap.SimpleEntry<String, Object>("model", token) new AbstractMap.SimpleEntry<String, Object>("model", token)
)); ));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).payload("Remove Credential Account Success")); return true;
} }
} }