2024-01-04 15:25:07 +01:00
|
|
|
package eu.eudat.service.contactsupport;
|
|
|
|
|
|
|
|
import eu.eudat.authorization.Permission;
|
|
|
|
import eu.eudat.commons.JsonHandlingService;
|
|
|
|
import eu.eudat.commons.enums.ContactInfoType;
|
|
|
|
import eu.eudat.commons.enums.notification.NotificationContactType;
|
|
|
|
import eu.eudat.commons.scope.user.UserScope;
|
|
|
|
import eu.eudat.commons.types.notification.*;
|
|
|
|
import eu.eudat.configurations.notification.NotificationProperties;
|
|
|
|
import eu.eudat.data.UserContactInfoEntity;
|
2024-01-19 14:12:33 +01:00
|
|
|
import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent;
|
|
|
|
import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler;
|
2024-01-04 15:25:07 +01:00
|
|
|
import eu.eudat.model.UserContactInfo;
|
|
|
|
import eu.eudat.model.persist.ContactSupportPersist;
|
|
|
|
import eu.eudat.model.persist.PublicContactSupportPersist;
|
|
|
|
import eu.eudat.query.UserContactInfoQuery;
|
|
|
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
|
|
|
import gr.cite.tools.data.query.Ordering;
|
|
|
|
import gr.cite.tools.data.query.QueryFactory;
|
|
|
|
import gr.cite.tools.logging.LoggerService;
|
|
|
|
import gr.cite.tools.logging.MapLogEntry;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.management.InvalidApplicationException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class ContactSupportServiceImpl implements ContactSupportService {
|
|
|
|
|
|
|
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ContactSupportServiceImpl.class));
|
|
|
|
|
|
|
|
|
|
|
|
private final AuthorizationService authorizationService;
|
|
|
|
|
|
|
|
private final QueryFactory queryFactory;
|
|
|
|
|
|
|
|
private final JsonHandlingService jsonHandlingService;
|
|
|
|
|
|
|
|
private final UserScope userScope;
|
|
|
|
|
2024-01-19 14:12:33 +01:00
|
|
|
private final NotifyIntegrationEventHandler notifyIntegrationEventHandler;
|
2024-01-04 15:25:07 +01:00
|
|
|
|
|
|
|
private final NotificationProperties notificationProperties;
|
|
|
|
@Autowired
|
|
|
|
public ContactSupportServiceImpl(
|
|
|
|
AuthorizationService authorizationService,
|
|
|
|
QueryFactory queryFactory,
|
|
|
|
JsonHandlingService jsonHandlingService,
|
|
|
|
UserScope userScope,
|
2024-01-19 14:12:33 +01:00
|
|
|
NotifyIntegrationEventHandler notifyIntegrationEventHandler,
|
2024-01-04 15:25:07 +01:00
|
|
|
NotificationProperties notificationProperties) {
|
|
|
|
this.authorizationService = authorizationService;
|
|
|
|
this.queryFactory = queryFactory;
|
|
|
|
this.jsonHandlingService = jsonHandlingService;
|
|
|
|
this.userScope = userScope;
|
2024-01-19 14:12:33 +01:00
|
|
|
this.notifyIntegrationEventHandler = notifyIntegrationEventHandler;
|
2024-01-04 15:25:07 +01:00
|
|
|
this.notificationProperties = notificationProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendContactEmail(ContactSupportPersist model) throws InvalidApplicationException {
|
|
|
|
logger.debug(new MapLogEntry("send contact email").And("model", model));
|
|
|
|
this.authorizationService.authorizeForce(Permission.SendContactSupport);
|
|
|
|
|
2024-01-19 14:12:33 +01:00
|
|
|
NotifyIntegrationEvent event = new NotifyIntegrationEvent();
|
2024-01-04 15:25:07 +01:00
|
|
|
|
2024-01-23 10:53:49 +01:00
|
|
|
event.setUserId(this.userScope.getUserId());
|
|
|
|
|
2024-01-04 15:25:07 +01:00
|
|
|
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(this.userScope.getUserId());
|
|
|
|
query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal));
|
|
|
|
UserContactInfoEntity contactInfo = query.first();
|
|
|
|
|
|
|
|
List<ContactPair> contactPairs = new ArrayList<>();
|
|
|
|
contactPairs.add(new ContactPair(ContactInfoType.Email, notificationProperties.getContactSupportEmail()));
|
|
|
|
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
|
|
|
|
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
|
|
|
|
event.setContactTypeHint(NotificationContactType.EMAIL);
|
|
|
|
|
|
|
|
event.setNotificationType(notificationProperties.getContactSupportType());
|
|
|
|
NotificationFieldData data = new NotificationFieldData();
|
|
|
|
List<FieldInfo> fieldInfoList = new ArrayList<>();
|
|
|
|
fieldInfoList.add(new FieldInfo("{subject}", DataType.String, model.getSubject()));
|
|
|
|
fieldInfoList.add(new FieldInfo("{description}", DataType.String, model.getDescription()));
|
|
|
|
fieldInfoList.add(new FieldInfo("{email}", DataType.String, contactInfo.getValue()));
|
|
|
|
data.setFields(fieldInfoList);
|
|
|
|
event.setData(jsonHandlingService.toJsonSafe(data));
|
|
|
|
|
2024-01-19 14:12:33 +01:00
|
|
|
notifyIntegrationEventHandler.handle(event);
|
2024-01-04 15:25:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendPublicContactEmail(PublicContactSupportPersist model) throws InvalidApplicationException {
|
|
|
|
logger.debug(new MapLogEntry("public send contact email").And("model", model));
|
2024-01-11 17:23:21 +01:00
|
|
|
this.authorizationService.authorizeForce(Permission.PublicSendContactSupport);
|
2024-01-04 15:25:07 +01:00
|
|
|
|
2024-01-19 14:12:33 +01:00
|
|
|
NotifyIntegrationEvent event = new NotifyIntegrationEvent();
|
2024-01-04 15:25:07 +01:00
|
|
|
|
|
|
|
List<ContactPair> contactPairs = new ArrayList<>();
|
|
|
|
contactPairs.add(new ContactPair(ContactInfoType.Email, notificationProperties.getContactSupportEmail()));
|
|
|
|
NotificationContactData contactData = new NotificationContactData(contactPairs, null, null);
|
|
|
|
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
|
|
|
|
event.setContactTypeHint(NotificationContactType.EMAIL);
|
|
|
|
|
|
|
|
event.setNotificationType(notificationProperties.getPublicContactSupportType());
|
|
|
|
NotificationFieldData data = new NotificationFieldData();
|
|
|
|
List<FieldInfo> fieldInfoList = new ArrayList<>();
|
|
|
|
fieldInfoList.add(new FieldInfo("{subject}", DataType.String, model.getAffiliation()));
|
|
|
|
fieldInfoList.add(new FieldInfo("{description}", DataType.String, model.getMessage()));
|
|
|
|
fieldInfoList.add(new FieldInfo("{email}", DataType.String, model.getEmail()));
|
|
|
|
fieldInfoList.add(new FieldInfo("{name}", DataType.String, model.getFullName()));
|
|
|
|
data.setFields(fieldInfoList);
|
|
|
|
event.setData(jsonHandlingService.toJsonSafe(data));
|
|
|
|
|
2024-01-19 14:12:33 +01:00
|
|
|
notifyIntegrationEventHandler.handle(event);
|
2024-01-04 15:25:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|