Search in sources :

Example 1 with HelpdeskBean

use of it.cnr.si.cool.jconon.model.HelpdeskBean in project cool-jconon by consiglionazionaledellericerche.

the class HelpDeskServiceTest method testPost.

@Test
@Disabled
public void testPost() throws IOException, InvocationTargetException, IllegalAccessException {
    MultipartFile allegato = new MockMultipartFile(NAME_ATTACHMENTS, NAME_ATTACHMENTS, MimeTypes.PDF.mimetype(), IOUtils.toByteArray(getClass().getResourceAsStream("/" + NAME_ATTACHMENTS)));
    HelpdeskBean hdBean = new HelpdeskBean();
    hdBean.setIp(SOURCE_IP);
    BeanUtils.populate(hdBean, postMap);
    helpdeskService.post(hdBean, allegato, cmisUser);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) HelpdeskBean(it.cnr.si.cool.jconon.model.HelpdeskBean) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with HelpdeskBean

use of it.cnr.si.cool.jconon.model.HelpdeskBean in project cool-jconon by consiglionazionaledellericerche.

the class HelpDeskServiceTest method testPostReopen.

@Test
@Disabled
public void testPostReopen() throws IOException, InvocationTargetException, IllegalAccessException {
    HelpdeskBean hdBean = new HelpdeskBean();
    hdBean.setIp(SOURCE_IP);
    Map parameterMapReopen = new HashMap();
    parameterMapReopen.put("id", ID);
    parameterMapReopen.put("azione", AZIONE);
    parameterMapReopen.put("message", MESSAGE_REOPEN);
    BeanUtils.populate(hdBean, parameterMapReopen);
    helpdeskService.sendReopenMessage(hdBean, cmisUser);
}
Also used : HelpdeskBean(it.cnr.si.cool.jconon.model.HelpdeskBean) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with HelpdeskBean

use of it.cnr.si.cool.jconon.model.HelpdeskBean in project cool-jconon by consiglionazionaledellericerche.

the class Helpdesk method send.

