Week 8 and 9
uploads/<uploadID>/licenses
endpoint completed
(August 14th, 2022)
Working on the uploads/<uploadID>/licenses
endpoint to return the latest clearing decision for each and every filepath completed this week.
Used ItemTreeBounds
to get the latest clearing decisions. Rather than using the seperate SQL qureies and modifications in the DAO files created seperate functions so that they can be reused and the funcionality of the earlier funtctions in the DAO files remain the same.
Was able to return the latest clearing status for each upload ID and return it in the api response:
The new function created in LicenseDao.php
:
public function getLicensesAndTreeIdPerFileNameForAgentId(ItemTreeBounds $itemTreeBounds,
$selectedAgentIds=null,
$includeSubfolders=true,
$excluding='',
$ignore=false,
&$clearingDecisionsForLicList = array())
{
$uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
$statementName = __METHOD__ . '.' . $uploadTreeTableName;
$param = array();
$condition = " (ufile_mode & (1<<28)) = 0";
if ($includeSubfolders) {
$param[] = $itemTreeBounds->getLeft();
$param[] = $itemTreeBounds->getRight();
$condition .= " AND lft BETWEEN $1 AND $2";
$statementName .= ".subfolders";
} else {
$param[] = $itemTreeBounds->getItemId();
$condition .= " AND realparent = $1";
}
if ('uploadtree_a' == $uploadTreeTableName) {
$param[] = $itemTreeBounds->getUploadId();
$condition .= " AND upload_fk=$".count($param);
}
$agentSelect = "";
if ($selectedAgentIds !== null) {
$statementName .= ".".count($selectedAgentIds)."agents";
$agentSelect = "WHERE agent_fk IS NULL";
foreach ($selectedAgentIds as $selectedAgentId) {
$param[] = $selectedAgentId;
$agentSelect .= " OR agent_fk = $".count($param);
}
}
$sql = "
SELECT uploadtree_pk, ufile_name, lft, rgt, ufile_mode,
rf_shortname, agent_fk
FROM (SELECT
uploadtree_pk, ufile_name,
lft, rgt, ufile_mode, pfile_fk
FROM $uploadTreeTableName
WHERE $condition) AS subselect1
LEFT JOIN (SELECT rf_shortname,pfile_fk,agent_fk
FROM license_file, license_ref
WHERE rf_fk = rf_pk) AS subselect2
ON subselect1.pfile_fk = subselect2.pfile_fk
$agentSelect
ORDER BY lft asc
";
$this->dbManager->prepare($statementName, $sql);
$result = $this->dbManager->execute($statementName, $param);
$licensesPerFileName = array();
$row = $this->dbManager->fetchArray($result);
$pathStack = array($row['ufile_name']);
$rgtStack = array($row['rgt']);
$lastLft = $row['lft'];
$path = implode('/', $pathStack);
$uploadTreeId = $row['uploadtree_pk'];
$this->addToLicensesAndTreeIdPerFileName($licensesPerFileName, $path, $row, $ignore, $clearingDecisionsForLicList, $uploadTreeId);
while ($row = $this->dbManager->fetchArray($result)) {
if (!empty($excluding) && false!==strpos("/$row[ufile_name]/", $excluding)) {
$lastLft = $row['rgt'] + 1;
continue;
}
if ($row['lft'] < $lastLft) {
continue;
}
$this->updateStackState($pathStack, $rgtStack, $lastLft, $row);
$path = implode('/', $pathStack);
$this->addToLicensesAndTreeIdPerFileName($licensesPerFileName, $path, $row, $ignore, $clearingDecisionsForLicList, $uploadTreeId);
}
$this->dbManager->freeResult($result);
return array_reverse($licensesPerFileName);
}
PR link - feat(api): clearing status
Download file using UploadID
Developed an API endpoint to send the file as a response for the respective UploadId
. The Api sends the file with their respective mimetype and file name which can be downloaded in the frontend.
Current status of the Download API response:
PR link - feat(api): Download file using UploadID
Conclusion and Further Plans
- Implementing the Import Report functionality.
- Focussing on the Docs section and writing docs for the Final Evaluation.