# Document Management

## Basic Concept

Uploading and managing various types of business documents are crucial for conducting insurance business operations.   

Through our Document Management System (DMS) API, users can effortlessly upload and retrieve documents. Most importantly, they can associate the documents with specific business entities.

## System Design 

### Storage

Actual DMS-related businesses and documents are ultimately stored in Amazon S3 (Simple Storage Service).

- Utilize custom and business-oriented APIs.
- Document indexing information is stored in a database table, with file contents stored in S3 objects such as storage.
- Different tenants define different own S3 buckets for segregation.

### Business Data Correlation 

Each DMS document is associated with a business entity with fields **EntityType** and **DmsEntityId**. 

- **EntityType** can represent various entities such as Policy, Endorsement, Claim, Customer, and Reinsurance Policy. 

- **DmsEntityId** does not necessarily have to be the primary key of the business entity, because the primary key may not exist initially or could be non-unique (e.g., proposalNo/policyNo, fnolNo/claimNo).

### Document Properties 

| Property           | Description                                                  |
| ------------------ | ------------------------------------------------------------ |
| DmsDocId           | Unique identification of the documents in DMS after uploading. |
| EntityType         | Business entity type of the document such as Policy and Claim. See code table **DmsEntityType**. |
| DmsEntityId        | Business entity primary key of the document. |
| BusinessCategory   | Business classification of the document, e.g., ID card, driver license, policy image, invoice image. See code table **DmsBusinessCategory**. |
| OriginalFileName   | Required file extension whitelist to identify the file type and prevent malicious file upload. |
| DisplayName        | Names displayed in the UI.                                         |
| AdditionalFileMeta | Meta information attached to the document, stored as key/value JSON. |
| S3Bucket           | Bucket name for the document stored in S3, varying by tenants. |
| S3Key              | Unique key for the document stored in S3.                 |
| ThumbnailS3Bucket  | Bucket name for the thumbnail of the image, varying by tenants. |
| ThumbnailS3Key     | Unique key for the thumbnail stored in S3               |
| SubDir             | Directory of the document displayed in the UI.                  |

### Thumbnail  

- For image documents, thumbnails are generated during upload, stored in S3.
- Thumbnail download is supported.

### Custom Storge

see [Custom Storge](https://docs.insuremo.com/ics/app_framework/file_storage&hcCat=InsureMO%20Offerings&hcCard=ICS&hcTitle=File%20Storage%20and%20Default%20S3%20Bucket#for-custom)

| Property  | Descritpion                          |
| --------- | ------------------------------------ |
| CustomApp | Custom file storge callback app name |



### Safety Permissions 

-  Support ID tamper-proof function during UI API calls.  
-  Require business EntityID to be entered after signatures (DMS primary key should also have signatures).
-  Restrict certain file types (suffix the whitelist, prevent virus files). 
-  Restrict the maximum file size (max 50MB by default).  

##  System Configuration Data 

### Code Table

The platform provides basic data, and tenants can extend code tables as required.

| Field            | Code Table           | Data Table           |
| ---------------- | ------------------- | ------------------- |
| EntityType       | DmsEntityType       | DmsEntityType       |
| BusinessCategory | DmsBusinessCategory | DmsBusinessCategory |


###  Configuration Parameter (Platform Only) 

Environment parameters of the DMS configuration have been set default values.

| Key                                       | Value Example                                                | Description                     |
| ----------------------------------------- | ------------------------------------------------------------ | ------------------------------- |
| `bucket.document` (removed, not in use)      | bucket-dms-document                                          | Formerly used S3 Bucket for documents           |
| `bucket.thumb` (removed, not in use)         | bucket-dms-thumb                                             | Formerly used S3 Bucket for thumbnails |
| `file.type.whiteList`                       | .csv, .xls, .xlsx, .png, .jpg, .jpeg, .tif, .imag                   | Suffix whitelist for allowed document types  |
| `spring.servlet.multipart.max-file-size`    | 50M                                                          | Maximum file size limit for documents         |
| `spring.servlet.multipart.max-request-size` | 50M                                                          | Maximum request size limit          |

<div class="docs-note"><span class="docs-admonitions-text">note</span>

For security reasons, only files with **.txt, .zip, .jpg, .pdf, .jpeg, .heic, .png, .docx, .htm, .json, .heif, .tiff, .gif, .mp4, .mov, .mp3, .rar, .bak, .csv, .xls, .xlsx, .tif, .imag, .bmp, .xml, .doc, .html, .ppt, .pptx, .wave, .mod, .midi, .ra, .ram, .avi, .rmvb, .rm, .flv, .3gp, .7z** extensions are allowed to be uploaded. If you have additional file types to upload or parameter values to modify, please contact the platform team for further assistance and evaluation.

</div>


### Safety Permission (Mask Program)

 Fields **DmsDocId** and **DmsEntityId** are masked for security purposes.


## FAQ

### Why I get 204 for /dms/v1/downloadDocument API?

This issue typically occurs when a user has uploaded an empty file (0 bytes). During the download process, the system (DMS) returns the file's byte stream. If the source file is empty, a byte stream with a length of 0 is returned, meaning no data is transmitted, which causes the failure.

​Solution: The frontend application should be enhanced to handle this scenario. When an empty byte stream is detected, the frontend should proactively create and deliver a blank file to the user, ensuring a successful download process.

​Verification:
To confirm this is the root cause, you can test the same download request in Postman using the "Send and Download" option—this will download an empty file. Alternatively, checking the file's properties on the backend storage will show its size is 0 bytes.




