Search in sources :

Example 1 with DocumentPrint

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));
}
Also used : IUserBL(org.adempiere.user.api.IUserBL) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) IOException(java.io.IOException) AdempiereException(org.adempiere.exceptions.AdempiereException) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with DocumentPrint

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)2 DocumentPrint (de.metas.ui.web.window.model.DocumentCollection.DocumentPrint)2 BoilerPlateContext (de.metas.letters.model.MADBoilerPlate.BoilerPlateContext)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 JSONLookupValue (de.metas.ui.web.window.datatypes.json.JSONLookupValue)1 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)1 IUserBL (org.adempiere.user.api.IUserBL)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1