class IdmNotificationAttachmentController extends AbstractReadWriteDtoController<IdmNotificationAttachmentDto, IdmNotificationAttachmentFilter> {

	@RequestMapping(value = "/{backendId}/download", method = RequestMethod.GET)
	@ResponseBody
	@PreAuthorize("hasAuthority('" + NotificationGroupPermission.NOTIFICATION_READ + "')")
	@ApiOperation(
			value = "Download notification attachment", 
			nickname = "downloadNotificationAttachment",
			tags = { IdmNotificationAttachmentController.TAG },
			notes = "Returns input stream to notification attachment.",
			authorizations = {
					@Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { 
							@AuthorizationScope(scope = NotificationGroupPermission.NOTIFICATION_READ, description = "") }),
					@Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { 
							@AuthorizationScope(scope = NotificationGroupPermission.NOTIFICATION_READ, description = "") })
					})
	public ResponseEntity<InputStreamResource> download(
			@ApiParam(value = "Notification attachment uuid identifier.", required = true)
			@PathVariable String backendId) {
		IdmNotificationAttachmentDto dto = getDto(backendId);
		if (dto == null) {
			throw new EntityNotFoundException(getService().getEntityClass(), backendId);
		}
		//
		UUID attachmentId = dto.getAttachment();
		IdmAttachmentDto attachment = attachmentManager.get(attachmentId);
		if (attachment == null) {
			throw new EntityNotFoundException(attachmentManager.getEntityClass(), attachmentId);
		}
		//
		InputStream is = attachmentManager.getAttachmentData(attachment.getId());
		//
		try {
			BodyBuilder response = ResponseEntity
					.ok()
					.contentLength(is.available())
					.header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s\"", attachment.getName()));
			// append media type, if it's filled
			String mimetype = attachment.getMimetype();
			if (StringUtils.isNotBlank(mimetype)) {
				response = response.contentType(MediaType.valueOf(attachment.getMimetype()));
			}
			//
			return response.body(new InputStreamResource(is));
		} catch (IOException e) {
			throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
		}
	}

	@Autowired public  IdmNotificationAttachmentController(IdmNotificationAttachmentService service);

}