Creates backend Controller for Contact mail and adds it's respected configuration. (Issue #128)

This commit is contained in:
gkolokythas 2019-08-21 11:37:47 +03:00
parent 3ed25bca11
commit 99f9776e54
4 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package eu.eudat.controllers;
import eu.eudat.logic.managers.ContactEmailManager;
import eu.eudat.models.data.ContactEmail.ContactEmailModel;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.transaction.Transactional;
@RestController
@CrossOrigin
@RequestMapping(value = "api/contactEmail")
public class ContactEmail {
private ContactEmailManager contactEmailManager;
public ContactEmail(ContactEmailManager contactEmailManager) {
this.contactEmailManager = contactEmailManager;
}
@Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity sendContactEmail(@RequestBody ContactEmailModel contactEmailModel, Principal principal) {
try {
this.contactEmailManager.sendContactEmail(contactEmailModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
}
}
}

View File

@ -0,0 +1,36 @@
package eu.eudat.logic.managers;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.ContactEmail.ContactEmailModel;
import eu.eudat.models.data.mail.SimpleMail;
import eu.eudat.models.data.security.Principal;
import org.springframework.core.env.Environment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.mail.MessagingException;
@Component
public class ContactEmailManager {
private ApiContext apiContext;
private Environment environment;
@Autowired
public ContactEmailManager(ApiContext apiContext, Environment environment) {
this.apiContext = apiContext;
this.environment = environment;
}
public void sendContactEmail(ContactEmailModel contactEmailModel, Principal principal) throws MessagingException {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
SimpleMail mail = new SimpleMail();
mail.setSubject(contactEmailModel.getSubject());
mail.setTo(environment.getProperty("contact_email.mail"));
mail.setContent(contactEmailModel.getDescription());
mail.setFrom(user.getEmail());
apiContext.getUtilitiesService().getMailService().sendSimpleMail(mail);
}
}

View File

@ -0,0 +1,21 @@
package eu.eudat.models.data.ContactEmail;
public class ContactEmailModel {
private String subject;
private String description;
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -50,3 +50,6 @@ conf_email.subject=OpenDMP email confirmation
#############ZENODO CONFIGURATIONS######### #############ZENODO CONFIGURATIONS#########
zenodo.url=https://sandbox.zenodo.org/api/ zenodo.url=https://sandbox.zenodo.org/api/
zenodo.access_token= zenodo.access_token=
#############CONTACT EMAIL CONFIGURATIONS#########
contact_email.mail=