-
Notifications
You must be signed in to change notification settings - Fork 0
3.1.2 SUBMOD.001.002 : Upload AML File
- Changelog
- 1. Scope
- 2. Definitions
- 3. Module Requirements
- 4. Analysis
- 5. Design
- 6. Implementation
- 7. Module Test
- 8. Summary
- 9. Appendix
Version | Date | Author | Comment |
---|---|---|---|
0.1 | 17.01.2021 | Namid Marxen und Nils-Christopher Wiesenauer | created |
1.0 | 14.05.2021 | Namid Marxen und Nils-Christopher Wiesenauer | finished |
The Module Documentations (MODs) describes the architecture, the interfaces and the main features of the module. It also describes the module/component test including the results. It can also serve as a programming or integration manual for the module. If there are some risks related to the module itself, they shall be noted and commented within this document.
AML: Automation Markup Language
CRUD: Create Read Update Delete
GUI: Graphical User Interface
JSend: A specification that lays down some rules for how JSON responses from web servers should be formatted
SAS: System Architecture Specification
SRS: System Requirements Specification
This submodule contains the endpoint for uploading an AML file to the database.
This REST API is the most important module because it contains the logic for converting the AML file to JSON. It also includes the authorization to the database. When a file is uploaded to the server it is converted from an AML format to a JSON format so that it can be saved in the MongoDB database. The content of the files are saved as a string and then converted into one JSON object, so that each file has their own database entry, with the Base64 encoded text as the content.
The submodule describes that the user has the ability to upload files from his computer to the database. He does this by uploading the file in a dialog in the GUI and the GUI sends a POST request to the REST API.
This submodule contains the requirement LF20
which specifies that the user can upload files to the database. The REST API processes the uploaded data and sends a request to the database to upload the file.
The submodule to upload AML files that are sent from the GUI provides the functionality to upload files to the database. The user send a file with the GUI and sends a POST request. When the file is converted, the file is uploaded to the database.
This submodule provides the user with the ability to upload files via the GUI. The uploaded file is sent to the REST API with a POST request and the API sends a create request to the database. This function is important, because it provides the application with data and without it, the user would not have the ability to upload files.
We included all /file
routes into our server.js
where the FILE
schema is imported to have every endpoint together and clear.
When the function to upload is not available the user can not upload files from his computer anymore. When a file needs to be shared, this would not be possible anymore.
Link to sourcecode: server.js
The needed /file POST endpoint is defined below. Here we are using the created FILE model to store file documents from MongoDB by using ´FILE.addFile()´. The file must be sent in the request body. (body: { file: ... }
).
const FILE = require('./models/file');
...
app.post('/file', (req, res) => {
const file = req.body.file;
>> 6.2 Validation check
});
...
In this codeblock we are checking the posted request body. The file in our req.body needs to have base64, name and the size. After this check, we are checking the file typ, if its allowed. process.env.ALLOWED_FILES
gives us all allowed file types. If the provided data is not allowed to be saved, we are sending a JSend with status 'error' and a message back. In the last step we are calculation our file size by using Buffer.
...
if (file && file.base64 && file.name && file.size) {
const availableFileTypes = process.env.ALLOWED_FILES.split(',');
if(!file.type) {
file.type = 'application/xml';
}
if (availableFileTypes.includes(`.${file.name.split('.').pop().toLowerCase()}`)) {
file.size = Buffer.from(file.base64.split(',')[1], 'base64').length;
file.base64 = file.base64.split(',')[1];
FILE.addFile(file, (err, savedFile) => {
if (!err && savedFile) {
savedFile.base64 = null;
res.status(200).send({ status: 'success', data: savedFile });
} else {
console.log(err.message)
res.status(200).send({ status: 'error', message: 'Unable to add file' });
}
});
} else {
res.status(200).send({ status: 'error', message: 'File type is not allowed' });
}
} else if (file && file.content && file.name) {
file.base64 = new Buffer(file.content).toString('base64');
delete file.content;
file.date = new Date();
file.size = Buffer.from(file.base64, 'base64').length;
file.type = 'application/xml';
file.name += '.aml';
FILE.addFile(
file,
(err, file) => {
if (!err && file) {
res.status(200).send({ status: 'success', data: file });
} else {
res.status(200).send({ status: 'error', message: 'Unable to save new file' });
}
}
);
} else {
res.status(200).send({ status: 'error', message: 'No file was uploaded. Please try again' });
}
...
After validation and modifying we are able to store the file in our database.
FILE.addFile(file, (err, savedFile) => {
if (!err && savedFile) {
savedFile.base64 = null;
res.status(200).send({ status: 'success', data: savedFile });
} else {
console.log(err.message)
res.status(200).send({ status: 'error', message: 'Unable to add file' });
}
});
The endpoint/submodule to upload an AML file is neccessary to provide the user with the ability to upload AML files. It is triggered by a request from the GUI when the user wants to upload a local AML file from his computer. The request is processed by the REST API and another request is sent to the database.
The implementation of the module is descriped with SwaggerUI.
The source code of this module can be found here: aml-database-management-api/server.js
Testcase ID: | TC.REST.002.F |
---|---|
Testcase Name: | POST call |
Requirement ID(s): |
LF110 , LF100 , LF30
|
Description: | The test case verifies that the REST API POST call works as documented in the SRS |
Test Steps:
Step | Action | Expected Result |
---|---|---|
1 | Open Postman and send the following POST request: localhost:3000/file and use the Testdata below as body | Verify that you receive a JSON response containing "status": "success", as well as the just object that hast just been added |
2 | Send the following GET request: localhost:3000/file | Verify that the file is now present in the database |
Testdata:
{
"file": {
"base64": "data:application/xml;base64,ZnVlciBiYWxsdWY=",
"name": "test-file.xml",
"size": 560,
"type": "text/xml"
}
}
© LMF.software - Jonas Bihr, Namid Marxen, Johannes Emanuel Timter & Nils-Christopher Wiesenauer
For any question regarding our software contact us on here on GitHub.
- Home
- 1. SRS (System Requirements Specification)
- 2. SAS (System Architecuture Specification)
- 3. MODs (Modul Documentations)
- 4. MM (Meeting Minutes)
- 5. User Manual
- 6. Systemtestplan
- 7. Systemtestreport