@POST
@Path("/send")
public Response send(@Context HttpServletRequest req) {
    MultipartHttpServletRequest mRequest = resolver.resolveMultipart(req);
    ResponseBuilder builder = null;
    HelpdeskBean hdBean = new HelpdeskBean();
    hdBean.setIp(req.getRemoteAddr());
    try {
        final Map<String, String[]> parameterMap = mRequest.getParameterMap();
        blockXSS(parameterMap.values().stream().map(strings -> Arrays.asList(strings)).flatMap(List::stream).collect(Collectors.toList()));
        BeanUtils.populate(hdBean, parameterMap);
        String idSegnalazione;
        if (mRequest.getParameter("id") != null && mRequest.getParameter("azione") != null) {
            helpdeskService.sendReopenMessage(hdBean, cmisService.getCMISUserFromSession(req));
        } else {
            helpdeskService.post(hdBean, mRequest.getFileMap().get("allegato"), cmisService.getCMISUserFromSession(req));
        }
        builder = Response.ok();
    } catch (ClientMessageException e) {
        builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Collections.singletonMap("message", e.getMessage()));
    } catch (IllegalAccessException | InvocationTargetException | IOException | MailException | CmisObjectNotFoundException exception) {
        LOGGER.error("helpdesk send error", exception);
        builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(exception.getMessage());
    }
    return builder.build();
}
Also used : CMISService(it.cnr.cool.cmis.service.CMISService) java.util(java.util) BeanUtils(org.apache.commons.beanutils.BeanUtils) LoggerFactory(org.slf4j.LoggerFactory) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Autowired(org.springframework.beans.factory.annotation.Autowired) CommonsMultipartResolver(org.springframework.web.multipart.commons.CommonsMultipartResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) SecurityRest(it.cnr.cool.rest.SecurityRest) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) IOException(java.io.IOException) StringUtil(it.cnr.cool.util.StringUtil) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) HelpdeskService(it.cnr.si.cool.jconon.service.helpdesk.HelpdeskService) SecurityChecked(it.cnr.cool.security.SecurityChecked) Pattern(java.util.regex.Pattern) MailException(org.springframework.mail.MailException) HelpdeskBean(it.cnr.si.cool.jconon.model.HelpdeskBean) HelpdeskBean(it.cnr.si.cool.jconon.model.HelpdeskBean) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ClientMessageException(it.cnr.cool.web.scripts.exception.ClientMessageException) MailException(org.springframework.mail.MailException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Example 4 with HelpdeskBean

use of it.cnr.si.cool.jconon.model.HelpdeskBean in project cool-jconon by consiglionazionaledellericerche.

the class HelpdeskService method sendMessage.

protected void sendMessage(HelpdeskBean hdBean, MultipartFile allegato, CMISUser user) throws MailException, IOException {
    StringBuilder subject = new StringBuilder();
    subject.append(hdBean.getCall() + " - " + hdBean.getSubject());
    // aggiunge il footer al messaggio
    StringBuilder testo = new StringBuilder();
    testo.append(hdBean.getMessage());
    testo.append("\n\n");
    testo.append("Utente: ");
    testo.append(hdBean.getFirstName());
    testo.append(" ");
    testo.append(hdBean.getLastName());
    if (Optional.ofNullable(hdBean.getMatricola()).isPresent()) {
        testo.append("  Matricola: ");
        testo.append(hdBean.getMatricola());
    }
    testo.append("  Email: ");
    testo.append(hdBean.getEmail());
    if (Optional.ofNullable(hdBean.getPhoneNumber()).isPresent()) {
        testo.append("  Tel: ");
        testo.append(hdBean.getPhoneNumber());
    }
    testo.append("  Data: ");
    DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy (HH:mm:ss)");
    testo.append(formatter.format(Calendar.getInstance().getTime()));
    testo.append("  IP: ");
    testo.append(hdBean.getIp());
    ExternalProblem externalProblem = new ExternalProblem();
    externalProblem.setFirstName(hdBean.getFirstName());
    externalProblem.setFamilyName(hdBean.getLastName());
    externalProblem.setEmail(hdBean.getEmail());
    externalProblem.setConfirmRequested(Optional.ofNullable(user).filter(cmisUser -> cmisUser.isGuest()).map(s -> "y").orElse("n"));
    externalProblem.setTitolo(subject.toString());
    externalProblem.setDescrizione(testo.toString());
    externalProblem.setStato(State.APERTA);
    externalProblem.setCategoria(Integer.valueOf(hdBean.getCategory()));
    final Optional<Long> idSegnalazione = oilService.map(oil -> oil.newProblem(externalProblem));
    if (allegato != null && !allegato.isEmpty() && idSegnalazione.isPresent()) {
        FormData formData = new FormData(allegato.getContentType(), allegato.getOriginalFilename(), allegato.getBytes());
        oilService.ifPresent(oil -> oil.addAttachments(idSegnalazione.get(), formData));
    }
}
Also used : CMISService(it.cnr.cool.cmis.service.CMISService) User(it.cnr.ict.domain.User) LoggerFactory(org.slf4j.LoggerFactory) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) OilService(it.cnr.ict.service.OilService) Value(org.springframework.beans.factory.annotation.Value) JSONObject(org.json.JSONObject) Calendar(java.util.Calendar) Service(org.springframework.stereotype.Service) State(it.cnr.ict.domain.State) UrlBuilder(org.apache.chemistry.opencmis.commons.impl.UrlBuilder) DateFormat(java.text.DateFormat) FeignException(feign.FeignException) CmisBindingsHelper(org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) Logger(org.slf4j.Logger) IOException(java.io.IOException) StringUtil(it.cnr.cool.util.StringUtil) CMISUser(it.cnr.cool.security.service.impl.alfresco.CMISUser) HttpStatus(org.springframework.http.HttpStatus) Category(it.cnr.ict.domain.Category) HelpDeskNotConfiguredException(it.cnr.si.cool.jconon.exception.HelpDeskNotConfiguredException) FormData(feign.form.FormData) MultipartFile(org.springframework.web.multipart.MultipartFile) Optional(java.util.Optional) ExternalProblem(it.cnr.ict.domain.ExternalProblem) MailException(org.springframework.mail.MailException) UserService(it.cnr.cool.security.service.UserService) Collections(java.util.Collections) HelpdeskBean(it.cnr.si.cool.jconon.model.HelpdeskBean) I18nService(it.cnr.cool.service.I18nService) FormData(feign.form.FormData) ExternalProblem(it.cnr.ict.domain.ExternalProblem) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

HelpdeskBean (it.cnr.si.cool.jconon.model.HelpdeskBean)4 CMISService (it.cnr.cool.cmis.service.CMISService)2 StringUtil (it.cnr.cool.util.StringUtil)2 IOException (java.io.IOException)2 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)2 Disabled (org.junit.jupiter.api.Disabled)2 Test (org.junit.jupiter.api.Test)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MailException (org.springframework.mail.MailException)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 FeignException (feign.FeignException)1 FormData (feign.form.FormData)1 SecurityRest (it.cnr.cool.rest.SecurityRest)1 SecurityChecked (it.cnr.cool.security.SecurityChecked)1 UserService (it.cnr.cool.security.service.UserService)1 CMISUser (it.cnr.cool.security.service.impl.alfresco.CMISUser)1 I18nService (it.cnr.cool.service.I18nService)1