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);
}
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);
}
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();
}
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));
}
}
Aggregations