Design for generating/filling a document based on a template-file, while considering permissions from a database?
You have the backend for a web application. I'd like to keep this is as disconnected from specific programming lanuages as possible, but if necessary, assume we're talking about PHP. You need to write code that generates or fills documents with data from a database, so that these documents can be stored as files. These documents are required from a third party and their structure is predetermined by that party; your job is to eventually fill prepared data-fields with your data. You initially have these empty documents at your disposal, which can be used as templates. If more specific info is necessary, I am talking about xlsx-files. The problem is that it is rather difficult to write generic code that can handle filling all required documents with your data, as their structure and the data they expect do not seem to follow any strict pattern or norm, which requires you to write new code for every single new document that you need to support. It can also be expected that over time more documents will be required, so you have to add support for them as well. In addition, information in a database dictates which of the users who request these documents have access to them. Problems that need to be solved: Where do you find the 'source of truth' for which documents the application supports? Should you persist it to the database, should you base it on the list of template-files that the application can find or should you hard-code it? How do you associate code that generates/fills a specific document with the document itself (that would be stuff like its name or file-properties of the provided template-file) How do you associate the database-data regarding access-permissions to the document with the document itself? These problems are largely about combining the truths of which documents/templates are known to exist with what the application knows to do with them by being able to reliably identify them. I'd like to hear what you think could be a solution for this.
You have the backend for a web application. I'd like to keep this is as disconnected from specific programming lanuages as possible, but if necessary, assume we're talking about PHP.
You need to write code that generates or fills documents with data from a database, so that these documents can be stored as files. These documents are required from a third party and their structure is predetermined by that party; your job is to eventually fill prepared data-fields with your data. You initially have these empty documents at your disposal, which can be used as templates. If more specific info is necessary, I am talking about xlsx-files.
The problem is that it is rather difficult to write generic code that can handle filling all required documents with your data, as their structure and the data they expect do not seem to follow any strict pattern or norm, which requires you to write new code for every single new document that you need to support. It can also be expected that over time more documents will be required, so you have to add support for them as well.
In addition, information in a database dictates which of the users who request these documents have access to them.
Problems that need to be solved:
- Where do you find the 'source of truth' for which documents the application supports? Should you persist it to the database, should you base it on the list of template-files that the application can find or should you hard-code it?
- How do you associate code that generates/fills a specific document with the document itself (that would be stuff like its name or file-properties of the provided template-file)
- How do you associate the database-data regarding access-permissions to the document with the document itself?
These problems are largely about combining the truths of which documents/templates are known to exist with what the application knows to do with them by being able to reliably identify them.
I'd like to hear what you think could be a solution for this.