Search in sources :

Example 1 with AttachmentEntryType

use of de.metas.attachments.AttachmentEntryType in project metasfresh-webui-api by metasfresh.

the class DocumentAttachmentsRestController method getAttachmentById.

@GetMapping("/{id}")
public ResponseEntity<byte[]> getAttachmentById(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentId, @PathVariable("id") final String entryIdStr) {
    userSession.assertLoggedIn();
    final DocumentId entryId = DocumentId.of(entryIdStr);
    final IDocumentAttachmentEntry entry = getDocumentAttachments(windowIdStr, documentId).getEntry(entryId);
    final AttachmentEntryType type = entry.getType();
    if (type == AttachmentEntryType.Data) {
        return extractResponseEntryFromData(entry);
    } else if (type == AttachmentEntryType.URL) {
        return extractResponseEntryFromURL(entry);
    } else {
        throw new AdempiereException("Invalid attachment entry").setParameter("reason", "invalid type").setParameter("type", type).setParameter("entry", entry);
    }
}
Also used : AttachmentEntryType(de.metas.attachments.AttachmentEntryType) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

AttachmentEntryType (de.metas.attachments.AttachmentEntryType)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1