use of de.metas.ui.web.window.model.DocumentCollection.DocumentPrint in project metasfresh-webui-api by metasfresh.
the class MailRestController method createNewEmail.
@PostMapping()
@ApiOperation("Creates a new email")
public JSONEmail createNewEmail(@RequestBody final JSONEmailRequest request) {
userSession.assertLoggedIn();
final int adUserId = userSession.getAD_User_ID();
Services.get(IUserBL.class).assertCanSendEMail(adUserId);
final IntegerLookupValue from = IntegerLookupValue.of(adUserId, userSession.getUserFullname() + " <" + userSession.getUserEmail() + "> ");
final DocumentPath contextDocumentPath = JSONDocumentPath.toDocumentPathOrNull(request.getDocumentPath());
final BoilerPlateContext attributes = documentCollection.createBoilerPlateContext(contextDocumentPath);
final Integer toUserId = attributes.getAD_User_ID();
final LookupValue to = mailRepo.getToByUserId(toUserId);
final String emailId = mailRepo.createNewEmail(adUserId, from, to, contextDocumentPath).getEmailId();
if (contextDocumentPath != null) {
try {
final DocumentPrint contextDocumentPrint = documentCollection.createDocumentPrint(contextDocumentPath);
attachFile(emailId, () -> mailAttachmentsRepo.createAttachment(emailId, contextDocumentPrint.getFilename(), contextDocumentPrint.getReportData()));
} catch (final Exception ex) {
logger.debug("Failed creating attachment from document print of {}", contextDocumentPath, ex);
}
}
return JSONEmail.of(mailRepo.getEmail(emailId));
}
use of de.metas.ui.web.window.model.DocumentCollection.DocumentPrint in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getDocumentPrint.
@GetMapping("/{windowId}/{documentId}/print/{filename:.*}")
public ResponseEntity<byte[]> getDocumentPrint(//
@PathVariable("windowId") final String windowIdStr, //
@PathVariable("documentId") final String documentIdStr, @PathVariable("filename") final String filename) {
userSession.assertLoggedIn();
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, documentIdStr);
final DocumentPrint documentPrint = documentCollection.createDocumentPrint(documentPath);
final byte[] reportData = documentPrint.getReportData();
final String reportContentType = documentPrint.getReportContentType();
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType(reportContentType));
headers.set(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + filename + "\"");
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
final ResponseEntity<byte[]> response = new ResponseEntity<>(reportData, headers, HttpStatus.OK);
return response;
}
Aggregations